User: ejort
Date: 02/03/29 04:14:34
Modified: src/main/test/compliance/monitor MonitorTestCase.java
Log:
Merge differences between RelMX_1_0_0_13 and RelMX_1_0_0_14 to head
Revision Changes Path
1.3 +1321 -183 jmx/src/main/test/compliance/monitor/MonitorTestCase.java
Index: MonitorTestCase.java
===================================================================
RCS file: /cvsroot/jboss/jmx/src/main/test/compliance/monitor/MonitorTestCase.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- MonitorTestCase.java 24 Mar 2002 13:12:12 -0000 1.2
+++ MonitorTestCase.java 29 Mar 2002 12:14:34 -0000 1.3
@@ -23,9 +23,11 @@
import java.util.ArrayList;
import java.util.Date;
+import java.util.HashSet;
import java.util.Iterator;
import javax.management.Attribute;
+import javax.management.MBeanNotificationInfo;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.ObjectName;
@@ -37,9 +39,9 @@
import javax.management.monitor.MonitorNotification;
import javax.management.monitor.StringMonitor;
+import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
-
/**
* Monitor Notification Tests
*
@@ -64,64 +66,998 @@
ObjectName monitorName;
/**
- * The monitor
+ * The monitor
+ */
+ Monitor monitor;
+
+ /**
+ * The object name of the mbean monitored
+ */
+ ObjectName monitoredName;
+
+ /**
+ * The monitored mbean
+ */
+ MonitorSupport monitored;
+
+ /**
+ * The notifications
+ */
+ ArrayList notifications = new ArrayList();
+
+ // Constructor -------------------------------------------------------------
+
+ /**
+ * Construct the test
+ */
+ public MonitorTestCase(String s)
+ {
+ super(s);
+ }
+
+ // Tests -------------------------------------------------------------------
+
+ /**
+ * Test notification types differ
+ */
+ public void testNotificationTypes()
+ {
+ assertEquals(MonitorNotification.OBSERVED_ATTRIBUTE_ERROR,
+ "jmx.monitor.error.attribute");
+ assertEquals(MonitorNotification.OBSERVED_ATTRIBUTE_TYPE_ERROR,
+ "jmx.monitor.error.type");
+ assertEquals(MonitorNotification.OBSERVED_OBJECT_ERROR,
+ "jmx.monitor.error.mbean");
+ assertEquals(MonitorNotification.RUNTIME_ERROR,
+ "jmx.monitor.error.runtime");
+ assertEquals(MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED,
+ "jmx.monitor.string.differs");
+ assertEquals(MonitorNotification.STRING_TO_COMPARE_VALUE_MATCHED,
+ "jmx.monitor.string.matches");
+ assertEquals(MonitorNotification.THRESHOLD_ERROR,
+ "jmx.monitor.error.threshold");
+ assertEquals(MonitorNotification.THRESHOLD_HIGH_VALUE_EXCEEDED,
+ "jmx.monitor.gauge.high");
+ assertEquals(MonitorNotification.THRESHOLD_LOW_VALUE_EXCEEDED,
+ "jmx.monitor.gauge.low");
+ assertEquals(MonitorNotification.THRESHOLD_VALUE_EXCEEDED,
+ "jmx.monitor.counter.threshold");
+ }
+
+ // Counter monitor notification info ---------------------------------------
+
+ /**
+ * Test the notification info of the counter
+ */
+ public void testCounterNotificationInfo()
+ throws Exception
+ {
+ HashSet expected = new HashSet();
+ expected.add(MonitorNotification.OBSERVED_ATTRIBUTE_ERROR);
+ expected.add(MonitorNotification.OBSERVED_ATTRIBUTE_TYPE_ERROR);
+ expected.add(MonitorNotification.OBSERVED_OBJECT_ERROR);
+ expected.add(MonitorNotification.RUNTIME_ERROR);
+ expected.add(MonitorNotification.THRESHOLD_ERROR);
+ expected.add(MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+
+ MBeanNotificationInfo[] mbni = new CounterMonitor().getNotificationInfo();
+ checkNotificationInfo("Counter", mbni, expected);
+ }
+
+ // Counter normal no offset no modulus tests -------------------------------
+
+ /**
+ * Test normal counter threshold no offset no modulus
+ */
+ public void testNormalCounterThresholdExceededEarlyNoOffsetNoModulus()
+ throws Exception
+ {
+ initTest();
+ try
+ {
+ initCounterMonitor(true, new Integer(10),
+ false, new Integer(0), new Integer(0));
+ expectStartMonitor(new Integer(10),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ }
+ finally
+ {
+ stopMonitor();
+ MBeanServerFactory.releaseMBeanServer(server);
+ }
+ }
+
+ /**
+ * Test normal counter threshold no offset no modulus
+ */
+ public void testNormalCounterThresholdExceededLateNoOffsetNoModulus()
+ throws Exception
+ {
+ initTest();
+ try
+ {
+ initCounterMonitor(true, new Integer(10),
+ false, new Integer(0), new Integer(0));
+ dontExpectStartMonitor(new Integer(0));
+ expect(new Integer(10),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ }
+ finally
+ {
+ stopMonitor();
+ MBeanServerFactory.releaseMBeanServer(server);
+ }
+ }
+
+ /**
+ * Test normal counter threshold no offset no modulus
+ */
+ public void testNormalCounterThresholdExceededManyNoOffsetNoModulus()
+ throws Exception
+ {
+ initTest();
+ try
+ {
+ initCounterMonitor(true, new Integer(10),
+ false, new Integer(0), new Integer(0));
+ dontExpectStartMonitor(new Integer(0));
+ expect(new Integer(10),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ dontExpect(new Integer(0));
+ expect(new Integer(11),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ }
+ finally
+ {
+ stopMonitor();
+ MBeanServerFactory.releaseMBeanServer(server);
+ }
+ }
+
+ /**
+ * Test normal counter threshold no offset no modulus
+ */
+ public void testNormalCounterThresholdNotExceededNoOffsetNoModulus()
+ throws Exception
+ {
+ initTest();
+ try
+ {
+ initCounterMonitor(true, new Integer(10),
+ false, new Integer(0), new Integer(0));
+ dontExpectStartMonitor(new Integer(0));
+ dontExpect(new Integer(1));
+ dontExpect(new Integer(-1));
+ dontExpect(new Integer(9));
+ expect(new Integer(10),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ dontExpect(new Integer(10));
+ dontExpect(new Integer(11));
+ dontExpect(new Integer(9));
+ expect(new Integer(10),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ dontExpect(new Integer(9));
+ }
+ finally
+ {
+ stopMonitor();
+ MBeanServerFactory.releaseMBeanServer(server);
+ }
+ }
+
+ /**
+ * Test normal counter threshold no offset no modulus
+ */
+ public void testNormalCounterThresholdExceededNoneNoOffsetNoModulus()
+ throws Exception
+ {
+ initTest();
+ try
+ {
+ initCounterMonitor(false, new Integer(10),
+ false, new Integer(0), new Integer(0));
+ dontExpectStartMonitor(new Integer(0));
+ dontExpect(new Integer(10));
+ dontExpect(new Integer(0));
+ dontExpect(new Integer(10));
+ }
+ finally
+ {
+ stopMonitor();
+ MBeanServerFactory.releaseMBeanServer(server);
+ }
+ }
+
+ // Counter normal offset no modulus tests ----------------------------------
+
+ /**
+ * Test normal counter threshold offset no modulus
+ */
+ public void testNormalCounterThresholdExceededEarlyOffsetNoModulus()
+ throws Exception
+ {
+ initTest();
+ try
+ {
+ initCounterMonitor(true, new Integer(10),
+ false, new Integer(10), new Integer(0));
+ expectStartMonitor(new Integer(10),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ }
+ finally
+ {
+ stopMonitor();
+ MBeanServerFactory.releaseMBeanServer(server);
+ }
+ }
+
+ /**
+ * Test normal counter threshold offset no modulus
+ */
+ public void testNormalCounterThresholdExceededLateOffsetNoModulus()
+ throws Exception
+ {
+ initTest();
+ try
+ {
+ initCounterMonitor(true, new Integer(10),
+ false, new Integer(10), new Integer(0));
+ dontExpectStartMonitor(new Integer(0));
+ expect(new Integer(10),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ }
+ finally
+ {
+ stopMonitor();
+ MBeanServerFactory.releaseMBeanServer(server);
+ }
+ }
+
+ /**
+ * Test normal counter threshold offset no modulus
+ */
+ public void testNormalCounterThresholdExceededManyOffsetNoModulus()
+ throws Exception
+ {
+ initTest();
+ try
+ {
+ initCounterMonitor(true, new Integer(10),
+ false, new Integer(10), new Integer(0));
+ dontExpectStartMonitor(new Integer(0));
+ expect(new Integer(10),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ dontExpect(new Integer(0));
+ dontExpect(new Integer(11));
+ expect(new Integer(20),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ dontExpect(new Integer(29));
+ expect(new Integer(30),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ expect(new Integer(40),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ }
+ finally
+ {
+ stopMonitor();
+ MBeanServerFactory.releaseMBeanServer(server);
+ }
+ }
+
+ /**
+ * Test normal counter threshold offset no modulus
+ */
+ public void testNormalCounterThresholdNotExceededOffsetNoModulus()
+ throws Exception
+ {
+ initTest();
+ try
+ {
+ initCounterMonitor(true, new Integer(10),
+ false, new Integer(10), new Integer(0));
+ dontExpectStartMonitor(new Integer(0));
+ dontExpect(new Integer(1));
+ dontExpect(new Integer(-1));
+ dontExpect(new Integer(9));
+ expect(new Integer(10),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ dontExpect(new Integer(10));
+ dontExpect(new Integer(11));
+ dontExpect(new Integer(9));
+ expect(new Integer(20),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ dontExpect(new Integer(19));
+ }
+ finally
+ {
+ stopMonitor();
+ MBeanServerFactory.releaseMBeanServer(server);
+ }
+ }
+
+ /**
+ * Test normal counter threshold offset no modulus
+ */
+ public void testNormalCounterThresholdExceededNoneOffsetNoModulus()
+ throws Exception
+ {
+ initTest();
+ try
+ {
+ initCounterMonitor(false, new Integer(10),
+ false, new Integer(10), new Integer(0));
+ dontExpectStartMonitor(new Integer(0));
+ dontExpect(new Integer(10));
+ dontExpect(new Integer(0));
+ dontExpect(new Integer(20));
+ }
+ finally
+ {
+ stopMonitor();
+ MBeanServerFactory.releaseMBeanServer(server);
+ }
+ }
+
+ // Counter normal no offset modulus tests ---------------------------------
+
+ /**
+ * Test normal counter threshold no offset modulus
+ */
+ public void testNormalCounterThresholdExceededEarlyNoOffsetModulus()
+ throws Exception
+ {
+ initTest();
+ try
+ {
+ initCounterMonitor(true, new Integer(10),
+ false, new Integer(0), new Integer(10));
+ expectStartMonitor(new Integer(10),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ }
+ finally
+ {
+ stopMonitor();
+ MBeanServerFactory.releaseMBeanServer(server);
+ }
+ }
+
+ /**
+ * Test normal counter threshold no offset modulus
+ */
+ public void testNormalCounterThresholdExceededLateNoOffsetModulus()
+ throws Exception
+ {
+ initTest();
+ try
+ {
+ initCounterMonitor(true, new Integer(10),
+ false, new Integer(0), new Integer(10));
+ dontExpectStartMonitor(new Integer(0));
+ expect(new Integer(10),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ }
+ finally
+ {
+ stopMonitor();
+ MBeanServerFactory.releaseMBeanServer(server);
+ }
+ }
+
+ /**
+ * Test normal counter threshold no offset modulus
+ */
+ public void testNormalCounterThresholdExceededManyNoOffsetModulus()
+ throws Exception
+ {
+ initTest();
+ try
+ {
+ initCounterMonitor(true, new Integer(10),
+ false, new Integer(0), new Integer(10));
+ dontExpectStartMonitor(new Integer(0));
+ expect(new Integer(10),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ dontExpect(new Integer(0));
+ expect(new Integer(11),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ expect(new Integer(12),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ dontExpect(new Integer(0));
+ expect(new Integer(10),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ }
+ catch (AssertionFailedError e)
+ {
+ fail("FAILS IN RI: Modulus ignored with no offset???");
+ }
+ finally
+ {
+ stopMonitor();
+ MBeanServerFactory.releaseMBeanServer(server);
+ }
+ }
+
+ /**
+ * Test normal counter threshold no offset modulus
+ */
+ public void testNormalCounterThresholdNotExceededNoOffsetModulus()
+ throws Exception
+ {
+ initTest();
+ try
+ {
+ initCounterMonitor(true, new Integer(10),
+ false, new Integer(0), new Integer(10));
+ dontExpectStartMonitor(new Integer(0));
+ dontExpect(new Integer(1));
+ dontExpect(new Integer(-1));
+ dontExpect(new Integer(9));
+ expect(new Integer(10),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ dontExpect(new Integer(9));
+ expect(new Integer(10),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ dontExpect(new Integer(9));
+ }
+ finally
+ {
+ stopMonitor();
+ MBeanServerFactory.releaseMBeanServer(server);
+ }
+ }
+
+ /**
+ * Test normal counter threshold no offset modulus
+ */
+ public void testNormalCounterThresholdExceededNoneNoOffsetModulus()
+ throws Exception
+ {
+ initTest();
+ try
+ {
+ initCounterMonitor(false, new Integer(10),
+ false, new Integer(0), new Integer(10));
+ dontExpectStartMonitor(new Integer(0));
+ dontExpect(new Integer(10));
+ dontExpect(new Integer(0));
+ dontExpect(new Integer(10));
+ }
+ finally
+ {
+ stopMonitor();
+ MBeanServerFactory.releaseMBeanServer(server);
+ }
+ }
+
+ // Counter normal offset modulus tests -------------------------------------
+
+ /**
+ * Test normal counter threshold offset modulus
+ */
+ public void testNormalCounterThresholdExceededEarlyOffsetModulus()
+ throws Exception
+ {
+ initTest();
+ try
+ {
+ initCounterMonitor(true, new Integer(10),
+ false, new Integer(10), new Integer(10));
+ expectStartMonitor(new Integer(10),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ }
+ finally
+ {
+ stopMonitor();
+ MBeanServerFactory.releaseMBeanServer(server);
+ }
+ }
+
+ /**
+ * Test normal counter threshold offset modulus
+ */
+ public void testNormalCounterThresholdExceededLateOffsetModulus()
+ throws Exception
+ {
+ initTest();
+ try
+ {
+ initCounterMonitor(true, new Integer(10),
+ false, new Integer(10), new Integer(10));
+ dontExpectStartMonitor(new Integer(0));
+ expect(new Integer(10),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ }
+ finally
+ {
+ stopMonitor();
+ MBeanServerFactory.releaseMBeanServer(server);
+ }
+ }
+
+ /**
+ * Test normal counter threshold offset modulus
+ */
+ public void testNormalCounterThresholdExceededManyOffsetModulus()
+ throws Exception
+ {
+ initTest();
+ try
+ {
+ initCounterMonitor(true, new Integer(10),
+ false, new Integer(10), new Integer(20));
+ dontExpectStartMonitor(new Integer(0));
+ expect(new Integer(10),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ dontExpect(new Integer(0));
+ dontExpect(new Integer(12));
+ expect(new Integer(20),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ if (((CounterMonitor)monitor).getThreshold().equals(new Integer(30)))
+ fail("FAILS IN RI: Threshold 10, Offset 10, Modulus 20 should " +
+ " never get a threshold of 30");
+ expect(new Integer(10),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ dontExpect(new Integer(10));
+ expect(new Integer(20),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ expect(new Integer(20),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ expect(new Integer(30),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ }
+ finally
+ {
+ stopMonitor();
+ MBeanServerFactory.releaseMBeanServer(server);
+ }
+ }
+
+ /**
+ * Test normal counter threshold offset modulus
+ */
+ public void testNormalCounterThresholdNotExceededOffsetModulus()
+ throws Exception
+ {
+ initTest();
+ try
+ {
+ initCounterMonitor(true, new Integer(10),
+ false, new Integer(10), new Integer(20));
+ dontExpectStartMonitor(new Integer(0));
+ dontExpect(new Integer(1));
+ dontExpect(new Integer(-1));
+ dontExpect(new Integer(9));
+ expect(new Integer(10),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ dontExpect(new Integer(10));
+ dontExpect(new Integer(11));
+ dontExpect(new Integer(9));
+ expect(new Integer(20),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ if (((CounterMonitor)monitor).getThreshold().equals(new Integer(30)))
+ fail("FAILS IN RI: Threshold 10, Offset 10, Modulus 20 should " +
+ " never get a threshold of 30");
+ expect(new Integer(19),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ }
+ finally
+ {
+ stopMonitor();
+ MBeanServerFactory.releaseMBeanServer(server);
+ }
+ }
+
+ /**
+ * Test normal counter threshold offset modulus
+ */
+ public void testNormalCounterThresholdExceededNoneOffsetModulus()
+ throws Exception
+ {
+ initTest();
+ try
+ {
+ initCounterMonitor(false, new Integer(10),
+ false, new Integer(10), new Integer(10));
+ dontExpectStartMonitor(new Integer(0));
+ dontExpect(new Integer(10));
+ dontExpect(new Integer(0));
+ dontExpect(new Integer(20));
+ }
+ finally
+ {
+ stopMonitor();
+ MBeanServerFactory.releaseMBeanServer(server);
+ }
+ }
+
+ // Counter difference no offset no modulus tests ---------------------------
+
+ /**
+ * Test difference counter threshold no offset no modulus
+ */
+ public void testDiffCounterThresholdExceededNoOffsetNoModulus()
+ throws Exception
+ {
+ initTest();
+ try
+ {
+ initCounterMonitor(true, new Integer(10),
+ true, new Integer(0), new Integer(0));
+ dontExpectStartMonitor(new Integer(0));
+ expect(new Integer(10),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ }
+ finally
+ {
+ stopMonitor();
+ MBeanServerFactory.releaseMBeanServer(server);
+ }
+ }
+
+ /**
+ * Test difference counter threshold no offset no modulus
+ */
+ public void testDiffCounterThresholdExceededManyNoOffsetNoModulus()
+ throws Exception
+ {
+ initTest();
+ try
+ {
+ initCounterMonitor(true, new Integer(10),
+ true, new Integer(0), new Integer(0));
+ dontExpectStartMonitor(new Integer(0));
+ expect(new Integer(10),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ expectDiff(new Integer(0), new Integer(11),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ }
+ finally
+ {
+ stopMonitor();
+ MBeanServerFactory.releaseMBeanServer(server);
+ }
+ }
+
+ /**
+ * Test difference counter threshold no offset no modulus
+ */
+ public void testDiffCounterThresholdNotExceededNoOffsetNoModulus()
+ throws Exception
+ {
+ initTest();
+ try
+ {
+ initCounterMonitor(true, new Integer(10),
+ true, new Integer(0), new Integer(0));
+ dontExpectStartMonitorDiff(new Integer(0), new Integer(1));
+ dontExpectDiff(new Integer(0), new Integer(9));
+ dontExpectDiff(new Integer(1), new Integer(10));
+ dontExpectDiff(new Integer(9), new Integer(11));
+ dontExpectDiff(new Integer(9), new Integer(0));
+ }
+ finally
+ {
+ stopMonitor();
+ MBeanServerFactory.releaseMBeanServer(server);
+ }
+ }
+
+ /**
+ * Test difference counter threshold no offset no modulus
+ */
+ public void testDiffCounterThresholdExceededNoneNoOffsetNoModulus()
+ throws Exception
+ {
+ initTest();
+ try
+ {
+ initCounterMonitor(false, new Integer(10),
+ true, new Integer(0), new Integer(0));
+ dontExpectStartMonitorDiff(new Integer(0), new Integer(10));
+ dontExpectDiff(new Integer(0), new Integer(-10));
+ dontExpectDiff(new Integer(0), new Integer(100));
+ }
+ finally
+ {
+ stopMonitor();
+ MBeanServerFactory.releaseMBeanServer(server);
+ }
+ }
+
+ // Counter difference offset no modulus tests ------------------------------
+
+ /**
+ * Test difference counter threshold offset no modulus
+ */
+ public void testDiffCounterThresholdExceededOffsetNoModulus()
+ throws Exception
+ {
+ initTest();
+ try
+ {
+ initCounterMonitor(true, new Integer(10),
+ true, new Integer(10), new Integer(0));
+ dontExpectStartMonitor(new Integer(0));
+ expect(new Integer(10),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ }
+ finally
+ {
+ stopMonitor();
+ MBeanServerFactory.releaseMBeanServer(server);
+ }
+ }
+
+ /**
+ * Test difference counter threshold offset no modulus
+ */
+ public void testDiffCounterThresholdExceededManyOffsetNoModulus()
+ throws Exception
+ {
+ initTest();
+ try
+ {
+ initCounterMonitor(true, new Integer(10),
+ true, new Integer(10), new Integer(0));
+ dontExpectStartMonitor(new Integer(0));
+ expect(new Integer(10),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ expectDiff(new Integer(0), new Integer(10),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ expectDiff(new Integer(10), new Integer(30),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ expectDiff(new Integer(30), new Integer(60),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ expectDiff(new Integer(60), new Integer(100),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ expectDiff(new Integer(0), new Integer(10),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ }
+ finally
+ {
+ stopMonitor();
+ MBeanServerFactory.releaseMBeanServer(server);
+ }
+ }
+
+ /**
+ * Test difference counter threshold offset no modulus
+ */
+ public void testDiffCounterThresholdNotExceededOffsetNoModulus()
+ throws Exception
+ {
+ initTest();
+ try
+ {
+ initCounterMonitor(true, new Integer(10),
+ true, new Integer(10), new Integer(0));
+ dontExpectStartMonitorDiff(new Integer(0), new Integer(1));
+ expectDiff(new Integer(0), new Integer(10),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ dontExpectDiff(new Integer(10), new Integer(20));
+ expectDiff(new Integer(20), new Integer(40),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ dontExpectDiff(new Integer(40), new Integer(69));
+ }
+ finally
+ {
+ stopMonitor();
+ MBeanServerFactory.releaseMBeanServer(server);
+ }
+ }
+
+ /**
+ * Test difference counter threshold offset no modulus
+ */
+ public void testDiffCounterThresholdExceededNoneOffsetNoModulus()
+ throws Exception
+ {
+ initTest();
+ try
+ {
+ initCounterMonitor(false, new Integer(10),
+ true, new Integer(10), new Integer(0));
+ dontExpectStartMonitorDiff(new Integer(0), new Integer(1));
+ dontExpectDiff(new Integer(0), new Integer(10));
+ dontExpectDiff(new Integer(10), new Integer(20));
+ dontExpectDiff(new Integer(20), new Integer(40));
+ dontExpectDiff(new Integer(40), new Integer(69));
+ }
+ finally
+ {
+ stopMonitor();
+ MBeanServerFactory.releaseMBeanServer(server);
+ }
+ }
+
+ // Counter difference no offset modulus tests ------------------------------
+
+ /**
+ * Test difference counter threshold no offset modulus
+ */
+ public void testDiffCounterThresholdExceededNoOffsetModulus()
+ throws Exception
+ {
+ initTest();
+ try
+ {
+ initCounterMonitor(true, new Integer(10),
+ true, new Integer(0), new Integer(10));
+ dontExpectStartMonitor(new Integer(0));
+ expect(new Integer(10),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ }
+ finally
+ {
+ stopMonitor();
+ MBeanServerFactory.releaseMBeanServer(server);
+ }
+ }
+
+ /**
+ * Test difference counter threshold no offset modulus
+ */
+ public void testDiffCounterThresholdExceededManyNoOffsetModulus()
+ throws Exception
+ {
+ initTest();
+ try
+ {
+ initCounterMonitor(true, new Integer(10),
+ true, new Integer(0), new Integer(10));
+ dontExpectStartMonitor(new Integer(0));
+ expect(new Integer(10),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ expectDiff(new Integer(0), new Integer(11),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ expectDiff(new Integer(12), new Integer(22),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ expectDiff(new Integer(0), new Integer(10),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ }
+ finally
+ {
+ stopMonitor();
+ MBeanServerFactory.releaseMBeanServer(server);
+ }
+ }
+
+ /**
+ * Test difference counter threshold no offset modulus
+ */
+ public void testDiffCounterThresholdNotExceededNoOffsetModulus()
+ throws Exception
+ {
+ initTest();
+ try
+ {
+ initCounterMonitor(true, new Integer(10),
+ true, new Integer(0), new Integer(10));
+ dontExpectStartMonitorDiff(new Integer(0), new Integer(1));
+ dontExpectDiff(new Integer(0), new Integer(9));
+ dontExpectDiff(new Integer(11), new Integer(20));
+ dontExpectDiffModulus(new Integer(10), new Integer(-3), new Integer(10));
+ }
+ finally
+ {
+ stopMonitor();
+ MBeanServerFactory.releaseMBeanServer(server);
+ }
+ }
+
+ /**
+ * Test difference counter threshold no offset modulus
*/
- Monitor monitor;
+ public void testDiffCounterThresholdExceededNoneNoOffsetModulus()
+ throws Exception
+ {
+ initTest();
+ try
+ {
+ initCounterMonitor(false, new Integer(10),
+ true, new Integer(0), new Integer(10));
+ dontExpectStartMonitorDiff(new Integer(0), new Integer(10));
+ dontExpectDiffModulus(new Integer(0), new Integer(-10), new Integer(10));
+ dontExpectDiff(new Integer(0), new Integer(100));
+ }
+ finally
+ {
+ stopMonitor();
+ MBeanServerFactory.releaseMBeanServer(server);
+ }
+ }
- /**
- * The object name of the mbean monitored
- */
- ObjectName monitoredName;
+ // Counter difference offset modulus tests ---------------------------------
/**
- * The monitored mbean
+ * Test difference counter threshold offset modulus
*/
- MonitorSupport monitored;
+ public void testDiffCounterThresholdExceededOffsetModulus()
+ throws Exception
+ {
+ initTest();
+ try
+ {
+ initCounterMonitor(true, new Integer(10),
+ true, new Integer(10), new Integer(10));
+ dontExpectStartMonitor(new Integer(0));
+ expect(new Integer(10),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ }
+ finally
+ {
+ stopMonitor();
+ MBeanServerFactory.releaseMBeanServer(server);
+ }
+ }
/**
- * The notifications
+ * Test difference counter threshold offset modulus
*/
- ArrayList notifications = new ArrayList();
-
- // Constructor -------------------------------------------------------------
+ public void testDiffCounterThresholdExceededManyOffsetModulus()
+ throws Exception
+ {
+ initTest();
+ try
+ {
+ initCounterMonitor(true, new Integer(10),
+ true, new Integer(10), new Integer(20));
+ dontExpectStartMonitor(new Integer(0));
+ expectDiff(new Integer(0), new Integer(11),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ expectDiff(new Integer(11), new Integer(31),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ expectDiff(new Integer(0), new Integer(10),
+ MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
+ }
+ finally
+ {
+ stopMonitor();
+ MBeanServerFactory.releaseMBeanServer(server);
+ }
+ }
/**
- * Construct the test
+ * Test difference counter threshold offset modulus
*/
- public MonitorTestCase(String s)
+ public void testDiffCounterThresholdNotExceededOffsetModulus()
+ throws Exception
{
- super(s);
+ initTest();
+ try
+ {
+ initCounterMonitor(true, new Integer(10),
+ true, new Integer(10), new Integer(20));
+ dontExpectStartMonitorDiff(new Integer(0), new Integer(1));
+ dontExpectDiff(new Integer(1), new Integer(10));
+ dontExpectDiffModulus(new Integer(10), new Integer(-13), new Integer(20));
+ }
+ finally
+ {
+ stopMonitor();
+ MBeanServerFactory.releaseMBeanServer(server);
+ }
}
- // Tests -------------------------------------------------------------------
-
/**
- * Test notification types differ
+ * Test difference counter threshold offset modulus
*/
- public void testNotificationTypesDiffer()
+ public void testDiffCounterThresholdExceededNoneOffsetModulus()
+ throws Exception
{
- String[] types = new String[]
+ initTest();
+ try
{
- MonitorNotification.OBSERVED_ATTRIBUTE_ERROR,
- MonitorNotification.OBSERVED_ATTRIBUTE_TYPE_ERROR,
- MonitorNotification.OBSERVED_OBJECT_ERROR,
- MonitorNotification.RUNTIME_ERROR,
- MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED,
- MonitorNotification.STRING_TO_COMPARE_VALUE_MATCHED,
- MonitorNotification.THRESHOLD_ERROR,
- MonitorNotification.THRESHOLD_HIGH_VALUE_EXCEEDED,
- MonitorNotification.THRESHOLD_LOW_VALUE_EXCEEDED,
- MonitorNotification.THRESHOLD_VALUE_EXCEEDED
- };
- for (int i = 0; i < types.length; i++)
- {
- if (types[i] == null)
- fail("Null notification type");
- for (int j = i + 1 ; j < types.length; j++)
- {
- if (types[i].equals(types[j]))
- fail("Equal notification types: " + types[i]);
- }
+ initCounterMonitor(false, new Integer(10),
+ true, new Integer(10), new Integer(20));
+ dontExpectStartMonitorDiff(new Integer(0), new Integer(10));
+ dontExpectDiffModulus(new Integer(0), new Integer(-10), new Integer(20));
+ dontExpectDiff(new Integer(0), new Integer(100));
+ }
+ finally
+ {
+ stopMonitor();
+ MBeanServerFactory.releaseMBeanServer(server);
}
}
@@ -136,9 +1072,9 @@
initTest();
try
{
- initCounterMonitor(true, new Integer(10), new Integer(0),
+ initCounterMonitor(true, new Integer(10),
false, new Integer(10), new Integer(10));
- attributeErrorStartMonitor();
+ attributeErrorStartMonitor(new Integer(0));
}
finally
{
@@ -156,9 +1092,9 @@
initTest();
try
{
- initCounterMonitor(true, new Integer(10), new Integer(0),
+ initCounterMonitor(true, new Integer(10),
false, new Integer(10), new Integer(10));
- attributeNullStartMonitor();
+ attributeNullStartMonitor(new Integer(0));
}
finally
{
@@ -176,9 +1112,9 @@
initTest();
try
{
- initCounterMonitor(true, new Integer(10), new Integer(0),
+ initCounterMonitor(true, new Integer(10),
false, new Integer(10), new Integer(10));
- attributeTypeStartMonitor();
+ attributeTypeStartMonitor(new Integer(0));
}
finally
{
@@ -196,9 +1132,9 @@
initTest();
try
{
- initCounterMonitor(true, new Integer(10), new Integer(0),
+ initCounterMonitor(true, new Integer(10),
false, new Integer(10), new Integer(10));
- attributeWriteStartMonitor();
+ attributeWriteStartMonitor(new Integer(0));
}
finally
{
@@ -216,9 +1152,9 @@
initTest();
try
{
- initCounterMonitor(true, new Integer(10), new Integer(0),
+ initCounterMonitor(true, new Integer(10),
false, new Integer(10), new Integer(10));
- objectNameStartMonitor();
+ objectNameStartMonitor(new Integer(0));
}
finally
{
@@ -236,9 +1172,9 @@
initTest();
try
{
- initCounterMonitor(true, new Long(10), new Integer(0),
+ initCounterMonitor(true, new Long(10),
false, new Integer(10), new Integer(10));
- objectNameStartMonitor();
+ objectNameStartMonitor(new Integer(0));
}
finally
{
@@ -256,9 +1192,9 @@
initTest();
try
{
- initCounterMonitor(true, new Integer(10), new Integer(0),
+ initCounterMonitor(true, new Integer(10),
false, new Long(10), new Integer(10));
- objectNameStartMonitor();
+ objectNameStartMonitor(new Integer(0));
}
finally
{
@@ -276,9 +1212,9 @@
initTest();
try
{
- initCounterMonitor(true, new Integer(10), new Integer(0),
+ initCounterMonitor(true, new Integer(10),
false, new Integer(10), new Long(10));
- objectNameStartMonitor();
+ objectNameStartMonitor(new Integer(0));
}
finally
{
@@ -296,9 +1232,9 @@
initTest();
try
{
- initCounterMonitor(true, new Integer(10), new Integer(0),
+ initCounterMonitor(true, new Integer(10),
false, new Integer(10), new Integer(10));
- runtimeErrorStartMonitor();
+ runtimeErrorStartMonitor(new Integer(0));
}
finally
{
@@ -307,6 +1243,27 @@
}
}
+ // Gauge notification tests ------------------------------------------------
+
+ /**
+ * Test the notification info of the gauge
+ */
+ public void testGaugeNotificationInfo()
+ throws Exception
+ {
+ HashSet expected = new HashSet();
+ expected.add(MonitorNotification.OBSERVED_ATTRIBUTE_ERROR);
+ expected.add(MonitorNotification.OBSERVED_ATTRIBUTE_TYPE_ERROR);
+ expected.add(MonitorNotification.OBSERVED_OBJECT_ERROR);
+ expected.add(MonitorNotification.RUNTIME_ERROR);
+ expected.add(MonitorNotification.THRESHOLD_ERROR);
+ expected.add(MonitorNotification.THRESHOLD_HIGH_VALUE_EXCEEDED);
+ expected.add(MonitorNotification.THRESHOLD_LOW_VALUE_EXCEEDED);
+
+ MBeanNotificationInfo[] mbni = new GaugeMonitor().getNotificationInfo();
+ checkNotificationInfo("Gauge", mbni, expected);
+ }
+
// Gauge error tests -------------------------------------------------------
/**
@@ -318,9 +1275,8 @@
initTest();
try
{
- initGaugeMonitor(true, true, new Integer(10), new Integer(0),
- false, new Integer(10));
- attributeErrorStartMonitor();
+ initGaugeMonitor(true, true, new Integer(10), new Integer(0), false);
+ attributeErrorStartMonitor(new Integer(0));
}
finally
{
@@ -338,9 +1294,8 @@
initTest();
try
{
- initGaugeMonitor(true, true, new Integer(10), new Integer(0),
- false, new Integer(10));
- attributeNullStartMonitor();
+ initGaugeMonitor(true, true, new Integer(10), new Integer(0), false);
+ attributeNullStartMonitor(new Integer(0));
}
finally
{
@@ -358,9 +1313,8 @@
initTest();
try
{
- initGaugeMonitor(true, true, new Integer(10), new Integer(0),
- false, new Integer(10));
- attributeTypeStartMonitor();
+ initGaugeMonitor(true, true, new Integer(10), new Integer(0), false);
+ attributeTypeStartMonitor(new Integer(0));
}
finally
{
@@ -378,9 +1332,8 @@
initTest();
try
{
- initGaugeMonitor(true, true, new Integer(10), new Integer(0),
- false, new Integer(10));
- attributeWriteStartMonitor();
+ initGaugeMonitor(true, true, new Integer(10), new Integer(0), false);
+ attributeWriteStartMonitor(new Integer(0));
}
finally
{
@@ -398,9 +1351,8 @@
initTest();
try
{
- initGaugeMonitor(true, true, new Integer(10), new Integer(0),
- false, new Integer(10));
- objectNameStartMonitor();
+ initGaugeMonitor(true, true, new Integer(10), new Integer(0), false);
+ objectNameStartMonitor(new Integer(0));
}
finally
{
@@ -418,9 +1370,8 @@
initTest();
try
{
- initGaugeMonitor(true, true, new Long(10), new Long(0),
- false, new Integer(10));
- objectNameStartMonitor();
+ initGaugeMonitor(true, true, new Long(10), new Long(0), false);
+ objectNameStartMonitor(new Integer(0));
}
finally
{
@@ -438,9 +1389,8 @@
initTest();
try
{
- initGaugeMonitor(true, true, new Integer(10), new Integer(0),
- false, new Integer(10));
- runtimeErrorStartMonitor();
+ initGaugeMonitor(true, true, new Integer(10), new Integer(0), false);
+ runtimeErrorStartMonitor(new Integer(0));
}
finally
{
@@ -449,6 +1399,26 @@
}
}
+ // String notification tests -----------------------------------------------
+
+ /**
+ * Test the notification info of the string
+ */
+ public void testStringNotificationInfo()
+ throws Exception
+ {
+ HashSet expected = new HashSet();
+ expected.add(MonitorNotification.OBSERVED_ATTRIBUTE_ERROR);
+ expected.add(MonitorNotification.OBSERVED_ATTRIBUTE_TYPE_ERROR);
+ expected.add(MonitorNotification.OBSERVED_OBJECT_ERROR);
+ expected.add(MonitorNotification.RUNTIME_ERROR);
+ expected.add(MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED);
+ expected.add(MonitorNotification.STRING_TO_COMPARE_VALUE_MATCHED);
+
+ MBeanNotificationInfo[] mbni = new StringMonitor().getNotificationInfo();
+ checkNotificationInfo("String", mbni, expected);
+ }
+
// String test -------------------------------------------------------------
/**
@@ -460,7 +1430,7 @@
initTest();
try
{
- initStringMonitor(true, false, "Hello", "Goodbye");
+ initStringMonitor(true, false, "Hello");
expectStartMonitor("Goodbye",
MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED);
}
@@ -480,7 +1450,7 @@
initTest();
try
{
- initStringMonitor(true, false, "Hello", "Hello");
+ initStringMonitor(true, false, "Hello");
dontExpectStartMonitor("Hello");
expect("Goodbye",
MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED);
@@ -501,7 +1471,7 @@
initTest();
try
{
- initStringMonitor(true, false, "Hello", "Goodbye");
+ initStringMonitor(true, false, "Hello");
expectStartMonitor("Goodbye",
MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED);
dontExpect("Hello");
@@ -528,7 +1498,7 @@
initTest();
try
{
- initStringMonitor(true, false, "Hello", "Hello");
+ initStringMonitor(true, false, "Hello");
dontExpectStartMonitor("Hello");
expect("Goodbye",
MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED);
@@ -556,7 +1526,7 @@
initTest();
try
{
- initStringMonitor(false, true, "Hello", "Hello");
+ initStringMonitor(false, true, "Hello");
expectStartMonitor("Hello",
MonitorNotification.STRING_TO_COMPARE_VALUE_MATCHED);
}
@@ -576,7 +1546,7 @@
initTest();
try
{
- initStringMonitor(false, true, "Hello", "Goodbye");
+ initStringMonitor(false, true, "Hello");
dontExpectStartMonitor("Goodbye");
expect("Hello",
MonitorNotification.STRING_TO_COMPARE_VALUE_MATCHED);
@@ -597,7 +1567,7 @@
initTest();
try
{
- initStringMonitor(false, true, "Hello", "Hello");
+ initStringMonitor(false, true, "Hello");
expectStartMonitor("Hello",
MonitorNotification.STRING_TO_COMPARE_VALUE_MATCHED);
dontExpect("Goodbye");
@@ -623,7 +1593,7 @@
initTest();
try
{
- initStringMonitor(false, true, "Hello", "Goodbye");
+ initStringMonitor(false, true, "Hello");
dontExpectStartMonitor("Goodbye");
expect("Hello",
MonitorNotification.STRING_TO_COMPARE_VALUE_MATCHED);
@@ -650,7 +1620,7 @@
initTest();
try
{
- initStringMonitor(true, true, "Hello", "Goodbye");
+ initStringMonitor(true, true, "Hello");
expectStartMonitor("Goodbye",
MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED);
expect("Hello",
@@ -672,7 +1642,7 @@
initTest();
try
{
- initStringMonitor(true, true, "Hello", "Goodbye");
+ initStringMonitor(true, true, "Hello");
expectStartMonitor("Goodbye",
MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED);
expect("Hello",
@@ -700,7 +1670,7 @@
initTest();
try
{
- initStringMonitor(false, false, "Hello", "Goodbye");
+ initStringMonitor(false, false, "Hello");
dontExpectStartMonitor("Goodbye");
dontExpect("Hello");
dontExpect("Goodbye");
@@ -723,8 +1693,8 @@
initTest();
try
{
- initStringMonitor(true, true, "Hello", "Goodbye");
- attributeErrorStartMonitor();
+ initStringMonitor(true, true, "Hello");
+ attributeErrorStartMonitor("Goodbye");
}
finally
{
@@ -742,8 +1712,8 @@
initTest();
try
{
- initStringMonitor(true, true, "Hello", "Goodbye");
- attributeNullStartMonitor();
+ initStringMonitor(true, true, "Hello");
+ attributeNullStartMonitor("Goodbye");
}
finally
{
@@ -761,8 +1731,8 @@
initTest();
try
{
- initStringMonitor(true, true, "Hello", "Goodbye");
- attributeTypeStartMonitor();
+ initStringMonitor(true, true, "Hello");
+ attributeTypeStartMonitor("Goodbye");
}
finally
{
@@ -780,8 +1750,8 @@
initTest();
try
{
- initStringMonitor(true, true, "Hello", "Goodbye");
- attributeWriteStartMonitor();
+ initStringMonitor(true, true, "Hello");
+ attributeWriteStartMonitor("Goodbye");
}
finally
{
@@ -799,8 +1769,8 @@
initTest();
try
{
- initStringMonitor(true, true, "Hello", "Goodbye");
- objectNameStartMonitor();
+ initStringMonitor(true, true, "Hello");
+ objectNameStartMonitor("Goodbye");
}
finally
{
@@ -818,8 +1788,8 @@
initTest();
try
{
- initStringMonitor(true, true, "Hello", "Goodbye");
- runtimeErrorStartMonitor();
+ initStringMonitor(true, true, "Hello");
+ runtimeErrorStartMonitor("Goodbye");
}
finally
{
@@ -834,7 +1804,7 @@
* Create a counter monitor
*/
private void initCounterMonitor(boolean notify, Number threshold,
- Number initial, boolean differenceMode, Number offset, Number modulus)
+ boolean differenceMode, Number offset, Number modulus)
{
try
{
@@ -845,7 +1815,6 @@
counterMonitor.setOffset(offset);
counterMonitor.setModulus(modulus);
CounterSupport support = new CounterSupport();
- support.setValue(initial);
monitor = counterMonitor;
monitored = support;
initMonitor();
@@ -868,8 +1837,7 @@
* Create a gauge monitor
*/
private void initGaugeMonitor(boolean notifyHigh, boolean notifyLow,
- Number thresholdHigh, Number thresholdLow, boolean differenceMode,
- Number initial)
+ Number thresholdHigh, Number thresholdLow, boolean differenceMode)
{
try
{
@@ -879,7 +1847,6 @@
gaugeMonitor.setThresholds(thresholdHigh, thresholdLow);
gaugeMonitor.setDifferenceMode(differenceMode);
GaugeSupport support = new GaugeSupport();
- support.setValue(initial);
monitor = gaugeMonitor;
monitored = support;
initMonitor();
@@ -893,8 +1860,7 @@
/**
* Create a string monitor
*/
- private void initStringMonitor(boolean differ, boolean match,
- String compare, String initial)
+ private void initStringMonitor(boolean differ, boolean match, String compare)
{
try
{
@@ -903,7 +1869,6 @@
stringMonitor.setNotifyMatch(match);
stringMonitor.setStringToCompare(compare);
StringSupport support = new StringSupport();
- support.setValue(initial);
monitor = stringMonitor;
monitored = support;
initMonitor();
@@ -945,6 +1910,7 @@
{
if (monitor != null)
{
+ monitored.end();
monitor.stop();
}
}
@@ -954,19 +1920,35 @@
*/
public void handleNotification(Notification n, Object ignored)
{
- // Make sure the test is ready to receive the notification
- monitored.lock("get");
-
- notifications.add(n);
+ synchronized(notifications)
+ {
+ notifications.add(n);
+ notifications.notifyAll();
+ }
+ }
- // Let the test continue
- monitored.unlock("get");
+ /**
+ * Sync with the notification handler
+ */
+ private void sync(boolean getWorks)
+ throws Exception
+ {
+ // Make sure the monitor has got the attribute
+ if (getWorks)
+ waitCycle();
+ else
+ {
+ synchronized(notifications)
+ {
+ notifications.wait(MonitorSUITE.MAX_WAIT);
+ }
+ }
}
/**
* Invalid attribute start monitor
*/
- private void attributeErrorStartMonitor()
+ private void attributeErrorStartMonitor(Object initial)
throws Exception
{
assertEquals(0, notifications.size());
@@ -980,12 +1962,17 @@
assertEquals(monitoredName, n.getObservedObject());
assertEquals("rubbish", n.getObservedAttribute());
assertEquals(MonitorNotification.OBSERVED_ATTRIBUTE_ERROR, n.getType());
+ n = serializeDeserialize(n);
+ assertEquals(monitorName, n.getSource());
+ assertEquals(monitoredName, n.getObservedObject());
+ assertEquals("rubbish", n.getObservedAttribute());
+ assertEquals(MonitorNotification.OBSERVED_ATTRIBUTE_ERROR, n.getType());
}
/**
* Invalid attribute null start monitor
*/
- private void attributeNullStartMonitor()
+ private void attributeNullStartMonitor(Object initial)
throws Exception
{
assertEquals(0, notifications.size());
@@ -1000,12 +1987,18 @@
assertEquals("WrongNull", n.getObservedAttribute());
assertEquals(MonitorNotification.OBSERVED_ATTRIBUTE_TYPE_ERROR,
n.getType());
+ n = serializeDeserialize(n);
+ assertEquals(monitorName, n.getSource());
+ assertEquals(monitoredName, n.getObservedObject());
+ assertEquals("WrongNull", n.getObservedAttribute());
+ assertEquals(MonitorNotification.OBSERVED_ATTRIBUTE_TYPE_ERROR,
+ n.getType());
}
/**
* Invalid attribute type start monitor
*/
- private void attributeTypeStartMonitor()
+ private void attributeTypeStartMonitor(Object initial)
throws Exception
{
assertEquals(0, notifications.size());
@@ -1020,12 +2013,17 @@
assertEquals("WrongType", n.getObservedAttribute());
assertEquals(MonitorNotification.OBSERVED_ATTRIBUTE_TYPE_ERROR,
n.getType());
+ n = serializeDeserialize(n);
+ assertEquals(monitoredName, n.getObservedObject());
+ assertEquals("WrongType", n.getObservedAttribute());
+ assertEquals(MonitorNotification.OBSERVED_ATTRIBUTE_TYPE_ERROR,
+ n.getType());
}
/**
* Write only Attribute start monitor
*/
- private void attributeWriteStartMonitor()
+ private void attributeWriteStartMonitor(Object initial)
throws Exception
{
assertEquals(0, notifications.size());
@@ -1040,12 +2038,18 @@
assertEquals("WriteOnly", n.getObservedAttribute());
assertEquals(MonitorNotification.OBSERVED_ATTRIBUTE_ERROR,
n.getType());
+ n = serializeDeserialize(n);
+ assertEquals(monitorName, n.getSource());
+ assertEquals(monitoredName, n.getObservedObject());
+ assertEquals("WriteOnly", n.getObservedAttribute());
+ assertEquals(MonitorNotification.OBSERVED_ATTRIBUTE_ERROR,
+ n.getType());
}
/**
* Invalid objectName start monitor
*/
- private void objectNameStartMonitor()
+ private void objectNameStartMonitor(Object initial)
throws Exception
{
assertEquals(0, notifications.size());
@@ -1061,12 +2065,18 @@
assertEquals("Value", n.getObservedAttribute());
assertEquals(MonitorNotification.OBSERVED_OBJECT_ERROR,
n.getType());
+ n = serializeDeserialize(n);
+ assertEquals(monitorName, n.getSource());
+ assertEquals(monitoredName, n.getObservedObject());
+ assertEquals("Value", n.getObservedAttribute());
+ assertEquals(MonitorNotification.OBSERVED_OBJECT_ERROR,
+ n.getType());
}
/**
* Invalid threshold start monitor
*/
- private void thresholdStartMonitor()
+ private void thresholdStartMonitor(Object initial)
throws Exception
{
assertEquals(0, notifications.size());
@@ -1080,25 +2090,26 @@
assertEquals("Value", n.getObservedAttribute());
assertEquals(MonitorNotification.THRESHOLD_ERROR,
n.getType());
+ n = serializeDeserialize(n);
+ assertEquals(monitorName, n.getSource());
+ assertEquals(monitoredName, n.getObservedObject());
+ assertEquals("Value", n.getObservedAttribute());
+ assertEquals(MonitorNotification.THRESHOLD_ERROR,
+ n.getType());
}
/**
* runtime error start monitor
*/
- private void runtimeErrorStartMonitor()
+ private void runtimeErrorStartMonitor(Object initial)
throws Exception
{
assertEquals(0, notifications.size());
monitor.setObservedAttribute("WrongException");
monitor.start();
- try
- {
- sync(false);
- }
- catch(Exception e)
- {
- fail("FAILS IN RI: No notification of exception thrown by getter");
- }
+ sync(false);
+ if (notifications.size() != 1)
+ fail ("FAILS IN RI: Does not notify of error thrown by getter");
assertEquals(1, notifications.size());
MonitorNotification n = (MonitorNotification) notifications.get(0);
notifications.clear();
@@ -1107,6 +2118,12 @@
assertEquals("WrongException", n.getObservedAttribute());
assertEquals(MonitorNotification.RUNTIME_ERROR,
n.getType());
+ n = serializeDeserialize(n);
+ assertEquals(monitorName, n.getSource());
+ assertEquals(monitoredName, n.getObservedObject());
+ assertEquals("WrongException", n.getObservedAttribute());
+ assertEquals(MonitorNotification.RUNTIME_ERROR,
+ n.getType());
}
/**
@@ -1117,6 +2134,7 @@
{
assertEquals(0, notifications.size());
monitor.start();
+ setValue(expected);
// Synchronize the notification
sync(true);
@@ -1131,36 +2149,49 @@
assertEquals("Value", n.getObservedAttribute());
assertEquals(type, n.getType());
assertEquals(expected, n.getDerivedGauge());
-
- // Allow the monitor to send an incorrect further notification
- waitCycle();
- monitored.lock("set");
- assertEquals(0, notifications.size());
- monitored.unlock("set");
+ n = serializeDeserialize(n);
+ assertEquals(monitorName, n.getSource());
+ assertEquals(monitoredName, n.getObservedObject());
+ assertEquals("Value", n.getObservedAttribute());
+ assertEquals(type, n.getType());
+ assertEquals(expected, n.getDerivedGauge());
}
/**
* Start a monitor, don't expect a notification
*/
- private void dontExpectStartMonitor(String initial)
+ private void dontExpectStartMonitor(Object initial)
throws Exception
{
assertEquals(0, notifications.size());
monitor.start();
-
- // Make sure the monitor has peformed the get
- monitored.unlock("set");
+ setValue(initial);
waitCycle();
- monitored.lock("set");
- checkGauge(initial);
assertEquals(0, notifications.size());
- monitored.unlock("set");
+ checkGauge(initial);
+ }
- // Give the monitor change to send a further notification
+ /**
+ * Start a monitor, don't expect a notification difference
+ */
+ private void dontExpectStartMonitorDiff(Object value1, Object value2)
+ throws Exception
+ {
+ monitor.start();
+ setValue(value1);
waitCycle();
- monitored.lock("set");
assertEquals(0, notifications.size());
- monitored.unlock("set");
+ setValue(value2);
+ waitCycle();
+ assertEquals(0, notifications.size());
+ checkGauge(sub(value2, value1));
+ }
+
+ private void setValue(Object value)
+ throws Exception
+ {
+ monitored.lock("set");
+ server.setAttribute(monitoredName, new Attribute("Value", value));
}
/**
@@ -1170,7 +2201,7 @@
throws Exception
{
assertEquals(0, notifications.size());
- server.setAttribute(monitoredName, new Attribute("Value", expected));
+ setValue(expected);
// Synchronize the notification
sync(true);
@@ -1185,12 +2216,32 @@
assertEquals("Value", n.getObservedAttribute());
assertEquals(type, n.getType());
assertEquals(gauge, n.getDerivedGauge());
+ }
- // Give the monitor chance to further unexpected notification
+ /**
+ * Expect a notification difference
+ */
+ private void expectDiff(Object value1, Object value2, String type)
+ throws Exception
+ {
+ waitCycle();
+ notifications.clear();
+ setValue(value1);
waitCycle();
- monitored.lock("set");
assertEquals(0, notifications.size());
- monitored.unlock("set");
+ setValue(value2);
+ sync(true);
+
+ // Check the result
+ checkGauge(sub(value2, value1));
+ assertEquals(1, notifications.size());
+ MonitorNotification n = (MonitorNotification) notifications.get(0);
+ notifications.clear();
+ assertEquals(monitorName, n.getSource());
+ assertEquals(monitoredName, n.getObservedObject());
+ assertEquals("Value", n.getObservedAttribute());
+ assertEquals(type, n.getType());
+ assertEquals(sub(value2, value1), n.getDerivedGauge());
}
/**
@@ -1209,22 +2260,44 @@
throws Exception
{
assertEquals(0, notifications.size());
- server.setAttribute(monitoredName, new Attribute("Value", unexpected));
-
- // Allow the monitor to get the value
- monitored.unlock("set");
+ setValue(unexpected);
waitCycle();
-
- // Make sure the monitor has done the get and is waiting for the next one
- monitored.lock("set");
+ assertEquals(0, notifications.size());
checkGauge(unexpected);
+ }
- // Give the monitor another change to spot further notifications
- monitored.unlock("set");
+ /**
+ * Don't expect a notification
+ */
+ private void dontExpectDiff(Object value1, Object value2)
+ throws Exception
+ {
+ waitCycle();
+ notifications.clear();
+ setValue(value1);
waitCycle();
- monitored.lock("set");
assertEquals(0, notifications.size());
- monitored.unlock("set");
+ setValue(value2);
+ waitCycle();
+ assertEquals(0, notifications.size());
+ checkGauge(sub(value2, value1));
+ }
+
+ /**
+ * Don't expect a notification
+ */
+ private void dontExpectDiffModulus(Object value1, Object value2, Object value3)
+ throws Exception
+ {
+ waitCycle();
+ notifications.clear();
+ setValue(value1);
+ waitCycle();
+ assertEquals(0, notifications.size());
+ setValue(value2);
+ waitCycle();
+ assertEquals(0, notifications.size());
+ checkGauge(add(sub(value2, value1), value3));
}
/**
@@ -1244,25 +2317,90 @@
}
/**
- * Sync with the notification handler
- */
- private void sync(boolean getWorks)
- {
- // Unlock from the set operation
- monitored.unlock("set");
- // Allow the monitor to get the attribute, unless get errors
- if (getWorks)
- waitCycle();
- // Make sure the monitor is waiting to try again
- waitCycle();
- }
-
- /**
* Wait one cycle of the monitor
*/
private void waitCycle()
{
- monitored.lock("set");
monitored.unlock("set");
+ monitored.lock("set");
}
+
+ /**
+ * Add two numbers.
+ * @param value1 the first value.
+ * @param value2 the second value.
+ * @return value1 + value2 of the correct type
+ */
+ private Number add(Object value1, Object value2)
+ {
+ if (value1 instanceof Byte)
+ return new Byte((byte) (((Byte)value1).byteValue() +
((Byte)value2).byteValue()));
+ if (value1 instanceof Integer)
+ return new Integer(((Integer)value1).intValue() +
((Integer)value2).intValue());
+ if (value1 instanceof Short)
+ return new Short((short) (((Short)value1).shortValue() +
((Short)value2).shortValue()));
+ if (value1 instanceof Long)
+ return new Long(((Long)value1).longValue() + ((Long)value2).longValue());
+ fail("You idiot!");
+ return null;
+ }
+
+ /**
+ * Subtract two numbers.
+ * @param value1 the first value.
+ * @param value2 the second value.
+ * @return value1 - value2 of the correct type
+ */
+ private Number sub(Object value1, Object value2)
+ {
+ if (value1 instanceof Byte)
+ return new Byte((byte) (((Byte)value1).byteValue() -
((Byte)value2).byteValue()));
+ if (value1 instanceof Integer)
+ return new Integer(((Integer)value1).intValue() -
((Integer)value2).intValue());
+ if (value1 instanceof Short)
+ return new Short((short) (((Short)value1).shortValue() -
((Short)value2).shortValue()));
+ if (value1 instanceof Long)
+ return new Long(((Long)value1).longValue() - ((Long)value2).longValue());
+ fail("You idiot!");
+ return null;
+ }
+
+ /**
+ * Check the notification info is as expected
+ *
+ * @param mbni the received notification info
+ * @param expected the expected notifications
+ */
+ private void checkNotificationInfo(String type,
+ MBeanNotificationInfo[] mbni,
+ HashSet expected)
+ {
+ String[] types = mbni[0].getNotifTypes();
+ for (int i = 0; i < types.length; i++)
+ if (expected.remove(types[i]) == false)
+ fail(type + ": didn't expect notification type " + types[i]);
+ Iterator iterator = expected.iterator();
+ while (iterator.hasNext())
+ fail(type + ": expected notification type " + iterator.next());
+ }
+
+ /**
+ * Serialize/Derserialize the notification
+ *
+ * @param n the notification
+ * @return the notification after serialize/deserialze
+ */
+ private MonitorNotification serializeDeserialize(MonitorNotification n)
+ throws Exception
+ {
+ // Serialize it
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+ oos.writeObject(n);
+
+ // Deserialize it
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+ ObjectInputStream ois = new ObjectInputStream(bais);
+ return (MonitorNotification) ois.readObject();
+ }
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development