You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2016/02/29 10:50:27 UTC
svn commit: r1732840 -
/sling/trunk/bundles/extensions/healthcheck/it/src/test/java/org/apache/sling/hc/it/core/JmxAdjustableStatusForTestingTest.java
Author: bdelacretaz
Date: Mon Feb 29 09:50:27 2016
New Revision: 1732840
URL: http://svn.apache.org/viewvc?rev=1732840&view=rev
Log:
SLING-4941 - restructure tests and add testAnotherTag()
Modified:
sling/trunk/bundles/extensions/healthcheck/it/src/test/java/org/apache/sling/hc/it/core/JmxAdjustableStatusForTestingTest.java
Modified: sling/trunk/bundles/extensions/healthcheck/it/src/test/java/org/apache/sling/hc/it/core/JmxAdjustableStatusForTestingTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/healthcheck/it/src/test/java/org/apache/sling/hc/it/core/JmxAdjustableStatusForTestingTest.java?rev=1732840&r1=1732839&r2=1732840&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/healthcheck/it/src/test/java/org/apache/sling/hc/it/core/JmxAdjustableStatusForTestingTest.java (original)
+++ sling/trunk/bundles/extensions/healthcheck/it/src/test/java/org/apache/sling/hc/it/core/JmxAdjustableStatusForTestingTest.java Mon Feb 29 09:50:27 2016
@@ -64,16 +64,28 @@ public class JmxAdjustableStatusForTesti
public Option[] config() {
return U.config();
}
+
+ private void assertResult(String tag, Result.Status expected) {
+ final Result result = getOverallResult(executor.execute(tag));
+ assertEquals("Expected status " + expected + " for tag " + tag, expected, result.getStatus());
+ }
@Before
public void setup() {
U.expectHealthChecks(0, executor, testTag);
registerHC(testTag);
+ U.expectHealthChecks(1, executor, testTag);
+ assertResult(testTag, Result.Status.OK);
}
@After
@SuppressWarnings("rawtypes")
- public void cleanup() {
+ public void cleanup() throws Exception {
+ invokeMBean("reset", new Object[] {}, new String[] {});
+
+ U.expectHealthChecks(1, executor, testTag);
+ assertResult(testTag, Result.Status.OK);
+
for (ServiceRegistration r : regs) {
r.unregister();
}
@@ -82,40 +94,31 @@ public class JmxAdjustableStatusForTesti
}
@Test
- public void testJmxAdjustableStatusForTesting() throws Exception {
-
- U.expectHealthChecks(1, executor, testTag);
-
- Result result = getOverallResult(executor.execute(testTag));
- assertEquals(Result.Status.OK, result.getStatus());
-
+ public void testWarnStatus() throws Exception {
invokeMBean("addWarnResultForTags", new Object[] { testTag }, new String[] { String.class.getName() });
-
- U.expectHealthChecks(2, executor, testTag);
- result = getOverallResult(executor.execute(testTag));
- assertEquals(Result.Status.WARN, result.getStatus());
-
- invokeMBean("reset", new Object[] {}, new String[] {});
-
- U.expectHealthChecks(1, executor, testTag);
- result = getOverallResult(executor.execute(testTag));
- assertEquals(Result.Status.OK, result.getStatus());
-
- invokeMBean("addCriticalResultForTags", new Object[] { "anotherTag," + testTag },
- new String[] { String.class.getName() });
-
U.expectHealthChecks(2, executor, testTag);
- result = getOverallResult(executor.execute(testTag));
- assertEquals(Result.Status.CRITICAL, result.getStatus());
-
- invokeMBean("reset", new Object[] {}, new String[] {});
-
- U.expectHealthChecks(1, executor, testTag);
- result = getOverallResult(executor.execute(testTag));
- assertEquals(Result.Status.OK, result.getStatus());
-
+ assertResult(testTag, Result.Status.WARN);
}
+ @Test
+ public void testCriticalStatus() throws Exception {
+ invokeMBean("addCriticalResultForTags", new Object[] { "anotherTag," + testTag },
+ new String[] { String.class.getName() });
+
+ final String [] tags = { "anotherTag", testTag };
+ for(String tag : tags) {
+ U.expectHealthChecks(2, executor, testTag);
+ assertResult(tag, Result.Status.CRITICAL);
+ }
+ }
+
+ @Test
+ public void testAnotherTag() throws Exception {
+ // Selecting an unused tag returns WARN - not sure why but
+ // if that changes we should detect it.
+ assertResult("some_unused_tag", Result.Status.WARN);
+ }
+
private void registerHC(final String... tags) {
final HealthCheck hc = new HealthCheck() {
@Override
@@ -149,5 +152,4 @@ public class JmxAdjustableStatusForTesti
}
return new Result(resultLog);
}
-
}