Package test

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


      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

      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

      }
   }

   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

      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

      MonitorTarget target = new MonitorTarget();
      target.setString(reference);
      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(), 1);
         MonitorNotification notification = (MonitorNotification)holder.get();
         assertEquals(notification.getType(), MonitorNotification.STRING_TO_COMPARE_VALUE_MATCHED);

         times.set(0);
         holder.set(null);
         target.setString("xx");

         sleep(period * 3);
         assertEquals(times.get(), 1);
         notification = (MonitorNotification)holder.get();
         assertEquals(notification.getType(), MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED);

         times.set(0);
         holder.set(null);
         target.setString(reference);

         sleep(period * 3);
         assertEquals(times.get(), 1);
         notification = (MonitorNotification)holder.get();
         assertEquals(notification.getType(), MonitorNotification.STRING_TO_COMPARE_VALUE_MATCHED);

         times.set(0);
         holder.set(null);
         target.setString("yyyy");

         sleep(period * 3);
         assertEquals(times.get(), 1);
         notification = (MonitorNotification)holder.get();
         assertEquals(notification.getType(), MonitorNotification.STRING_TO_COMPARE_VALUE_DIFFERED);

         times.set(0);
         holder.set(null);
         target.setString("zzzzz");

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

      NotificationBroadcasterSupport mbean2 = new NotificationSupport.Emitter();

      server.registerMBean(mbean1, name1);
      server.registerMBean(mbean2, name2);

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

      server.addNotificationListener(name1, listener, null, null);
      server.addNotificationListener(name2, listener, null, null);

      Notification notification = new Notification("test", mbean1, 1);
      mbean1.sendNotification(notification);

      // Be sure the listener is called
      assertEquals("Listener is not called", integer.get(), 1);

      mbean2.sendNotification(notification);

      // Be sure the listener is called
      assertEquals("Listener is not called", integer.get(), 2);

      // Remove one listener
      server.removeNotificationListener(name1, listener);

      // Be sure it is not called
      mbean1.sendNotification(notification);
      assertEquals("Listener is called", integer.get(), 2);

      // Be sure it is called
      mbean2.sendNotification(notification);
      assertEquals("Listener is not called", integer.get(), 3);

      try
      {
         server.removeNotificationListener(name1, listener);
         fail("Listener has been removed");
      }
      catch (ListenerNotFoundException ignored)
      {
      }

      // Remove also the second listener
      server.removeNotificationListener(name2, listener);

      // Be sure it is not called
      mbean2.sendNotification(notification);
      assertEquals("Listener is called", integer.get(), 3);
   }
View Full Code Here

      NotificationBroadcasterSupport mbean2 = new NotificationSupport.Emitter();

      server.registerMBean(mbean1, name1);
      server.registerMBean(mbean2, name2);

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

      server.addNotificationListener(name1, listener, null, null);
      server.addNotificationListener(name2, listener, null, null);
      mbean2.addNotificationListener(listener, null, null);

      Notification notification = new Notification("test", mbean1, 1);
      mbean1.sendNotification(notification);

      // Be sure the listener is called
      assertEquals("Listener is not called", integer.get(), 1);

      mbean2.sendNotification(notification);

      // Be sure the listeners are called
      assertEquals("Listeners are not called", integer.get(), 3);

      // Remove one listener
      server.removeNotificationListener(name2, listener);

      // Be sure the listener is called
      mbean2.sendNotification(notification);
      assertEquals("Listener is not called", integer.get(), 4);

      // Be sure it is called
      mbean1.sendNotification(notification);
      assertEquals("Listener is not called", integer.get(), 5);

      server.removeNotificationListener(name1, listener);

      // Be sure it is not called
      mbean1.sendNotification(notification);
      assertEquals("Listener is called", integer.get(), 5);

      // Be sure it is called
      mbean2.sendNotification(notification);
      assertEquals("Listener is not called", integer.get(), 6);

      try
      {
         server.removeNotificationListener(name2, listener);
         fail("Listener has been removed");
      }
      catch (ListenerNotFoundException ignored)
      {
      }

      // Remove also the second listener
      mbean2.removeNotificationListener(listener);

      // Be sure it is not called
      mbean2.sendNotification(notification);
      assertEquals("Listener is called", integer.get(), 6);
   }
View Full Code Here

   public void testAddRemoveMBeanServerInterceptor() throws Exception
   {
      MBeanServer server = newMBeanServer();
      ObjectName configurator = new ObjectName(MBeanServerInterceptorConfigurator.OBJECT_NAME);

      MutableInteger integer = new MutableInteger(0);
      TestMBeanServerInterceptor tester = new TestMBeanServerInterceptor(integer);
      server.invoke(configurator, "addInterceptor", new Object[]{tester}, new String[]{MBeanServerInterceptor.class.getName()});

      server.getAttribute(configurator, "Running");
      if (integer.get() != 1) fail("Interceptor not installed");

      server.invoke(configurator, "clearInterceptors", null, null);
      server.getAttribute(configurator, "Running");

      // Be sure the interceptor is not anymore in the chain
      if (integer.get() != 1) fail("Interceptor not removed");
   }
View Full Code Here

   public void testRegisterRemoveMBeanServerInterceptor() throws Exception
   {
      MBeanServer server = newMBeanServer();
      ObjectName configurator = new ObjectName(MBeanServerInterceptorConfigurator.OBJECT_NAME);

      MutableInteger integer = new MutableInteger(0);
      TestMBeanServerInterceptor tester = new TestMBeanServerInterceptor(integer);
      ObjectName name = new ObjectName("Interceptor:category=MBeanServer,type=Test");
      server.invoke(configurator, "registerInterceptor", new Object[]{tester, name}, new String[]{MBeanServerInterceptor.class.getName(), ObjectName.class.getName()});

      server.getMBeanInfo(configurator);
      if (integer.get() != 1) fail("Interceptor not installed");

      // Let's check if the interceptor is registered, let's change something in it
      server.setAttribute(name, new Attribute("Enabled", Boolean.FALSE));

      // Call again
      server.getMBeanInfo(configurator);
      if (integer.get() != 1) fail("Interceptor not registered");

      AttributeList list = new AttributeList();
      list.add(new Attribute("Enabled", Boolean.TRUE));
      server.setAttributes(name, list);

      server.getMBeanInfo(configurator);
      if (integer.get() != 2) fail("Interceptor not enabled");

      server.invoke(configurator, "clearInterceptors", null, null);
      server.getAttribute(configurator, "Running");

      // Be sure the interceptor is not anymore in the chain
      if (integer.get() != 2) fail("Interceptor not removed");
   }
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.