Skip to content

Commit eea4eb0

Browse files
test: reduce test noise (#2257)
* test: reduce noise by properly closing stubs Change-Id: I50f954be0d6a0c5b4db6377e3403c81f3b14a167 * test: fix some of the noise during builds and test runs - make sure to close stubs to avoid grpc warnings - add missing plugin versions - fix deprecated syntax in pom.xml - filter out useless "Connecting to the Bigtable emulator..." log lines - configure logs to be on a single line Change-Id: Iacbd41c953ef0f3f726ef041dde0093d8bc2c6e6 * cleanup Change-Id: I6cbd1c5d194112c7587f58337d7a810f81375ba7
1 parent e62c969 commit eea4eb0

File tree

5 files changed

+111
-99
lines changed

5 files changed

+111
-99
lines changed

google-cloud-bigtable/pom.xml

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,6 @@
121121
<groupId>com.google.guava</groupId>
122122
<artifactId>guava</artifactId>
123123
</dependency>
124-
<dependency>
125-
<groupId>com.google.http-client</groupId>
126-
<artifactId>google-http-client</artifactId>
127-
<scope>runtime</scope>
128-
</dependency>
129-
<dependency>
130-
<groupId>com.google.http-client</groupId>
131-
<artifactId>google-http-client-gson</artifactId>
132-
<scope>runtime</scope>
133-
</dependency>
134124
<dependency>
135125
<groupId>com.google.protobuf</groupId>
136126
<artifactId>protobuf-java</artifactId>
@@ -151,7 +141,8 @@
151141
<dependency>
152142
<groupId>org.checkerframework</groupId>
153143
<artifactId>checker-qual</artifactId>
154-
</dependency><!-- Runtime dependencies for credentials -->
144+
</dependency>
145+
<!-- Runtime dependencies for credentials -->
155146
<dependency>
156147
<groupId>com.google.http-client</groupId>
157148
<artifactId>google-http-client</artifactId>
@@ -749,6 +740,10 @@
749740
<threadCount>10</threadCount>
750741

751742
<trimStackTrace>false</trimStackTrace>
743+
744+
<systemPropertyVariables>
745+
<java.util.logging.config.file>src/test/resources/logging.properties</java.util.logging.config.file>
746+
</systemPropertyVariables>
752747
</configuration>
753748
</plugin>
754749

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubTest.java

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.google.api.gax.grpc.GrpcTransportChannel;
3434
import com.google.api.gax.rpc.FixedTransportChannelProvider;
3535
import com.google.api.gax.rpc.InstantiatingWatchdogProvider;
36+
import com.google.api.gax.rpc.ServerStream;
3637
import com.google.api.gax.rpc.ServerStreamingCallable;
3738
import com.google.api.gax.rpc.WatchdogTimeoutException;
3839
import com.google.auth.oauth2.ServiceAccountJwtAccessCredentials;
@@ -86,13 +87,11 @@
8687
import java.security.NoSuchAlgorithmException;
8788
import java.util.Base64;
8889
import java.util.Collection;
89-
import java.util.Iterator;
9090
import java.util.concurrent.ArrayBlockingQueue;
9191
import java.util.concurrent.BlockingQueue;
9292
import java.util.concurrent.ExecutionException;
9393
import java.util.concurrent.TimeUnit;
9494
import org.junit.After;
95-
import org.junit.Assert;
9695
import org.junit.Before;
9796
import org.junit.Test;
9897
import org.junit.runner.RunWith;
@@ -523,8 +522,9 @@ public void testBulkMutationFlowControlFeatureFlagIsSet() throws Exception {
523522
// Test the header is set when the feature is enabled
524523
EnhancedBigtableStubSettings.Builder settings = defaultSettings.toBuilder();
525524
settings.bulkMutateRowsSettings().setServerInitiatedFlowControl(true);
526-
EnhancedBigtableStub stub = EnhancedBigtableStub.create(settings.build());
527-
stub.bulkMutateRowsCallable().call(bulkMutation);
525+
try (EnhancedBigtableStub stub = EnhancedBigtableStub.create(settings.build())) {
526+
stub.bulkMutateRowsCallable().call(bulkMutation);
527+
}
528528
assertThat(metadataInterceptor.headers).hasSize(1);
529529
Metadata metadata = metadataInterceptor.headers.take();
530530
String encodedFlags =
@@ -543,8 +543,9 @@ public void testBulkMutationFlowControlFeatureFlagIsNotSet() throws Exception {
543543

544544
EnhancedBigtableStubSettings.Builder settings = defaultSettings.toBuilder();
545545
settings.bulkMutateRowsSettings().setServerInitiatedFlowControl(false);
546-
EnhancedBigtableStub stub = EnhancedBigtableStub.create(settings.build());
547-
stub.bulkMutateRowsCallable().call(bulkMutation);
546+
try (EnhancedBigtableStub stub = EnhancedBigtableStub.create(settings.build())) {
547+
stub.bulkMutateRowsCallable().call(bulkMutation);
548+
}
548549
assertThat(metadataInterceptor.headers).hasSize(1);
549550
Metadata metadata = metadataInterceptor.headers.take();
550551
String encodedFlags =
@@ -553,7 +554,6 @@ public void testBulkMutationFlowControlFeatureFlagIsNotSet() throws Exception {
553554
FeatureFlags featureFlags = FeatureFlags.parseFrom(decodedFlags);
554555
assertThat(featureFlags.getMutateRowsRateLimit()).isFalse();
555556
assertThat(featureFlags.getMutateRowsRateLimit2()).isFalse();
556-
stub.close();
557557
}
558558

559559
@Test
@@ -564,14 +564,12 @@ public void testWaitTimeoutIsSet() throws Exception {
564564
settings.setStreamWatchdogProvider(
565565
InstantiatingWatchdogProvider.create().withCheckInterval(WATCHDOG_CHECK_DURATION));
566566

567-
EnhancedBigtableStub stub = EnhancedBigtableStub.create(settings.build());
568-
Iterator<Row> iterator =
569-
stub.readRowsCallable().call(Query.create(WAIT_TIME_TABLE_ID)).iterator();
570-
try {
571-
iterator.next();
572-
Assert.fail("Should throw watchdog timeout exception");
573-
} catch (WatchdogTimeoutException e) {
574-
assertThat(e.getMessage()).contains("Canceled due to timeout waiting for next response");
567+
try (EnhancedBigtableStub stub = EnhancedBigtableStub.create(settings.build())) {
568+
ServerStream<Row> results = stub.readRowsCallable().call(Query.create(WAIT_TIME_TABLE_ID));
569+
WatchdogTimeoutException ex =
570+
assertThrows(WatchdogTimeoutException.class, () -> results.iterator().next());
571+
572+
assertThat(ex).hasMessageThat().contains("Canceled due to timeout waiting for next response");
575573
}
576574
}
577575

@@ -583,16 +581,12 @@ public void testReadChangeStreamWaitTimeoutIsSet() throws Exception {
583581
settings.setStreamWatchdogProvider(
584582
InstantiatingWatchdogProvider.create().withCheckInterval(WATCHDOG_CHECK_DURATION));
585583

586-
EnhancedBigtableStub stub = EnhancedBigtableStub.create(settings.build());
587-
Iterator<ChangeStreamRecord> iterator =
588-
stub.readChangeStreamCallable()
589-
.call(ReadChangeStreamQuery.create(WAIT_TIME_TABLE_ID))
590-
.iterator();
591-
try {
592-
iterator.next();
593-
Assert.fail("Should throw watchdog timeout exception");
594-
} catch (WatchdogTimeoutException e) {
595-
assertThat(e.getMessage()).contains("Canceled due to timeout waiting for next response");
584+
try (EnhancedBigtableStub stub = EnhancedBigtableStub.create(settings.build())) {
585+
ServerStream<ChangeStreamRecord> results =
586+
stub.readChangeStreamCallable().call(ReadChangeStreamQuery.create(WAIT_TIME_TABLE_ID));
587+
WatchdogTimeoutException ex =
588+
assertThrows(WatchdogTimeoutException.class, () -> results.iterator().next());
589+
assertThat(ex).hasMessageThat().contains("Canceled due to timeout waiting for next response");
596590
}
597591
}
598592

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/ErrorCountPerConnectionTest.java

Lines changed: 67 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import static com.google.common.truth.Truth.assertThat;
1919
import static org.mockito.ArgumentMatchers.any;
2020
import static org.mockito.ArgumentMatchers.anyLong;
21+
import static org.mockito.Mockito.when;
2122

2223
import com.google.api.gax.core.FixedExecutorProvider;
2324
import com.google.api.gax.grpc.ChannelPoolSettings;
@@ -46,13 +47,15 @@
4647
import java.util.List;
4748
import java.util.Map;
4849
import java.util.concurrent.ScheduledExecutorService;
50+
import java.util.concurrent.ScheduledFuture;
4951
import org.junit.After;
5052
import org.junit.Before;
5153
import org.junit.Test;
5254
import org.junit.runner.RunWith;
5355
import org.junit.runners.JUnit4;
5456
import org.mockito.ArgumentCaptor;
5557
import org.mockito.Mockito;
58+
import org.mockito.stubbing.Answer;
5659

5760
@RunWith(JUnit4.class)
5861
public class ErrorCountPerConnectionTest {
@@ -103,9 +106,8 @@ public void setup() throws Exception {
103106
.setMetricsProvider(CustomOpenTelemetryMetricsProvider.create(otel));
104107

105108
runnableCaptor = ArgumentCaptor.forClass(Runnable.class);
106-
Mockito.when(
107-
executors.scheduleAtFixedRate(runnableCaptor.capture(), anyLong(), anyLong(), any()))
108-
.thenReturn(null);
109+
when(executors.scheduleAtFixedRate(runnableCaptor.capture(), anyLong(), anyLong(), any()))
110+
.then((Answer<ScheduledFuture<?>>) invocation -> Mockito.mock(ScheduledFuture.class));
109111
}
110112

111113
@After
@@ -117,21 +119,22 @@ public void tearDown() throws Exception {
117119

118120
@Test
119121
public void readWithOneChannel() throws Exception {
120-
EnhancedBigtableStub stub = EnhancedBigtableStub.create(builder.build());
121122
long errorCount = 0;
122123

123-
for (int i = 0; i < 20; i++) {
124-
Query query;
125-
if (i % 3 == 0) {
126-
query = Query.create(ERROR_TABLE_NAME);
127-
errorCount += 1;
128-
} else {
129-
query = Query.create(SUCCESS_TABLE_NAME);
130-
}
131-
try {
132-
stub.readRowsCallable().call(query).iterator().hasNext();
133-
} catch (Exception e) {
134-
// noop
124+
try (EnhancedBigtableStub stub = EnhancedBigtableStub.create(builder.build())) {
125+
for (int i = 0; i < 20; i++) {
126+
Query query;
127+
if (i % 3 == 0) {
128+
query = Query.create(ERROR_TABLE_NAME);
129+
errorCount += 1;
130+
} else {
131+
query = Query.create(SUCCESS_TABLE_NAME);
132+
}
133+
try {
134+
stub.readRowsCallable().call(query).iterator().hasNext();
135+
} catch (Exception e) {
136+
// noop
137+
}
135138
}
136139
}
137140

@@ -158,19 +161,19 @@ public void readWithTwoChannels() throws Exception {
158161
.toBuilder()
159162
.setChannelPoolSettings(ChannelPoolSettings.staticallySized(2))
160163
.build());
161-
EnhancedBigtableStub stub = EnhancedBigtableStub.create(builderWithTwoChannels.build());
162164
long totalErrorCount = 0;
163-
164-
for (int i = 0; i < 20; i++) {
165-
try {
166-
if (i < 10) {
167-
totalErrorCount += 1;
168-
stub.readRowsCallable().call(Query.create(ERROR_TABLE_NAME)).iterator().hasNext();
169-
} else {
170-
stub.readRowsCallable().call(Query.create(SUCCESS_TABLE_NAME)).iterator().hasNext();
165+
try (EnhancedBigtableStub stub = EnhancedBigtableStub.create(builderWithTwoChannels.build())) {
166+
for (int i = 0; i < 20; i++) {
167+
try {
168+
if (i < 10) {
169+
totalErrorCount += 1;
170+
stub.readRowsCallable().call(Query.create(ERROR_TABLE_NAME)).iterator().hasNext();
171+
} else {
172+
stub.readRowsCallable().call(Query.create(SUCCESS_TABLE_NAME)).iterator().hasNext();
173+
}
174+
} catch (Exception e) {
175+
// noop
171176
}
172-
} catch (Exception e) {
173-
// noop
174177
}
175178
}
176179
runInterceptorTasksAndAssertCount();
@@ -193,39 +196,40 @@ public void readWithTwoChannels() throws Exception {
193196

194197
@Test
195198
public void readOverTwoPeriods() throws Exception {
196-
EnhancedBigtableStub stub = EnhancedBigtableStub.create(builder.build());
197199
long errorCount1 = 0;
200+
long errorCount2 = 0;
201+
try (EnhancedBigtableStub stub = EnhancedBigtableStub.create(builder.build())) {
198202

199-
for (int i = 0; i < 20; i++) {
200-
Query query;
201-
if (i % 3 == 0) {
202-
query = Query.create(ERROR_TABLE_NAME);
203-
errorCount1 += 1;
204-
} else {
205-
query = Query.create(SUCCESS_TABLE_NAME);
206-
}
207-
try {
208-
stub.readRowsCallable().call(query).iterator().hasNext();
209-
} catch (Exception e) {
210-
// noop
203+
for (int i = 0; i < 20; i++) {
204+
Query query;
205+
if (i % 3 == 0) {
206+
query = Query.create(ERROR_TABLE_NAME);
207+
errorCount1 += 1;
208+
} else {
209+
query = Query.create(SUCCESS_TABLE_NAME);
210+
}
211+
try {
212+
stub.readRowsCallable().call(query).iterator().hasNext();
213+
} catch (Exception e) {
214+
// noop
215+
}
211216
}
212-
}
213217

214-
runInterceptorTasksAndAssertCount();
215-
long errorCount2 = 0;
218+
runInterceptorTasksAndAssertCount();
216219

217-
for (int i = 0; i < 20; i++) {
218-
Query query;
219-
if (i % 3 == 0) {
220-
query = Query.create(SUCCESS_TABLE_NAME);
221-
} else {
222-
query = Query.create(ERROR_TABLE_NAME);
223-
errorCount2 += 1;
224-
}
225-
try {
226-
stub.readRowsCallable().call(query).iterator().hasNext();
227-
} catch (Exception e) {
228-
// noop
220+
for (int i = 0; i < 20; i++) {
221+
Query query;
222+
if (i % 3 == 0) {
223+
query = Query.create(SUCCESS_TABLE_NAME);
224+
} else {
225+
query = Query.create(ERROR_TABLE_NAME);
226+
errorCount2 += 1;
227+
}
228+
try {
229+
stub.readRowsCallable().call(query).iterator().hasNext();
230+
} catch (Exception e) {
231+
// noop
232+
}
229233
}
230234
}
231235

@@ -247,15 +251,16 @@ public void readOverTwoPeriods() throws Exception {
247251

248252
@Test
249253
public void noFailedRequests() throws Exception {
250-
EnhancedBigtableStub stub = EnhancedBigtableStub.create(builder.build());
251-
252-
for (int i = 0; i < 20; i++) {
253-
try {
254-
stub.readRowsCallable().call(Query.create(SUCCESS_TABLE_NAME)).iterator().hasNext();
255-
} catch (Exception e) {
256-
// noop
254+
try (EnhancedBigtableStub stub = EnhancedBigtableStub.create(builder.build())) {
255+
for (int i = 0; i < 20; i++) {
256+
try {
257+
stub.readRowsCallable().call(Query.create(SUCCESS_TABLE_NAME)).iterator().hasNext();
258+
} catch (Exception e) {
259+
// noop
260+
}
257261
}
258262
}
263+
259264
runInterceptorTasksAndAssertCount();
260265
MetricData metricData =
261266
BuiltinMetricsTestUtils.getMetricData(
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
handlers= java.util.logging.ConsoleHandler
2+
.level= INFO
3+
4+
java.util.logging.ConsoleHandler.level = INFO
5+
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
6+
7+
# Example to customize the SimpleFormatter output format
8+
# to print one-line log message like this:
9+
# <level>: <log message> [<date/time>]
10+
#
11+
12+
#java.util.logging.SimpleFormatter.format=%4$s: %5$s [%1$tc]%n
13+
# time [level] loggerName: message
14+
java.util.logging.SimpleFormatter.format=%1$tT [%4$-7s] %2$s: %5$s%n
15+
16+
# hide "Connecting to the Bigtable emulator at localhost:XXXX" lines
17+
com.google.cloud.bigtable.data.v2.BigtableDataSettings.level=WARNING

pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@
226226
<plugin>
227227
<groupId>org.apache.maven.plugins</groupId>
228228
<artifactId>maven-javadoc-plugin</artifactId>
229+
<version>3.7.0</version>
229230
<executions>
230231
<execution>
231232
<id>aggregate</id>
@@ -321,7 +322,7 @@
321322
<docletPath>${docletPath}</docletPath>
322323
<additionalOptions>
323324
-outputpath ${project.build.directory}/docfx-yml
324-
-projectname ${artifactId}
325+
-projectname ${project.artifactId}
325326
<!-- List of excluded packages as regex, separated by a colon-->
326327
<!-- Exclude generating javadocs for internal implementations for admin and data, which
327328
are under internal/ and .v2.stub/, and exclude all BaseClients and BaseSettings.

0 commit comments

Comments
 (0)