public List<ILoggingEvent> assertHasEventEventually() { Asserts.succeedsEventually(new Runnable() { @Override public void run() { assertFalse(events.isEmpty()); }}); return getEvents(); }
@Test public void testTurningOffLoggingStdoutAndStderr() { RecordingSshTool.setCustomResponse(".*mycommand.*", new CustomResponse(0, "mystdout1\nmystdout2", "mystderr1\nmystderr2")); List<String> loggerNames = ImmutableList.of( SshMachineLocation.class.getName(), BrooklynLogging.SSH_IO, SshjTool.class.getName()); ch.qos.logback.classic.Level logLevel = ch.qos.logback.classic.Level.DEBUG; Predicate<ILoggingEvent> filter = Predicates.alwaysTrue(); LogWatcher watcher = new LogWatcher(loggerNames, logLevel, filter); watcher.start(); try { host.execCommands( ImmutableMap.of(SshMachineLocation.NO_STDOUT_LOGGING.getName(), true, SshMachineLocation.NO_STDERR_LOGGING.getName(), true), "mySummary", ImmutableList.of("mycommand")); assertFalse(Iterables.tryFind(watcher.getEvents(), EventPredicates.containsMessage(":stdout]")).isPresent()); assertFalse(Iterables.tryFind(watcher.getEvents(), EventPredicates.containsMessage(":stderr]")).isPresent()); } finally { watcher.close(); } } }
@Test public void testNoLogWarningsWhenRebindToMachineEntity() throws Exception { String loggerName = InternalFactory.class.getName(); ch.qos.logback.classic.Level logLevel = ch.qos.logback.classic.Level.WARN; Predicate<ILoggingEvent> filter = Predicates.alwaysTrue(); LogWatcher watcher = new LogWatcher(loggerName, logLevel, filter); watcher.start(); try { origApp.createAndManageChild(EntitySpec.create(MachineEntity.class) .configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, true)); origApp.start(ImmutableList.of(origMachine)); rebind(); List<ILoggingEvent> events = watcher.getEvents(); assertTrue(events.isEmpty(), "events="+events); } finally { watcher.close(); } } }
@Test public void testDoesNotLogPasswordsInEnvironmentVariables() { List<String> loggerNames = ImmutableList.of( SshMachineLocation.class.getName(), BrooklynLogging.SSH_IO, SshjTool.class.getName()); ch.qos.logback.classic.Level logLevel = ch.qos.logback.classic.Level.DEBUG; Predicate<ILoggingEvent> filter = Predicates.or( EventPredicates.containsMessage("DB_PASSWORD"), EventPredicates.containsMessage("mypassword")); LogWatcher watcher = new LogWatcher(loggerNames, logLevel, filter); watcher.start(); try { host.execCommands("mySummary", ImmutableList.of("true"), ImmutableMap.of("DB_PASSWORD", "mypassword")); watcher.assertHasEventEventually(); Optional<ILoggingEvent> eventWithPasswd = Iterables.tryFind(watcher.getEvents(), EventPredicates.containsMessage("mypassword")); assertFalse(eventWithPasswd.isPresent(), "event="+eventWithPasswd); } finally { watcher.close(); } }
@Test public void testExternalisedConfigValueNotLogged() throws Exception { ConfigKey<String> MY_CONFIG_KEY = ConfigKeys.newStringConfigKey("my.config.key"); String loggerName = BrooklynDslDeferredSupplier.class.getName(); ch.qos.logback.classic.Level logLevel = ch.qos.logback.classic.Level.DEBUG; Predicate<ILoggingEvent> filter = EventPredicates.containsMessage("myval"); LogWatcher watcher = new LogWatcher(loggerName, logLevel, filter); watcher.start(); try { String yaml = Joiner.on("\n").join( "services:", "- serviceType: org.apache.brooklyn.core.test.entity.TestApplication", " brooklyn.config:", " my.config.key: $brooklyn:external(\"myprovider\", \"mykey\")"); TestApplication app = (TestApplication) createAndStartApplication(yaml); waitForApplicationTasks(app); assertEquals(app.getConfig(MY_CONFIG_KEY), "myval"); List<ILoggingEvent> events = watcher.getEvents(); assertTrue(events.isEmpty(), "events="+events); } finally { watcher.close(); } }
@Test public void testStopDuringProvisionTimesOut() throws Exception { entity = app.createAndManageChild(EntitySpec.create(EmptySoftwareProcess.class) .configure(MachineLifecycleEffectorTasks.STOP_WAIT_PROVISIONING_TIMEOUT, Duration.millis(100))); executor.submit(new Runnable() { @Override public void run() { entity.start(ImmutableList.<Location>of(loc)); }}); loc.getObtainCalledLatch(0).await(); LogWatcher watcher = new LogWatcher( MachineLifecycleEffectorTasks.class.getName(), ch.qos.logback.classic.Level.WARN, EventPredicates.containsMessage("timed out after 100ms waiting for the machine to finish provisioning - machine may we left running") ); watcher.start(); try { Stopwatch stopwatch = Stopwatch.createStarted(); entity.stop(); long elapsed = stopwatch.elapsed(TimeUnit.MILLISECONDS); assertEquals(watcher.getEvents().size(), 1); assertTrue(elapsed > (100 - 10), "elapsed="+elapsed); } finally { watcher.close(); } assertEquals(loc.getCalls(), ImmutableList.of("obtain")); }
assertTrue(watcher.getEvents().isEmpty(), ignoreOption);