Package test

Examples of test.MutableObject


         ObjectName emitterName = ObjectName.getInstance(":mbean=emitter");
         MBeanEmitter emitter = new MBeanEmitter();
         server.registerMBean(emitter, emitterName);

         // Register an MBean Listener
         MutableObject notificationHolder = new MutableObject(null);
         MutableObject handbackHolder = new MutableObject(null);
         ObjectName listenerName = ObjectName.getInstance(":mbean=listener");
         MBeanListener listener = new MBeanListener(notificationHolder, handbackHolder);
         server.registerMBean(listener, listenerName);

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

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

         // Non-serializable filter
         try
         {
            mbsc.addNotificationListener(emitterName, listenerName, new NotificationFilter()
            {
               public boolean isNotificationEnabled(Notification notification)
               {
                  return false;
               }
            }, null);
            fail();
         } catch (IOException x)
         {
         }

         // Non-serializable handback
         try
         {
            mbsc.addNotificationListener(emitterName, listenerName, null, new Object());
            fail();
         } catch (IOException x)
         {
         }

         // Non-serializable filter and non serializable handback
         try
         {
            mbsc.addNotificationListener(emitterName, listenerName, new NotificationFilter()
            {
               public boolean isNotificationEnabled(Notification notification)
               {
                  return false;
               }
            }, new Object());
            fail();
         } catch (IOException x)
         {
         }

         // Everything is serializable
         ObjectName name = ObjectName.getInstance(":mbean=dummy");
         MBeanServerNotificationFilter filter = new MBeanServerNotificationFilter();
         filter.disableObjectName(name);
         Object handback = new Integer(13);
         mbsc.addNotificationListener(emitterName, listenerName, filter, handback);

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

         Notification notification = new MBeanServerNotification(MBeanServerNotification.REGISTRATION_NOTIFICATION, this, 0, name);
         emitter.emit(notification);

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

         // Be sure the notification has been filtered
         assertNull(notificationHolder.get());
         assertNull(handbackHolder.get());

         // Disable filtering
         filter.enableAllObjectNames();
         // Remove and readd: on server side there is a serialized copy of the filter
         mbsc.removeNotificationListener(emitterName, listenerName);
         mbsc.addNotificationListener(emitterName, listenerName, filter, handback);

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

         emitter.emit(notification);

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

         // Be sure we got it
         assertEquals(handbackHolder.get(), handback);
         Notification emitted = (Notification) notificationHolder.get();
         assertNotNull(emitted);
         if (!(notification instanceof MBeanServerNotification)) fail();
         assertEquals(((MBeanServerNotification) emitted).getMBeanName(), name);
         notificationHolder.set(null);
         handbackHolder.set(null);

         mbsc.removeNotificationListener(emitterName, listenerName, filter, handback);

         // Be sure we don't get notifications anymore
         emitter.emit(notification);

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

         assertNull(notificationHolder.get());
         assertNull(handbackHolder.get());
      } 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);

         MutableObject notificationHolder = new MutableObject(null);
         MutableObject handbackHolder = new MutableObject(null);
         MBeanListener listener = new MBeanListener(notificationHolder, handbackHolder);

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

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

         // Non-serializable filter, should run on client side
         final MutableBoolean enable = new MutableBoolean(false);
         NotificationFilter filter = new NotificationFilter()
         {
            public boolean isNotificationEnabled(Notification notification)
            {
               return enable.get();
            }
         };
         mbsc.addNotificationListener(emitterName, listener, filter, null);

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

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

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

         // Be sure the notification has been filtered
         assertNull(notificationHolder.get());
         assertNull(handbackHolder.get());

         // Disable the filter
         enable.set(true);

         emitter.emit(notification);

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

         // Be sure we got the notification
         assertNull(handbackHolder.get());
         Notification emitted = (Notification) notificationHolder.get();
         assertNotNull(emitted);
         notificationHolder.set(null);
         handbackHolder.set(null);

         mbsc.removeNotificationListener(emitterName, listener, filter, null);

         // Be sure we don't get notifications anymore
         emitter.emit(notification);

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

         assertNull(notificationHolder.get());
         assertNull(handbackHolder.get());
      } 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);

         MutableObject notificationHolder = new MutableObject(null);
         MutableObject handbackHolder = new MutableObject(null);
         MBeanListener listener = new MBeanListener(notificationHolder, handbackHolder);

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

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

         // Non-serializable handback, should stay on client side
         Object handback = new Object();
         mbsc.addNotificationListener(emitterName, listener, null, handback);

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

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

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

         // Be sure we got the notification
         assertSame(handbackHolder.get(), handback);
         Notification emitted = (Notification) notificationHolder.get();
         assertNotNull(emitted);
         notificationHolder.set(null);
         handbackHolder.set(null);

         mbsc.removeNotificationListener(emitterName, listener, null, handback);

         // Be sure we don't get notifications anymore
         emitter.emit(notification);

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

         assertNull(notificationHolder.get());
         assertNull(handbackHolder.get());
      } catch (Exception x)
      {
         x.printStackTrace();
         throw x;
      } finally
View Full Code Here

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

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

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

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

      server.removeNotificationListener(objectName, listener, null, null);
      assertEquals(emitter.getNotificationListeners().size(), 0);
   }
View Full Code Here

      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);
View Full Code Here

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

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

      int value = low.intValue() - 1;
      target.setInteger(value);
      server.registerMBean(target, name);

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

      try
      {
         sleep(period * 3);
         assertEquals(times.get(), 0);
         assertNull(holder.get());

         // Set gauge above high threshold
         value = value + high.intValue() + 1;
         target.setInteger(value);
         sleep(period * 3);
         assertEquals(times.get(), 1);
         MonitorNotification notification = (MonitorNotification)holder.get();
         assertEquals(notification.getType(), MonitorNotification.THRESHOLD_HIGH_VALUE_EXCEEDED);

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

         // Set gauge inside threshold
         value = value + low.intValue() + 1;
         target.setInteger(value);
         sleep(period * 3);
         assertEquals(times.get(), 0);
         assertNull(holder.get());

         // Set gauge above threshold again
         value = value + high.intValue() + 1;
         target.setInteger(value);
         sleep(period * 3);
         assertEquals(times.get(), 1);
         notification = (MonitorNotification)holder.get();
         assertEquals(notification.getType(), MonitorNotification.THRESHOLD_HIGH_VALUE_EXCEEDED);
      }
      finally
      {
         monitor.stop();
View Full Code Here

      int value = low.intValue() + 1;
      target.setInteger(value);
      server.registerMBean(target, name);

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

      try
      {
         // Inside the thresholds, be sure low notification
         sleep(period * 3);
         assertEquals(times.get(), 1);
         MonitorNotification notification = (MonitorNotification)holder.get();
         assertEquals(notification.getType(), MonitorNotification.THRESHOLD_LOW_VALUE_EXCEEDED);

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

         // Monitoring takes time, so I disable low notification to be sure to get only the high one
         // The monitor is in difference mode, so the first time will get the high notification, but
         // the second time will get zero, since the gauge did not change, which will triggers a low notification
         monitor.setNotifyLow(false);
         // Set gauge above high threshold
         value = value + high.intValue() + 1;
         target.setInteger(value);
         sleep(period * 3);
         assertEquals(times.get(), 1);
         notification = (MonitorNotification)holder.get();
         assertEquals(notification.getType(), MonitorNotification.THRESHOLD_HIGH_VALUE_EXCEEDED);

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

         monitor.setNotifyHigh(false);
         monitor.setNotifyLow(true);
         // Set gauge above high threshold, so just after goes below low threshold
         value = value + high.intValue() + 1;
         target.setInteger(value);
         sleep(period * 3);
         assertEquals(times.get(), 1);
         notification = (MonitorNotification)holder.get();
         assertEquals(notification.getType(), MonitorNotification.THRESHOLD_LOW_VALUE_EXCEEDED);

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

         // Set gauge inside threshold
         value = value + low.intValue() + 1;
         target.setInteger(value);
         sleep(period * 3);
         assertEquals(times.get(), 0);
         assertNull(holder.get());
      }
      finally
      {
         monitor.stop();
      }
View Full Code Here

      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

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.