Skip to content

Commit

Permalink
test: reduce test log spam (#2794)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
olavloite authored Jan 26, 2024
1 parent 420dcf4 commit d3b0812
Show file tree
Hide file tree
Showing 11 changed files with 723 additions and 620 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,13 @@ void close(long timeout, TimeUnit unit) {
synchronized (this) {
checkClosed();
closedException = new ClosedException();
}
try {
closureFutures = new ArrayList<>();
for (DatabaseClientImpl dbClient : dbClients.values()) {
closureFutures.add(dbClient.closeAsync(closedException));
}
dbClients.clear();
}
try {
Futures.successfulAsList(closureFutures).get(timeout, unit);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
throw SpannerExceptionFactory.newSpannerException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public CommitResponse writeWithOptions(
void runMaintenanceLoop(FakeClock clock, SessionPool pool, long numCycles) {
for (int i = 0; i < numCycles; i++) {
pool.poolMaintainer.maintainPool();
clock.currentTimeMillis += pool.poolMaintainer.loopFrequency;
clock.currentTimeMillis.addAndGet(pool.poolMaintainer.loopFrequency);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
Expand Down Expand Up @@ -111,6 +113,8 @@ public static Collection<Object[]> data() {
ConcurrentHashMap.newKeySet();
private static final Set<InetSocketAddress> executeSqlLocalIps = ConcurrentHashMap.newKeySet();

private static Level originalLogLevel;

@BeforeClass
public static void startServer() throws IOException {
mockSpanner = new MockSpannerServiceImpl();
Expand Down Expand Up @@ -167,6 +171,19 @@ public static void stopServer() throws InterruptedException {
server.awaitTermination();
}

@BeforeClass
public static void disableLogging() {
Logger logger = Logger.getLogger("");
originalLogLevel = logger.getLevel();
logger.setLevel(Level.OFF);
}

@AfterClass
public static void resetLogging() {
Logger logger = Logger.getLogger("");
logger.setLevel(originalLogLevel);
}

@After
public void reset() {
mockSpanner.reset();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ public class DatabaseAdminClientTest {
private static MockOperationsServiceImpl mockOperations;
private static MockDatabaseAdminServiceImpl mockDatabaseAdmin;
private static Server server;
private static InetSocketAddress address;

private static Spanner spanner;
private static DatabaseAdminClient client;
Expand All @@ -98,7 +97,7 @@ public static void startStaticServer() throws Exception {
mockOperations = new MockOperationsServiceImpl();
mockDatabaseAdmin = new MockDatabaseAdminServiceImpl(mockOperations);
// This test uses a NettyServer to properly test network and timeout issues.
address = new InetSocketAddress("localhost", 0);
InetSocketAddress address = new InetSocketAddress("localhost", 0);
server =
NettyServerBuilder.forAddress(address)
.addService(mockOperations)
Expand Down Expand Up @@ -952,14 +951,20 @@ public void testRetriesDisabledForOperationOnAdminMethodQuotaPerMinutePerProject
Status.RESOURCE_EXHAUSTED.withDescription("foo").asRuntimeException(trailers));
mockDatabaseAdmin.clearRequests();

Spanner spannerWithoutRetries =
spanner.getOptions().toBuilder().disableAdministrativeRequestRetries().build().getService();
AdminRequestsPerMinuteExceededException exception =
assertThrows(
AdminRequestsPerMinuteExceededException.class,
() -> spannerWithoutRetries.getDatabaseAdminClient().getDatabase(INSTANCE_ID, DB_ID));
assertEquals(ErrorCode.RESOURCE_EXHAUSTED, exception.getErrorCode());
// There should be only one request on the server, as the request was not retried.
assertEquals(1, mockDatabaseAdmin.countRequestsOfType(GetDatabaseRequest.class));
try (Spanner spannerWithoutRetries =
spanner
.getOptions()
.toBuilder()
.disableAdministrativeRequestRetries()
.build()
.getService()) {
AdminRequestsPerMinuteExceededException exception =
assertThrows(
AdminRequestsPerMinuteExceededException.class,
() -> spannerWithoutRetries.getDatabaseAdminClient().getDatabase(INSTANCE_ID, DB_ID));
assertEquals(ErrorCode.RESOURCE_EXHAUSTED, exception.getErrorCode());
// There should be only one request on the server, as the request was not retried.
assertEquals(1, mockDatabaseAdmin.countRequestsOfType(GetDatabaseRequest.class));
}
}
}
Loading

0 comments on commit d3b0812

Please sign in to comment.