Package test

Examples of test.MutableInteger


      monitor.addObservedObject(counterName);
      monitor.setGranularityPeriod(1000);
      monitor.setObservedAttribute("ObjectCounter");

      final MutableInteger times = new MutableInteger(0);
      final MutableObject holder = new MutableObject(null);
      monitor.addNotificationListener(new NotificationListener()
      {
         public void handleNotification(Notification notification, Object handback)
         {
            times.set(times.get() + 1);
            holder.set(notification);
         }
      }, null, null);
      monitor.start();

      try
      {
         // Wait for notification to arrive
         while (holder.get() == null) sleep(10);

         // Be sure only one arrived
         sleep(5000);
         assertEquals(times.get(), 1);

         MonitorNotification notification = (MonitorNotification)holder.get();
         assertEquals(notification.getType(), MonitorNotification.OBSERVED_ATTRIBUTE_TYPE_ERROR);
      }
      finally
View Full Code Here


      monitor.setNotify(true);
      // No modulus, no offset

      counter.setIntegerCounter(initThreshold.intValue() - 1);

      final MutableInteger times = new MutableInteger(0);
      final MutableObject holder = new MutableObject(null);
      monitor.addNotificationListener(new NotificationListener()
      {
         public void handleNotification(Notification notification, Object handback)
         {
            times.set(times.get() + 1);
            holder.set(notification);
         }
      }, null, null);
      monitor.start();

      try
      {
         // Below threshold, no notifications should be sent
         sleep(period * 3);
         assertEquals(times.get(), 0);
         assertNull(holder.get());

         // Above threshold, just one notification should be sent
         counter.setIntegerCounter(initThreshold.intValue() + 1);
         sleep(period * 3);
         assertEquals(times.get(), 1);
         MonitorNotification notification = (MonitorNotification)holder.get();
         assertEquals(notification.getType(), MonitorNotification.THRESHOLD_VALUE_EXCEEDED);

         times.set(0);
         holder.set(null);
         sleep(period * 3);
         assertEquals(times.get(), 0);
      }
      finally
      {
         monitor.stop();
      }
View Full Code Here

      monitor.setOffset(offset);
      // No modulus

      counter.setIntegerCounter(initThreshold.intValue() - 1);

      final MutableInteger times = new MutableInteger(0);
      final MutableObject holder = new MutableObject(null);
      monitor.addNotificationListener(new NotificationListener()
      {
         public void handleNotification(Notification notification, Object handback)
         {
            times.set(times.get() + 1);
            holder.set(notification);
         }
      }, null, null);
      monitor.start();

      try
      {
         // Below threshold, no notifications should be sent
         sleep(period * 3);
         assertEquals(times.get(), 0);
         assertNull(holder.get());

         // Above threshold, just one notification should be sent
         counter.setIntegerCounter(initThreshold.intValue() + 1);
         sleep(period * 3);
         assertEquals(times.get(), 1);
         MonitorNotification notification = (MonitorNotification)holder.get();
         assertEquals(notification.getType(), MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
         // The threshold should have offset
         Number threshold = monitor.getThreshold(counterName);
         assertEquals(threshold.intValue(), monitor.getInitThreshold().intValue() + offset.intValue());

         times.set(0);
         holder.set(null);
         sleep(period * 3);
         assertEquals(times.get(), 0);

         // Above threshold by more than 1 offset
         counter.setIntegerCounter(initThreshold.intValue() + offset.intValue() * 2 + 1);
         sleep(period * 3);
         assertEquals(times.get(), 1);
         notification = (MonitorNotification)holder.get();
         assertEquals(notification.getType(), MonitorNotification.THRESHOLD_VALUE_EXCEEDED);
         // The threshold should have offset correctly
         threshold = monitor.getThreshold(counterName);
         assertEquals(threshold.intValue(), monitor.getInitThreshold().intValue() + offset.intValue() * 3);

         times.set(0);
         holder.set(null);
         sleep(period * 3);
         assertEquals(times.get(), 0);
      }
      finally
      {
         monitor.stop();
      }
View Full Code Here

      LoggerBroadcasterMBean redirector = (LoggerBroadcasterMBean)MBeanServerInvocationHandler.newProxyInstance(server, name, LoggerBroadcasterMBean.class, false);

      try
      {
         // Register a notification listener
         final MutableInteger notified = new MutableInteger(0);
         NotificationListener listener = new NotificationListener()
         {
            public void handleNotification(Notification notification, Object handback)
            {
               notified.set(notified.get() + 1);
            }
         };

         server.addNotificationListener(name, listener, null, null);

         // Redirect logging
         redirector.start();

         // Create some log
         ObjectName mlet = new ObjectName(":type=mlet");
         server.createMBean("javax.management.loading.MLet", mlet, null);
         // This should create some log
         server.invoke(mlet, "addURL", new Object[]{new URL("http://mx4j.sourceforge.net")}, new String[]{"java.net.URL"});

         // Test if redirection worked
         if (notified.get() < 1) fail("Notification listener not called");
      }
      finally
      {
         redirector.stop();
      }
View Full Code Here

         // Register an MBean Emitter
         ObjectName emitterName = ObjectName.getInstance(":mbean=emitter");
         MBeanEmitter emitter = new MBeanEmitter();
         server.registerMBean(emitter, emitterName);

         final MutableInteger counter1 = new MutableInteger(0);
         NotificationListener listener1 = new NotificationListener()
         {
            public void handleNotification(Notification notification, Object handback)
            {
               counter1.set(counter1.get() + 1);
            }
         };
         final MutableInteger counter2 = new MutableInteger(0);
         NotificationListener listener2 = new NotificationListener()
         {
            public void handleNotification(Notification notification, Object handback)
            {
               counter2.set(counter2.get() + 1);
            }
         };

         JMXServiceURL url = createJMXConnectorServerAddress();
         cntorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, getEnvironment(), server);
         cntorServer.start();
         sleep(5000);

         cntor = JMXConnectorFactory.connect(cntorServer.getAddress(), getEnvironment());
         MBeanServerConnection mbsc = cntor.getMBeanServerConnection();

         String type = "notification.type";

         // First listener
         mbsc.addNotificationListener(emitterName, listener1, null, null);
         // Second listener
         NotificationFilterSupport filter = new NotificationFilterSupport();
         filter.enableType(type);
         mbsc.addNotificationListener(emitterName, listener1, filter, null);
         // Third listener
         Object handback = new Object();
         mbsc.addNotificationListener(emitterName, listener1, null, handback);
         // Fourth listener
         mbsc.addNotificationListener(emitterName, listener2, null, null);

         // Wait for notification threads to start
         sleep(1000);

         Notification notification = new Notification(type, this, 0);
         emitter.emit(notification);
         // Wait for notification to arrive
         sleep(1000);

         // Be sure we got all notifications
         assertEquals(counter1.get(), 3);
         assertEquals(counter2.get(), 1);
         counter1.set(0);
         counter2.set(0);

         // Remove one listener
         mbsc.removeNotificationListener(emitterName, listener1, null, handback);

         emitter.emit(notification);
         // Wait for notification to arrive
         sleep(1000);

         assertEquals(counter1.get(), 2);
         assertEquals(counter2.get(), 1);
         counter1.set(0);
         counter2.set(0);

         // Remove all listeners
         mbsc.removeNotificationListener(emitterName, listener1);

         emitter.emit(notification);
         // Wait for notification to arrive
         sleep(1000);

         assertEquals(counter1.get(), 0);
         assertEquals(counter2.get(), 1);
         counter1.set(0);
         counter2.set(0);

         mbsc.removeNotificationListener(emitterName, listener2);

         emitter.emit(notification);
         // Wait for notification to arrive
         sleep(1000);

         assertEquals(counter1.get(), 0);
         assertEquals(counter2.get(), 0);
      } catch (Exception x)
      {
         x.printStackTrace();
         throw x;
      } finally
View Full Code Here

         // Register an MBean Emitter
         ObjectName emitterName = ObjectName.getInstance(":mbean=emitter");
         MBeanEmitter emitter = new MBeanEmitter();
         server.registerMBean(emitter, emitterName);

         final MutableInteger counter = new MutableInteger(0);
         NotificationListener listener = new NotificationListener()
         {
            public void handleNotification(Notification notification, Object handback)
            {
               counter.set(counter.get() + 1);
            }
         };

         JMXServiceURL url = createJMXConnectorServerAddress();
         cntorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, getEnvironment(), server);
         cntorServer.start();
         sleep(5000);

         cntor = JMXConnectorFactory.connect(cntorServer.getAddress(), getEnvironment());
         MBeanServerConnection mbsc1 = cntor.getMBeanServerConnection();

         mbsc1.addNotificationListener(emitterName, listener, null, null);
         // Wait for notification threads to start
         sleep(1000);

         Notification notification = new Notification("type", emitter, 0);
         emitter.emit(notification);

         // Wait for the notification to arrive
         sleep(1000);

         // Be sure it's received
         assertEquals(counter.get(), 1);

         // Be sure I can remove the same listener from another MBeanServerConnection
         MBeanServerConnection mbsc2 = cntor.getMBeanServerConnection();
         mbsc2.removeNotificationListener(emitterName, listener, null, null);

         emitter.emit(notification);

         // Be sure no listeners anymore
         assertEquals(counter.get(), 1);
      } catch (Exception x)
      {
         x.printStackTrace();
         throw x;
      } finally
View Full Code Here

         return super.getImpact(info);
      }

      private void increment()
      {
         if (count == null) count = new MutableInteger(0);
         count.set(count.get() + 1);
      }
View Full Code Here

      MBeanServer server = newMBeanServer();
      IdentityEmitter emitter = new IdentityEmitter();
      ObjectName objectName = ObjectName.getInstance("test:type=emitter");
      server.registerMBean(emitter, objectName);

      final MutableInteger count = new MutableInteger(0);
      final MutableObject source = new MutableObject(null);
      NotificationListener listener = new NotificationListener()
      {
         public void handleNotification(Notification notification, Object handback)
         {
            source.set(notification.getSource());
            count.set(count.get() + 1);
         }
      };

      // Add same listener twice, with different handbacks
      Object handback = new Object();
      server.addNotificationListener(objectName, listener, null, null);
      server.addNotificationListener(objectName, listener, null, handback);
      assertEquals(emitter.getNotificationListeners().size(), 2);

      Notification notification = new Notification("type", emitter, 0);
      emitter.sendNotification(notification);
      assertEquals(objectName, source.get());
      assertEquals(count.get(), 2);

      server.removeNotificationListener(objectName, listener, null, null);
      assertEquals(emitter.getNotificationListeners().size(), 1);

      server.removeNotificationListener(objectName, listener, null, handback);
View Full Code Here

      ObjectName name1 = ObjectName.getInstance(":name=one");
      monitor.addObservedObject(name1);
      monitor.setGranularityPeriod(1000);
      monitor.setObservedAttribute("dummy");

      final MutableInteger counter = new MutableInteger(0);
      final MutableObject holder = new MutableObject(null);
      monitor.addNotificationListener(new NotificationListener()
      {
         public void handleNotification(Notification notification, Object handback)
         {
            counter.set(counter.get() + 1);
            holder.set(notification);
         }
      }, null, null);
      monitor.start();

      try
      {
         // Wait for notification to arrive
         while (holder.get() == null) sleep(10);

         // Be sure only one arrived
         sleep(5000);
         assertEquals(counter.get(), 1);

         MonitorNotification notification = (MonitorNotification)holder.get();
         assertEquals(notification.getType(), MonitorNotification.OBSERVED_OBJECT_ERROR);
      }
      finally
View Full Code Here

      ObjectName name1 = ObjectName.getInstance("JMImplementation:type=MBeanServerDelegate");
      monitor.addObservedObject(name1);
      monitor.setGranularityPeriod(1000);
      monitor.setObservedAttribute("dummy");

      final MutableInteger counter = new MutableInteger(0);
      final MutableObject holder = new MutableObject(null);
      monitor.addNotificationListener(new NotificationListener()
      {
         public void handleNotification(Notification notification, Object handback)
         {
            counter.set(counter.get() + 1);
            holder.set(notification);
         }
      }, null, null);
      monitor.start();

      try
      {
         // Wait for notification to arrive
         while (holder.get() == null) sleep(10);

         // Be sure only one arrived
         sleep(5000);
         assertEquals(counter.get(), 1);

         MonitorNotification notification = (MonitorNotification)holder.get();
         assertEquals(notification.getType(), MonitorNotification.OBSERVED_ATTRIBUTE_ERROR);
      }
      finally
View Full Code Here

TOP

Related Classes of test.MutableInteger

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.