[GitHub] brooklyn-server pull request #473: Test framework: avoid repeated stacktrace...
Github user asfgit closed the pull request at: https://github.com/apache/brooklyn-server/pull/473 --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] brooklyn-server pull request #473: Test framework: avoid repeated stacktrace...
Github user grkvlt commented on a diff in the pull request: https://github.com/apache/brooklyn-server/pull/473#discussion_r90473445 --- Diff: test-framework/src/test/java/org/apache/brooklyn/test/framework/TestSensorTest.java --- @@ -332,6 +343,56 @@ public void testFailFastIfNoSensor() throws Exception { assertStartFails(app, NullPointerException.class, Asserts.DEFAULT_LONG_TIMEOUT); } +@Test +public void testDoesNotLogStacktraceRepeatedly() throws Exception { +final long time = System.currentTimeMillis(); +final String sensorValue = String.format("%s%s%s", Identifiers.makeRandomId(8), time, Identifiers.makeRandomId(8)); + +// Test case will repeatedly fail until we have finished our logging assertions. +// Then we'll let it complete by setting the sensor. +TestSensor testCase = app.createAndManageChild(EntitySpec.create(TestSensor.class) +.configure(TestSensor.TIMEOUT, Asserts.DEFAULT_LONG_TIMEOUT) +.configure(TestSensor.TARGET_ENTITY, app) +.configure(TestSensor.SENSOR_NAME, STRING_SENSOR.getName()) +.configure(TestSensor.ASSERTIONS, newListAssertion("matches", String.format(".*%s.*", time; + +String loggerName = Repeater.class.getName(); +ch.qos.logback.classic.Level logLevel = ch.qos.logback.classic.Level.DEBUG; +Predicate repeatedFailureMsgMatcher = EventPredicates.containsMessage("repeated failure; excluding stacktrace"); +Predicate stacktraceMatcher = EventPredicates.containsExceptionStackLine(TestFrameworkAssertions.class, "checkActualAgainstAssertions"); +Predicate filter = Predicates.or(repeatedFailureMsgMatcher, stacktraceMatcher); +LogWatcher watcher = new LogWatcher(loggerName, logLevel, filter); + +Task task; --- End diff -- Why is this declared outside the `try`/`catch` block? It doesn't seem to be used anywhere else? --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] brooklyn-server pull request #473: Test framework: avoid repeated stacktrace...
Github user grkvlt commented on a diff in the pull request: https://github.com/apache/brooklyn-server/pull/473#discussion_r90475367 --- Diff: utils/common/src/main/java/org/apache/brooklyn/util/repeat/Repeater.java --- @@ -334,8 +335,14 @@ public void runRequiringTrue() { try { lastError = null; done = exitCondition.call(); +hasLoggedTransientException = false; } catch (Throwable e) { -if (log.isDebugEnabled()) log.debug(description, e); +if (hasLoggedTransientException) { +if (log.isDebugEnabled()) log.debug(description + " (repeated failure; excluding stacktrace): " + e); --- End diff -- Do not need to check `log.isDebugEnabled()` for simple logging like this --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] brooklyn-server pull request #473: Test framework: avoid repeated stacktrace...
Github user grkvlt commented on a diff in the pull request: https://github.com/apache/brooklyn-server/pull/473#discussion_r90474345 --- Diff: test-framework/src/test/java/org/apache/brooklyn/test/framework/TestSensorTest.java --- @@ -332,6 +343,56 @@ public void testFailFastIfNoSensor() throws Exception { assertStartFails(app, NullPointerException.class, Asserts.DEFAULT_LONG_TIMEOUT); } +@Test +public void testDoesNotLogStacktraceRepeatedly() throws Exception { +final long time = System.currentTimeMillis(); +final String sensorValue = String.format("%s%s%s", Identifiers.makeRandomId(8), time, Identifiers.makeRandomId(8)); + +// Test case will repeatedly fail until we have finished our logging assertions. +// Then we'll let it complete by setting the sensor. +TestSensor testCase = app.createAndManageChild(EntitySpec.create(TestSensor.class) +.configure(TestSensor.TIMEOUT, Asserts.DEFAULT_LONG_TIMEOUT) +.configure(TestSensor.TARGET_ENTITY, app) +.configure(TestSensor.SENSOR_NAME, STRING_SENSOR.getName()) +.configure(TestSensor.ASSERTIONS, newListAssertion("matches", String.format(".*%s.*", time; + +String loggerName = Repeater.class.getName(); +ch.qos.logback.classic.Level logLevel = ch.qos.logback.classic.Level.DEBUG; +Predicate repeatedFailureMsgMatcher = EventPredicates.containsMessage("repeated failure; excluding stacktrace"); +Predicate stacktraceMatcher = EventPredicates.containsExceptionStackLine(TestFrameworkAssertions.class, "checkActualAgainstAssertions"); +Predicate filter = Predicates.or(repeatedFailureMsgMatcher, stacktraceMatcher); +LogWatcher watcher = new LogWatcher(loggerName, logLevel, filter); + +Task task; +watcher.start(); +try { +// Invoke async; will let it complete after we see the log messages we expect +task = Entities.invokeEffector(app, app, Startable.START, ImmutableMap.of("locations", locs)); --- End diff -- Define variable here as `Task task = Entities...` --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] brooklyn-server pull request #473: Test framework: avoid repeated stacktrace...
Github user grkvlt commented on a diff in the pull request: https://github.com/apache/brooklyn-server/pull/473#discussion_r90474128 --- Diff: test-framework/src/test/java/org/apache/brooklyn/test/framework/TestSensorTest.java --- @@ -332,6 +343,56 @@ public void testFailFastIfNoSensor() throws Exception { assertStartFails(app, NullPointerException.class, Asserts.DEFAULT_LONG_TIMEOUT); } +@Test +public void testDoesNotLogStacktraceRepeatedly() throws Exception { +final long time = System.currentTimeMillis(); +final String sensorValue = String.format("%s%s%s", Identifiers.makeRandomId(8), time, Identifiers.makeRandomId(8)); + +// Test case will repeatedly fail until we have finished our logging assertions. +// Then we'll let it complete by setting the sensor. +TestSensor testCase = app.createAndManageChild(EntitySpec.create(TestSensor.class) +.configure(TestSensor.TIMEOUT, Asserts.DEFAULT_LONG_TIMEOUT) +.configure(TestSensor.TARGET_ENTITY, app) +.configure(TestSensor.SENSOR_NAME, STRING_SENSOR.getName()) +.configure(TestSensor.ASSERTIONS, newListAssertion("matches", String.format(".*%s.*", time; + +String loggerName = Repeater.class.getName(); +ch.qos.logback.classic.Level logLevel = ch.qos.logback.classic.Level.DEBUG; +Predicate repeatedFailureMsgMatcher = EventPredicates.containsMessage("repeated failure; excluding stacktrace"); +Predicate stacktraceMatcher = EventPredicates.containsExceptionStackLine(TestFrameworkAssertions.class, "checkActualAgainstAssertions"); +Predicate filter = Predicates.or(repeatedFailureMsgMatcher, stacktraceMatcher); +LogWatcher watcher = new LogWatcher(loggerName, logLevel, filter); + +Task task; +watcher.start(); +try { --- End diff -- Since `LogWartcher` is `Closeable` can do this in the `try` block and it will be closed automatically. ```Java try (LogWatcher watcher = new LogWatcher(loggerName, logLevel, filter)) { // stuff } ``` --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---