use of com.google.common.testing.TestLogHandler in project guava by google.
the class CacheLoadingTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
logHandler = new TestLogHandler();
LocalCache.logger.addHandler(logHandler);
}
use of com.google.common.testing.TestLogHandler in project guava by google.
the class LocalCacheTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
logHandler = new TestLogHandler();
LocalCache.logger.addHandler(logHandler);
}
use of com.google.common.testing.TestLogHandler in project guava by google.
the class ByteSourceTest method testCopyExceptions.
public void testCopyExceptions() {
if (!Closer.SuppressingSuppressor.isAvailable()) {
// test that exceptions are logged
TestLogHandler logHandler = new TestLogHandler();
Closeables.logger.addHandler(logHandler);
try {
for (ByteSource in : BROKEN_SOURCES) {
runFailureTest(in, newNormalByteSink());
assertTrue(logHandler.getStoredLogRecords().isEmpty());
runFailureTest(in, BROKEN_CLOSE_SINK);
assertEquals((in == BROKEN_OPEN_SOURCE) ? 0 : 1, getAndResetRecords(logHandler));
}
for (ByteSink out : BROKEN_SINKS) {
runFailureTest(newNormalByteSource(), out);
assertTrue(logHandler.getStoredLogRecords().isEmpty());
runFailureTest(BROKEN_CLOSE_SOURCE, out);
assertEquals(1, getAndResetRecords(logHandler));
}
for (ByteSource in : BROKEN_SOURCES) {
for (ByteSink out : BROKEN_SINKS) {
runFailureTest(in, out);
assertTrue(getAndResetRecords(logHandler) <= 1);
}
}
} finally {
Closeables.logger.removeHandler(logHandler);
}
} else {
for (ByteSource in : BROKEN_SOURCES) {
int suppressed = runSuppressionFailureTest(in, newNormalByteSink());
assertEquals(0, suppressed);
suppressed = runSuppressionFailureTest(in, BROKEN_CLOSE_SINK);
assertEquals((in == BROKEN_OPEN_SOURCE) ? 0 : 1, suppressed);
}
for (ByteSink out : BROKEN_SINKS) {
int suppressed = runSuppressionFailureTest(newNormalByteSource(), out);
assertEquals(0, suppressed);
suppressed = runSuppressionFailureTest(BROKEN_CLOSE_SOURCE, out);
assertEquals(1, suppressed);
}
for (ByteSource in : BROKEN_SOURCES) {
for (ByteSink out : BROKEN_SINKS) {
int suppressed = runSuppressionFailureTest(in, out);
assertTrue(suppressed <= 1);
}
}
}
}
use of com.google.common.testing.TestLogHandler in project guava by google.
the class ServiceManagerTest method testPartiallyConstructedManager.
/**
* Catches a bug where when constructing a service manager failed, later interactions with the
* service could cause IllegalStateExceptions inside the partially constructed ServiceManager.
* This ISE wouldn't actually bubble up but would get logged by ExecutionQueue. This obfuscated
* the original error (which was not constructing ServiceManager correctly).
*/
public void testPartiallyConstructedManager() {
Logger logger = Logger.getLogger("global");
logger.setLevel(Level.FINEST);
TestLogHandler logHandler = new TestLogHandler();
logger.addHandler(logHandler);
NoOpService service = new NoOpService();
service.startAsync();
try {
new ServiceManager(Arrays.asList(service));
fail();
} catch (IllegalArgumentException expected) {
}
service.stopAsync();
// Nothing was logged!
assertEquals(0, logHandler.getStoredLogRecords().size());
}
use of com.google.common.testing.TestLogHandler in project guava by google.
the class ServiceManagerTest method testEmptyServiceManager.
/**
* This is for covering a case where the ServiceManager would behave strangely if constructed
* with no service under management. Listeners would never fire because the ServiceManager was
* healthy and stopped at the same time. This test ensures that listeners fire and isHealthy
* makes sense.
*/
public void testEmptyServiceManager() {
Logger logger = Logger.getLogger(ServiceManager.class.getName());
logger.setLevel(Level.FINEST);
TestLogHandler logHandler = new TestLogHandler();
logger.addHandler(logHandler);
ServiceManager manager = new ServiceManager(Arrays.<Service>asList());
RecordingListener listener = new RecordingListener();
manager.addListener(listener);
manager.startAsync().awaitHealthy();
assertTrue(manager.isHealthy());
assertTrue(listener.healthyCalled);
assertFalse(listener.stoppedCalled);
assertTrue(listener.failedServices.isEmpty());
manager.stopAsync().awaitStopped();
assertFalse(manager.isHealthy());
assertTrue(listener.stoppedCalled);
assertTrue(listener.failedServices.isEmpty());
// check that our NoOpService is not directly observable via any of the inspection methods or
// via logging.
assertEquals("ServiceManager{services=[]}", manager.toString());
assertTrue(manager.servicesByState().isEmpty());
assertTrue(manager.startupTimes().isEmpty());
Formatter logFormatter = new Formatter() {
@Override
public String format(LogRecord record) {
return formatMessage(record);
}
};
for (LogRecord record : logHandler.getStoredLogRecords()) {
assertThat(logFormatter.format(record)).doesNotContain("NoOpService");
}
}
Aggregations