KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > compliance > monitor > MonitorTestCase


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7
8 package test.compliance.monitor;
9
10 import java.io.ByteArrayInputStream;
11 import java.io.ByteArrayOutputStream;
12 import java.io.ObjectInputStream;
13 import java.io.ObjectOutputStream;
14 import java.util.ArrayList;
15 import java.util.HashSet;
16 import java.util.Iterator;
17
18 import javax.management.Attribute;
19 import javax.management.MBeanNotificationInfo;
20 import javax.management.MBeanServer;
21 import javax.management.MBeanServerFactory;
22 import javax.management.Notification;
23 import javax.management.NotificationListener;
24 import javax.management.ObjectName;
25 import javax.management.monitor.CounterMonitor;
26 import javax.management.monitor.GaugeMonitor;
27 import javax.management.monitor.Monitor;
28 import javax.management.monitor.MonitorNotification;
29 import javax.management.monitor.StringMonitor;
30
31 import junit.framework.AssertionFailedError;
32 import junit.framework.TestCase;
33 import test.compliance.monitor.support.CounterSupport;
34 import test.compliance.monitor.support.GaugeSupport;
35 import test.compliance.monitor.support.MonitorSupport;
36 import test.compliance.monitor.support.StringSupport;
37
38 /**
39  * Monitor Notification Tests
40  *
41  * @author <a HREF="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>.
42  */

43 public class MonitorTestCase
44    extends TestCase
45    implements NotificationListener
46 {
47    // Constants ---------------------------------------------------------------
48

49    // Attributes --------------------------------------------------------------
50

51    /**
52     * The MBeanServer
53     */

54    MBeanServer server;
55
56    /**
57     * The object name of the monitor service
58     */

59    ObjectName monitorName;
60
61    /**
62     * The monitor
63     */

64    Monitor monitor;
65
66    /**
67     * The object name of the mbean monitored
68     */

69    ObjectName monitoredName;
70
71    /**
72     * The monitored mbean
73     */

74    MonitorSupport monitored;
75
76    /**
77     * The notifications
78     */

79    ArrayList notifications = new ArrayList();
80
81    // Constructor -------------------------------------------------------------
82

83    /**
84     * Construct the test
85     */

86    public MonitorTestCase(String s)
87    {
88       super(s);
89    }
90
91    // Tests -------------------------------------------------------------------
92

93    /**
94     * Test notification types differ
95     */

96    public void testNotificationTypes()
97    {
98       assertEquals(MonitorNotification.OBSERVED_ATTRIBUTE_ERROR,
99                    "jmx.monitor.error.attribute");
100       assertEquals(MonitorNotification.OBSERVED_ATTRIBUTE_TYPE_ERROR,
101                    "jmx.monitor.error.type");
102       assertEquals(MonitorNotification.OBSERVED_OBJECT_ERROR,
103                    "jmx.monitor.error.mbean");
104       assertEquals(MonitorNotification.RUNTIME_ERROR,
105                    "jmx.monitor.error.runtime");
106       assertEquals(MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED,
107                    "jmx.monitor.string.differs");
108       assertEquals(MonitorNotification.STRING_TO_COMPARE_VALUE_MATCHED,
109                    "jmx.monitor.string.matches");
110       assertEquals(MonitorNotification.THRESHOLD_ERROR,
111                    "jmx.monitor.error.threshold");
112       assertEquals(MonitorNotification.THRESHOLD_HIGH_VALUE_EXCEEDED,
113                    "jmx.monitor.gauge.high");
114       assertEquals(MonitorNotification.THRESHOLD_LOW_VALUE_EXCEEDED,
115                    "jmx.monitor.gauge.low");
116       assertEquals(MonitorNotification.THRESHOLD_VALUE_EXCEEDED,
117                    "jmx.monitor.counter.threshold");
118    }
119
120    // Counter monitor notification info ---------------------------------------
121

122    /**
123     * Test the notification info of the counter
124     */

125    public void testCounterNotificationInfo()
126       throws Exception
127    {
128       HashSet expected = new HashSet();
129       expected.add(MonitorNotification.OBSERVED_ATTRIBUTE_ERROR);
130       expected.add(MonitorNotification.OBSERVED_ATTRIBUTE_TYPE_ERROR);
131       expected.add(MonitorNotification.OBSERVED_OBJECT_ERROR);
132       expected.add(MonitorNotification.RUNTIME_ERROR);
133       expected.add(MonitorNotification.THRESHOLD_ERROR);
134       expected.add(MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
135
136       MBeanNotificationInfo[] mbni = new CounterMonitor().getNotificationInfo();
137       checkNotificationInfo("Counter", mbni, expected);
138    }
139
140    // Counter normal no offset no modulus tests -------------------------------
141

142    /**
143     * Test normal counter threshold no offset no modulus
144     */

145    public void testNormalCounterThresholdExceededEarlyNoOffsetNoModulus()
146       throws Exception
147    {
148       initTest();
149       try
150       {
151          initCounterMonitor(true, new Integer(10),
152                             false, new Integer(0), new Integer(0));
153          expectStartMonitor(new Integer(10),
154             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
155       }
156       finally
157       {
158          stopMonitor();
159          MBeanServerFactory.releaseMBeanServer(server);
160       }
161    }
162
163    /**
164     * Test normal counter threshold no offset no modulus
165     */

166    public void testNormalCounterThresholdExceededLateNoOffsetNoModulus()
167       throws Exception
168    {
169       initTest();
170       try
171       {
172          initCounterMonitor(true, new Integer(10),
173                             false, new Integer(0), new Integer(0));
174          dontExpectStartMonitor(new Integer(0));
175          expect(new Integer(10),
176             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
177       }
178       finally
179       {
180          stopMonitor();
181          MBeanServerFactory.releaseMBeanServer(server);
182       }
183    }
184
185    /**
186     * Test normal counter threshold no offset no modulus
187     */

188    public void testNormalCounterThresholdExceededManyNoOffsetNoModulus()
189       throws Exception
190    {
191       initTest();
192       try
193       {
194          initCounterMonitor(true, new Integer(10),
195                             false, new Integer(0), new Integer(0));
196          dontExpectStartMonitor(new Integer(0));
197          expect(new Integer(10),
198             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
199          dontExpect(new Integer(0));
200          expect(new Integer(11),
201             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
202       }
203       finally
204       {
205          stopMonitor();
206          MBeanServerFactory.releaseMBeanServer(server);
207       }
208    }
209
210    /**
211     * Test normal counter threshold no offset no modulus
212     */

213    public void testNormalCounterThresholdNotExceededNoOffsetNoModulus()
214       throws Exception
215    {
216       initTest();
217       try
218       {
219          initCounterMonitor(true, new Integer(10),
220                             false, new Integer(0), new Integer(0));
221          dontExpectStartMonitor(new Integer(0));
222          dontExpect(new Integer(1));
223          dontExpect(new Integer(-1));
224          dontExpect(new Integer(9));
225          expect(new Integer(10),
226             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
227          dontExpect(new Integer(10));
228          dontExpect(new Integer(11));
229          dontExpect(new Integer(9));
230          expect(new Integer(10),
231             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
232          dontExpect(new Integer(9));
233       }
234       finally
235       {
236          stopMonitor();
237          MBeanServerFactory.releaseMBeanServer(server);
238       }
239    }
240
241    /**
242     * Test normal counter threshold no offset no modulus
243     */

244    public void testNormalCounterThresholdExceededNoneNoOffsetNoModulus()
245       throws Exception
246    {
247       initTest();
248       try
249       {
250          initCounterMonitor(false, new Integer(10),
251                             false, new Integer(0), new Integer(0));
252          dontExpectStartMonitor(new Integer(0));
253          dontExpect(new Integer(10));
254          dontExpect(new Integer(0));
255          dontExpect(new Integer(10));
256       }
257       finally
258       {
259          stopMonitor();
260          MBeanServerFactory.releaseMBeanServer(server);
261       }
262    }
263
264    // Counter normal offset no modulus tests ----------------------------------
265

266    /**
267     * Test normal counter threshold offset no modulus
268     */

269    public void testNormalCounterThresholdExceededEarlyOffsetNoModulus()
270       throws Exception
271    {
272       initTest();
273       try
274       {
275          initCounterMonitor(true, new Integer(10),
276                             false, new Integer(10), new Integer(0));
277          expectStartMonitor(new Integer(10),
278             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
279       }
280       finally
281       {
282          stopMonitor();
283          MBeanServerFactory.releaseMBeanServer(server);
284       }
285    }
286
287    /**
288     * Test normal counter threshold offset no modulus
289     */

290    public void testNormalCounterThresholdExceededLateOffsetNoModulus()
291       throws Exception
292    {
293       initTest();
294       try
295       {
296          initCounterMonitor(true, new Integer(10),
297                             false, new Integer(10), new Integer(0));
298          dontExpectStartMonitor(new Integer(0));
299          expect(new Integer(10),
300             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
301       }
302       finally
303       {
304          stopMonitor();
305          MBeanServerFactory.releaseMBeanServer(server);
306       }
307    }
308
309    /**
310     * Test normal counter threshold offset no modulus
311     */

312    public void testNormalCounterThresholdExceededManyOffsetNoModulus()
313       throws Exception
314    {
315       initTest();
316       try
317       {
318          initCounterMonitor(true, new Integer(10),
319                             false, new Integer(10), new Integer(0));
320          dontExpectStartMonitor(new Integer(0));
321          expect(new Integer(10),
322             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
323          dontExpect(new Integer(0));
324          dontExpect(new Integer(11));
325          expect(new Integer(20),
326             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
327          dontExpect(new Integer(29));
328          expect(new Integer(30),
329             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
330          expect(new Integer(40),
331             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
332       }
333       finally
334       {
335          stopMonitor();
336          MBeanServerFactory.releaseMBeanServer(server);
337       }
338    }
339
340    /**
341     * Test normal counter threshold offset no modulus
342     */

343    public void testNormalCounterThresholdNotExceededOffsetNoModulus()
344       throws Exception
345    {
346       initTest();
347       try
348       {
349          initCounterMonitor(true, new Integer(10),
350                             false, new Integer(10), new Integer(0));
351          dontExpectStartMonitor(new Integer(0));
352          dontExpect(new Integer(1));
353          dontExpect(new Integer(-1));
354          dontExpect(new Integer(9));
355          expect(new Integer(10),
356             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
357          dontExpect(new Integer(10));
358          dontExpect(new Integer(11));
359          dontExpect(new Integer(9));
360          expect(new Integer(20),
361             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
362          dontExpect(new Integer(19));
363       }
364       finally
365       {
366          stopMonitor();
367          MBeanServerFactory.releaseMBeanServer(server);
368       }
369    }
370
371    /**
372     * Test normal counter threshold offset no modulus
373     */

374    public void testNormalCounterThresholdExceededNoneOffsetNoModulus()
375       throws Exception
376    {
377       initTest();
378       try
379       {
380          initCounterMonitor(false, new Integer(10),
381                             false, new Integer(10), new Integer(0));
382          dontExpectStartMonitor(new Integer(0));
383          dontExpect(new Integer(10));
384          dontExpect(new Integer(0));
385          dontExpect(new Integer(20));
386       }
387       finally
388       {
389          stopMonitor();
390          MBeanServerFactory.releaseMBeanServer(server);
391       }
392    }
393
394    // Counter normal no offset modulus tests ---------------------------------
395

396    /**
397     * Test normal counter threshold no offset modulus
398     */

399    public void testNormalCounterThresholdExceededEarlyNoOffsetModulus()
400       throws Exception
401    {
402       initTest();
403       try
404       {
405          initCounterMonitor(true, new Integer(10),
406                             false, new Integer(0), new Integer(10));
407          expectStartMonitor(new Integer(10),
408             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
409       }
410       finally
411       {
412          stopMonitor();
413          MBeanServerFactory.releaseMBeanServer(server);
414       }
415    }
416
417    /**
418     * Test normal counter threshold no offset modulus
419     */

420    public void testNormalCounterThresholdExceededLateNoOffsetModulus()
421       throws Exception
422    {
423       initTest();
424       try
425       {
426          initCounterMonitor(true, new Integer(10),
427                             false, new Integer(0), new Integer(10));
428          dontExpectStartMonitor(new Integer(0));
429          expect(new Integer(10),
430             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
431       }
432       finally
433       {
434          stopMonitor();
435          MBeanServerFactory.releaseMBeanServer(server);
436       }
437    }
438
439    /**
440     * Test normal counter threshold no offset modulus
441     */

442    public void testNormalCounterThresholdExceededManyNoOffsetModulus()
443       throws Exception
444    {
445       initTest();
446       try
447       {
448          initCounterMonitor(true, new Integer(10),
449                             false, new Integer(0), new Integer(10));
450          dontExpectStartMonitor(new Integer(0));
451          expect(new Integer(10),
452             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
453          dontExpect(new Integer(0));
454          expect(new Integer(11),
455             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
456          expect(new Integer(12),
457             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
458          dontExpect(new Integer(0));
459          expect(new Integer(10),
460             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
461       }
462       catch (AssertionFailedError e)
463       {
464          fail("FAILS IN RI: Modulus ignored with no offset???");
465       }
466       finally
467       {
468          stopMonitor();
469          MBeanServerFactory.releaseMBeanServer(server);
470       }
471    }
472
473    /**
474     * Test normal counter threshold no offset modulus
475     */

476    public void testNormalCounterThresholdNotExceededNoOffsetModulus()
477       throws Exception
478    {
479       initTest();
480       try
481       {
482          initCounterMonitor(true, new Integer(10),
483                             false, new Integer(0), new Integer(10));
484          dontExpectStartMonitor(new Integer(0));
485          dontExpect(new Integer(1));
486          dontExpect(new Integer(-1));
487          dontExpect(new Integer(9));
488          expect(new Integer(10),
489             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
490          dontExpect(new Integer(9));
491          expect(new Integer(10),
492             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
493          dontExpect(new Integer(9));
494       }
495       finally
496       {
497          stopMonitor();
498          MBeanServerFactory.releaseMBeanServer(server);
499       }
500    }
501
502    /**
503     * Test normal counter threshold no offset modulus
504     */

505    public void testNormalCounterThresholdExceededNoneNoOffsetModulus()
506       throws Exception
507    {
508       initTest();
509       try
510       {
511          initCounterMonitor(false, new Integer(10),
512                             false, new Integer(0), new Integer(10));
513          dontExpectStartMonitor(new Integer(0));
514          dontExpect(new Integer(10));
515          dontExpect(new Integer(0));
516          dontExpect(new Integer(10));
517       }
518       finally
519       {
520          stopMonitor();
521          MBeanServerFactory.releaseMBeanServer(server);
522       }
523    }
524
525    // Counter normal offset modulus tests -------------------------------------
526

527    /**
528     * Test normal counter threshold offset modulus
529     */

530    public void testNormalCounterThresholdExceededEarlyOffsetModulus()
531       throws Exception
532    {
533       initTest();
534       try
535       {
536          initCounterMonitor(true, new Integer(10),
537                             false, new Integer(10), new Integer(10));
538          expectStartMonitor(new Integer(10),
539             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
540       }
541       finally
542       {
543          stopMonitor();
544          MBeanServerFactory.releaseMBeanServer(server);
545       }
546    }
547
548    /**
549     * Test normal counter threshold offset modulus
550     */

551    public void testNormalCounterThresholdExceededLateOffsetModulus()
552       throws Exception
553    {
554       initTest();
555       try
556       {
557          initCounterMonitor(true, new Integer(10),
558                             false, new Integer(10), new Integer(10));
559          dontExpectStartMonitor(new Integer(0));
560          expect(new Integer(10),
561             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
562       }
563       finally
564       {
565          stopMonitor();
566          MBeanServerFactory.releaseMBeanServer(server);
567       }
568    }
569
570    /**
571     * Test normal counter threshold offset modulus
572     */

573    public void testNormalCounterThresholdExceededManyOffsetModulus()
574       throws Exception
575    {
576       initTest();
577       try
578       {
579          initCounterMonitor(true, new Integer(10),
580                             false, new Integer(10), new Integer(20));
581          dontExpectStartMonitor(new Integer(0));
582          expect(new Integer(10),
583             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
584          dontExpect(new Integer(0));
585          dontExpect(new Integer(12));
586          expect(new Integer(20),
587             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
588          if (((CounterMonitor)monitor).getThreshold().equals(new Integer(30)))
589            fail("FAILS IN RI: Threshold 10, Offset 10, Modulus 20 should " +
590                 " never get a threshold of 30");
591          expect(new Integer(10),
592             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
593          dontExpect(new Integer(10));
594          expect(new Integer(20),
595             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
596          expect(new Integer(20),
597             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
598          expect(new Integer(30),
599             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
600       }
601       finally
602       {
603          stopMonitor();
604          MBeanServerFactory.releaseMBeanServer(server);
605       }
606    }
607
608    /**
609     * Test normal counter threshold offset modulus
610     */

611    public void testNormalCounterThresholdNotExceededOffsetModulus()
612       throws Exception
613    {
614       initTest();
615       try
616       {
617          initCounterMonitor(true, new Integer(10),
618                             false, new Integer(10), new Integer(20));
619          dontExpectStartMonitor(new Integer(0));
620          dontExpect(new Integer(1));
621          dontExpect(new Integer(-1));
622          dontExpect(new Integer(9));
623          expect(new Integer(10),
624             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
625          dontExpect(new Integer(10));
626          dontExpect(new Integer(11));
627          dontExpect(new Integer(9));
628          expect(new Integer(20),
629             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
630          if (((CounterMonitor)monitor).getThreshold().equals(new Integer(30)))
631            fail("FAILS IN RI: Threshold 10, Offset 10, Modulus 20 should " +
632                 " never get a threshold of 30");
633          expect(new Integer(19),
634             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
635       }
636       finally
637       {
638          stopMonitor();
639          MBeanServerFactory.releaseMBeanServer(server);
640       }
641    }
642
643    /**
644     * Test normal counter threshold offset modulus
645     */

646    public void testNormalCounterThresholdExceededNoneOffsetModulus()
647       throws Exception
648    {
649       initTest();
650       try
651       {
652          initCounterMonitor(false, new Integer(10),
653                             false, new Integer(10), new Integer(10));
654          dontExpectStartMonitor(new Integer(0));
655          dontExpect(new Integer(10));
656          dontExpect(new Integer(0));
657          dontExpect(new Integer(20));
658       }
659       finally
660       {
661          stopMonitor();
662          MBeanServerFactory.releaseMBeanServer(server);
663       }
664    }
665
666    // Counter difference no offset no modulus tests ---------------------------
667

668    /**
669     * Test difference counter threshold no offset no modulus
670     */

671    public void testDiffCounterThresholdExceededNoOffsetNoModulus()
672       throws Exception
673    {
674       initTest();
675       try
676       {
677          initCounterMonitor(true, new Integer(10),
678                             true, new Integer(0), new Integer(0));
679          dontExpectStartMonitor(new Integer(0));
680          expect(new Integer(10),
681             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
682       }
683       finally
684       {
685          stopMonitor();
686          MBeanServerFactory.releaseMBeanServer(server);
687       }
688    }
689
690    /**
691     * Test difference counter threshold no offset no modulus
692     */

693    public void testDiffCounterThresholdExceededManyNoOffsetNoModulus()
694       throws Exception
695    {
696       initTest();
697       try
698       {
699          initCounterMonitor(true, new Integer(10),
700                             true, new Integer(0), new Integer(0));
701          dontExpectStartMonitor(new Integer(0));
702          expect(new Integer(10),
703             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
704          expectDiff(new Integer(0), new Integer(11),
705             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
706       }
707       finally
708       {
709          stopMonitor();
710          MBeanServerFactory.releaseMBeanServer(server);
711       }
712    }
713
714    /**
715     * Test difference counter threshold no offset no modulus
716     */

717    public void testDiffCounterThresholdNotExceededNoOffsetNoModulus()
718       throws Exception
719    {
720       initTest();
721       try
722       {
723          initCounterMonitor(true, new Integer(10),
724                             true, new Integer(0), new Integer(0));
725          dontExpectStartMonitorDiff(new Integer(0), new Integer(1));
726          dontExpectDiff(new Integer(0), new Integer(9));
727          dontExpectDiff(new Integer(1), new Integer(10));
728          dontExpectDiff(new Integer(9), new Integer(11));
729          dontExpectDiff(new Integer(9), new Integer(0));
730       }
731       finally
732       {
733          stopMonitor();
734          MBeanServerFactory.releaseMBeanServer(server);
735       }
736    }
737
738    /**
739     * Test difference counter threshold no offset no modulus
740     */

741    public void testDiffCounterThresholdExceededNoneNoOffsetNoModulus()
742       throws Exception
743    {
744       initTest();
745       try
746       {
747          initCounterMonitor(false, new Integer(10),
748                             true, new Integer(0), new Integer(0));
749          dontExpectStartMonitorDiff(new Integer(0), new Integer(10));
750          dontExpectDiff(new Integer(0), new Integer(-10));
751          dontExpectDiff(new Integer(0), new Integer(100));
752       }
753       finally
754       {
755          stopMonitor();
756          MBeanServerFactory.releaseMBeanServer(server);
757       }
758    }
759
760    // Counter difference offset no modulus tests ------------------------------
761

762    /**
763     * Test difference counter threshold offset no modulus
764     */

765    public void testDiffCounterThresholdExceededOffsetNoModulus()
766       throws Exception
767    {
768       initTest();
769       try
770       {
771          initCounterMonitor(true, new Integer(10),
772                             true, new Integer(10), new Integer(0));
773          dontExpectStartMonitor(new Integer(0));
774          expect(new Integer(10),
775             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
776       }
777       finally
778       {
779          stopMonitor();
780          MBeanServerFactory.releaseMBeanServer(server);
781       }
782    }
783
784    /**
785     * Test difference counter threshold offset no modulus
786     */

787    public void testDiffCounterThresholdExceededManyOffsetNoModulus()
788       throws Exception
789    {
790       initTest();
791       try
792       {
793          initCounterMonitor(true, new Integer(10),
794                             true, new Integer(10), new Integer(0));
795          dontExpectStartMonitor(new Integer(0));
796          expect(new Integer(10),
797             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
798          expectDiff(new Integer(0), new Integer(10),
799             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
800          expectDiff(new Integer(10), new Integer(30),
801             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
802          expectDiff(new Integer(30), new Integer(60),
803             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
804          expectDiff(new Integer(60), new Integer(100),
805             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
806          expectDiff(new Integer(0), new Integer(10),
807             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
808       }
809       finally
810       {
811          stopMonitor();
812          MBeanServerFactory.releaseMBeanServer(server);
813       }
814    }
815
816    /**
817     * Test difference counter threshold offset no modulus
818     */

819    public void testDiffCounterThresholdNotExceededOffsetNoModulus()
820       throws Exception
821    {
822       initTest();
823       try
824       {
825          initCounterMonitor(true, new Integer(10),
826                             true, new Integer(10), new Integer(0));
827          dontExpectStartMonitorDiff(new Integer(0), new Integer(1));
828          expectDiff(new Integer(0), new Integer(10),
829             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
830          dontExpectDiff(new Integer(10), new Integer(20));
831          expectDiff(new Integer(20), new Integer(40),
832             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
833          dontExpectDiff(new Integer(40), new Integer(69));
834       }
835       finally
836       {
837          stopMonitor();
838          MBeanServerFactory.releaseMBeanServer(server);
839       }
840    }
841
842    /**
843     * Test difference counter threshold offset no modulus
844     */

845    public void testDiffCounterThresholdExceededNoneOffsetNoModulus()
846       throws Exception
847    {
848       initTest();
849       try
850       {
851          initCounterMonitor(false, new Integer(10),
852                             true, new Integer(10), new Integer(0));
853          dontExpectStartMonitorDiff(new Integer(0), new Integer(1));
854          dontExpectDiff(new Integer(0), new Integer(10));
855          dontExpectDiff(new Integer(10), new Integer(20));
856          dontExpectDiff(new Integer(20), new Integer(40));
857          dontExpectDiff(new Integer(40), new Integer(69));
858       }
859       finally
860       {
861          stopMonitor();
862          MBeanServerFactory.releaseMBeanServer(server);
863       }
864    }
865
866    // Counter difference no offset modulus tests ------------------------------
867

868    /**
869     * Test difference counter threshold no offset modulus
870     */

871    public void testDiffCounterThresholdExceededNoOffsetModulus()
872       throws Exception
873    {
874       initTest();
875       try
876       {
877          initCounterMonitor(true, new Integer(10),
878                             true, new Integer(0), new Integer(10));
879          dontExpectStartMonitor(new Integer(0));
880          expect(new Integer(10),
881             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
882       }
883       finally
884       {
885          stopMonitor();
886          MBeanServerFactory.releaseMBeanServer(server);
887       }
888    }
889
890    /**
891     * Test difference counter threshold no offset modulus
892     */

893    public void testDiffCounterThresholdExceededManyNoOffsetModulus()
894       throws Exception
895    {
896       initTest();
897       try
898       {
899          initCounterMonitor(true, new Integer(10),
900                             true, new Integer(0), new Integer(10));
901          dontExpectStartMonitor(new Integer(0));
902          expect(new Integer(10),
903             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
904          expectDiff(new Integer(0), new Integer(11),
905             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
906          expectDiff(new Integer(12), new Integer(22),
907             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
908          expectDiff(new Integer(0), new Integer(10),
909             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
910       }
911       finally
912       {
913          stopMonitor();
914          MBeanServerFactory.releaseMBeanServer(server);
915       }
916    }
917
918    /**
919     * Test difference counter threshold no offset modulus
920     */

921    public void testDiffCounterThresholdNotExceededNoOffsetModulus()
922       throws Exception
923    {
924       initTest();
925       try
926       {
927          initCounterMonitor(true, new Integer(10),
928                             true, new Integer(0), new Integer(10));
929          dontExpectStartMonitorDiff(new Integer(0), new Integer(1));
930          dontExpectDiff(new Integer(0), new Integer(9));
931          dontExpectDiff(new Integer(11), new Integer(20));
932          dontExpectDiffModulus(new Integer(10), new Integer(-3), new Integer(10));
933       }
934       finally
935       {
936          stopMonitor();
937          MBeanServerFactory.releaseMBeanServer(server);
938       }
939    }
940
941    /**
942     * Test difference counter threshold no offset modulus
943     */

944    public void testDiffCounterThresholdExceededNoneNoOffsetModulus()
945       throws Exception
946    {
947       initTest();
948       try
949       {
950          initCounterMonitor(false, new Integer(10),
951                             true, new Integer(0), new Integer(10));
952          dontExpectStartMonitorDiff(new Integer(0), new Integer(10));
953          dontExpectDiffModulus(new Integer(0), new Integer(-10), new Integer(10));
954          dontExpectDiff(new Integer(0), new Integer(100));
955       }
956       finally
957       {
958          stopMonitor();
959          MBeanServerFactory.releaseMBeanServer(server);
960       }
961    }
962
963    // Counter difference offset modulus tests ---------------------------------
964

965    /**
966     * Test difference counter threshold offset modulus
967     */

968    public void testDiffCounterThresholdExceededOffsetModulus()
969       throws Exception
970    {
971       initTest();
972       try
973       {
974          initCounterMonitor(true, new Integer(10),
975                             true, new Integer(10), new Integer(10));
976          dontExpectStartMonitor(new Integer(0));
977          expect(new Integer(10),
978             MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
979       }
980       finally
981       {
982          stopMonitor();
983          MBeanServerFactory.releaseMBeanServer(server);
984       }
985    }
986
987    /**
988     * Test difference counter threshold offset modulus
989     */

990    public void testDiffCounterThresholdExceededManyOffsetModulus()
991       throws Exception
992    {
993       initTest();
994       try
995       {
996          initCounterMonitor(true, new Integer(10),
997                             true, new Integer(10), new Integer(20));
998          dontExpectStartMonitor(new Integer(0));
999          expectDiff(new Integer(0), new Integer(11),
1000            MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
1001         expectDiff(new Integer(11), new Integer(31),
1002            MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
1003         expectDiff(new Integer(0), new Integer(10),
1004            MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
1005      }
1006      finally
1007      {
1008         stopMonitor();
1009         MBeanServerFactory.releaseMBeanServer(server);
1010      }
1011   }
1012
1013   /**
1014    * Test difference counter threshold offset modulus
1015    */

1016   public void testDiffCounterThresholdNotExceededOffsetModulus()
1017      throws Exception
1018   {
1019      initTest();
1020      try
1021      {
1022         initCounterMonitor(true, new Integer(10),
1023                            true, new Integer(10), new Integer(20));
1024         dontExpectStartMonitorDiff(new Integer(0), new Integer(1));
1025         dontExpectDiff(new Integer(1), new Integer(10));
1026         dontExpectDiffModulus(new Integer(10), new Integer(-13), new Integer(20));
1027      }
1028      finally
1029      {
1030         stopMonitor();
1031         MBeanServerFactory.releaseMBeanServer(server);
1032      }
1033   }
1034
1035   /**
1036    * Test difference counter threshold offset modulus
1037    */

1038   public void testDiffCounterThresholdExceededNoneOffsetModulus()
1039      throws Exception
1040   {
1041      initTest();
1042      try
1043      {
1044         initCounterMonitor(false, new Integer(10),
1045                            true, new Integer(10), new Integer(20));
1046         dontExpectStartMonitorDiff(new Integer(0), new Integer(10));
1047         dontExpectDiffModulus(new Integer(0), new Integer(-10), new Integer(20));
1048         dontExpectDiff(new Integer(0), new Integer(100));
1049      }
1050      finally
1051      {
1052         stopMonitor();
1053         MBeanServerFactory.releaseMBeanServer(server);
1054      }
1055   }
1056
1057   // Counter error tests -----------------------------------------------------
1058

1059   /**
1060    * Test invalid attribute
1061    */

1062   public void testCounterInvalidAttribute()
1063      throws Exception
1064   {
1065      initTest();
1066      try
1067      {
1068         initCounterMonitor(true, new Integer(10),
1069                            false, new Integer(10), new Integer(10));
1070         attributeErrorStartMonitor(new Integer(0));
1071      }
1072      finally
1073      {
1074         stopMonitor();
1075         MBeanServerFactory.releaseMBeanServer(server);
1076      }
1077   }
1078
1079   /**
1080    * Test invalid attribute
1081    */

1082   public void testCounterInvalidAttributeNull()
1083      throws Exception
1084   {
1085      initTest();
1086      try
1087      {
1088         initCounterMonitor(true, new Integer(10),
1089                            false, new Integer(10), new Integer(10));
1090         attributeNullStartMonitor(new Integer(0));
1091      }
1092      finally
1093      {
1094         stopMonitor();
1095         MBeanServerFactory.releaseMBeanServer(server);
1096      }
1097   }
1098
1099   /**
1100    * Test invalid attribute type
1101    */

1102   public void testCounterInvalidAttributeType()
1103      throws Exception
1104   {
1105      initTest();
1106      try
1107      {
1108         initCounterMonitor(true, new Integer(10),
1109                            false, new Integer(10), new Integer(10));
1110         attributeTypeStartMonitor(new Integer(0));
1111      }
1112      finally
1113      {
1114         stopMonitor();
1115         MBeanServerFactory.releaseMBeanServer(server);
1116      }
1117   }
1118
1119   /**
1120    * Test write only attribute
1121    */

1122   public void testCounterWriteOnly()
1123      throws Exception
1124   {
1125      initTest();
1126      try
1127      {
1128         initCounterMonitor(true, new Integer(10),
1129                            false, new Integer(10), new Integer(10));
1130         attributeWriteStartMonitor(new Integer(0));
1131      }
1132      finally
1133      {
1134         stopMonitor();
1135         MBeanServerFactory.releaseMBeanServer(server);
1136      }
1137   }
1138
1139   /**
1140    * Test invalid attribute type
1141    */

1142   public void testCounterInvalidObjectName()
1143      throws Exception
1144   {
1145      initTest();
1146      try
1147      {
1148         initCounterMonitor(true, new Integer(10),
1149                            false, new Integer(10), new Integer(10));
1150         objectNameStartMonitor(new Integer(0));
1151      }
1152      finally
1153      {
1154         stopMonitor();
1155         MBeanServerFactory.releaseMBeanServer(server);
1156      }
1157   }
1158
1159   /**
1160    * Test invalid threshold
1161    */

1162   public void testCounterInvalidThreshold()
1163      throws Exception
1164   {
1165      initTest();
1166      try
1167      {
1168         initCounterMonitor(true, new Long(10),
1169                            false, new Integer(10), new Integer(10));
1170         objectNameStartMonitor(new Integer(0));
1171      }
1172      finally
1173      {
1174         stopMonitor();
1175         MBeanServerFactory.releaseMBeanServer(server);
1176      }
1177   }
1178
1179   /**
1180    * Test invalid threshold
1181    */

1182   public void testCounterInvalidOffset()
1183      throws Exception
1184   {
1185      initTest();
1186      try
1187      {
1188         initCounterMonitor(true, new Integer(10),
1189                            false, new Long(10), new Integer(10));
1190         objectNameStartMonitor(new Integer(0));
1191      }
1192      finally
1193      {
1194         stopMonitor();
1195         MBeanServerFactory.releaseMBeanServer(server);
1196      }
1197   }
1198
1199   /**
1200    * Test invalid threshold
1201    */

1202   public void testCounterInvalidModulus()
1203      throws Exception
1204   {
1205      initTest();
1206      try
1207      {
1208         initCounterMonitor(true, new Integer(10),
1209                            false, new Integer(10), new Long(10));
1210         objectNameStartMonitor(new Integer(0));
1211      }
1212      finally
1213      {
1214         stopMonitor();
1215         MBeanServerFactory.releaseMBeanServer(server);
1216      }
1217   }
1218
1219   /**
1220    * Test runtime error
1221    */

1222   public void testCounterRuntimeError()
1223      throws Exception
1224   {
1225      initTest();
1226      try
1227      {
1228         initCounterMonitor(true, new Integer(10),
1229                            false, new Integer(10), new Integer(10));
1230         runtimeErrorStartMonitor(new Integer(0));
1231      }
1232      finally
1233      {
1234         stopMonitor();
1235         MBeanServerFactory.releaseMBeanServer(server);
1236      }
1237   }
1238
1239   // Gauge notification tests ------------------------------------------------
1240

1241   /**
1242    * Test the notification info of the gauge
1243    */

1244   public void testGaugeNotificationInfo()
1245      throws Exception
1246   {
1247      HashSet expected = new HashSet();
1248      expected.add(MonitorNotification.OBSERVED_ATTRIBUTE_ERROR);
1249      expected.add(MonitorNotification.OBSERVED_ATTRIBUTE_TYPE_ERROR);
1250      expected.add(MonitorNotification.OBSERVED_OBJECT_ERROR);
1251      expected.add(MonitorNotification.RUNTIME_ERROR);
1252      expected.add(MonitorNotification.THRESHOLD_ERROR);
1253      expected.add(MonitorNotification.THRESHOLD_HIGH_VALUE_EXCEEDED);
1254      expected.add(MonitorNotification.THRESHOLD_LOW_VALUE_EXCEEDED);
1255
1256      MBeanNotificationInfo[] mbni = new GaugeMonitor().getNotificationInfo();
1257      checkNotificationInfo("Gauge", mbni, expected);
1258   }
1259
1260   // Gauge error tests -------------------------------------------------------
1261

1262   /**
1263    * Test invalid attribute
1264    */

1265   public void testGaugeInvalidAttribute()
1266      throws Exception
1267   {
1268      initTest();
1269      try
1270      {
1271         initGaugeMonitor(true, true, new Integer(10), new Integer(0), false);
1272         attributeErrorStartMonitor(new Integer(0));
1273      }
1274      finally
1275      {
1276         stopMonitor();
1277         MBeanServerFactory.releaseMBeanServer(server);
1278      }
1279   }
1280
1281   /**
1282    * Test invalid attribute
1283    */

1284   public void testGaugeInvalidAttributeNull()
1285      throws Exception
1286   {
1287      initTest();
1288      try
1289      {
1290         initGaugeMonitor(true, true, new Integer(10), new Integer(0), false);
1291         attributeNullStartMonitor(new Integer(0));
1292      }
1293      finally
1294      {
1295         stopMonitor();
1296         MBeanServerFactory.releaseMBeanServer(server);
1297      }
1298   }
1299
1300   /**
1301    * Test invalid attribute type
1302    */

1303   public void testGaugeInvalidAttributeType()
1304      throws Exception
1305   {
1306      initTest();
1307      try
1308      {
1309         initGaugeMonitor(true, true, new Integer(10), new Integer(0), false);
1310         attributeTypeStartMonitor(new Integer(0));
1311      }
1312      finally
1313      {
1314         stopMonitor();
1315         MBeanServerFactory.releaseMBeanServer(server);
1316      }
1317   }
1318
1319   /**
1320    * Test write only
1321    */

1322   public void testGaugeWriteOnly()
1323      throws Exception
1324   {
1325      initTest();
1326      try
1327      {
1328         initGaugeMonitor(true, true, new Integer(10), new Integer(0), false);
1329         attributeWriteStartMonitor(new Integer(0));
1330      }
1331      finally
1332      {
1333         stopMonitor();
1334         MBeanServerFactory.releaseMBeanServer(server);
1335      }
1336   }
1337
1338   /**
1339    * Test invalid attribute type
1340    */

1341   public void testGaugeInvalidObjectName()
1342      throws Exception
1343   {
1344      initTest();
1345      try
1346      {
1347         initGaugeMonitor(true, true, new Integer(10), new Integer(0), false);
1348         objectNameStartMonitor(new Integer(0));
1349      }
1350      finally
1351      {
1352         stopMonitor();
1353         MBeanServerFactory.releaseMBeanServer(server);
1354      }
1355   }
1356
1357   /**
1358    * Test invalid threshold
1359    */

1360   public void testGaugeInvalidThreshold()
1361      throws Exception
1362   {
1363      initTest();
1364      try
1365      {
1366         initGaugeMonitor(true, true, new Long(10), new Long(0), false);
1367         objectNameStartMonitor(new Integer(0));
1368      }
1369      finally
1370      {
1371         stopMonitor();
1372         MBeanServerFactory.releaseMBeanServer(server);
1373      }
1374   }
1375
1376   /**
1377    * Test runtime error
1378    */

1379   public void testGaugeRuntimeError()
1380      throws Exception
1381   {
1382      initTest();
1383      try
1384      {
1385         initGaugeMonitor(true, true, new Integer(10), new Integer(0), false);
1386         runtimeErrorStartMonitor(new Integer(0));
1387      }
1388      finally
1389      {
1390         stopMonitor();
1391         MBeanServerFactory.releaseMBeanServer(server);
1392      }
1393   }
1394
1395   // String notification tests -----------------------------------------------
1396

1397   /**
1398    * Test the notification info of the string
1399    */

1400   public void testStringNotificationInfo()
1401      throws Exception
1402   {
1403      HashSet expected = new HashSet();
1404      expected.add(MonitorNotification.OBSERVED_ATTRIBUTE_ERROR);
1405      expected.add(MonitorNotification.OBSERVED_ATTRIBUTE_TYPE_ERROR);
1406      expected.add(MonitorNotification.OBSERVED_OBJECT_ERROR);
1407      expected.add(MonitorNotification.RUNTIME_ERROR);
1408      expected.add(MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED);
1409      expected.add(MonitorNotification.STRING_TO_COMPARE_VALUE_MATCHED);
1410
1411      MBeanNotificationInfo[] mbni = new StringMonitor().getNotificationInfo();
1412      checkNotificationInfo("String", mbni, expected);
1413   }
1414
1415   // String test -------------------------------------------------------------
1416

1417   /**
1418    * Test a string differs
1419    */

1420   public void testStringDifferEarly()
1421      throws Exception
1422   {
1423      initTest();
1424      try
1425      {
1426         initStringMonitor(true, false, "Hello");
1427         expectStartMonitor("Goodbye",
1428            MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED);
1429      }
1430      finally
1431      {
1432         stopMonitor();
1433         MBeanServerFactory.releaseMBeanServer(server);
1434      }
1435   }
1436
1437   /**
1438    * Test a string differs
1439    */

1440   public void testStringDifferLate()
1441      throws Exception
1442   {
1443      initTest();
1444      try
1445      {
1446         initStringMonitor(true, false, "Hello");
1447         dontExpectStartMonitor("Hello");
1448         expect("Goodbye",
1449            MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED);
1450      }
1451      finally
1452      {
1453         stopMonitor();
1454         MBeanServerFactory.releaseMBeanServer(server);
1455      }
1456   }
1457
1458   /**
1459    * Test a string differs many
1460    */

1461   public void testStringDifferManyEarly()
1462      throws Exception
1463   {
1464      initTest();
1465      try
1466      {
1467         initStringMonitor(true, false, "Hello");
1468         expectStartMonitor("Goodbye",
1469            MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED);
1470         dontExpect("Hello");
1471         expect("Goodbye",
1472            MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED);
1473         dontExpect("Hello");
1474         expect("Goodbye",
1475            MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED);
1476         dontExpect("Hello");
1477      }
1478      finally
1479      {
1480         stopMonitor();
1481         MBeanServerFactory.releaseMBeanServer(server);
1482      }
1483   }
1484
1485   /**
1486    * Test a string differs many
1487    */

1488   public void testStringDifferManyLate()
1489      throws Exception
1490   {
1491      initTest();
1492      try
1493      {
1494         initStringMonitor(true, false, "Hello");
1495         dontExpectStartMonitor("Hello");
1496         expect("Goodbye",
1497            MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED);
1498         dontExpect("Hello");
1499         expect("Goodbye",
1500            MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED);
1501         dontExpect("Hello");
1502         expect("Goodbye",
1503            MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED);
1504         dontExpect("Hello");
1505      }
1506      finally
1507      {
1508         stopMonitor();
1509         MBeanServerFactory.releaseMBeanServer(server);
1510      }
1511   }
1512
1513   /**
1514    * Test a string matches
1515    */

1516   public void testStringMatchEarly()
1517      throws Exception
1518   {
1519      initTest();
1520      try
1521      {
1522         initStringMonitor(false, true, "Hello");
1523         expectStartMonitor("Hello",
1524            MonitorNotification.STRING_TO_COMPARE_VALUE_MATCHED);
1525      }
1526      finally
1527      {
1528         stopMonitor();
1529         MBeanServerFactory.releaseMBeanServer(server);
1530      }
1531   }
1532
1533   /**
1534    * Test a string matches
1535    */

1536   public void testStringMatchLate()
1537      throws Exception
1538   {
1539      initTest();
1540      try
1541      {
1542         initStringMonitor(false, true, "Hello");
1543         dontExpectStartMonitor("Goodbye");
1544         expect("Hello",
1545            MonitorNotification.STRING_TO_COMPARE_VALUE_MATCHED);
1546      }
1547      finally
1548      {
1549         stopMonitor();
1550         MBeanServerFactory.releaseMBeanServer(server);
1551      }
1552   }
1553
1554   /**
1555    * Test a string matches
1556    */

1557   public void testStringMatchManyEarly()
1558      throws Exception
1559   {
1560      initTest();
1561      try
1562      {
1563         initStringMonitor(false, true, "Hello");
1564         expectStartMonitor("Hello",
1565            MonitorNotification.STRING_TO_COMPARE_VALUE_MATCHED);
1566         dontExpect("Goodbye");
1567         expect("Hello",
1568            MonitorNotification.STRING_TO_COMPARE_VALUE_MATCHED);
1569         dontExpect("Goodbye");
1570         expect("Hello",
1571            MonitorNotification.STRING_TO_COMPARE_VALUE_MATCHED);
1572      }
1573      finally
1574      {
1575         stopMonitor();
1576         MBeanServerFactory.releaseMBeanServer(server);
1577      }
1578   }
1579
1580   /**
1581    * Test a string matches
1582    */

1583   public void testStringMatchManyLate()
1584      throws Exception
1585   {
1586      initTest();
1587      try
1588      {
1589         initStringMonitor(false, true, "Hello");
1590         dontExpectStartMonitor("Goodbye");
1591         expect("Hello",
1592            MonitorNotification.STRING_TO_COMPARE_VALUE_MATCHED);
1593         dontExpect("Goodbye");
1594         expect("Hello",
1595            MonitorNotification.STRING_TO_COMPARE_VALUE_MATCHED);
1596         dontExpect("Goodbye");
1597         expect("Hello",
1598            MonitorNotification.STRING_TO_COMPARE_VALUE_MATCHED);
1599      }
1600      finally
1601      {
1602         stopMonitor();
1603         MBeanServerFactory.releaseMBeanServer(server);
1604      }
1605   }
1606
1607   /**
1608    * Test a string differs and matches
1609    */

1610   public void testStringBoth()
1611      throws Exception
1612   {
1613      initTest();
1614      try
1615      {
1616         initStringMonitor(true, true, "Hello");
1617         expectStartMonitor("Goodbye",
1618            MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED);
1619         expect("Hello",
1620            MonitorNotification.STRING_TO_COMPARE_VALUE_MATCHED);
1621      }
1622      finally
1623      {
1624         stopMonitor();
1625         MBeanServerFactory.releaseMBeanServer(server);
1626      }
1627   }
1628
1629   /**
1630    * Test a string differs and matches
1631    */

1632   public void testStringBothMany()
1633      throws Exception
1634   {
1635      initTest();
1636      try
1637      {
1638         initStringMonitor(true, true, "Hello");
1639         expectStartMonitor("Goodbye",
1640            MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED);
1641         expect("Hello",
1642            MonitorNotification.STRING_TO_COMPARE_VALUE_MATCHED);
1643         expect("Goodbye",
1644            MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED);
1645         expect("Hello",
1646            MonitorNotification.STRING_TO_COMPARE_VALUE_MATCHED);
1647         expect("Goodbye",
1648            MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED);
1649      }
1650      finally
1651      {
1652         stopMonitor();
1653         MBeanServerFactory.releaseMBeanServer(server);
1654      }
1655   }
1656
1657   /**
1658    * Test a string nothing
1659    */

1660   public void testStringNever()
1661      throws Exception
1662   {
1663      initTest();
1664      try
1665      {
1666         initStringMonitor(false, false, "Hello");
1667         dontExpectStartMonitor("Goodbye");
1668         dontExpect("Hello");
1669         dontExpect("Goodbye");
1670      }
1671      finally
1672      {
1673         stopMonitor();
1674         MBeanServerFactory.releaseMBeanServer(server);
1675      }
1676   }
1677
1678   // String error tests ------------------------------------------------------
1679

1680   /**
1681    * Test invalid attribute
1682    */

1683   public void testStringInvalidAttribute()
1684      throws Exception
1685   {
1686      initTest();
1687      try
1688      {
1689         initStringMonitor(true, true, "Hello");
1690         attributeErrorStartMonitor("Goodbye");
1691      }
1692      finally
1693      {
1694         stopMonitor();
1695         MBeanServerFactory.releaseMBeanServer(server);
1696      }
1697   }
1698
1699   /**
1700    * Test invalid attribute
1701    */

1702   public void testStringInvalidAttributeNull()
1703      throws Exception
1704   {
1705      initTest();
1706      try
1707      {
1708         initStringMonitor(true, true, "Hello");
1709         attributeNullStartMonitor("Goodbye");
1710      }
1711      finally
1712      {
1713         stopMonitor();
1714         MBeanServerFactory.releaseMBeanServer(server);
1715      }
1716   }
1717
1718   /**
1719    * Test invalid attribute type
1720    */

1721   public void testStringInvalidAttributeType()
1722      throws Exception
1723   {
1724      initTest();
1725      try
1726      {
1727         initStringMonitor(true, true, "Hello");
1728         attributeTypeStartMonitor("Goodbye");
1729      }
1730      finally
1731      {
1732         stopMonitor();
1733         MBeanServerFactory.releaseMBeanServer(server);
1734      }
1735   }
1736
1737   /**
1738    * Test write only attribute
1739    */

1740   public void testStringWriteOnly()
1741      throws Exception
1742   {
1743      initTest();
1744      try
1745      {
1746         initStringMonitor(true, true, "Hello");
1747         attributeWriteStartMonitor("Goodbye");
1748      }
1749      finally
1750      {
1751         stopMonitor();
1752         MBeanServerFactory.releaseMBeanServer(server);
1753      }
1754   }
1755
1756   /**
1757    * Test invalid attribute type
1758    */

1759   public void testStringInvalidObjectName()
1760      throws Exception
1761   {
1762      initTest();
1763      try
1764      {
1765         initStringMonitor(true, true, "Hello");
1766         objectNameStartMonitor("Goodbye");
1767      }
1768      finally
1769      {
1770         stopMonitor();
1771         MBeanServerFactory.releaseMBeanServer(server);
1772      }
1773   }
1774
1775   /**
1776    * Test runtime error
1777    */

1778   public void testStringRuntimeError()
1779      throws Exception
1780   {
1781      initTest();
1782      try
1783      {
1784         initStringMonitor(true, true, "Hello");
1785         runtimeErrorStartMonitor("Goodbye");
1786      }
1787      finally
1788      {
1789         stopMonitor();
1790         MBeanServerFactory.releaseMBeanServer(server);
1791      }
1792   }
1793
1794   // Support -----------------------------------------------------------------
1795

1796   /**
1797    * Create a counter monitor
1798    */

1799   private void initCounterMonitor(boolean notify, Number threshold,
1800        boolean differenceMode, Number offset, Number modulus)
1801   {
1802      try
1803      {
1804         CounterMonitor counterMonitor = new CounterMonitor();
1805         counterMonitor.setNotify(notify);
1806         counterMonitor.setThreshold(threshold);
1807         counterMonitor.setDifferenceMode(differenceMode);
1808         counterMonitor.setOffset(offset);
1809         counterMonitor.setModulus(modulus);
1810         CounterSupport support = new CounterSupport();
1811         monitor = counterMonitor;
1812         monitored = support;
1813         initMonitor();
1814      }
1815      catch (Exception e)
1816      {
1817         fail(e.toString());
1818      }
1819   }
1820
1821   /**
1822    * Check a counter's threshold
1823    */

1824   private void checkThreshold(Number number)
1825   {
1826      assertEquals(number, ((CounterMonitor)monitor).getThreshold());
1827   }
1828
1829   /**
1830    * Create a gauge monitor
1831    */

1832   private void initGaugeMonitor(boolean notifyHigh, boolean notifyLow,
1833        Number thresholdHigh, Number thresholdLow, boolean differenceMode)
1834   {
1835      try
1836      {
1837         GaugeMonitor gaugeMonitor = new GaugeMonitor();
1838         gaugeMonitor.setNotifyHigh(notifyHigh);
1839         gaugeMonitor.setNotifyLow(notifyLow);
1840         gaugeMonitor.setThresholds(thresholdHigh, thresholdLow);
1841         gaugeMonitor.setDifferenceMode(differenceMode);
1842         GaugeSupport support = new GaugeSupport();
1843         monitor = gaugeMonitor;
1844         monitored = support;
1845         initMonitor();
1846      }
1847      catch (Exception e)
1848      {
1849         fail(e.toString());
1850      }
1851   }
1852
1853   /**
1854    * Create a string monitor
1855    */

1856   private void initStringMonitor(boolean differ, boolean match, String compare)
1857   {
1858      try
1859      {
1860         StringMonitor stringMonitor = new StringMonitor();
1861         stringMonitor.setNotifyDiffer(differ);
1862         stringMonitor.setNotifyMatch(match);
1863         stringMonitor.setStringToCompare(compare);
1864         StringSupport support = new StringSupport();
1865         monitor = stringMonitor;
1866         monitored = support;
1867         initMonitor();
1868      }
1869      catch (Exception e)
1870      {
1871         fail(e.toString());
1872      }
1873   }
1874
1875   /**
1876    * Start a new test
1877    */

1878   private void initTest()
1879   {
1880      notifications.clear();
1881      server = MBeanServerFactory.createMBeanServer();
1882   }
1883
1884   /**
1885    * Create the monitor
1886    */

1887   private void initMonitor() throws Exception
1888   {
1889      monitorName = new ObjectName("test:type=monitor");
1890      monitoredName = new ObjectName("test:type=monitored");
1891      monitor.setObservedObject(monitoredName);
1892      monitor.setObservedAttribute("Value");
1893      monitor.setGranularityPeriod(MonitorSUITE.GRANULARITY_TIME);
1894      server.registerMBean(monitor, monitorName);
1895      server.registerMBean(monitored, monitoredName);
1896      server.addNotificationListener(monitorName, this, null, null);
1897   }
1898
1899   /**
1900    * Stop the monitor
1901    */

1902   private void stopMonitor()
1903   {
1904      if (monitor != null)
1905      {
1906         monitored.end();
1907         monitor.stop();
1908      }
1909   }
1910
1911   /**
1912    * Handle the notification, just add it to the list
1913    */

1914   public void handleNotification(Notification n, Object ignored)
1915   {
1916      synchronized(notifications)
1917      {
1918         notifications.add(n);
1919         notifications.notifyAll();
1920      }
1921   }
1922
1923   /**
1924    * Sync with the notification handler
1925    */

1926   private void sync(boolean getWorks)
1927      throws Exception
1928   {
1929      // Make sure the monitor has got the attribute
1930
if (getWorks)
1931         waitCycle();
1932      else
1933      {
1934         synchronized(notifications)
1935         {
1936            notifications.wait(MonitorSUITE.MAX_WAIT);
1937         }
1938      }
1939   }
1940
1941   /**
1942    * Invalid attribute start monitor
1943    */

1944   private void attributeErrorStartMonitor(Object initial)
1945      throws Exception
1946   {
1947      assertEquals(0, notifications.size());
1948      monitor.setObservedAttribute("rubbish");
1949      monitor.start();
1950      sync(false);
1951      assertEquals(1, notifications.size());
1952      MonitorNotification n = (MonitorNotification) notifications.get(0);
1953      notifications.clear();
1954      assertEquals(monitorName, n.getSource());
1955      assertEquals(monitoredName, n.getObservedObject());
1956      assertEquals("rubbish", n.getObservedAttribute());
1957      assertEquals(MonitorNotification.OBSERVED_ATTRIBUTE_ERROR, n.getType());
1958      n = serializeDeserialize(n);
1959      assertEquals(monitorName, n.getSource());
1960      assertEquals(monitoredName, n.getObservedObject());
1961      assertEquals("rubbish", n.getObservedAttribute());
1962      assertEquals(MonitorNotification.OBSERVED_ATTRIBUTE_ERROR, n.getType());
1963   }
1964
1965   /**
1966    * Invalid attribute null start monitor
1967    */

1968   private void attributeNullStartMonitor(Object initial)
1969      throws Exception
1970   {
1971      assertEquals(0, notifications.size());
1972      monitor.setObservedAttribute("WrongNull");
1973      monitor.start();
1974      sync(false);
1975      assertEquals(1, notifications.size());
1976      MonitorNotification n = (MonitorNotification) notifications.get(0);
1977      notifications.clear();
1978      assertEquals(monitorName, n.getSource());
1979      assertEquals(monitoredName, n.getObservedObject());
1980      assertEquals("WrongNull", n.getObservedAttribute());
1981      assertEquals(MonitorNotification.OBSERVED_ATTRIBUTE_TYPE_ERROR,
1982                   n.getType());
1983      n = serializeDeserialize(n);
1984      assertEquals(monitorName, n.getSource());
1985      assertEquals(monitoredName, n.getObservedObject());
1986      assertEquals("WrongNull", n.getObservedAttribute());
1987      assertEquals(MonitorNotification.OBSERVED_ATTRIBUTE_TYPE_ERROR,
1988                   n.getType());
1989   }
1990
1991   /**
1992    * Invalid attribute type start monitor
1993    */

1994   private void attributeTypeStartMonitor(Object initial)
1995      throws Exception
1996   {
1997      assertEquals(0, notifications.size());
1998      monitor.setObservedAttribute("WrongType");
1999      monitor.start();
2000      sync(false);
2001      assertEquals(1, notifications.size());
2002      MonitorNotification n = (MonitorNotification) notifications.get(0);
2003      notifications.clear();
2004      assertEquals(monitorName, n.getSource());
2005      assertEquals(monitoredName, n.getObservedObject());
2006      assertEquals("WrongType", n.getObservedAttribute());
2007      assertEquals(MonitorNotification.OBSERVED_ATTRIBUTE_TYPE_ERROR,
2008                   n.getType());
2009      n = serializeDeserialize(n);
2010      assertEquals(monitoredName, n.getObservedObject());
2011      assertEquals("WrongType", n.getObservedAttribute());
2012      assertEquals(MonitorNotification.OBSERVED_ATTRIBUTE_TYPE_ERROR,
2013                   n.getType());
2014   }
2015
2016   /**
2017    * Write only Attribute start monitor
2018    */

2019   private void attributeWriteStartMonitor(Object initial)
2020      throws Exception
2021   {
2022      assertEquals(0, notifications.size());
2023      monitor.setObservedAttribute("WriteOnly");
2024      monitor.start();
2025      sync(false);
2026      assertEquals(1, notifications.size());
2027      MonitorNotification n = (MonitorNotification) notifications.get(0);
2028      notifications.clear();
2029      assertEquals(monitorName, n.getSource());
2030      assertEquals(monitoredName, n.getObservedObject());
2031      assertEquals("WriteOnly", n.getObservedAttribute());
2032      assertEquals(MonitorNotification.OBSERVED_ATTRIBUTE_ERROR,
2033                   n.getType());
2034      n = serializeDeserialize(n);
2035      assertEquals(monitorName, n.getSource());
2036      assertEquals(monitoredName, n.getObservedObject());
2037      assertEquals("WriteOnly", n.getObservedAttribute());
2038      assertEquals(MonitorNotification.OBSERVED_ATTRIBUTE_ERROR,
2039                   n.getType());
2040   }
2041
2042   /**
2043    * Invalid objectName start monitor
2044    */

2045   private void objectNameStartMonitor(Object initial)
2046      throws Exception
2047   {
2048      assertEquals(0, notifications.size());
2049      monitoredName = new ObjectName("rubbish:type=pants");
2050      monitor.setObservedObject(monitoredName);
2051      monitor.start();
2052      sync(false);
2053      assertEquals(1, notifications.size());
2054      MonitorNotification n = (MonitorNotification) notifications.get(0);
2055      notifications.clear();
2056      assertEquals(monitorName, n.getSource());
2057      assertEquals(monitoredName, n.getObservedObject());
2058      assertEquals("Value", n.getObservedAttribute());
2059      assertEquals(MonitorNotification.OBSERVED_OBJECT_ERROR,
2060                   n.getType());
2061      n = serializeDeserialize(n);
2062      assertEquals(monitorName, n.getSource());
2063      assertEquals(monitoredName, n.getObservedObject());
2064      assertEquals("Value", n.getObservedAttribute());
2065      assertEquals(MonitorNotification.OBSERVED_OBJECT_ERROR,
2066                   n.getType());
2067   }
2068
2069   /**
2070    * Invalid threshold start monitor
2071    */

2072   private void thresholdStartMonitor(Object initial)
2073      throws Exception
2074   {
2075      assertEquals(0, notifications.size());
2076      monitor.start();
2077      sync(false);
2078      assertEquals(1, notifications.size());
2079      MonitorNotification n = (MonitorNotification) notifications.get(0);
2080      notifications.clear();
2081      assertEquals(monitorName, n.getSource());
2082      assertEquals(monitoredName, n.getObservedObject());
2083      assertEquals("Value", n.getObservedAttribute());
2084      assertEquals(MonitorNotification.THRESHOLD_ERROR,
2085                   n.getType());
2086      n = serializeDeserialize(n);
2087      assertEquals(monitorName, n.getSource());
2088      assertEquals(monitoredName, n.getObservedObject());
2089      assertEquals("Value", n.getObservedAttribute());
2090      assertEquals(MonitorNotification.THRESHOLD_ERROR,
2091                   n.getType());
2092   }
2093
2094   /**
2095    * runtime error start monitor
2096    */

2097   private void runtimeErrorStartMonitor(Object initial)
2098      throws Exception
2099   {
2100      assertEquals(0, notifications.size());
2101      monitor.setObservedAttribute("WrongException");
2102      monitor.start();
2103      sync(false);
2104      if (notifications.size() != 1)
2105         fail ("FAILS IN RI: Does not notify of error thrown by getter");
2106      assertEquals(1, notifications.size());
2107      MonitorNotification n = (MonitorNotification) notifications.get(0);
2108      notifications.clear();
2109      assertEquals(monitorName, n.getSource());
2110      assertEquals(monitoredName, n.getObservedObject());
2111      assertEquals("WrongException", n.getObservedAttribute());
2112      assertEquals(MonitorNotification.RUNTIME_ERROR,
2113                   n.getType());
2114      n = serializeDeserialize(n);
2115      assertEquals(monitorName, n.getSource());
2116      assertEquals(monitoredName, n.getObservedObject());
2117      assertEquals("WrongException", n.getObservedAttribute());
2118      assertEquals(MonitorNotification.RUNTIME_ERROR,
2119                   n.getType());
2120   }
2121
2122   /**
2123    * Start a monitor expect a notification
2124    */

2125   private void expectStartMonitor(Object expected, String type)
2126      throws Exception
2127   {
2128      assertEquals(0, notifications.size());
2129      monitor.start();
2130      setValue(expected);
2131
2132      // Synchronize the notification
2133
sync(true);
2134
2135      // Check the result
2136
checkGauge(expected);
2137      assertEquals(1, notifications.size());
2138      MonitorNotification n = (MonitorNotification) notifications.get(0);
2139      notifications.clear();
2140      assertEquals(monitorName, n.getSource());
2141      assertEquals(monitoredName, n.getObservedObject());
2142      assertEquals("Value", n.getObservedAttribute());
2143      assertEquals(type, n.getType());
2144      assertEquals(expected, n.getDerivedGauge());
2145      n = serializeDeserialize(n);
2146      assertEquals(monitorName, n.getSource());
2147      assertEquals(monitoredName, n.getObservedObject());
2148      assertEquals("Value", n.getObservedAttribute());
2149      assertEquals(type, n.getType());
2150      assertEquals(expected, n.getDerivedGauge());
2151   }
2152
2153   /**
2154    * Start a monitor, don't expect a notification
2155    */

2156   private void dontExpectStartMonitor(Object initial)
2157      throws Exception
2158   {
2159      assertEquals(0, notifications.size());
2160      monitor.start();
2161      setValue(initial);
2162      waitCycle();
2163      assertEquals(0, notifications.size());
2164      checkGauge(initial);
2165   }
2166
2167   /**
2168    * Start a monitor, don't expect a notification difference
2169    */

2170   private void dontExpectStartMonitorDiff(Object value1, Object value2)
2171      throws Exception
2172   {
2173      monitor.start();
2174      setValue(value1);
2175      waitCycle();
2176      assertEquals(0, notifications.size());
2177      setValue(value2);
2178      waitCycle();
2179      assertEquals(0, notifications.size());
2180      checkGauge(sub(value2, value1));
2181   }
2182
2183   private void setValue(Object value)
2184      throws Exception
2185   {
2186      monitored.lock("set");
2187      server.setAttribute(monitoredName, new Attribute("Value", value));
2188   }
2189
2190   /**
2191    * Expect a notification
2192    */

2193   private void expect(Object expected, Object gauge, String type)
2194      throws Exception
2195   {
2196      assertEquals(0, notifications.size());
2197      setValue(expected);
2198
2199      // Synchronize the notification
2200
sync(true);
2201
2202      // Check the result
2203
checkGauge(gauge);
2204      assertEquals(1, notifications.size());
2205      MonitorNotification n = (MonitorNotification) notifications.get(0);
2206      notifications.clear();
2207      assertEquals(monitorName, n.getSource());
2208      assertEquals(monitoredName, n.getObservedObject());
2209      assertEquals("Value", n.getObservedAttribute());
2210      assertEquals(type, n.getType());
2211      assertEquals(gauge, n.getDerivedGauge());
2212   }
2213
2214   /**
2215    * Expect a notification difference
2216    */

2217   private void expectDiff(Object value1, Object value2, String type)
2218      throws Exception
2219   {
2220      waitCycle();
2221      notifications.clear();
2222      setValue(value1);
2223      waitCycle();
2224      assertEquals(0, notifications.size());
2225      setValue(value2);
2226      sync(true);
2227
2228      // Check the result
2229
checkGauge(sub(value2, value1));
2230      assertEquals(1, notifications.size());
2231      MonitorNotification n = (MonitorNotification) notifications.get(0);
2232      notifications.clear();
2233      assertEquals(monitorName, n.getSource());
2234      assertEquals(monitoredName, n.getObservedObject());
2235      assertEquals("Value", n.getObservedAttribute());
2236      assertEquals(type, n.getType());
2237      assertEquals(sub(value2, value1), n.getDerivedGauge());
2238   }
2239
2240   /**
2241    * Expect a notification
2242    */

2243   private void expect(Object expected, String type)
2244      throws Exception
2245   {
2246      expect(expected, expected, type);
2247   }
2248
2249   /**
2250    * Don't expect a notification
2251    */

2252   private void dontExpect(Object unexpected)
2253      throws Exception
2254   {
2255      assertEquals(0, notifications.size());
2256      setValue(unexpected);
2257      waitCycle();
2258      assertEquals(0, notifications.size());
2259      checkGauge(unexpected);
2260   }
2261
2262   /**
2263    * Don't expect a notification
2264    */

2265   private void dontExpectDiff(Object value1, Object value2)
2266      throws Exception
2267   {
2268      waitCycle();
2269      notifications.clear();
2270      setValue(value1);
2271      waitCycle();
2272      assertEquals(0, notifications.size());
2273      setValue(value2);
2274      waitCycle();
2275      assertEquals(0, notifications.size());
2276      checkGauge(sub(value2, value1));
2277   }
2278
2279   /**
2280    * Don't expect a notification
2281    */

2282   private void dontExpectDiffModulus(Object value1, Object value2, Object value3)
2283      throws Exception
2284   {
2285      waitCycle();
2286      notifications.clear();
2287      setValue(value1);
2288      waitCycle();
2289      assertEquals(0, notifications.size());
2290      setValue(value2);
2291      waitCycle();
2292      assertEquals(0, notifications.size());
2293      checkGauge(add(sub(value2, value1), value3));
2294   }
2295
2296   /**
2297    * Check the gauge
2298    */

2299  private void checkGauge(Object gauge)
2300     throws Exception
2301  {
2302      if (monitor instanceof StringMonitor)
2303         assertEquals(gauge, ((StringMonitor)monitor).getDerivedGauge());
2304      else if (monitor instanceof CounterMonitor)
2305         assertEquals(gauge, ((CounterMonitor)monitor).getDerivedGauge());
2306      else if (monitor instanceof GaugeMonitor)
2307         assertEquals(gauge, ((GaugeMonitor)monitor).getDerivedGauge());
2308      else
2309         fail("You idiot!");
2310  }
2311
2312   /**
2313    * Wait one cycle of the monitor
2314    */

2315   private void waitCycle()
2316   {
2317      monitored.unlock("set");
2318      monitored.lock("set");
2319   }
2320
2321  /**
2322   * Add two numbers.
2323   * @param value1 the first value.
2324   * @param value2 the second value.
2325   * @return value1 + value2 of the correct type
2326   */

2327  private Number add(Object value1, Object value2)
2328  {
2329     if (value1 instanceof Byte)
2330       return new Byte((byte) (((Byte)value1).byteValue() + ((Byte)value2).byteValue()));
2331     if (value1 instanceof Integer)
2332       return new Integer(((Integer)value1).intValue() + ((Integer)value2).intValue());
2333     if (value1 instanceof Short)
2334       return new Short((short) (((Short)value1).shortValue() + ((Short)value2).shortValue()));
2335     if (value1 instanceof Long)
2336       return new Long(((Long)value1).longValue() + ((Long)value2).longValue());
2337     fail("You idiot!");
2338     return null;
2339  }
2340
2341  /**
2342   * Subtract two numbers.
2343   * @param value1 the first value.
2344   * @param value2 the second value.
2345   * @return value1 - value2 of the correct type
2346   */

2347  private Number sub(Object value1, Object value2)
2348  {
2349     if (value1 instanceof Byte)
2350       return new Byte((byte) (((Byte)value1).byteValue() - ((Byte)value2).byteValue()));
2351     if (value1 instanceof Integer)
2352       return new Integer(((Integer)value1).intValue() - ((Integer)value2).intValue());
2353     if (value1 instanceof Short)
2354       return new Short((short) (((Short)value1).shortValue() - ((Short)value2).shortValue()));
2355     if (value1 instanceof Long)
2356       return new Long(((Long)value1).longValue() - ((Long)value2).longValue());
2357     fail("You idiot!");
2358     return null;
2359  }
2360
2361  /**
2362   * Check the notification info is as expected
2363   *
2364   * @param mbni the received notification info
2365   * @param expected the expected notifications
2366   */

2367  private void checkNotificationInfo(String type,
2368                                     MBeanNotificationInfo[] mbni,
2369                                     HashSet expected)
2370  {
2371     String[] types = mbni[0].getNotifTypes();
2372     for (int i = 0; i < types.length; i++)
2373         if (expected.remove(types[i]) == false)
2374            fail(type + ": didn't expect notification type " + types[i]);
2375     Iterator iterator = expected.iterator();
2376     while (iterator.hasNext())
2377         fail(type + ": expected notification type " + iterator.next());
2378  }
2379
2380  /**
2381   * Serialize/Derserialize the notification
2382   *
2383   * @param n the notification
2384   * @return the notification after serialize/deserialze
2385   */

2386  private MonitorNotification serializeDeserialize(MonitorNotification n)
2387     throws Exception
2388  {
2389      // Serialize it
2390
ByteArrayOutputStream baos = new ByteArrayOutputStream();
2391      ObjectOutputStream oos = new ObjectOutputStream(baos);
2392      oos.writeObject(n);
2393    
2394      // Deserialize it
2395
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
2396      ObjectInputStream ois = new ObjectInputStream(bais);
2397      return (MonitorNotification) ois.readObject();
2398  }
2399}
2400
Popular Tags