Skip to content

Commit 8ed8df9

Browse files
committed
Replace
>> assertThat(testAppender.getMessagesAtLevel().stream().anyMatch($COND)).isTrue()" with >> assertThat(testAppender.getMessagesAtLevel()).contains("$MSG") This provides way more explanatory error message: >> expected to contain: projects/my-project >> but was : [projects/test-project] instead of >> "expected to be true"
1 parent 59b8522 commit 8ed8df9

File tree

3 files changed

+33
-90
lines changed

3 files changed

+33
-90
lines changed

lib/src/test/java/com/google/cloud/datalineage/producerclient/StandardApiEnablementCacheLoggingTest.java

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,9 @@ public void tearDown() {
7373
@Test
7474
public void testCacheInitializationLogging() {
7575
// Verify that cache initialization is logged
76-
boolean found =
77-
testAppender.getMessagesAtLevel(Level.DEBUG).stream()
78-
.anyMatch(
79-
log ->
80-
log.contains("Initializing StandardApiEnablementCache with cache size: 100")
81-
&& log.contains("default disabled duration: PT5M"));
82-
assertThat(found).isTrue();
76+
assertThat(testAppender.getMessagesAtLevel(Level.DEBUG)).contains(
77+
"Initializing StandardApiEnablementCache with cache size: 100, "
78+
+ "default disabled duration: PT5M");
8379
}
8480

8581
@Test
@@ -92,14 +88,9 @@ public void testMarkServiceAsDisabledLogging() {
9288
cache.markServiceAsDisabled(projectName, duration);
9389

9490
// Verify that marking service as disabled is logged
95-
boolean found =
96-
testAppender.getMessagesAtLevel(Level.WARN).stream()
97-
.anyMatch(
98-
log ->
99-
log.contains(
100-
"Marking service as disabled for project 'test-project'"
101-
+ " for duration: PT10M"));
102-
assertThat(found).isTrue();
91+
assertThat(testAppender.getMessagesAtLevel(Level.WARN)).contains(
92+
"Marking service as disabled for project 'test-project'"
93+
+ " for duration: PT10M");
10394
}
10495

10596
@Test
@@ -111,11 +102,8 @@ public void testIsServiceMarkedAsDisabledLogging_NotFound() {
111102
boolean result = cache.isServiceMarkedAsDisabled(projectName);
112103

113104
assertThat(result).isFalse();
114-
boolean found =
115-
testAppender.getMessagesAtLevel(Level.DEBUG).stream()
116-
.anyMatch(
117-
log -> log.contains("No cache entry found for project: non-existent-project"));
118-
assertThat(found).isTrue();
105+
assertThat(testAppender.getMessagesAtLevel(Level.DEBUG)).contains(
106+
"No cache entry found for project: non-existent-project");
119107
}
120108

121109
@Test
@@ -155,10 +143,7 @@ public void testIsServiceMarkedAsDisabledLogging_Expired() {
155143
boolean result = cache.isServiceMarkedAsDisabled("test-project");
156144

157145
assertThat(result).isFalse();
158-
boolean found =
159-
testAppender.getMessagesAtLevel(Level.DEBUG).stream()
160-
.anyMatch(
161-
log -> log.contains("Service disability has expired for project: test-project"));
162-
assertThat(found).isTrue();
146+
assertThat(testAppender.getMessagesAtLevel(Level.DEBUG)).contains(
147+
"Service disability has expired for project: test-project");
163148
}
164149
}

lib/src/test/java/com/google/cloud/datalineage/producerclient/helpers/GrpcHelperLoggingTest.java

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,8 @@ public void testGetReason_ValidErrorInfo_LogsSuccess() {
9090
assertThat(reason).isEqualTo("API_DISABLED");
9191

9292
// Verify debug logging
93-
boolean found =
94-
testAppender.getMessagesAtLevel(Level.DEBUG).stream()
95-
.anyMatch(
96-
log -> log.contains("Successfully extracted reason from ErrorInfo: API_DISABLED"));
97-
assertThat(found).isTrue();
93+
assertThat(testAppender.getMessagesAtLevel(Level.DEBUG)).contains(
94+
"Successfully extracted reason from ErrorInfo: API_DISABLED");
9895
}
9996

10097
@Test
@@ -124,11 +121,8 @@ public void testGetReason_InvalidProtocolBuffer_LogsError() {
124121
assertThat(thrown.getMessage()).contains("Invalid protocol buffer message");
125122

126123
// Verify error logging
127-
boolean found =
128-
testAppender.getMessagesAtLevel(Level.ERROR).stream()
129-
.anyMatch(
130-
log -> log.contains("Invalid protocol buffer message while extracting ErrorInfo"));
131-
assertThat(found).isTrue();
124+
assertThat(testAppender.getMessagesAtLevel(Level.ERROR)).contains(
125+
"Invalid protocol buffer message while extracting ErrorInfo");
132126
}
133127

134128
@Test
@@ -151,14 +145,9 @@ public void testGetReason_NoErrorInfo_LogsWarning() {
151145
assertThat(thrown.getMessage()).contains("Message does not contain ErrorInfo");
152146

153147
// Verify warning logging
154-
boolean found =
155-
testAppender.getMessagesAtLevel(Level.WARN).stream()
156-
.anyMatch(
157-
log ->
158-
log.contains(
159-
"Message does not contain ErrorInfo for exception:"
160-
+ " FAILED_PRECONDITION: API is disabled"));
161-
assertThat(found).isTrue();
148+
assertThat(testAppender.getMessagesAtLevel(Level.WARN)).contains(
149+
"Message does not contain ErrorInfo for exception:"
150+
+ " FAILED_PRECONDITION: API is disabled");
162151
}
163152

164153
@Test

lib/src/test/java/com/google/cloud/datalineage/producerclient/v1/AsyncLineageProducerClientLoggingTest.java

Lines changed: 16 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,8 @@ public void testDeleteLineageEventLogging() {
8383
// Expected to fail in test environment, we're just testing logging
8484
}
8585
// Verify the debug log was created
86-
boolean found =
87-
testAppender.getMessagesAtLevel(Level.DEBUG).stream()
88-
.anyMatch(
89-
log ->
90-
log.contains(
91-
"Deleting lineage event: projects/test-project/locations/us-central1/processes/test-process/runs/test-run/lineageEvents/test-event"));
92-
assertThat(found).isTrue();
86+
assertThat(testAppender.getMessagesAtLevel(Level.DEBUG)).contains(
87+
"Deleting lineage event: projects/test-project/locations/us-central1/processes/test-process/runs/test-run/lineageEvents/test-event");
9388
}
9489

9590
@Test
@@ -105,13 +100,8 @@ public void testGetLineageEventLogging() {
105100
// Expected to fail in test environment, we're just testing logging
106101
}
107102
// Verify the debug log was created
108-
boolean found =
109-
testAppender.getMessagesAtLevel(Level.DEBUG).stream()
110-
.anyMatch(
111-
log ->
112-
log.contains(
113-
"Getting lineage event: projects/test-project/locations/us-central1/processes/test-process/runs/test-run/lineageEvents/test-event"));
114-
assertThat(found).isTrue();
103+
assertThat(testAppender.getMessagesAtLevel(Level.DEBUG)).contains(
104+
"Getting lineage event: projects/test-project/locations/us-central1/processes/test-process/runs/test-run/lineageEvents/test-event");
115105
}
116106

117107
@Test
@@ -126,10 +116,8 @@ public void testProcessOpenLineageRunEventLogging() {
126116
// Expected to fail in test environment, we're just testing logging
127117
}
128118
// Verify the debug log was created
129-
boolean found =
130-
testAppender.getMessagesAtLevel(Level.DEBUG).stream()
131-
.anyMatch(log -> log.contains("Processing OpenLineage run event:"));
132-
assertThat(found).isTrue();
119+
assertThat(testAppender.getMessagesAtLevel(Level.DEBUG)).contains(
120+
"Processing OpenLineage run event: ");
133121
}
134122

135123
@Test
@@ -144,14 +132,9 @@ public void testListProcessesBasicLogging() {
144132
// Expected to fail in test environment, we're just testing logging
145133
}
146134
// Verify the debug log was created
147-
boolean found =
148-
testAppender.getMessagesAtLevel(Level.DEBUG).stream()
149-
.anyMatch(
150-
log ->
151-
log.contains(
152-
"Listing processes for parent: "
153-
+ "projects/test-project/locations/us-central1"));
154-
assertThat(found).isTrue();
135+
assertThat(testAppender.getMessagesAtLevel(Level.DEBUG)).contains(
136+
"Listing processes for parent: "
137+
+ "projects/test-project/locations/us-central1");
155138
}
156139

157140
@Test
@@ -168,25 +151,17 @@ public void testListProcessesWithParametersLogging() {
168151
// Expected to fail in test environment, we're just testing logging
169152
}
170153
// Verify the debug log includes parent (parameters are not logged individually)
171-
boolean found =
172-
testAppender.getMessagesAtLevel(Level.DEBUG).stream()
173-
.anyMatch(
174-
log ->
175-
log.contains(
176-
"Listing processes for parent: "
177-
+ "projects/test-project/locations/us-central1"));
178-
assertThat(found).isTrue();
154+
assertThat(testAppender.getMessagesAtLevel(Level.DEBUG)).contains(
155+
"Listing processes for parent: projects/test-project/locations/us-central1");
179156
}
180157

181158
@Test
182159
public void testDefaultGracefulShutdownLogging() throws Exception {
183160
// Test graceful shutdown logging
184161
client.close();
185162
// Verify shutdown logging
186-
boolean found =
187-
testAppender.getMessagesAtLevel(Level.DEBUG).stream()
188-
.anyMatch(log -> log.contains("Starting graceful shutdown with duration: PT30S"));
189-
assertThat(found).isTrue();
163+
assertThat(testAppender.getMessagesAtLevel(Level.DEBUG)).contains(
164+
"Starting graceful shutdown with duration: PT30S");
190165
}
191166

192167
@Test
@@ -239,15 +214,9 @@ public void testShutdownTimeoutLogging() throws Exception {
239214
}
240215

241216
// Verify timeout warning was logged
242-
boolean found =
243-
testAppender.getMessagesAtLevel(Level.WARN).stream()
244-
.anyMatch(
245-
log ->
246-
log.contains(
247-
"AsyncLineageProducerClient did not terminate within the"
248-
+ " graceful shutdown duration"));
249-
assertThat(found).isTrue();
250-
217+
assertThat(testAppender.getMessagesAtLevel(Level.WARN)).contains(
218+
"AsyncLineageProducerClient did not terminate within the"
219+
+ " graceful shutdown duration");
251220
shortTimeoutClient.shutdownNow();
252221
}
253222
}

0 commit comments

Comments
 (0)