Examples of MutableInteger


Examples of test.MutableInteger

      assertTrue(m_timer.isEmpty());
   }

   public void testSendPastNotifications4() throws Exception
   {
      final MutableInteger count = new MutableInteger(0);
      NotificationListener listener = new NotificationListener()
      {
         public void handleNotification(Notification notification, Object handback)
         {
            count.set(count.get() + 1);
         }
      };
      m_server.addNotificationListener(m_timerName, listener, null, null);

      long now = System.currentTimeMillis();

      // This periodic notification started in the past, sendPastNotifications is true
      // so all notifications must be emitted
      long occurrences = 10;
      long skip = 4;
      Date date = new Date(now - Timer.ONE_SECOND * skip);
      m_timer.setSendPastNotifications(true);
      m_timer.addNotification("notif-type", "notif-message", "notif-data", date, Timer.ONE_SECOND, occurrences);
      m_timer.start();

      // Wait for the notifications to happen
      sleep(Timer.ONE_SECOND * (occurrences + 1));

      assertEquals(count.get(), occurrences);
      assertTrue(m_timer.isEmpty());
   }
View Full Code Here

Examples of test.MutableInteger

      assertTrue(m_timer.isEmpty());
   }

   public void testSendPastNotifications5() throws Exception
   {
      final MutableInteger count = new MutableInteger(0);
      NotificationListener listener = new NotificationListener()
      {
         public void handleNotification(Notification notification, Object handback)
         {
            count.set(count.get() + 1);
         }
      };
      m_server.addNotificationListener(m_timerName, listener, null, null);

      long now = System.currentTimeMillis();

      // This periodic notification is started, sendPastNotifications is false
      // the Timer is started, then stopped, then restarted
      long occurrences = 10;
      long pre = 2;
      long skip = 4;
      Date date = new Date(now + Timer.ONE_SECOND);
      m_timer.setSendPastNotifications(false);
      m_timer.addNotification("notif-type", "notif-message", "notif-data", date, Timer.ONE_SECOND, occurrences);
      m_timer.start();

      // Wait for the notifications to happen
      sleep(Timer.ONE_SECOND * pre);
      m_timer.stop();

      // Sometimes we loose one notification because we're not that fast, it's ok.
      if (count.get() != pre && count.get() != pre - 1)
         fail("Expected notifications not emitted: expecting " + pre + " got " + count.get());
      assertEquals(m_timer.getNbNotifications(), 1);

      // Wait to skip some notification
      sleep(Timer.ONE_SECOND * skip);

      // Restart the Timer
      m_timer.start();

      // Wait for the remaining notifications to happen
      sleep(Timer.ONE_SECOND * (occurrences - pre - skip + 1));

      m_timer.stop();

      // Sometimes we loose one notification because we're not that fast, it's ok.
      long expected = occurrences - skip;
      if (count.get() != expected && count.get() != expected - 1)
         fail("Expected notifications not emitted.  Expected " + expected + " or " + (expected - 1) + ". got " + count.get());
      assertTrue(m_timer.isEmpty());
   }
View Full Code Here

Examples of test.MutableInteger

      assertTrue(m_timer.isEmpty());
   }

   public void testSendPastNotifications6() throws Exception
   {
      final MutableInteger count = new MutableInteger(0);
      NotificationListener listener = new NotificationListener()
      {
         public void handleNotification(Notification notification, Object handback)
         {
            count.set(count.get() + 1);
         }
      };
      m_server.addNotificationListener(m_timerName, listener, null, null);

      long now = System.currentTimeMillis();

      // This periodic notification is started, sendPastNotifications is true
      // the Timer is started, then stopped, then restarted
      long occurrences = 10;
      long pre = 2;
      long skip = 4;
      Date date = new Date(now + Timer.ONE_SECOND);
      m_timer.setSendPastNotifications(true);
      m_timer.addNotification("notif-type", "notif-message", "notif-data", date, Timer.ONE_SECOND, occurrences, true);
      m_timer.start();

      // Wait for the notifications to happen
      sleep(Timer.ONE_SECOND * pre);
      m_timer.stop();

      // Sometimes we loose one notification because we're not that fast, it's ok.
      if (count.get() != pre && count.get() != pre - 1)
         fail("Expected notifications not emitted: expecting " + pre + " got " + count.get());
      assertFalse(m_timer.isEmpty());

      // Wait to skip some notification
      sleep(Timer.ONE_SECOND * skip);

      // Restart the Timer
      m_timer.start();

      // Wait for the remaining notifications to happen
      sleep(Timer.ONE_SECOND * (occurrences - pre - skip + 1));

      m_timer.stop();
      assertEquals(count.get(), occurrences);
      assertTrue(m_timer.isEmpty());
   }
View Full Code Here

Examples of test.MutableInteger

      final int occurrences = 100;
      final String fdNotifType = "timer-test-fixed-delay";
      final String frNotifType = "timer-test-fixed-rate";

      final MutableInteger frOccurrences = new MutableInteger(0);
      final MutableLong frElapsedTime = new MutableLong(0);
      final MutableLong frLastTime = new MutableLong(System.currentTimeMillis());

      NotificationListener frListener = new NotificationListener()
      {
         public void handleNotification(Notification notification, Object handback)
         {
            if (frOccurrences.get() < occurrences)
            {
               long now = System.currentTimeMillis();
               frElapsedTime.set(frElapsedTime.get() + (now - frLastTime.get()));
               frLastTime.set(now);
               frOccurrences.set(frOccurrences.get() + 1);
            }
         }
      };

      final MutableInteger fdOccurrences = new MutableInteger(0);
      final MutableLong fdElapsedTime = new MutableLong(0);
      final MutableLong fdLastTime = new MutableLong(System.currentTimeMillis());

      NotificationListener fdListener = new NotificationListener()
      {
         public void handleNotification(Notification notification, Object handback)
         {
            if (fdOccurrences.get() < occurrences)
            {
               long now = System.currentTimeMillis();
               fdElapsedTime.set(fdElapsedTime.get() + (now - fdLastTime.get()));
               fdLastTime.set(now);
               fdOccurrences.set(fdOccurrences.get() + 1);
            }
         }
      };

      m_server.addNotificationListener(m_timerName, fdListener, new NotificationFilter()
      {
         public boolean isNotificationEnabled(Notification notification)
         {
            return notification.getType().equals(fdNotifType);
         }
      }, null);

      m_server.addNotificationListener(m_timerName, frListener, new NotificationFilter()
      {
         public boolean isNotificationEnabled(Notification notification)
         {
            return notification.getType().equals(frNotifType);
         }
      }, null);

      // Testing fixed delay/fixed rate
      long now = System.currentTimeMillis();
      // Notify in one second
      Date date = new Date(now + Timer.ONE_SECOND);
      // Register to happen 10 times
      m_timer.addNotification(fdNotifType, "timer-message", "user-data", date, 10, occurrences, false);
      m_timer.addNotification(frNotifType, "timer-message", "user-data", date, 10, occurrences, true);

      // Sleep some time
      while (frOccurrences.get() < occurrences || fdOccurrences.get() < occurrences)
      {
         sleep(10);
         System.gc();
      }

      assertEquals(frOccurrences.get(), occurrences);
      assertEquals(fdOccurrences.get(), occurrences);

      if (((1.0f * frElapsedTime.get()) / fdElapsedTime.get()) > 0.95)
         fail("Fixed rate and fixed delay exhibit no execution rate differences");
   }
View Full Code Here

Examples of test.MutableInteger

      System.setProperty(property, "mx4j.server.CachingReflectionMBeanInvoker");
      MBeanServer server = newMBeanServer();
      ObjectName name = new ObjectName("BCEL:test=performance,type=reflection");
      try
      {
         MutableInteger integer = new MutableInteger(0);
         BCELPerformance mbean = new BCELPerformance(integer);
         server.registerMBean(mbean, name);

         long[] results = new long[m_reps];
         for (int i = 0; i < m_reps; ++i)
         {
            long start = System.currentTimeMillis();
            for (int j = 0; j < m_calls; ++j)
            {
               server.getAttribute(name, "Test");
            }
            long end = System.currentTimeMillis();
            results[i] = end - start;
            System.out.println("Reflection result: " + results[i]);
         }

         if (integer.get() != m_calls * m_reps)
         {
            fail("MBean not called !");
         }

         long reflectionAverage = 0;
View Full Code Here

Examples of test.MutableInteger

      System.setProperty(property, "mx4j.server.CachingReflectionMBeanInvoker");
      MBeanServer server = newMBeanServer();
      ObjectName name = new ObjectName("BCEL:test=performance,type=reflection");
      try
      {
         MutableInteger integer = new MutableInteger(0);
         BCELPerformance mbean = new BCELPerformance(integer);
         server.registerMBean(mbean, name);

         long[] results = new long[m_reps];
         for (int i = 0; i < m_reps; ++i)
         {
            long start = System.currentTimeMillis();
            for (int j = 0; j < m_calls; ++j)
            {
               server.invoke(name, "test", null, null);
            }
            long end = System.currentTimeMillis();
            results[i] = end - start;
            System.out.println("Reflection result: " + results[i]);
         }

         if (integer.get() != m_calls * m_reps)
         {
            fail("MBean not called !");
         }

         long reflectionAverage = 0;
View Full Code Here

Examples of test.MutableInteger

      MBeanServer server = newMBeanServer();
      ObjectName name = new ObjectName("BCEL:test=performance,type=direct");
      try
      {
         MutableInteger integer = new MutableInteger(0);
         BCELPerformance mbean = new BCELPerformance(integer);
         server.registerMBean(mbean, name);

         long[] results = new long[m_reps];
         for (int i = 0; i < m_reps; ++i)
         {
            long start = System.currentTimeMillis();
            for (int j = 0; j < m_calls; ++j)
            {
               server.getAttribute(name, "Test");
            }
            long end = System.currentTimeMillis();
            results[i] = end - start;
            System.out.println("Direct result: " + results[i]);
         }

         if (integer.get() != m_calls * m_reps)
         {
            fail("MBean not called !");
         }

         long directAverage = 0;
View Full Code Here

Examples of test.MutableInteger

      MBeanServer server = newMBeanServer();
      ObjectName name = new ObjectName("BCEL:test=performance,type=direct");
      try
      {
         MutableInteger integer = new MutableInteger(0);
         BCELPerformance mbean = new BCELPerformance(integer);
         server.registerMBean(mbean, name);

         long[] results = new long[m_reps];
         for (int i = 0; i < m_reps; ++i)
         {
            long start = System.currentTimeMillis();
            for (int j = 0; j < m_calls; ++j)
            {
               server.invoke(name, "test", null, null);
            }
            long end = System.currentTimeMillis();
            results[i] = end - start;
            System.out.println("Direct result: " + results[i]);
         }

         if (integer.get() != m_calls * m_reps)
         {
            fail("MBean not called !");
         }

         long directAverage = 0;
View Full Code Here

Examples of test.MutableInteger

      }
   }

   public void testPlainReflectionPerformance() throws Exception
   {
      MutableInteger integer = new MutableInteger(0);
      BCELPerformance mbean = new BCELPerformance(integer);
      Method test = mbean.getClass().getMethod("test", (Class[])null);

      int factor = 100;
      int calls = m_calls * factor;

      long[] results = new long[m_reps];
      for (int i = 0; i < m_reps; ++i)
      {
         long start = System.currentTimeMillis();
         for (int j = 0; j < calls; ++j)
         {
            test.invoke(mbean, (Object[])null);
         }
         long end = System.currentTimeMillis();
         results[i] = end - start;
         System.out.println("Plain reflection: " + (results[i] / factor));
      }

      if (integer.get() != calls * m_reps)
      {
         fail("MBean not called !");
      }

      long directAverage = 0;
View Full Code Here

Examples of test.MutableInteger

      MBeanServer server = newMBeanServer();
      ObjectName name = new ObjectName("BCEL:test=package,type=direct");
      try
      {
         MutableInteger integer = new MutableInteger(0);
         BCELPerformance mbean = new BCELPerformance(integer);
         server.registerMBean(mbean, name);

         PackagePrivate arg = new PackagePrivate();

         server.invoke(name, "testPackagePrivate", new Object[]{arg}, new String[]{arg.getClass().getName()});

         if (integer.get() != 1)
         {
            fail("MBean not called !");
         }
      }
      finally
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.