Skip to content

Commit d3b0812

Browse files
authored
test: reduce test log spam (#2794)
Several tests spammed the build log with various warnings and other log items that were irrelevant for the test output. This change removes as much as possible of that.
1 parent 420dcf4 commit d3b0812

11 files changed

+723
-620
lines changed

google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerImpl.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,13 @@ void close(long timeout, TimeUnit unit) {
250250
synchronized (this) {
251251
checkClosed();
252252
closedException = new ClosedException();
253+
}
254+
try {
253255
closureFutures = new ArrayList<>();
254256
for (DatabaseClientImpl dbClient : dbClients.values()) {
255257
closureFutures.add(dbClient.closeAsync(closedException));
256258
}
257259
dbClients.clear();
258-
}
259-
try {
260260
Futures.successfulAsList(closureFutures).get(timeout, unit);
261261
} catch (InterruptedException | ExecutionException | TimeoutException e) {
262262
throw SpannerExceptionFactory.newSpannerException(e);

google-cloud-spanner/src/test/java/com/google/cloud/spanner/BaseSessionPoolTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public CommitResponse writeWithOptions(
124124
void runMaintenanceLoop(FakeClock clock, SessionPool pool, long numCycles) {
125125
for (int i = 0; i < numCycles; i++) {
126126
pool.poolMaintainer.maintainPool();
127-
clock.currentTimeMillis += pool.poolMaintainer.loopFrequency;
127+
clock.currentTimeMillis.addAndGet(pool.poolMaintainer.loopFrequency);
128128
}
129129
}
130130
}

google-cloud-spanner/src/test/java/com/google/cloud/spanner/ChannelUsageTest.java

+17
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
import java.util.concurrent.ExecutionException;
5353
import java.util.concurrent.Executors;
5454
import java.util.concurrent.TimeUnit;
55+
import java.util.logging.Level;
56+
import java.util.logging.Logger;
5557
import org.junit.After;
5658
import org.junit.AfterClass;
5759
import org.junit.BeforeClass;
@@ -111,6 +113,8 @@ public static Collection<Object[]> data() {
111113
ConcurrentHashMap.newKeySet();
112114
private static final Set<InetSocketAddress> executeSqlLocalIps = ConcurrentHashMap.newKeySet();
113115

116+
private static Level originalLogLevel;
117+
114118
@BeforeClass
115119
public static void startServer() throws IOException {
116120
mockSpanner = new MockSpannerServiceImpl();
@@ -167,6 +171,19 @@ public static void stopServer() throws InterruptedException {
167171
server.awaitTermination();
168172
}
169173

174+
@BeforeClass
175+
public static void disableLogging() {
176+
Logger logger = Logger.getLogger("");
177+
originalLogLevel = logger.getLevel();
178+
logger.setLevel(Level.OFF);
179+
}
180+
181+
@AfterClass
182+
public static void resetLogging() {
183+
Logger logger = Logger.getLogger("");
184+
logger.setLevel(originalLogLevel);
185+
}
186+
170187
@After
171188
public void reset() {
172189
mockSpanner.reset();

google-cloud-spanner/src/test/java/com/google/cloud/spanner/DatabaseAdminClientTest.java

+16-11
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ public class DatabaseAdminClientTest {
8585
private static MockOperationsServiceImpl mockOperations;
8686
private static MockDatabaseAdminServiceImpl mockDatabaseAdmin;
8787
private static Server server;
88-
private static InetSocketAddress address;
8988

9089
private static Spanner spanner;
9190
private static DatabaseAdminClient client;
@@ -98,7 +97,7 @@ public static void startStaticServer() throws Exception {
9897
mockOperations = new MockOperationsServiceImpl();
9998
mockDatabaseAdmin = new MockDatabaseAdminServiceImpl(mockOperations);
10099
// This test uses a NettyServer to properly test network and timeout issues.
101-
address = new InetSocketAddress("localhost", 0);
100+
InetSocketAddress address = new InetSocketAddress("localhost", 0);
102101
server =
103102
NettyServerBuilder.forAddress(address)
104103
.addService(mockOperations)
@@ -952,14 +951,20 @@ public void testRetriesDisabledForOperationOnAdminMethodQuotaPerMinutePerProject
952951
Status.RESOURCE_EXHAUSTED.withDescription("foo").asRuntimeException(trailers));
953952
mockDatabaseAdmin.clearRequests();
954953

955-
Spanner spannerWithoutRetries =
956-
spanner.getOptions().toBuilder().disableAdministrativeRequestRetries().build().getService();
957-
AdminRequestsPerMinuteExceededException exception =
958-
assertThrows(
959-
AdminRequestsPerMinuteExceededException.class,
960-
() -> spannerWithoutRetries.getDatabaseAdminClient().getDatabase(INSTANCE_ID, DB_ID));
961-
assertEquals(ErrorCode.RESOURCE_EXHAUSTED, exception.getErrorCode());
962-
// There should be only one request on the server, as the request was not retried.
963-
assertEquals(1, mockDatabaseAdmin.countRequestsOfType(GetDatabaseRequest.class));
954+
try (Spanner spannerWithoutRetries =
955+
spanner
956+
.getOptions()
957+
.toBuilder()
958+
.disableAdministrativeRequestRetries()
959+
.build()
960+
.getService()) {
961+
AdminRequestsPerMinuteExceededException exception =
962+
assertThrows(
963+
AdminRequestsPerMinuteExceededException.class,
964+
() -> spannerWithoutRetries.getDatabaseAdminClient().getDatabase(INSTANCE_ID, DB_ID));
965+
assertEquals(ErrorCode.RESOURCE_EXHAUSTED, exception.getErrorCode());
966+
// There should be only one request on the server, as the request was not retried.
967+
assertEquals(1, mockDatabaseAdmin.countRequestsOfType(GetDatabaseRequest.class));
968+
}
964969
}
965970
}

0 commit comments

Comments
 (0)