ImmutableList.of(LoggerFactory.getLogger(TemplateOptionsOption.class).getName()), ch.qos.logback.classic.Level.WARN, Predicates.and(containsMessage(ignoreOption), containsMessage("subnetId")));
MachineLifecycleEffectorTasks.class.getName(), ch.qos.logback.classic.Level.INFO, EventPredicates.containsMessage("for the machine to finish provisioning, before terminating it") ); watcher.start(); try {
MachineLifecycleEffectorTasks.class.getName(), ch.qos.logback.classic.Level.INFO, EventPredicates.containsMessage("for the machine to finish provisioning, before terminating it") ); watcher.start(); try {
String loggerName = EffectorUtils.class.getName(); ch.qos.logback.classic.Level logLevel = ch.qos.logback.classic.Level.DEBUG; Predicate<ILoggingEvent> filter = Predicates.and(EventPredicates.containsMessage("Error invoking myEffector"), EventPredicates.containsExceptionStackLine(ThrowingEntitlementManager.class, "isEntitled")); LogWatcher watcher = new LogWatcher(loggerName, logLevel, filter);
Predicate<ILoggingEvent> filter = Predicates.and(EventPredicates.containsMessage("Error invoking "), EventPredicates.containsExceptionStackLine(ThrowingEntitlementManager.class, "isEntitled")); LogWatcher watcher = new LogWatcher(loggerName, logLevel, filter);
@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")); }
@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 testTask() throws Exception { final TestApplication app = TestApplication.Factory.newManagedInstanceForTests(); mgmt = app.getManagementContext(); Task<String> completedTask = app.getExecutionContext().submit(Callables.returning("myval")); completedTask.get(); String loggerName = UnwantedStateLoggingMapper.class.getName(); ch.qos.logback.classic.Level logLevel = ch.qos.logback.classic.Level.WARN; Predicate<ILoggingEvent> filter = EventPredicates.containsMessage("Task object serialization is not supported or recommended"); LogWatcher watcher = new LogWatcher(loggerName, logLevel, filter); String serializedForm; watcher.start(); try { serializedForm = serializer.toString(completedTask); watcher.assertHasEvent(); } finally { watcher.close(); } assertEquals(serializedForm.trim(), "<"+BasicTask.class.getName()+">myval</"+BasicTask.class.getName()+">"); Object deserialized = serializer.fromString(serializedForm); assertEquals(deserialized, null, "serializedForm="+serializedForm+"; deserialized="+deserialized); }
@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 testLogsStdoutAndStderr() { 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("mySummary", ImmutableList.of("mycommand")); watcher.assertHasEvent(EventPredicates.containsMessage("[1.2.3.4:22:stdout] mystdout1")); watcher.assertHasEvent(EventPredicates.containsMessage("[1.2.3.4:22:stdout] mystdout2")); watcher.assertHasEvent(EventPredicates.containsMessage("[1.2.3.4:22:stderr] mystderr1")); watcher.assertHasEvent(EventPredicates.containsMessage("[1.2.3.4:22:stderr] mystderr2")); } 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(groups="Integration") public void testLogsStdoutAndStderr() { 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("mySummary", ImmutableList.of("echo mystdout1", "echo mystdout2", "echo mystderr1 1>&2", "echo mystderr2 1>&2")); watcher.assertHasEvent(EventPredicates.containsMessage(":22:stdout] mystdout1")); watcher.assertHasEvent(EventPredicates.containsMessage(":22:stdout] mystdout2")); watcher.assertHasEvent(EventPredicates.containsMessage(":22:stderr] mystderr1")); watcher.assertHasEvent(EventPredicates.containsMessage(":22:stderr] mystderr2")); } finally { watcher.close(); } }
@Test public void testLogsIfDeprecatedNameUsed() throws Exception { // FIXME Which logger? String loggerName = ConfigUtilsInternal.class.getName(); ch.qos.logback.classic.Level logLevel = ch.qos.logback.classic.Level.WARN; Predicate<ILoggingEvent> filter = EventPredicates.containsMessages( "Using deprecated config value on MyBaseEntity", "should use 'superKey1', but used 'oldSuperKey1'"); LogWatcher watcher = new LogWatcher(loggerName, logLevel, filter); watcher.start(); try { testUsingDeprecatedName(); watcher.assertHasEvent(); } finally { watcher.close(); } }
@Test public void testLogsWarningIfNonDeprecatedAndDeprecatedNamesUsed() throws Exception { String loggerName = ConfigUtilsInternal.class.getName(); ch.qos.logback.classic.Level logLevel = ch.qos.logback.classic.Level.WARN; Predicate<ILoggingEvent> filter = EventPredicates.containsMessages( "Ignoring deprecated config value(s) on MyBaseEntity", "because contains value for 'superKey1', other deprecated name(s) present were: [oldSuperKey1]"); LogWatcher watcher = new LogWatcher(loggerName, logLevel, filter); watcher.start(); try { testPrefersNonDeprecatedName(); watcher.assertHasEvent(); } finally { watcher.close(); } }
public static Predicate<ILoggingEvent> containsMessage(final String expected) { return containsMessages(expected); }
@Test public void testLogsWarningIfMultipleDeprecatedNamesUsed() throws Exception { String loggerName = ConfigUtilsInternal.class.getName(); ch.qos.logback.classic.Level logLevel = ch.qos.logback.classic.Level.WARN; Predicate<ILoggingEvent> filter = EventPredicates.containsMessages( "Using deprecated config value on MyBaseEntity", "should use 'superKey1', but used 'oldSuperKey1b' and ignored values present for other deprecated name(s) [oldSuperKey1b]"); LogWatcher watcher = new LogWatcher(loggerName, logLevel, filter); watcher.start(); try { testPrefersFirstDeprecatedNameIfMultiple(); watcher.assertHasEvent(); } finally { watcher.close(); } }