0001: /*
0002: * JBoss, Home of Professional Open Source.
0003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
0004: * as indicated by the @author tags. See the copyright.txt file in the
0005: * distribution for a full listing of individual contributors.
0006: *
0007: * This is free software; you can redistribute it and/or modify it
0008: * under the terms of the GNU Lesser General Public License as
0009: * published by the Free Software Foundation; either version 2.1 of
0010: * the License, or (at your option) any later version.
0011: *
0012: * This software is distributed in the hope that it will be useful,
0013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
0014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0015: * Lesser General Public License for more details.
0016: *
0017: * You should have received a copy of the GNU Lesser General Public
0018: * License along with this software; if not, write to the Free
0019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
0020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
0021: */
0022: package test.compliance.monitor;
0023:
0024: import java.io.ByteArrayInputStream;
0025: import java.io.ByteArrayOutputStream;
0026: import java.io.ObjectInputStream;
0027: import java.io.ObjectOutputStream;
0028: import java.util.ArrayList;
0029: import java.util.HashSet;
0030: import java.util.Iterator;
0031:
0032: import javax.management.Attribute;
0033: import javax.management.MBeanNotificationInfo;
0034: import javax.management.MBeanServer;
0035: import javax.management.MBeanServerFactory;
0036: import javax.management.Notification;
0037: import javax.management.NotificationListener;
0038: import javax.management.ObjectName;
0039: import javax.management.monitor.CounterMonitor;
0040: import javax.management.monitor.GaugeMonitor;
0041: import javax.management.monitor.Monitor;
0042: import javax.management.monitor.MonitorNotification;
0043: import javax.management.monitor.StringMonitor;
0044:
0045: import junit.framework.AssertionFailedError;
0046: import junit.framework.TestCase;
0047: import test.compliance.monitor.support.CounterSupport;
0048: import test.compliance.monitor.support.GaugeSupport;
0049: import test.compliance.monitor.support.MonitorSupport;
0050: import test.compliance.monitor.support.StringSupport;
0051:
0052: /**
0053: * Monitor Notification Tests
0054: *
0055: * @author <a href="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>.
0056: */
0057: public class MonitorTestCase extends TestCase implements
0058: NotificationListener {
0059: // Constants ---------------------------------------------------------------
0060:
0061: // Attributes --------------------------------------------------------------
0062:
0063: /**
0064: * The MBeanServer
0065: */
0066: MBeanServer server;
0067:
0068: /**
0069: * The object name of the monitor service
0070: */
0071: ObjectName monitorName;
0072:
0073: /**
0074: * The monitor
0075: */
0076: Monitor monitor;
0077:
0078: /**
0079: * The object name of the mbean monitored
0080: */
0081: ObjectName monitoredName;
0082:
0083: /**
0084: * The monitored mbean
0085: */
0086: MonitorSupport monitored;
0087:
0088: /**
0089: * The notifications
0090: */
0091: ArrayList notifications = new ArrayList();
0092:
0093: // Constructor -------------------------------------------------------------
0094:
0095: /**
0096: * Construct the test
0097: */
0098: public MonitorTestCase(String s) {
0099: super (s);
0100: }
0101:
0102: // Tests -------------------------------------------------------------------
0103:
0104: /**
0105: * Test notification types differ
0106: */
0107: public void testNotificationTypes() {
0108: assertEquals(MonitorNotification.OBSERVED_ATTRIBUTE_ERROR,
0109: "jmx.monitor.error.attribute");
0110: assertEquals(MonitorNotification.OBSERVED_ATTRIBUTE_TYPE_ERROR,
0111: "jmx.monitor.error.type");
0112: assertEquals(MonitorNotification.OBSERVED_OBJECT_ERROR,
0113: "jmx.monitor.error.mbean");
0114: assertEquals(MonitorNotification.RUNTIME_ERROR,
0115: "jmx.monitor.error.runtime");
0116: assertEquals(
0117: MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED,
0118: "jmx.monitor.string.differs");
0119: assertEquals(
0120: MonitorNotification.STRING_TO_COMPARE_VALUE_MATCHED,
0121: "jmx.monitor.string.matches");
0122: assertEquals(MonitorNotification.THRESHOLD_ERROR,
0123: "jmx.monitor.error.threshold");
0124: assertEquals(MonitorNotification.THRESHOLD_HIGH_VALUE_EXCEEDED,
0125: "jmx.monitor.gauge.high");
0126: assertEquals(MonitorNotification.THRESHOLD_LOW_VALUE_EXCEEDED,
0127: "jmx.monitor.gauge.low");
0128: assertEquals(MonitorNotification.THRESHOLD_VALUE_EXCEEDED,
0129: "jmx.monitor.counter.threshold");
0130: }
0131:
0132: // Counter monitor notification info ---------------------------------------
0133:
0134: /**
0135: * Test the notification info of the counter
0136: */
0137: public void testCounterNotificationInfo() throws Exception {
0138: HashSet expected = new HashSet();
0139: expected.add(MonitorNotification.OBSERVED_ATTRIBUTE_ERROR);
0140: expected.add(MonitorNotification.OBSERVED_ATTRIBUTE_TYPE_ERROR);
0141: expected.add(MonitorNotification.OBSERVED_OBJECT_ERROR);
0142: expected.add(MonitorNotification.RUNTIME_ERROR);
0143: expected.add(MonitorNotification.THRESHOLD_ERROR);
0144: expected.add(MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0145:
0146: MBeanNotificationInfo[] mbni = new CounterMonitor()
0147: .getNotificationInfo();
0148: checkNotificationInfo("Counter", mbni, expected);
0149: }
0150:
0151: // Counter normal no offset no modulus tests -------------------------------
0152:
0153: /**
0154: * Test normal counter threshold no offset no modulus
0155: */
0156: public void testNormalCounterThresholdExceededEarlyNoOffsetNoModulus()
0157: throws Exception {
0158: initTest();
0159: try {
0160: initCounterMonitor(true, new Integer(10), false,
0161: new Integer(0), new Integer(0));
0162: expectStartMonitor(new Integer(10),
0163: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0164: } finally {
0165: stopMonitor();
0166: MBeanServerFactory.releaseMBeanServer(server);
0167: }
0168: }
0169:
0170: /**
0171: * Test normal counter threshold no offset no modulus
0172: */
0173: public void testNormalCounterThresholdExceededLateNoOffsetNoModulus()
0174: throws Exception {
0175: initTest();
0176: try {
0177: initCounterMonitor(true, new Integer(10), false,
0178: new Integer(0), new Integer(0));
0179: dontExpectStartMonitor(new Integer(0));
0180: expect(new Integer(10),
0181: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0182: } finally {
0183: stopMonitor();
0184: MBeanServerFactory.releaseMBeanServer(server);
0185: }
0186: }
0187:
0188: /**
0189: * Test normal counter threshold no offset no modulus
0190: */
0191: public void testNormalCounterThresholdExceededManyNoOffsetNoModulus()
0192: throws Exception {
0193: initTest();
0194: try {
0195: initCounterMonitor(true, new Integer(10), false,
0196: new Integer(0), new Integer(0));
0197: dontExpectStartMonitor(new Integer(0));
0198: expect(new Integer(10),
0199: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0200: dontExpect(new Integer(0));
0201: expect(new Integer(11),
0202: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0203: } finally {
0204: stopMonitor();
0205: MBeanServerFactory.releaseMBeanServer(server);
0206: }
0207: }
0208:
0209: /**
0210: * Test normal counter threshold no offset no modulus
0211: */
0212: public void testNormalCounterThresholdNotExceededNoOffsetNoModulus()
0213: throws Exception {
0214: initTest();
0215: try {
0216: initCounterMonitor(true, new Integer(10), false,
0217: new Integer(0), new Integer(0));
0218: dontExpectStartMonitor(new Integer(0));
0219: dontExpect(new Integer(1));
0220: dontExpect(new Integer(-1));
0221: dontExpect(new Integer(9));
0222: expect(new Integer(10),
0223: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0224: dontExpect(new Integer(10));
0225: dontExpect(new Integer(11));
0226: dontExpect(new Integer(9));
0227: expect(new Integer(10),
0228: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0229: dontExpect(new Integer(9));
0230: } finally {
0231: stopMonitor();
0232: MBeanServerFactory.releaseMBeanServer(server);
0233: }
0234: }
0235:
0236: /**
0237: * Test normal counter threshold no offset no modulus
0238: */
0239: public void testNormalCounterThresholdExceededNoneNoOffsetNoModulus()
0240: throws Exception {
0241: initTest();
0242: try {
0243: initCounterMonitor(false, new Integer(10), false,
0244: new Integer(0), new Integer(0));
0245: dontExpectStartMonitor(new Integer(0));
0246: dontExpect(new Integer(10));
0247: dontExpect(new Integer(0));
0248: dontExpect(new Integer(10));
0249: } finally {
0250: stopMonitor();
0251: MBeanServerFactory.releaseMBeanServer(server);
0252: }
0253: }
0254:
0255: // Counter normal offset no modulus tests ----------------------------------
0256:
0257: /**
0258: * Test normal counter threshold offset no modulus
0259: */
0260: public void testNormalCounterThresholdExceededEarlyOffsetNoModulus()
0261: throws Exception {
0262: initTest();
0263: try {
0264: initCounterMonitor(true, new Integer(10), false,
0265: new Integer(10), new Integer(0));
0266: expectStartMonitor(new Integer(10),
0267: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0268: } finally {
0269: stopMonitor();
0270: MBeanServerFactory.releaseMBeanServer(server);
0271: }
0272: }
0273:
0274: /**
0275: * Test normal counter threshold offset no modulus
0276: */
0277: public void testNormalCounterThresholdExceededLateOffsetNoModulus()
0278: throws Exception {
0279: initTest();
0280: try {
0281: initCounterMonitor(true, new Integer(10), false,
0282: new Integer(10), new Integer(0));
0283: dontExpectStartMonitor(new Integer(0));
0284: expect(new Integer(10),
0285: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0286: } finally {
0287: stopMonitor();
0288: MBeanServerFactory.releaseMBeanServer(server);
0289: }
0290: }
0291:
0292: /**
0293: * Test normal counter threshold offset no modulus
0294: */
0295: public void testNormalCounterThresholdExceededManyOffsetNoModulus()
0296: throws Exception {
0297: initTest();
0298: try {
0299: initCounterMonitor(true, new Integer(10), false,
0300: new Integer(10), new Integer(0));
0301: dontExpectStartMonitor(new Integer(0));
0302: expect(new Integer(10),
0303: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0304: dontExpect(new Integer(0));
0305: dontExpect(new Integer(11));
0306: expect(new Integer(20),
0307: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0308: dontExpect(new Integer(29));
0309: expect(new Integer(30),
0310: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0311: expect(new Integer(40),
0312: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0313: } finally {
0314: stopMonitor();
0315: MBeanServerFactory.releaseMBeanServer(server);
0316: }
0317: }
0318:
0319: /**
0320: * Test normal counter threshold offset no modulus
0321: */
0322: public void testNormalCounterThresholdNotExceededOffsetNoModulus()
0323: throws Exception {
0324: initTest();
0325: try {
0326: initCounterMonitor(true, new Integer(10), false,
0327: new Integer(10), new Integer(0));
0328: dontExpectStartMonitor(new Integer(0));
0329: dontExpect(new Integer(1));
0330: dontExpect(new Integer(-1));
0331: dontExpect(new Integer(9));
0332: expect(new Integer(10),
0333: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0334: dontExpect(new Integer(10));
0335: dontExpect(new Integer(11));
0336: dontExpect(new Integer(9));
0337: expect(new Integer(20),
0338: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0339: dontExpect(new Integer(19));
0340: } finally {
0341: stopMonitor();
0342: MBeanServerFactory.releaseMBeanServer(server);
0343: }
0344: }
0345:
0346: /**
0347: * Test normal counter threshold offset no modulus
0348: */
0349: public void testNormalCounterThresholdExceededNoneOffsetNoModulus()
0350: throws Exception {
0351: initTest();
0352: try {
0353: initCounterMonitor(false, new Integer(10), false,
0354: new Integer(10), new Integer(0));
0355: dontExpectStartMonitor(new Integer(0));
0356: dontExpect(new Integer(10));
0357: dontExpect(new Integer(0));
0358: dontExpect(new Integer(20));
0359: } finally {
0360: stopMonitor();
0361: MBeanServerFactory.releaseMBeanServer(server);
0362: }
0363: }
0364:
0365: // Counter normal no offset modulus tests ---------------------------------
0366:
0367: /**
0368: * Test normal counter threshold no offset modulus
0369: */
0370: public void testNormalCounterThresholdExceededEarlyNoOffsetModulus()
0371: throws Exception {
0372: initTest();
0373: try {
0374: initCounterMonitor(true, new Integer(10), false,
0375: new Integer(0), new Integer(10));
0376: expectStartMonitor(new Integer(10),
0377: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0378: } finally {
0379: stopMonitor();
0380: MBeanServerFactory.releaseMBeanServer(server);
0381: }
0382: }
0383:
0384: /**
0385: * Test normal counter threshold no offset modulus
0386: */
0387: public void testNormalCounterThresholdExceededLateNoOffsetModulus()
0388: throws Exception {
0389: initTest();
0390: try {
0391: initCounterMonitor(true, new Integer(10), false,
0392: new Integer(0), new Integer(10));
0393: dontExpectStartMonitor(new Integer(0));
0394: expect(new Integer(10),
0395: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0396: } finally {
0397: stopMonitor();
0398: MBeanServerFactory.releaseMBeanServer(server);
0399: }
0400: }
0401:
0402: /**
0403: * Test normal counter threshold no offset modulus
0404: */
0405: public void testNormalCounterThresholdExceededManyNoOffsetModulus()
0406: throws Exception {
0407: initTest();
0408: try {
0409: initCounterMonitor(true, new Integer(10), false,
0410: new Integer(0), new Integer(10));
0411: dontExpectStartMonitor(new Integer(0));
0412: expect(new Integer(10),
0413: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0414: dontExpect(new Integer(0));
0415: expect(new Integer(11),
0416: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0417: expect(new Integer(12),
0418: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0419: dontExpect(new Integer(0));
0420: expect(new Integer(10),
0421: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0422: } catch (AssertionFailedError e) {
0423: fail("FAILS IN RI: Modulus ignored with no offset???");
0424: } finally {
0425: stopMonitor();
0426: MBeanServerFactory.releaseMBeanServer(server);
0427: }
0428: }
0429:
0430: /**
0431: * Test normal counter threshold no offset modulus
0432: */
0433: public void testNormalCounterThresholdNotExceededNoOffsetModulus()
0434: throws Exception {
0435: initTest();
0436: try {
0437: initCounterMonitor(true, new Integer(10), false,
0438: new Integer(0), new Integer(10));
0439: dontExpectStartMonitor(new Integer(0));
0440: dontExpect(new Integer(1));
0441: dontExpect(new Integer(-1));
0442: dontExpect(new Integer(9));
0443: expect(new Integer(10),
0444: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0445: dontExpect(new Integer(9));
0446: expect(new Integer(10),
0447: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0448: dontExpect(new Integer(9));
0449: } finally {
0450: stopMonitor();
0451: MBeanServerFactory.releaseMBeanServer(server);
0452: }
0453: }
0454:
0455: /**
0456: * Test normal counter threshold no offset modulus
0457: */
0458: public void testNormalCounterThresholdExceededNoneNoOffsetModulus()
0459: throws Exception {
0460: initTest();
0461: try {
0462: initCounterMonitor(false, new Integer(10), false,
0463: new Integer(0), new Integer(10));
0464: dontExpectStartMonitor(new Integer(0));
0465: dontExpect(new Integer(10));
0466: dontExpect(new Integer(0));
0467: dontExpect(new Integer(10));
0468: } finally {
0469: stopMonitor();
0470: MBeanServerFactory.releaseMBeanServer(server);
0471: }
0472: }
0473:
0474: // Counter normal offset modulus tests -------------------------------------
0475:
0476: /**
0477: * Test normal counter threshold offset modulus
0478: */
0479: public void testNormalCounterThresholdExceededEarlyOffsetModulus()
0480: throws Exception {
0481: initTest();
0482: try {
0483: initCounterMonitor(true, new Integer(10), false,
0484: new Integer(10), new Integer(10));
0485: expectStartMonitor(new Integer(10),
0486: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0487: } finally {
0488: stopMonitor();
0489: MBeanServerFactory.releaseMBeanServer(server);
0490: }
0491: }
0492:
0493: /**
0494: * Test normal counter threshold offset modulus
0495: */
0496: public void testNormalCounterThresholdExceededLateOffsetModulus()
0497: throws Exception {
0498: initTest();
0499: try {
0500: initCounterMonitor(true, new Integer(10), false,
0501: new Integer(10), new Integer(10));
0502: dontExpectStartMonitor(new Integer(0));
0503: expect(new Integer(10),
0504: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0505: } finally {
0506: stopMonitor();
0507: MBeanServerFactory.releaseMBeanServer(server);
0508: }
0509: }
0510:
0511: /**
0512: * Test normal counter threshold offset modulus
0513: */
0514: public void testNormalCounterThresholdExceededManyOffsetModulus()
0515: throws Exception {
0516: initTest();
0517: try {
0518: initCounterMonitor(true, new Integer(10), false,
0519: new Integer(10), new Integer(20));
0520: dontExpectStartMonitor(new Integer(0));
0521: expect(new Integer(10),
0522: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0523: dontExpect(new Integer(0));
0524: dontExpect(new Integer(12));
0525: expect(new Integer(20),
0526: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0527: if (((CounterMonitor) monitor).getThreshold().equals(
0528: new Integer(30)))
0529: fail("FAILS IN RI: Threshold 10, Offset 10, Modulus 20 should "
0530: + " never get a threshold of 30");
0531: expect(new Integer(10),
0532: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0533: dontExpect(new Integer(10));
0534: expect(new Integer(20),
0535: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0536: expect(new Integer(20),
0537: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0538: expect(new Integer(30),
0539: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0540: } finally {
0541: stopMonitor();
0542: MBeanServerFactory.releaseMBeanServer(server);
0543: }
0544: }
0545:
0546: /**
0547: * Test normal counter threshold offset modulus
0548: */
0549: public void testNormalCounterThresholdNotExceededOffsetModulus()
0550: throws Exception {
0551: initTest();
0552: try {
0553: initCounterMonitor(true, new Integer(10), false,
0554: new Integer(10), new Integer(20));
0555: dontExpectStartMonitor(new Integer(0));
0556: dontExpect(new Integer(1));
0557: dontExpect(new Integer(-1));
0558: dontExpect(new Integer(9));
0559: expect(new Integer(10),
0560: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0561: dontExpect(new Integer(10));
0562: dontExpect(new Integer(11));
0563: dontExpect(new Integer(9));
0564: expect(new Integer(20),
0565: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0566: if (((CounterMonitor) monitor).getThreshold().equals(
0567: new Integer(30)))
0568: fail("FAILS IN RI: Threshold 10, Offset 10, Modulus 20 should "
0569: + " never get a threshold of 30");
0570: expect(new Integer(19),
0571: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0572: } finally {
0573: stopMonitor();
0574: MBeanServerFactory.releaseMBeanServer(server);
0575: }
0576: }
0577:
0578: /**
0579: * Test normal counter threshold offset modulus
0580: */
0581: public void testNormalCounterThresholdExceededNoneOffsetModulus()
0582: throws Exception {
0583: initTest();
0584: try {
0585: initCounterMonitor(false, new Integer(10), false,
0586: new Integer(10), new Integer(10));
0587: dontExpectStartMonitor(new Integer(0));
0588: dontExpect(new Integer(10));
0589: dontExpect(new Integer(0));
0590: dontExpect(new Integer(20));
0591: } finally {
0592: stopMonitor();
0593: MBeanServerFactory.releaseMBeanServer(server);
0594: }
0595: }
0596:
0597: // Counter difference no offset no modulus tests ---------------------------
0598:
0599: /**
0600: * Test difference counter threshold no offset no modulus
0601: */
0602: public void testDiffCounterThresholdExceededNoOffsetNoModulus()
0603: throws Exception {
0604: initTest();
0605: try {
0606: initCounterMonitor(true, new Integer(10), true,
0607: new Integer(0), new Integer(0));
0608: dontExpectStartMonitor(new Integer(0));
0609: expect(new Integer(10),
0610: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0611: } finally {
0612: stopMonitor();
0613: MBeanServerFactory.releaseMBeanServer(server);
0614: }
0615: }
0616:
0617: /**
0618: * Test difference counter threshold no offset no modulus
0619: */
0620: public void testDiffCounterThresholdExceededManyNoOffsetNoModulus()
0621: throws Exception {
0622: initTest();
0623: try {
0624: initCounterMonitor(true, new Integer(10), true,
0625: new Integer(0), new Integer(0));
0626: dontExpectStartMonitor(new Integer(0));
0627: expect(new Integer(10),
0628: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0629: expectDiff(new Integer(0), new Integer(11),
0630: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0631: } finally {
0632: stopMonitor();
0633: MBeanServerFactory.releaseMBeanServer(server);
0634: }
0635: }
0636:
0637: /**
0638: * Test difference counter threshold no offset no modulus
0639: */
0640: public void testDiffCounterThresholdNotExceededNoOffsetNoModulus()
0641: throws Exception {
0642: initTest();
0643: try {
0644: initCounterMonitor(true, new Integer(10), true,
0645: new Integer(0), new Integer(0));
0646: dontExpectStartMonitorDiff(new Integer(0), new Integer(1));
0647: dontExpectDiff(new Integer(0), new Integer(9));
0648: dontExpectDiff(new Integer(1), new Integer(10));
0649: dontExpectDiff(new Integer(9), new Integer(11));
0650: dontExpectDiff(new Integer(9), new Integer(0));
0651: } finally {
0652: stopMonitor();
0653: MBeanServerFactory.releaseMBeanServer(server);
0654: }
0655: }
0656:
0657: /**
0658: * Test difference counter threshold no offset no modulus
0659: */
0660: public void testDiffCounterThresholdExceededNoneNoOffsetNoModulus()
0661: throws Exception {
0662: initTest();
0663: try {
0664: initCounterMonitor(false, new Integer(10), true,
0665: new Integer(0), new Integer(0));
0666: dontExpectStartMonitorDiff(new Integer(0), new Integer(10));
0667: dontExpectDiff(new Integer(0), new Integer(-10));
0668: dontExpectDiff(new Integer(0), new Integer(100));
0669: } finally {
0670: stopMonitor();
0671: MBeanServerFactory.releaseMBeanServer(server);
0672: }
0673: }
0674:
0675: // Counter difference offset no modulus tests ------------------------------
0676:
0677: /**
0678: * Test difference counter threshold offset no modulus
0679: */
0680: public void testDiffCounterThresholdExceededOffsetNoModulus()
0681: throws Exception {
0682: initTest();
0683: try {
0684: initCounterMonitor(true, new Integer(10), true,
0685: new Integer(10), new Integer(0));
0686: dontExpectStartMonitor(new Integer(0));
0687: expect(new Integer(10),
0688: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0689: } finally {
0690: stopMonitor();
0691: MBeanServerFactory.releaseMBeanServer(server);
0692: }
0693: }
0694:
0695: /**
0696: * Test difference counter threshold offset no modulus
0697: */
0698: public void testDiffCounterThresholdExceededManyOffsetNoModulus()
0699: throws Exception {
0700: initTest();
0701: try {
0702: initCounterMonitor(true, new Integer(10), true,
0703: new Integer(10), new Integer(0));
0704: dontExpectStartMonitor(new Integer(0));
0705: expect(new Integer(10),
0706: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0707: expectDiff(new Integer(0), new Integer(10),
0708: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0709: expectDiff(new Integer(10), new Integer(30),
0710: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0711: expectDiff(new Integer(30), new Integer(60),
0712: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0713: expectDiff(new Integer(60), new Integer(100),
0714: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0715: expectDiff(new Integer(0), new Integer(10),
0716: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0717: } finally {
0718: stopMonitor();
0719: MBeanServerFactory.releaseMBeanServer(server);
0720: }
0721: }
0722:
0723: /**
0724: * Test difference counter threshold offset no modulus
0725: */
0726: public void testDiffCounterThresholdNotExceededOffsetNoModulus()
0727: throws Exception {
0728: initTest();
0729: try {
0730: initCounterMonitor(true, new Integer(10), true,
0731: new Integer(10), new Integer(0));
0732: dontExpectStartMonitorDiff(new Integer(0), new Integer(1));
0733: expectDiff(new Integer(0), new Integer(10),
0734: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0735: dontExpectDiff(new Integer(10), new Integer(20));
0736: expectDiff(new Integer(20), new Integer(40),
0737: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0738: dontExpectDiff(new Integer(40), new Integer(69));
0739: } finally {
0740: stopMonitor();
0741: MBeanServerFactory.releaseMBeanServer(server);
0742: }
0743: }
0744:
0745: /**
0746: * Test difference counter threshold offset no modulus
0747: */
0748: public void testDiffCounterThresholdExceededNoneOffsetNoModulus()
0749: throws Exception {
0750: initTest();
0751: try {
0752: initCounterMonitor(false, new Integer(10), true,
0753: new Integer(10), new Integer(0));
0754: dontExpectStartMonitorDiff(new Integer(0), new Integer(1));
0755: dontExpectDiff(new Integer(0), new Integer(10));
0756: dontExpectDiff(new Integer(10), new Integer(20));
0757: dontExpectDiff(new Integer(20), new Integer(40));
0758: dontExpectDiff(new Integer(40), new Integer(69));
0759: } finally {
0760: stopMonitor();
0761: MBeanServerFactory.releaseMBeanServer(server);
0762: }
0763: }
0764:
0765: // Counter difference no offset modulus tests ------------------------------
0766:
0767: /**
0768: * Test difference counter threshold no offset modulus
0769: */
0770: public void testDiffCounterThresholdExceededNoOffsetModulus()
0771: throws Exception {
0772: initTest();
0773: try {
0774: initCounterMonitor(true, new Integer(10), true,
0775: new Integer(0), new Integer(10));
0776: dontExpectStartMonitor(new Integer(0));
0777: expect(new Integer(10),
0778: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0779: } finally {
0780: stopMonitor();
0781: MBeanServerFactory.releaseMBeanServer(server);
0782: }
0783: }
0784:
0785: /**
0786: * Test difference counter threshold no offset modulus
0787: */
0788: public void testDiffCounterThresholdExceededManyNoOffsetModulus()
0789: throws Exception {
0790: initTest();
0791: try {
0792: initCounterMonitor(true, new Integer(10), true,
0793: new Integer(0), new Integer(10));
0794: dontExpectStartMonitor(new Integer(0));
0795: expect(new Integer(10),
0796: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0797: expectDiff(new Integer(0), new Integer(11),
0798: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0799: expectDiff(new Integer(12), new Integer(22),
0800: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0801: expectDiff(new Integer(0), new Integer(10),
0802: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0803: } finally {
0804: stopMonitor();
0805: MBeanServerFactory.releaseMBeanServer(server);
0806: }
0807: }
0808:
0809: /**
0810: * Test difference counter threshold no offset modulus
0811: */
0812: public void testDiffCounterThresholdNotExceededNoOffsetModulus()
0813: throws Exception {
0814: initTest();
0815: try {
0816: initCounterMonitor(true, new Integer(10), true,
0817: new Integer(0), new Integer(10));
0818: dontExpectStartMonitorDiff(new Integer(0), new Integer(1));
0819: dontExpectDiff(new Integer(0), new Integer(9));
0820: dontExpectDiff(new Integer(11), new Integer(20));
0821: dontExpectDiffModulus(new Integer(10), new Integer(-3),
0822: new Integer(10));
0823: } finally {
0824: stopMonitor();
0825: MBeanServerFactory.releaseMBeanServer(server);
0826: }
0827: }
0828:
0829: /**
0830: * Test difference counter threshold no offset modulus
0831: */
0832: public void testDiffCounterThresholdExceededNoneNoOffsetModulus()
0833: throws Exception {
0834: initTest();
0835: try {
0836: initCounterMonitor(false, new Integer(10), true,
0837: new Integer(0), new Integer(10));
0838: dontExpectStartMonitorDiff(new Integer(0), new Integer(10));
0839: dontExpectDiffModulus(new Integer(0), new Integer(-10),
0840: new Integer(10));
0841: dontExpectDiff(new Integer(0), new Integer(100));
0842: } finally {
0843: stopMonitor();
0844: MBeanServerFactory.releaseMBeanServer(server);
0845: }
0846: }
0847:
0848: // Counter difference offset modulus tests ---------------------------------
0849:
0850: /**
0851: * Test difference counter threshold offset modulus
0852: */
0853: public void testDiffCounterThresholdExceededOffsetModulus()
0854: throws Exception {
0855: initTest();
0856: try {
0857: initCounterMonitor(true, new Integer(10), true,
0858: new Integer(10), new Integer(10));
0859: dontExpectStartMonitor(new Integer(0));
0860: expect(new Integer(10),
0861: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0862: } finally {
0863: stopMonitor();
0864: MBeanServerFactory.releaseMBeanServer(server);
0865: }
0866: }
0867:
0868: /**
0869: * Test difference counter threshold offset modulus
0870: */
0871: public void testDiffCounterThresholdExceededManyOffsetModulus()
0872: throws Exception {
0873: initTest();
0874: try {
0875: initCounterMonitor(true, new Integer(10), true,
0876: new Integer(10), new Integer(20));
0877: dontExpectStartMonitor(new Integer(0));
0878: expectDiff(new Integer(0), new Integer(11),
0879: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0880: expectDiff(new Integer(11), new Integer(31),
0881: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0882: expectDiff(new Integer(0), new Integer(10),
0883: MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
0884: } finally {
0885: stopMonitor();
0886: MBeanServerFactory.releaseMBeanServer(server);
0887: }
0888: }
0889:
0890: /**
0891: * Test difference counter threshold offset modulus
0892: */
0893: public void testDiffCounterThresholdNotExceededOffsetModulus()
0894: throws Exception {
0895: initTest();
0896: try {
0897: initCounterMonitor(true, new Integer(10), true,
0898: new Integer(10), new Integer(20));
0899: dontExpectStartMonitorDiff(new Integer(0), new Integer(1));
0900: dontExpectDiff(new Integer(1), new Integer(10));
0901: dontExpectDiffModulus(new Integer(10), new Integer(-13),
0902: new Integer(20));
0903: } finally {
0904: stopMonitor();
0905: MBeanServerFactory.releaseMBeanServer(server);
0906: }
0907: }
0908:
0909: /**
0910: * Test difference counter threshold offset modulus
0911: */
0912: public void testDiffCounterThresholdExceededNoneOffsetModulus()
0913: throws Exception {
0914: initTest();
0915: try {
0916: initCounterMonitor(false, new Integer(10), true,
0917: new Integer(10), new Integer(20));
0918: dontExpectStartMonitorDiff(new Integer(0), new Integer(10));
0919: dontExpectDiffModulus(new Integer(0), new Integer(-10),
0920: new Integer(20));
0921: dontExpectDiff(new Integer(0), new Integer(100));
0922: } finally {
0923: stopMonitor();
0924: MBeanServerFactory.releaseMBeanServer(server);
0925: }
0926: }
0927:
0928: // Counter error tests -----------------------------------------------------
0929:
0930: /**
0931: * Test invalid attribute
0932: */
0933: public void testCounterInvalidAttribute() throws Exception {
0934: initTest();
0935: try {
0936: initCounterMonitor(true, new Integer(10), false,
0937: new Integer(10), new Integer(10));
0938: attributeErrorStartMonitor(new Integer(0));
0939: } finally {
0940: stopMonitor();
0941: MBeanServerFactory.releaseMBeanServer(server);
0942: }
0943: }
0944:
0945: /**
0946: * Test invalid attribute
0947: */
0948: public void testCounterInvalidAttributeNull() throws Exception {
0949: initTest();
0950: try {
0951: initCounterMonitor(true, new Integer(10), false,
0952: new Integer(10), new Integer(10));
0953: attributeNullStartMonitor(new Integer(0));
0954: } finally {
0955: stopMonitor();
0956: MBeanServerFactory.releaseMBeanServer(server);
0957: }
0958: }
0959:
0960: /**
0961: * Test invalid attribute type
0962: */
0963: public void testCounterInvalidAttributeType() throws Exception {
0964: initTest();
0965: try {
0966: initCounterMonitor(true, new Integer(10), false,
0967: new Integer(10), new Integer(10));
0968: attributeTypeStartMonitor(new Integer(0));
0969: } finally {
0970: stopMonitor();
0971: MBeanServerFactory.releaseMBeanServer(server);
0972: }
0973: }
0974:
0975: /**
0976: * Test write only attribute
0977: */
0978: public void testCounterWriteOnly() throws Exception {
0979: initTest();
0980: try {
0981: initCounterMonitor(true, new Integer(10), false,
0982: new Integer(10), new Integer(10));
0983: attributeWriteStartMonitor(new Integer(0));
0984: } finally {
0985: stopMonitor();
0986: MBeanServerFactory.releaseMBeanServer(server);
0987: }
0988: }
0989:
0990: /**
0991: * Test invalid attribute type
0992: */
0993: public void testCounterInvalidObjectName() throws Exception {
0994: initTest();
0995: try {
0996: initCounterMonitor(true, new Integer(10), false,
0997: new Integer(10), new Integer(10));
0998: objectNameStartMonitor(new Integer(0));
0999: } finally {
1000: stopMonitor();
1001: MBeanServerFactory.releaseMBeanServer(server);
1002: }
1003: }
1004:
1005: /**
1006: * Test invalid threshold
1007: */
1008: public void testCounterInvalidThreshold() throws Exception {
1009: initTest();
1010: try {
1011: initCounterMonitor(true, new Long(10), false, new Integer(
1012: 10), new Integer(10));
1013: objectNameStartMonitor(new Integer(0));
1014: } finally {
1015: stopMonitor();
1016: MBeanServerFactory.releaseMBeanServer(server);
1017: }
1018: }
1019:
1020: /**
1021: * Test invalid threshold
1022: */
1023: public void testCounterInvalidOffset() throws Exception {
1024: initTest();
1025: try {
1026: initCounterMonitor(true, new Integer(10), false, new Long(
1027: 10), new Integer(10));
1028: objectNameStartMonitor(new Integer(0));
1029: } finally {
1030: stopMonitor();
1031: MBeanServerFactory.releaseMBeanServer(server);
1032: }
1033: }
1034:
1035: /**
1036: * Test invalid threshold
1037: */
1038: public void testCounterInvalidModulus() throws Exception {
1039: initTest();
1040: try {
1041: initCounterMonitor(true, new Integer(10), false,
1042: new Integer(10), new Long(10));
1043: objectNameStartMonitor(new Integer(0));
1044: } finally {
1045: stopMonitor();
1046: MBeanServerFactory.releaseMBeanServer(server);
1047: }
1048: }
1049:
1050: /**
1051: * Test runtime error
1052: */
1053: public void testCounterRuntimeError() throws Exception {
1054: initTest();
1055: try {
1056: initCounterMonitor(true, new Integer(10), false,
1057: new Integer(10), new Integer(10));
1058: runtimeErrorStartMonitor(new Integer(0));
1059: } finally {
1060: stopMonitor();
1061: MBeanServerFactory.releaseMBeanServer(server);
1062: }
1063: }
1064:
1065: // Gauge notification tests ------------------------------------------------
1066:
1067: /**
1068: * Test the notification info of the gauge
1069: */
1070: public void testGaugeNotificationInfo() throws Exception {
1071: HashSet expected = new HashSet();
1072: expected.add(MonitorNotification.OBSERVED_ATTRIBUTE_ERROR);
1073: expected.add(MonitorNotification.OBSERVED_ATTRIBUTE_TYPE_ERROR);
1074: expected.add(MonitorNotification.OBSERVED_OBJECT_ERROR);
1075: expected.add(MonitorNotification.RUNTIME_ERROR);
1076: expected.add(MonitorNotification.THRESHOLD_ERROR);
1077: expected.add(MonitorNotification.THRESHOLD_HIGH_VALUE_EXCEEDED);
1078: expected.add(MonitorNotification.THRESHOLD_LOW_VALUE_EXCEEDED);
1079:
1080: MBeanNotificationInfo[] mbni = new GaugeMonitor()
1081: .getNotificationInfo();
1082: checkNotificationInfo("Gauge", mbni, expected);
1083: }
1084:
1085: // Gauge error tests -------------------------------------------------------
1086:
1087: /**
1088: * Test invalid attribute
1089: */
1090: public void testGaugeInvalidAttribute() throws Exception {
1091: initTest();
1092: try {
1093: initGaugeMonitor(true, true, new Integer(10),
1094: new Integer(0), false);
1095: attributeErrorStartMonitor(new Integer(0));
1096: } finally {
1097: stopMonitor();
1098: MBeanServerFactory.releaseMBeanServer(server);
1099: }
1100: }
1101:
1102: /**
1103: * Test invalid attribute
1104: */
1105: public void testGaugeInvalidAttributeNull() throws Exception {
1106: initTest();
1107: try {
1108: initGaugeMonitor(true, true, new Integer(10),
1109: new Integer(0), false);
1110: attributeNullStartMonitor(new Integer(0));
1111: } finally {
1112: stopMonitor();
1113: MBeanServerFactory.releaseMBeanServer(server);
1114: }
1115: }
1116:
1117: /**
1118: * Test invalid attribute type
1119: */
1120: public void testGaugeInvalidAttributeType() throws Exception {
1121: initTest();
1122: try {
1123: initGaugeMonitor(true, true, new Integer(10),
1124: new Integer(0), false);
1125: attributeTypeStartMonitor(new Integer(0));
1126: } finally {
1127: stopMonitor();
1128: MBeanServerFactory.releaseMBeanServer(server);
1129: }
1130: }
1131:
1132: /**
1133: * Test write only
1134: */
1135: public void testGaugeWriteOnly() throws Exception {
1136: initTest();
1137: try {
1138: initGaugeMonitor(true, true, new Integer(10),
1139: new Integer(0), false);
1140: attributeWriteStartMonitor(new Integer(0));
1141: } finally {
1142: stopMonitor();
1143: MBeanServerFactory.releaseMBeanServer(server);
1144: }
1145: }
1146:
1147: /**
1148: * Test invalid attribute type
1149: */
1150: public void testGaugeInvalidObjectName() throws Exception {
1151: initTest();
1152: try {
1153: initGaugeMonitor(true, true, new Integer(10),
1154: new Integer(0), false);
1155: objectNameStartMonitor(new Integer(0));
1156: } finally {
1157: stopMonitor();
1158: MBeanServerFactory.releaseMBeanServer(server);
1159: }
1160: }
1161:
1162: /**
1163: * Test invalid threshold
1164: */
1165: public void testGaugeInvalidThreshold() throws Exception {
1166: initTest();
1167: try {
1168: initGaugeMonitor(true, true, new Long(10), new Long(0),
1169: false);
1170: objectNameStartMonitor(new Integer(0));
1171: } finally {
1172: stopMonitor();
1173: MBeanServerFactory.releaseMBeanServer(server);
1174: }
1175: }
1176:
1177: /**
1178: * Test runtime error
1179: */
1180: public void testGaugeRuntimeError() throws Exception {
1181: initTest();
1182: try {
1183: initGaugeMonitor(true, true, new Integer(10),
1184: new Integer(0), false);
1185: runtimeErrorStartMonitor(new Integer(0));
1186: } finally {
1187: stopMonitor();
1188: MBeanServerFactory.releaseMBeanServer(server);
1189: }
1190: }
1191:
1192: // String notification tests -----------------------------------------------
1193:
1194: /**
1195: * Test the notification info of the string
1196: */
1197: public void testStringNotificationInfo() throws Exception {
1198: HashSet expected = new HashSet();
1199: expected.add(MonitorNotification.OBSERVED_ATTRIBUTE_ERROR);
1200: expected.add(MonitorNotification.OBSERVED_ATTRIBUTE_TYPE_ERROR);
1201: expected.add(MonitorNotification.OBSERVED_OBJECT_ERROR);
1202: expected.add(MonitorNotification.RUNTIME_ERROR);
1203: expected
1204: .add(MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED);
1205: expected
1206: .add(MonitorNotification.STRING_TO_COMPARE_VALUE_MATCHED);
1207:
1208: MBeanNotificationInfo[] mbni = new StringMonitor()
1209: .getNotificationInfo();
1210: checkNotificationInfo("String", mbni, expected);
1211: }
1212:
1213: // String test -------------------------------------------------------------
1214:
1215: /**
1216: * Test a string differs
1217: */
1218: public void testStringDifferEarly() throws Exception {
1219: initTest();
1220: try {
1221: initStringMonitor(true, false, "Hello");
1222: expectStartMonitor(
1223: "Goodbye",
1224: MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED);
1225: } finally {
1226: stopMonitor();
1227: MBeanServerFactory.releaseMBeanServer(server);
1228: }
1229: }
1230:
1231: /**
1232: * Test a string differs
1233: */
1234: public void testStringDifferLate() throws Exception {
1235: initTest();
1236: try {
1237: initStringMonitor(true, false, "Hello");
1238: dontExpectStartMonitor("Hello");
1239: expect(
1240: "Goodbye",
1241: MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED);
1242: } finally {
1243: stopMonitor();
1244: MBeanServerFactory.releaseMBeanServer(server);
1245: }
1246: }
1247:
1248: /**
1249: * Test a string differs many
1250: */
1251: public void testStringDifferManyEarly() throws Exception {
1252: initTest();
1253: try {
1254: initStringMonitor(true, false, "Hello");
1255: expectStartMonitor(
1256: "Goodbye",
1257: MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED);
1258: dontExpect("Hello");
1259: expect(
1260: "Goodbye",
1261: MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED);
1262: dontExpect("Hello");
1263: expect(
1264: "Goodbye",
1265: MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED);
1266: dontExpect("Hello");
1267: } finally {
1268: stopMonitor();
1269: MBeanServerFactory.releaseMBeanServer(server);
1270: }
1271: }
1272:
1273: /**
1274: * Test a string differs many
1275: */
1276: public void testStringDifferManyLate() throws Exception {
1277: initTest();
1278: try {
1279: initStringMonitor(true, false, "Hello");
1280: dontExpectStartMonitor("Hello");
1281: expect(
1282: "Goodbye",
1283: MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED);
1284: dontExpect("Hello");
1285: expect(
1286: "Goodbye",
1287: MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED);
1288: dontExpect("Hello");
1289: expect(
1290: "Goodbye",
1291: MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED);
1292: dontExpect("Hello");
1293: } finally {
1294: stopMonitor();
1295: MBeanServerFactory.releaseMBeanServer(server);
1296: }
1297: }
1298:
1299: /**
1300: * Test a string matches
1301: */
1302: public void testStringMatchEarly() throws Exception {
1303: initTest();
1304: try {
1305: initStringMonitor(false, true, "Hello");
1306: expectStartMonitor("Hello",
1307: MonitorNotification.STRING_TO_COMPARE_VALUE_MATCHED);
1308: } finally {
1309: stopMonitor();
1310: MBeanServerFactory.releaseMBeanServer(server);
1311: }
1312: }
1313:
1314: /**
1315: * Test a string matches
1316: */
1317: public void testStringMatchLate() throws Exception {
1318: initTest();
1319: try {
1320: initStringMonitor(false, true, "Hello");
1321: dontExpectStartMonitor("Goodbye");
1322: expect("Hello",
1323: MonitorNotification.STRING_TO_COMPARE_VALUE_MATCHED);
1324: } finally {
1325: stopMonitor();
1326: MBeanServerFactory.releaseMBeanServer(server);
1327: }
1328: }
1329:
1330: /**
1331: * Test a string matches
1332: */
1333: public void testStringMatchManyEarly() throws Exception {
1334: initTest();
1335: try {
1336: initStringMonitor(false, true, "Hello");
1337: expectStartMonitor("Hello",
1338: MonitorNotification.STRING_TO_COMPARE_VALUE_MATCHED);
1339: dontExpect("Goodbye");
1340: expect("Hello",
1341: MonitorNotification.STRING_TO_COMPARE_VALUE_MATCHED);
1342: dontExpect("Goodbye");
1343: expect("Hello",
1344: MonitorNotification.STRING_TO_COMPARE_VALUE_MATCHED);
1345: } finally {
1346: stopMonitor();
1347: MBeanServerFactory.releaseMBeanServer(server);
1348: }
1349: }
1350:
1351: /**
1352: * Test a string matches
1353: */
1354: public void testStringMatchManyLate() throws Exception {
1355: initTest();
1356: try {
1357: initStringMonitor(false, true, "Hello");
1358: dontExpectStartMonitor("Goodbye");
1359: expect("Hello",
1360: MonitorNotification.STRING_TO_COMPARE_VALUE_MATCHED);
1361: dontExpect("Goodbye");
1362: expect("Hello",
1363: MonitorNotification.STRING_TO_COMPARE_VALUE_MATCHED);
1364: dontExpect("Goodbye");
1365: expect("Hello",
1366: MonitorNotification.STRING_TO_COMPARE_VALUE_MATCHED);
1367: } finally {
1368: stopMonitor();
1369: MBeanServerFactory.releaseMBeanServer(server);
1370: }
1371: }
1372:
1373: /**
1374: * Test a string differs and matches
1375: */
1376: public void testStringBoth() throws Exception {
1377: initTest();
1378: try {
1379: initStringMonitor(true, true, "Hello");
1380: expectStartMonitor(
1381: "Goodbye",
1382: MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED);
1383: expect("Hello",
1384: MonitorNotification.STRING_TO_COMPARE_VALUE_MATCHED);
1385: } finally {
1386: stopMonitor();
1387: MBeanServerFactory.releaseMBeanServer(server);
1388: }
1389: }
1390:
1391: /**
1392: * Test a string differs and matches
1393: */
1394: public void testStringBothMany() throws Exception {
1395: initTest();
1396: try {
1397: initStringMonitor(true, true, "Hello");
1398: expectStartMonitor(
1399: "Goodbye",
1400: MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED);
1401: expect("Hello",
1402: MonitorNotification.STRING_TO_COMPARE_VALUE_MATCHED);
1403: expect(
1404: "Goodbye",
1405: MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED);
1406: expect("Hello",
1407: MonitorNotification.STRING_TO_COMPARE_VALUE_MATCHED);
1408: expect(
1409: "Goodbye",
1410: MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED);
1411: } finally {
1412: stopMonitor();
1413: MBeanServerFactory.releaseMBeanServer(server);
1414: }
1415: }
1416:
1417: /**
1418: * Test a string nothing
1419: */
1420: public void testStringNever() throws Exception {
1421: initTest();
1422: try {
1423: initStringMonitor(false, false, "Hello");
1424: dontExpectStartMonitor("Goodbye");
1425: dontExpect("Hello");
1426: dontExpect("Goodbye");
1427: } finally {
1428: stopMonitor();
1429: MBeanServerFactory.releaseMBeanServer(server);
1430: }
1431: }
1432:
1433: // String error tests ------------------------------------------------------
1434:
1435: /**
1436: * Test invalid attribute
1437: */
1438: public void testStringInvalidAttribute() throws Exception {
1439: initTest();
1440: try {
1441: initStringMonitor(true, true, "Hello");
1442: attributeErrorStartMonitor("Goodbye");
1443: } finally {
1444: stopMonitor();
1445: MBeanServerFactory.releaseMBeanServer(server);
1446: }
1447: }
1448:
1449: /**
1450: * Test invalid attribute
1451: */
1452: public void testStringInvalidAttributeNull() throws Exception {
1453: initTest();
1454: try {
1455: initStringMonitor(true, true, "Hello");
1456: attributeNullStartMonitor("Goodbye");
1457: } finally {
1458: stopMonitor();
1459: MBeanServerFactory.releaseMBeanServer(server);
1460: }
1461: }
1462:
1463: /**
1464: * Test invalid attribute type
1465: */
1466: public void testStringInvalidAttributeType() throws Exception {
1467: initTest();
1468: try {
1469: initStringMonitor(true, true, "Hello");
1470: attributeTypeStartMonitor("Goodbye");
1471: } finally {
1472: stopMonitor();
1473: MBeanServerFactory.releaseMBeanServer(server);
1474: }
1475: }
1476:
1477: /**
1478: * Test write only attribute
1479: */
1480: public void testStringWriteOnly() throws Exception {
1481: initTest();
1482: try {
1483: initStringMonitor(true, true, "Hello");
1484: attributeWriteStartMonitor("Goodbye");
1485: } finally {
1486: stopMonitor();
1487: MBeanServerFactory.releaseMBeanServer(server);
1488: }
1489: }
1490:
1491: /**
1492: * Test invalid attribute type
1493: */
1494: public void testStringInvalidObjectName() throws Exception {
1495: initTest();
1496: try {
1497: initStringMonitor(true, true, "Hello");
1498: objectNameStartMonitor("Goodbye");
1499: } finally {
1500: stopMonitor();
1501: MBeanServerFactory.releaseMBeanServer(server);
1502: }
1503: }
1504:
1505: /**
1506: * Test runtime error
1507: */
1508: public void testStringRuntimeError() throws Exception {
1509: initTest();
1510: try {
1511: initStringMonitor(true, true, "Hello");
1512: runtimeErrorStartMonitor("Goodbye");
1513: } finally {
1514: stopMonitor();
1515: MBeanServerFactory.releaseMBeanServer(server);
1516: }
1517: }
1518:
1519: // Support -----------------------------------------------------------------
1520:
1521: /**
1522: * Create a counter monitor
1523: */
1524: private void initCounterMonitor(boolean notify, Number threshold,
1525: boolean differenceMode, Number offset, Number modulus) {
1526: try {
1527: CounterMonitor counterMonitor = new CounterMonitor();
1528: counterMonitor.setNotify(notify);
1529: counterMonitor.setThreshold(threshold);
1530: counterMonitor.setDifferenceMode(differenceMode);
1531: counterMonitor.setOffset(offset);
1532: counterMonitor.setModulus(modulus);
1533: CounterSupport support = new CounterSupport();
1534: monitor = counterMonitor;
1535: monitored = support;
1536: initMonitor();
1537: } catch (Exception e) {
1538: fail(e.toString());
1539: }
1540: }
1541:
1542: /**
1543: * Check a counter's threshold
1544: */
1545: private void checkThreshold(Number number) {
1546: assertEquals(number, ((CounterMonitor) monitor).getThreshold());
1547: }
1548:
1549: /**
1550: * Create a gauge monitor
1551: */
1552: private void initGaugeMonitor(boolean notifyHigh,
1553: boolean notifyLow, Number thresholdHigh,
1554: Number thresholdLow, boolean differenceMode) {
1555: try {
1556: GaugeMonitor gaugeMonitor = new GaugeMonitor();
1557: gaugeMonitor.setNotifyHigh(notifyHigh);
1558: gaugeMonitor.setNotifyLow(notifyLow);
1559: gaugeMonitor.setThresholds(thresholdHigh, thresholdLow);
1560: gaugeMonitor.setDifferenceMode(differenceMode);
1561: GaugeSupport support = new GaugeSupport();
1562: monitor = gaugeMonitor;
1563: monitored = support;
1564: initMonitor();
1565: } catch (Exception e) {
1566: fail(e.toString());
1567: }
1568: }
1569:
1570: /**
1571: * Create a string monitor
1572: */
1573: private void initStringMonitor(boolean differ, boolean match,
1574: String compare) {
1575: try {
1576: StringMonitor stringMonitor = new StringMonitor();
1577: stringMonitor.setNotifyDiffer(differ);
1578: stringMonitor.setNotifyMatch(match);
1579: stringMonitor.setStringToCompare(compare);
1580: StringSupport support = new StringSupport();
1581: monitor = stringMonitor;
1582: monitored = support;
1583: initMonitor();
1584: } catch (Exception e) {
1585: fail(e.toString());
1586: }
1587: }
1588:
1589: /**
1590: * Start a new test
1591: */
1592: private void initTest() {
1593: notifications.clear();
1594: server = MBeanServerFactory.createMBeanServer();
1595: }
1596:
1597: /**
1598: * Create the monitor
1599: */
1600: private void initMonitor() throws Exception {
1601: monitorName = new ObjectName("test:type=monitor");
1602: monitoredName = new ObjectName("test:type=monitored");
1603: monitor.setObservedObject(monitoredName);
1604: monitor.setObservedAttribute("Value");
1605: monitor.setGranularityPeriod(MonitorSUITE.GRANULARITY_TIME);
1606: server.registerMBean(monitor, monitorName);
1607: server.registerMBean(monitored, monitoredName);
1608: server.addNotificationListener(monitorName, this , null, null);
1609: }
1610:
1611: /**
1612: * Stop the monitor
1613: */
1614: private void stopMonitor() {
1615: if (monitor != null) {
1616: monitored.end();
1617: monitor.stop();
1618: }
1619: }
1620:
1621: /**
1622: * Handle the notification, just add it to the list
1623: */
1624: public void handleNotification(Notification n, Object ignored) {
1625: synchronized (notifications) {
1626: notifications.add(n);
1627: notifications.notifyAll();
1628: }
1629: }
1630:
1631: /**
1632: * Sync with the notification handler
1633: */
1634: private void sync(boolean getWorks) throws Exception {
1635: // Make sure the monitor has got the attribute
1636: if (getWorks)
1637: waitCycle();
1638: else {
1639: synchronized (notifications) {
1640: notifications.wait(MonitorSUITE.MAX_WAIT);
1641: }
1642: }
1643: }
1644:
1645: /**
1646: * Invalid attribute start monitor
1647: */
1648: private void attributeErrorStartMonitor(Object initial)
1649: throws Exception {
1650: assertEquals(0, notifications.size());
1651: monitor.setObservedAttribute("rubbish");
1652: monitor.start();
1653: sync(false);
1654: assertEquals(1, notifications.size());
1655: MonitorNotification n = (MonitorNotification) notifications
1656: .get(0);
1657: notifications.clear();
1658: assertEquals(monitorName, n.getSource());
1659: assertEquals(monitoredName, n.getObservedObject());
1660: assertEquals("rubbish", n.getObservedAttribute());
1661: assertEquals(MonitorNotification.OBSERVED_ATTRIBUTE_ERROR, n
1662: .getType());
1663: n = serializeDeserialize(n);
1664: assertEquals(monitorName, n.getSource());
1665: assertEquals(monitoredName, n.getObservedObject());
1666: assertEquals("rubbish", n.getObservedAttribute());
1667: assertEquals(MonitorNotification.OBSERVED_ATTRIBUTE_ERROR, n
1668: .getType());
1669: }
1670:
1671: /**
1672: * Invalid attribute null start monitor
1673: */
1674: private void attributeNullStartMonitor(Object initial)
1675: throws Exception {
1676: assertEquals(0, notifications.size());
1677: monitor.setObservedAttribute("WrongNull");
1678: monitor.start();
1679: sync(false);
1680: assertEquals(1, notifications.size());
1681: MonitorNotification n = (MonitorNotification) notifications
1682: .get(0);
1683: notifications.clear();
1684: assertEquals(monitorName, n.getSource());
1685: assertEquals(monitoredName, n.getObservedObject());
1686: assertEquals("WrongNull", n.getObservedAttribute());
1687: assertEquals(MonitorNotification.OBSERVED_ATTRIBUTE_TYPE_ERROR,
1688: n.getType());
1689: n = serializeDeserialize(n);
1690: assertEquals(monitorName, n.getSource());
1691: assertEquals(monitoredName, n.getObservedObject());
1692: assertEquals("WrongNull", n.getObservedAttribute());
1693: assertEquals(MonitorNotification.OBSERVED_ATTRIBUTE_TYPE_ERROR,
1694: n.getType());
1695: }
1696:
1697: /**
1698: * Invalid attribute type start monitor
1699: */
1700: private void attributeTypeStartMonitor(Object initial)
1701: throws Exception {
1702: assertEquals(0, notifications.size());
1703: monitor.setObservedAttribute("WrongType");
1704: monitor.start();
1705: sync(false);
1706: assertEquals(1, notifications.size());
1707: MonitorNotification n = (MonitorNotification) notifications
1708: .get(0);
1709: notifications.clear();
1710: assertEquals(monitorName, n.getSource());
1711: assertEquals(monitoredName, n.getObservedObject());
1712: assertEquals("WrongType", n.getObservedAttribute());
1713: assertEquals(MonitorNotification.OBSERVED_ATTRIBUTE_TYPE_ERROR,
1714: n.getType());
1715: n = serializeDeserialize(n);
1716: assertEquals(monitoredName, n.getObservedObject());
1717: assertEquals("WrongType", n.getObservedAttribute());
1718: assertEquals(MonitorNotification.OBSERVED_ATTRIBUTE_TYPE_ERROR,
1719: n.getType());
1720: }
1721:
1722: /**
1723: * Write only Attribute start monitor
1724: */
1725: private void attributeWriteStartMonitor(Object initial)
1726: throws Exception {
1727: assertEquals(0, notifications.size());
1728: monitor.setObservedAttribute("WriteOnly");
1729: monitor.start();
1730: sync(false);
1731: assertEquals(1, notifications.size());
1732: MonitorNotification n = (MonitorNotification) notifications
1733: .get(0);
1734: notifications.clear();
1735: assertEquals(monitorName, n.getSource());
1736: assertEquals(monitoredName, n.getObservedObject());
1737: assertEquals("WriteOnly", n.getObservedAttribute());
1738: assertEquals(MonitorNotification.OBSERVED_ATTRIBUTE_ERROR, n
1739: .getType());
1740: n = serializeDeserialize(n);
1741: assertEquals(monitorName, n.getSource());
1742: assertEquals(monitoredName, n.getObservedObject());
1743: assertEquals("WriteOnly", n.getObservedAttribute());
1744: assertEquals(MonitorNotification.OBSERVED_ATTRIBUTE_ERROR, n
1745: .getType());
1746: }
1747:
1748: /**
1749: * Invalid objectName start monitor
1750: */
1751: private void objectNameStartMonitor(Object initial)
1752: throws Exception {
1753: assertEquals(0, notifications.size());
1754: monitoredName = new ObjectName("rubbish:type=pants");
1755: monitor.setObservedObject(monitoredName);
1756: monitor.start();
1757: sync(false);
1758: assertEquals(1, notifications.size());
1759: MonitorNotification n = (MonitorNotification) notifications
1760: .get(0);
1761: notifications.clear();
1762: assertEquals(monitorName, n.getSource());
1763: assertEquals(monitoredName, n.getObservedObject());
1764: assertEquals("Value", n.getObservedAttribute());
1765: assertEquals(MonitorNotification.OBSERVED_OBJECT_ERROR, n
1766: .getType());
1767: n = serializeDeserialize(n);
1768: assertEquals(monitorName, n.getSource());
1769: assertEquals(monitoredName, n.getObservedObject());
1770: assertEquals("Value", n.getObservedAttribute());
1771: assertEquals(MonitorNotification.OBSERVED_OBJECT_ERROR, n
1772: .getType());
1773: }
1774:
1775: /**
1776: * Invalid threshold start monitor
1777: */
1778: private void thresholdStartMonitor(Object initial) throws Exception {
1779: assertEquals(0, notifications.size());
1780: monitor.start();
1781: sync(false);
1782: assertEquals(1, notifications.size());
1783: MonitorNotification n = (MonitorNotification) notifications
1784: .get(0);
1785: notifications.clear();
1786: assertEquals(monitorName, n.getSource());
1787: assertEquals(monitoredName, n.getObservedObject());
1788: assertEquals("Value", n.getObservedAttribute());
1789: assertEquals(MonitorNotification.THRESHOLD_ERROR, n.getType());
1790: n = serializeDeserialize(n);
1791: assertEquals(monitorName, n.getSource());
1792: assertEquals(monitoredName, n.getObservedObject());
1793: assertEquals("Value", n.getObservedAttribute());
1794: assertEquals(MonitorNotification.THRESHOLD_ERROR, n.getType());
1795: }
1796:
1797: /**
1798: * runtime error start monitor
1799: */
1800: private void runtimeErrorStartMonitor(Object initial)
1801: throws Exception {
1802: assertEquals(0, notifications.size());
1803: monitor.setObservedAttribute("WrongException");
1804: monitor.start();
1805: sync(false);
1806: if (notifications.size() != 1)
1807: fail("FAILS IN RI: Does not notify of error thrown by getter");
1808: assertEquals(1, notifications.size());
1809: MonitorNotification n = (MonitorNotification) notifications
1810: .get(0);
1811: notifications.clear();
1812: assertEquals(monitorName, n.getSource());
1813: assertEquals(monitoredName, n.getObservedObject());
1814: assertEquals("WrongException", n.getObservedAttribute());
1815: assertEquals(MonitorNotification.RUNTIME_ERROR, n.getType());
1816: n = serializeDeserialize(n);
1817: assertEquals(monitorName, n.getSource());
1818: assertEquals(monitoredName, n.getObservedObject());
1819: assertEquals("WrongException", n.getObservedAttribute());
1820: assertEquals(MonitorNotification.RUNTIME_ERROR, n.getType());
1821: }
1822:
1823: /**
1824: * Start a monitor expect a notification
1825: */
1826: private void expectStartMonitor(Object expected, String type)
1827: throws Exception {
1828: assertEquals(0, notifications.size());
1829: monitor.start();
1830: setValue(expected);
1831:
1832: // Synchronize the notification
1833: sync(true);
1834:
1835: // Check the result
1836: checkGauge(expected);
1837: assertEquals(1, notifications.size());
1838: MonitorNotification n = (MonitorNotification) notifications
1839: .get(0);
1840: notifications.clear();
1841: assertEquals(monitorName, n.getSource());
1842: assertEquals(monitoredName, n.getObservedObject());
1843: assertEquals("Value", n.getObservedAttribute());
1844: assertEquals(type, n.getType());
1845: assertEquals(expected, n.getDerivedGauge());
1846: n = serializeDeserialize(n);
1847: assertEquals(monitorName, n.getSource());
1848: assertEquals(monitoredName, n.getObservedObject());
1849: assertEquals("Value", n.getObservedAttribute());
1850: assertEquals(type, n.getType());
1851: assertEquals(expected, n.getDerivedGauge());
1852: }
1853:
1854: /**
1855: * Start a monitor, don't expect a notification
1856: */
1857: private void dontExpectStartMonitor(Object initial)
1858: throws Exception {
1859: assertEquals(0, notifications.size());
1860: monitor.start();
1861: setValue(initial);
1862: waitCycle();
1863: assertEquals(0, notifications.size());
1864: checkGauge(initial);
1865: }
1866:
1867: /**
1868: * Start a monitor, don't expect a notification difference
1869: */
1870: private void dontExpectStartMonitorDiff(Object value1, Object value2)
1871: throws Exception {
1872: monitor.start();
1873: setValue(value1);
1874: waitCycle();
1875: assertEquals(0, notifications.size());
1876: setValue(value2);
1877: waitCycle();
1878: assertEquals(0, notifications.size());
1879: checkGauge(sub(value2, value1));
1880: }
1881:
1882: private void setValue(Object value) throws Exception {
1883: monitored.lock("set");
1884: server.setAttribute(monitoredName,
1885: new Attribute("Value", value));
1886: }
1887:
1888: /**
1889: * Expect a notification
1890: */
1891: private void expect(Object expected, Object gauge, String type)
1892: throws Exception {
1893: assertEquals(0, notifications.size());
1894: setValue(expected);
1895:
1896: // Synchronize the notification
1897: sync(true);
1898:
1899: // Check the result
1900: checkGauge(gauge);
1901: assertEquals(1, notifications.size());
1902: MonitorNotification n = (MonitorNotification) notifications
1903: .get(0);
1904: notifications.clear();
1905: assertEquals(monitorName, n.getSource());
1906: assertEquals(monitoredName, n.getObservedObject());
1907: assertEquals("Value", n.getObservedAttribute());
1908: assertEquals(type, n.getType());
1909: assertEquals(gauge, n.getDerivedGauge());
1910: }
1911:
1912: /**
1913: * Expect a notification difference
1914: */
1915: private void expectDiff(Object value1, Object value2, String type)
1916: throws Exception {
1917: waitCycle();
1918: notifications.clear();
1919: setValue(value1);
1920: waitCycle();
1921: assertEquals(0, notifications.size());
1922: setValue(value2);
1923: sync(true);
1924:
1925: // Check the result
1926: checkGauge(sub(value2, value1));
1927: assertEquals(1, notifications.size());
1928: MonitorNotification n = (MonitorNotification) notifications
1929: .get(0);
1930: notifications.clear();
1931: assertEquals(monitorName, n.getSource());
1932: assertEquals(monitoredName, n.getObservedObject());
1933: assertEquals("Value", n.getObservedAttribute());
1934: assertEquals(type, n.getType());
1935: assertEquals(sub(value2, value1), n.getDerivedGauge());
1936: }
1937:
1938: /**
1939: * Expect a notification
1940: */
1941: private void expect(Object expected, String type) throws Exception {
1942: expect(expected, expected, type);
1943: }
1944:
1945: /**
1946: * Don't expect a notification
1947: */
1948: private void dontExpect(Object unexpected) throws Exception {
1949: assertEquals(0, notifications.size());
1950: setValue(unexpected);
1951: waitCycle();
1952: assertEquals(0, notifications.size());
1953: checkGauge(unexpected);
1954: }
1955:
1956: /**
1957: * Don't expect a notification
1958: */
1959: private void dontExpectDiff(Object value1, Object value2)
1960: throws Exception {
1961: waitCycle();
1962: notifications.clear();
1963: setValue(value1);
1964: waitCycle();
1965: assertEquals(0, notifications.size());
1966: setValue(value2);
1967: waitCycle();
1968: assertEquals(0, notifications.size());
1969: checkGauge(sub(value2, value1));
1970: }
1971:
1972: /**
1973: * Don't expect a notification
1974: */
1975: private void dontExpectDiffModulus(Object value1, Object value2,
1976: Object value3) throws Exception {
1977: waitCycle();
1978: notifications.clear();
1979: setValue(value1);
1980: waitCycle();
1981: assertEquals(0, notifications.size());
1982: setValue(value2);
1983: waitCycle();
1984: assertEquals(0, notifications.size());
1985: checkGauge(add(sub(value2, value1), value3));
1986: }
1987:
1988: /**
1989: * Check the gauge
1990: */
1991: private void checkGauge(Object gauge) throws Exception {
1992: if (monitor instanceof StringMonitor)
1993: assertEquals(gauge, ((StringMonitor) monitor)
1994: .getDerivedGauge());
1995: else if (monitor instanceof CounterMonitor)
1996: assertEquals(gauge, ((CounterMonitor) monitor)
1997: .getDerivedGauge());
1998: else if (monitor instanceof GaugeMonitor)
1999: assertEquals(gauge, ((GaugeMonitor) monitor)
2000: .getDerivedGauge());
2001: else
2002: fail("You idiot!");
2003: }
2004:
2005: /**
2006: * Wait one cycle of the monitor
2007: */
2008: private void waitCycle() {
2009: monitored.unlock("set");
2010: monitored.lock("set");
2011: }
2012:
2013: /**
2014: * Add two numbers.
2015: * @param value1 the first value.
2016: * @param value2 the second value.
2017: * @return value1 + value2 of the correct type
2018: */
2019: private Number add(Object value1, Object value2) {
2020: if (value1 instanceof Byte)
2021: return new Byte(
2022: (byte) (((Byte) value1).byteValue() + ((Byte) value2)
2023: .byteValue()));
2024: if (value1 instanceof Integer)
2025: return new Integer(((Integer) value1).intValue()
2026: + ((Integer) value2).intValue());
2027: if (value1 instanceof Short)
2028: return new Short(
2029: (short) (((Short) value1).shortValue() + ((Short) value2)
2030: .shortValue()));
2031: if (value1 instanceof Long)
2032: return new Long(((Long) value1).longValue()
2033: + ((Long) value2).longValue());
2034: fail("You idiot!");
2035: return null;
2036: }
2037:
2038: /**
2039: * Subtract two numbers.
2040: * @param value1 the first value.
2041: * @param value2 the second value.
2042: * @return value1 - value2 of the correct type
2043: */
2044: private Number sub(Object value1, Object value2) {
2045: if (value1 instanceof Byte)
2046: return new Byte(
2047: (byte) (((Byte) value1).byteValue() - ((Byte) value2)
2048: .byteValue()));
2049: if (value1 instanceof Integer)
2050: return new Integer(((Integer) value1).intValue()
2051: - ((Integer) value2).intValue());
2052: if (value1 instanceof Short)
2053: return new Short(
2054: (short) (((Short) value1).shortValue() - ((Short) value2)
2055: .shortValue()));
2056: if (value1 instanceof Long)
2057: return new Long(((Long) value1).longValue()
2058: - ((Long) value2).longValue());
2059: fail("You idiot!");
2060: return null;
2061: }
2062:
2063: /**
2064: * Check the notification info is as expected
2065: *
2066: * @param mbni the received notification info
2067: * @param expected the expected notifications
2068: */
2069: private void checkNotificationInfo(String type,
2070: MBeanNotificationInfo[] mbni, HashSet expected) {
2071: String[] types = mbni[0].getNotifTypes();
2072: for (int i = 0; i < types.length; i++)
2073: if (expected.remove(types[i]) == false)
2074: fail(type + ": didn't expect notification type "
2075: + types[i]);
2076: Iterator iterator = expected.iterator();
2077: while (iterator.hasNext())
2078: fail(type + ": expected notification type "
2079: + iterator.next());
2080: }
2081:
2082: /**
2083: * Serialize/Derserialize the notification
2084: *
2085: * @param n the notification
2086: * @return the notification after serialize/deserialze
2087: */
2088: private MonitorNotification serializeDeserialize(
2089: MonitorNotification n) throws Exception {
2090: // Serialize it
2091: ByteArrayOutputStream baos = new ByteArrayOutputStream();
2092: ObjectOutputStream oos = new ObjectOutputStream(baos);
2093: oos.writeObject(n);
2094:
2095: // Deserialize it
2096: ByteArrayInputStream bais = new ByteArrayInputStream(baos
2097: .toByteArray());
2098: ObjectInputStream ois = new ObjectInputStream(bais);
2099: return (MonitorNotification) ois.readObject();
2100: }
2101: }
|