Package test

Examples of test.MutableObject


      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
      {
         monitor.stop();
View Full Code Here


      // 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
      {
View Full Code Here

      // 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
      {
View Full Code Here

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

         final MutableObject holder = new MutableObject(null);
         cntorServer.addNotificationListener(new NotificationListener()
         {
            public void handleNotification(Notification notification, Object handback)
            {
               holder.set(notification);
            }
         }, null, null);

         JMXConnectorFactory.connect(cntorServer.getAddress(), getEnvironment());

         Notification notification = (Notification) holder.get();
         if (!(notification instanceof JMXConnectionNotification)) fail();
         assertEquals(notification.getType(), JMXConnectionNotification.OPENED);
      } catch (Exception x)
      {
         x.printStackTrace();
View Full Code Here

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

         final MutableObject holder = new MutableObject(null);
         cntorServer.addNotificationListener(new NotificationListener()
         {
            public void handleNotification(Notification notification, Object handback)
            {
               holder.set(notification);
            }
         }, null, null);

         JMXConnector cntor = JMXConnectorFactory.connect(cntorServer.getAddress(), getEnvironment());
         cntor.close();

         Notification notification = (Notification) holder.get();
         if (!(notification instanceof JMXConnectionNotification)) fail();
         assertEquals(notification.getType(), JMXConnectionNotification.CLOSED);
      } catch (Exception x)
      {
         x.printStackTrace();
View Full Code Here

         MBeanServer server = newMBeanServer();
         cntorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, getEnvironment(), server);
         cntorServer.start();
         sleep(5000);

         final MutableObject holder = new MutableObject(null);
         cntor = JMXConnectorFactory.newJMXConnector(cntorServer.getAddress(), getEnvironment());
         cntor.addConnectionNotificationListener(new NotificationListener()
         {
            public void handleNotification(Notification notification, Object handback)
            {
               holder.set(notification);
            }
         }, null, null);

         cntor.connect(getEnvironment());

         JMXConnectionNotification notification = (JMXConnectionNotification) holder.get();
         assertEquals(notification.getType(), JMXConnectionNotification.OPENED);
      } catch (Exception x)
      {
         x.printStackTrace();
         throw x;
View Full Code Here

         MBeanServer server = newMBeanServer();
         cntorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, getEnvironment(), server);
         cntorServer.start();
         sleep(5000);

         final MutableObject holder = new MutableObject(null);
         cntor = JMXConnectorFactory.newJMXConnector(cntorServer.getAddress(), getEnvironment());
         cntor.addConnectionNotificationListener(new NotificationListener()
         {
            public void handleNotification(Notification notification, Object handback)
            {
               holder.set(notification);
            }
         }, null, null);

         cntor.connect(getEnvironment());
         cntor.close();

         JMXConnectionNotification notification = (JMXConnectionNotification) holder.get();
         assertEquals(notification.getType(), JMXConnectionNotification.CLOSED);
      } catch (Exception x)
      {
         x.printStackTrace();
         throw x;
View Full Code Here

      JMXConnectorServer cntorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, getEnvironment(), server);

      cntorServer.start();
      sleep(5000);

      final MutableObject holder = new MutableObject(null);
      long period = 1000;
      int retries = 3;
      try
      {
         JMXConnector cntor = JMXConnectorFactory.newJMXConnector(cntorServer.getAddress(), getEnvironment());
         cntor.addConnectionNotificationListener(new NotificationListener()
         {
            public void handleNotification(Notification notification, Object handback)
            {
               holder.set(notification);
            }
         }, null, null);

         Map clientEnv = getEnvironment();
         clientEnv.put(MX4JRemoteConstants.CONNECTION_HEARTBEAT_PERIOD, new Long(period));
         clientEnv.put(MX4JRemoteConstants.CONNECTION_HEARTBEAT_RETRIES, new Integer(retries));
         cntor.connect(clientEnv);

         JMXConnectionNotification notification = (JMXConnectionNotification) holder.get();
         assertEquals(notification.getType(), JMXConnectionNotification.OPENED);
         holder.set(null);
      } catch (Exception x)
      {
         x.printStackTrace();
         throw x;
      } finally
      {
         cntorServer.stop();
         sleep(5000);
      }

      // Wait for the heartbeat to send the failed notification
      sleep((retries * 3) * period);

      JMXConnectionNotification notification = (JMXConnectionNotification) holder.get();
      assertNotNull(notification);
      assertEquals(notification.getType(), JMXConnectionNotification.FAILED);
   }
View Full Code Here

         cntor = JMXConnectorFactory.connect(cntorServer.getAddress(), getEnvironment());
         MBeanServerConnection mbsc = cntor.getMBeanServerConnection();
         ObjectName delegate = new ObjectName("JMImplementation:type=MBeanServerDelegate");

         final MutableObject holder = new MutableObject(null);
         mbsc.addNotificationListener(delegate, new NotificationListener()
         {
            public void handleNotification(Notification notification, Object handback)
            {
               holder.set(notification);
            }
         }, null, null);

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

         // Register a new MBean, it will generate a notification
         MLet mlet = new MLet();
         ObjectName name = new ObjectName(":mbean=mlet");
         server.registerMBean(mlet, name);

         // Wait for notifications to arrive
         sleep(1000);

         Notification notification = (Notification) holder.get();
         assertEquals(notification.getType(), MBeanServerNotification.REGISTRATION_NOTIFICATION);
         holder.set(null);

         // Unregister the MBean
         server.unregisterMBean(name);

         // Wait for notifications to arrive
         sleep(1000);

         notification = (Notification) holder.get();
         assertEquals(notification.getType(), MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
         holder.set(null);
      } catch (Exception x)
      {
         x.printStackTrace();
         throw x;
      } finally
View Full Code Here

         cntorServer.start();
         sleep(5000);

         cntor = JMXConnectorFactory.connect(cntorServer.getAddress(), getEnvironment());
         MBeanServerConnection mbsc = cntor.getMBeanServerConnection();
         final MutableObject plainNotification = new MutableObject(null);
         mbsc.addNotificationListener(emitterName, new NotificationListener()
         {
            public void handleNotification(Notification notification, Object handback)
            {
               plainNotification.set(notification);
            }
         }, null, null);

         final MutableObject connectionNotification = new MutableObject(null);
         cntor.addConnectionNotificationListener(new NotificationListener()
         {
            public void handleNotification(Notification notification, Object handback)
            {
               connectionNotification.set(notification);
            }
         }, null, null);

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

         String type = "notification.type";
         Notification notification = new Notification(type, this, 0);
         // Make it non-serializable
         notification.setUserData(this);
         emitter.emit(notification);

         // Wait for notifications to arrive
         sleep(1000);

         assertNull(plainNotification.get());
         assertNotNull(connectionNotification.get());
         assertEquals(((Notification) connectionNotification.get()).getType(), JMXConnectionNotification.NOTIFS_LOST);
      } catch (Exception x)
      {
         x.printStackTrace();
         throw x;
      } finally
View Full Code Here

TOP

Related Classes of test.MutableObject

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.