Package com.google.common.testing

Examples of com.google.common.testing.TestLogHandler


  @Override protected void setUp() throws Exception {
    test = new TearDownTestCase() {};
    test.setUp();
    messages = new ArrayList<String>();
    handler = new TestLogHandler();
    TearDownStack.logger.addHandler(handler);
    TearDownStack.logger.setUseParentHandlers(false);
  }
View Full Code Here


  private TestLogHandler handler;

  @Override protected void setUp() throws Exception {
    test = new TearDownTestCase() {};
    messages = new ArrayList<String>();
    handler = new TestLogHandler();
    TearDownStack.logger.addHandler(handler);
    TearDownStack.logger.setUseParentHandlers(false);
  }
View Full Code Here

  TestLogHandler logHandler;

  @Override
  public void setUp() throws Exception {
    super.setUp();
    logHandler = new TestLogHandler();
    LocalCache.logger.addHandler(logHandler);
  }
View Full Code Here

   * 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()) {
      assertFalse(logFormatter.format(record).contains("NoOpService"));
    }
  }
View Full Code Here

   * 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());
  }
View Full Code Here

  public void testCopyExceptions() {
    if (!Closer.SuppressingSuppressor.isAvailable()) {
      // test that exceptions are logged

      TestLogHandler logHandler = new TestLogHandler();
      Closeables.logger.addHandler(logHandler);
      try {
        for (CharSource in : BROKEN_SOURCES) {
          runFailureTest(in, newNormalCharSink());
          assertTrue(logHandler.getStoredLogRecords().isEmpty());

          runFailureTest(in, BROKEN_CLOSE_SINK);
          assertEquals((in == BROKEN_OPEN_SOURCE) ? 0 : 1, getAndResetRecords(logHandler));
        }

        for (CharSink out : BROKEN_SINKS) {
          runFailureTest(newNormalCharSource(), out);
          assertTrue(logHandler.getStoredLogRecords().isEmpty());

          runFailureTest(BROKEN_CLOSE_SOURCE, out);
          assertEquals(1, getAndResetRecords(logHandler));
        }
View Full Code Here

        new Suppression(c2, c3Exception, c2Exception),
        new Suppression(c1, c3Exception, c1Exception));
  }

  public static void testLoggingSuppressor() throws IOException {
    TestLogHandler logHandler = new TestLogHandler();

    Closeables.logger.addHandler(logHandler);
    try {
      Closer closer = new Closer(new Closer.LoggingSuppressor());

      TestCloseable c1 = closer.register(TestCloseable.throwsOnClose(new IOException()));
      TestCloseable c2 = closer.register(TestCloseable.throwsOnClose(new RuntimeException()));
      try {
        throw closer.rethrow(new IOException("thrown"), IOException.class);
      } catch (IOException expected) {}

      assertTrue(logHandler.getStoredLogRecords().isEmpty());

      closer.close();

      assertEquals(2, logHandler.getStoredLogRecords().size());

      LogRecord record = logHandler.getStoredLogRecords().get(0);
      assertEquals("Suppressing exception thrown when closing " + c2, record.getMessage());

      record = logHandler.getStoredLogRecords().get(1);
      assertEquals("Suppressing exception thrown when closing " + c1, record.getMessage());
    } finally {
      Closeables.logger.removeHandler(logHandler);
    }
  }
View Full Code Here

  TestLogHandler logHandler;

  @Override
  public void setUp() throws Exception {
    super.setUp();
    logHandler = new TestLogHandler();
    LocalCache.logger.addHandler(logHandler);
  }
View Full Code Here

  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));
        }
View Full Code Here

  TestLogHandler logHandler;

  @Override
  public void setUp() throws Exception {
    super.setUp();
    logHandler = new TestLogHandler();
    LocalCache.logger.addHandler(logHandler);
  }
View Full Code Here

TOP

Related Classes of com.google.common.testing.TestLogHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.