Package test

Examples of test.MutableBoolean


      int queueCapacity = 10;
      final int count = 4;
      final long sleep = 500;
      final Integer id = new Integer(1);
      final ObjectName name = ObjectName.getInstance(":name=emitter");
      final MutableBoolean notify = new MutableBoolean(true);
      final MutableLong queued = new MutableLong(0);
      final MutableLong delivered = new MutableLong(0);

      Map environment = new HashMap();
      environment.put(MX4JRemoteConstants.NOTIFICATION_QUEUE_CAPACITY, new Integer(queueCapacity));
      RemoteNotificationClientHandler handler = new AbstractRemoteNotificationClientHandler(null, null, environment)
      {
         protected NotificationResult fetchNotifications(long sequenceNumber, int maxNumber, long timeout)
         {
            if (sequenceNumber < 0) return new NotificationResult(0, 0, new TargetedNotification[0]);

            boolean doNotify = false;
            synchronized (lock)
            {
               doNotify = notify.get();
            }

            if (doNotify)
            {
               // Avoid spin looping the fetcher thread, but don't sleep too much, we have to fill the client's queue
               sleep(sleep);
               TargetedNotification[] notifications = new TargetedNotification[count];
               for (int i = 0; i < count; ++i) notifications[i] = new TargetedNotification(new Notification("type", name, sequenceNumber + i), id);
               long nextSequence = sequenceNumber + count;
               NotificationResult result = new NotificationResult(0, nextSequence, notifications);
               synchronized (lock)
               {
                  queued.set(getNotificationsCount());
               }
               return result;
            }
            else
            {
               sleep(timeout);
               return new NotificationResult(0, sequenceNumber, new TargetedNotification[0]);
            }
         }

         protected long getRetryPeriod()
         {
            return 1000;
         }

         protected int getMaxRetries()
         {
            return 5;
         }

         protected void sendConnectionNotificationLost(long number)
         {
            System.out.println("Lost notifications: " + number);
            // Stop sending notifications
            synchronized (lock)
            {
               notify.set(false);
               // Deliver notifications until the last we queued on the client
               queued.set(getNotificationsCount());
            }
         }
      };

      NotificationListener listener = new NotificationListener()
      {
         public void handleNotification(Notification notification, Object handback)
         {
            long sequence = notification.getSequenceNumber();
            synchronized (lock)
            {
               delivered.set(sequence);
            }
            System.out.println("Received notification, sequence is " + sequence);
            // Sleep longer than notification emission, to fill the client's queue
            sleep(sleep * 2);
            System.out.println("Handled notification, sequence is " + sequence);
         }
      };

      try
      {
         handler.start();
         handler.addNotificationListener(id, new NotificationTuple(name, listener, null, null));
         // Wait until we empty the client's queue
         synchronized (lock)
         {
            while (notify.get())
            {
               lock.wait(50);
               if (queued.get() > queueCapacity) fail("Queued notifications " + queued.get() + " must not pass max capacity " + queueCapacity);
            }

View Full Code Here


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

   public void testRegistration() throws Exception
   {
      MBeanServer server = newMBeanServer();
      int count = server.getMBeanCount().intValue();
      final MutableBoolean bool1 = new MutableBoolean(false);
      final MutableBoolean bool2 = new MutableBoolean(false);
      Object empty = new RegistrationSupport.Empty(bool1, bool2);
      final ObjectName name = new ObjectName("simon:mbean=empty");
      server.registerMBean(empty, name);
      // Check registration
      if (!bool1.get())
View Full Code Here

   public void testDuplicateRegistration() throws Exception
   {
      MBeanServer server = newMBeanServer();
      int count = server.getMBeanCount().intValue();
      final MutableBoolean bool1 = new MutableBoolean(false);
      final MutableBoolean bool2 = new MutableBoolean(false);
      Object empty = new RegistrationSupport.Empty(bool1, bool2);
      final ObjectName name = new ObjectName("simon:mbean=empty");
      server.registerMBean(empty, name);
      if (server.getMBeanCount().intValue() != count + 1)
      {
View Full Code Here

   public void testDeregistration() throws Exception
   {
      MBeanServer server = newMBeanServer();
      int count = server.getMBeanCount().intValue();
      final MutableBoolean bool1 = new MutableBoolean(false);
      final MutableBoolean bool2 = new MutableBoolean(false);
      Object empty = new RegistrationSupport.Empty(bool1, bool2);
      final ObjectName name = new ObjectName("simon:mbean=empty");
      server.registerMBean(empty, name);
      if (server.getMBeanCount().intValue() != count + 1)
      {
         fail("MBean was not registered");
      }

      bool1.set(true);
      bool2.set(true);
      server.unregisterMBean(name);
      if (server.getMBeanCount().intValue() != count)
      {
         fail("MBean was not unregistered");
      }
      if (bool1.get() || bool2.get())
      {
         fail("preDeregister or postDeregister are not called");
      }
   }
View Full Code Here

   public void testDuplicateDeregistration() throws Exception
   {
      MBeanServer server = newMBeanServer();
      int count = server.getMBeanCount().intValue();
      final MutableBoolean bool1 = new MutableBoolean(false);
      final MutableBoolean bool2 = new MutableBoolean(false);
      Object empty = new RegistrationSupport.Empty(bool1, bool2);
      final ObjectName name = new ObjectName("simon:mbean=empty");
      server.registerMBean(empty, name);
      if (server.getMBeanCount().intValue() != count + 1)
      {
         fail("MBean was not registered");
      }

      bool1.set(true);
      bool2.set(true);
      server.unregisterMBean(name);
      if (server.getMBeanCount().intValue() != count)
      {
         fail("MBean was not unregistered");
      }
      if (bool1.get() || bool2.get())
      {
         fail("preDeregister or postDeregister are not called");
      }

      // Try again
View Full Code Here

   public void testTimerNotStarted() throws Exception
   {
      // Don't start the Timer. Notification should not be emitted
//      m_timer.start();

      final MutableBoolean bool = new MutableBoolean(false);
      NotificationListener listener = new NotificationListener()
      {
         public void handleNotification(Notification notification, Object handback)
         {
            bool.set(true);
         }
      };
      m_server.addNotificationListener(m_timerName, listener, null, null);

      long now = System.currentTimeMillis();
      m_timer.addNotification("timer-notif", "Must not be emitted", null, new Date(now + Timer.ONE_SECOND));

      // Sleep to wait for the notification to happen
      sleep(Timer.ONE_SECOND * 2);

      assertFalse(bool.get());
   }
View Full Code Here

      assertEquals(counted, count.get());
   }

   public void testSendPastNotifications1() throws Exception
   {
      final MutableBoolean bool = new MutableBoolean(false);
      NotificationListener listener = new NotificationListener()
      {
         public void handleNotification(Notification notification, Object handback)
         {
            bool.set(true);
         }
      };
      m_server.addNotificationListener(m_timerName, listener, null, null);

      long now = System.currentTimeMillis();

      // This one-shot notification is already passed, sendPastNotifications is false
      // so the notification must not be emitted
      Date date = new Date(now - Timer.ONE_SECOND);
      m_timer.setSendPastNotifications(false);
      m_timer.addNotification("notif-type", "notif-message", "notif-data", date);
      m_timer.start();

      // Wait that the notification arrives
      sleep(Timer.ONE_SECOND);

      assertFalse(bool.get());
      assertTrue(m_timer.isEmpty());
   }
View Full Code Here

      assertTrue(m_timer.isEmpty());
   }

   public void testNotificationsWithOldDate() throws Exception
   {
      final MutableBoolean bool = new MutableBoolean(false);
      NotificationListener listener = new NotificationListener()
      {
         public void handleNotification(Notification notification, Object handback)
         {
            bool.set(true);
         }
      };
      m_server.addNotificationListener(m_timerName, listener, null, null);

      long now = System.currentTimeMillis();

      m_timer.start();
      Date date = new Date(now - Timer.ONE_SECOND);
      m_timer.addNotification("notif-type", "notif-message", "notif-data", date);

      // Wait that the notification arrives
      sleep(Timer.ONE_SECOND);

      assertTrue(bool.get());
      assertTrue(m_timer.isEmpty());
   }
View Full Code Here

      assertTrue(m_timer.isEmpty());
   }

   public void testSendPastNotifications2() throws Exception
   {
      final MutableBoolean bool = new MutableBoolean(false);
      NotificationListener listener = new NotificationListener()
      {
         public void handleNotification(Notification notification, Object handback)
         {
            bool.set(true);
         }
      };
      m_server.addNotificationListener(m_timerName, listener, null, null);

      long now = System.currentTimeMillis();

      // This one-shot notification is already passed, sendPastNotifications is true
      // so the notification must be emitted
      Date date = new Date(now - Timer.ONE_SECOND);
      m_timer.setSendPastNotifications(true);
      m_timer.addNotification("notif-type", "notif-message", "notif-data", date);
      m_timer.start();

      // Wait that the notification arrives
      sleep(Timer.ONE_SECOND);

      assertTrue(bool.get());
      assertTrue(m_timer.isEmpty());
   }
View Full Code Here

TOP

Related Classes of test.MutableBoolean

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.