[jboss-cvs] JBossAS SVN: r108237 - in branches/JBPAPP_4_2_0_GA_CP: testsuite/src/main/org/jboss/test/util/test/jbas8382 and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Sep 20 22:22:20 EDT 2010


Author: tkobayas at redhat.com
Date: 2010-09-20 22:22:19 -0400 (Mon, 20 Sep 2010)
New Revision: 108237

Added:
   branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/util/test/jbas8382/
   branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/util/test/jbas8382/JBAS8382UnitTestCase.java
   branches/JBPAPP_4_2_0_GA_CP/testsuite/src/resources/util/test-jbas8382-scheduler-service.xml
Modified:
   branches/JBPAPP_4_2_0_GA_CP/varia/src/main/org/jboss/varia/scheduler/ScheduleManager.java
Log:
JBPAPP-5009 ScheduleManagers skip repeats can be negative

Added: branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/util/test/jbas8382/JBAS8382UnitTestCase.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/util/test/jbas8382/JBAS8382UnitTestCase.java	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/util/test/jbas8382/JBAS8382UnitTestCase.java	2010-09-21 02:22:19 UTC (rev 108237)
@@ -0,0 +1,124 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.util.test.jbas8382;
+
+import java.net.URL;
+import java.util.Date;
+
+import javax.management.MBeanServerInvocationHandler;
+import javax.management.ObjectName;
+
+import org.jboss.test.JBossTestCase;
+import org.jboss.varia.scheduler.ScheduleManager;
+import org.jboss.varia.scheduler.SingleScheduleProviderMBean;
+import org.jboss.varia.scheduler.example.SchedulableMBeanExampleMBean;
+
+/**
+ * [JBPAPP-5009] JBAS-8382 ScheduleManager's skip repeats can be negative
+ *
+ * @see org.jboss.varia.scheduler.ScheduleManager
+ *
+ * @author Toshiya Kobayashi
+ * @version $Revision: 84000 $
+ */
+public class JBAS8382UnitTestCase
+   extends JBossTestCase
+{
+   /**
+    * Constructor for the JBAS8382UnitTestCase object
+    *
+    * @param name Test case name
+    */
+   public JBAS8382UnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   protected void setUp() throws Exception {
+	  super.setUp();
+   }
+
+   protected void tearDown() throws Exception {
+	  super.tearDown();
+   }
+
+   // Public --------------------------------------------------------
+
+   private void registered(ObjectName on) throws Exception
+   {
+	  assertTrue(on + " isRegistered", getServer().isRegistered(on));
+   }
+
+   /**
+    * Tests ScheduleManager when (now - startDate) > Integer.MAX_VALUE and period == 1
+    */
+   public void testScheduleManagerWithIntegerOverflow()
+      throws Exception
+   {
+      // The class loader used to locate the configuration file
+      ClassLoader lLoader = Thread.currentThread().getContextClassLoader();
+      assertTrue("ContextClassloader missing", lLoader != null);
+      //Get URL for deployable *service.xml file in resources
+      URL serviceURL = lLoader.getResource("util/test-jbas8382-scheduler-service.xml");
+      if (serviceURL == null)
+      {
+         //if we're running from the jmxtest.jar, it should be here instead
+         serviceURL = lLoader.getResource("test-jbas8382-scheduler-service.xml");
+      }
+      assertTrue("resource test-default-scheduler-service.xml not found", serviceURL != null);
+
+      ObjectName example = new ObjectName("test:name=SchedulableMBeanExample");
+      ObjectName manager = new ObjectName("test:service=Scheduler,name=ScheduleManager");
+      ObjectName provider = new ObjectName("test:service=SingleScheduleProvider");
+
+      deploy(serviceURL.toString());
+
+      try
+      {
+		 registered(new ObjectName(ScheduleManager.DEFAULT_TIMER_NAME));
+		 registered(example);
+		 registered(manager);
+		 registered(provider);
+
+                 // JBAS-8382 if (now - startDate) > Integer.MAX_VALUE and period == 1, then skip repeats can be negative and it causes wrong (too much) repetition
+                 SingleScheduleProviderMBean pr = (SingleScheduleProviderMBean)
+                     MBeanServerInvocationHandler.newProxyInstance(getServer(), provider,
+                     SingleScheduleProviderMBean.class, false);
+                 pr.setStartDate(String.valueOf(System.currentTimeMillis() - Integer.MAX_VALUE - 1));
+                 pr.stop();
+                 pr.start();
+
+                 SchedulableMBeanExampleMBean ex = (SchedulableMBeanExampleMBean)
+		     MBeanServerInvocationHandler.newProxyInstance(getServer(), example,
+                     SchedulableMBeanExampleMBean.class, false);
+
+		 Thread.sleep(1000); // just wait for a while
+                 assertEquals("hits", 0, ex.getHitCount()); // No repetitions left because start date is in the past and could not be reached by Initial Repetitions * Schedule Period 
+		 
+      }
+      finally
+      {
+         undeploy(serviceURL.toString());
+      }
+   }
+
+}

Added: branches/JBPAPP_4_2_0_GA_CP/testsuite/src/resources/util/test-jbas8382-scheduler-service.xml
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/testsuite/src/resources/util/test-jbas8382-scheduler-service.xml	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/testsuite/src/resources/util/test-jbas8382-scheduler-service.xml	2010-09-21 02:22:19 UTC (rev 108237)
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- Tests of the Scheduler services
+$Id: test-default-scheduler-service.xml 81742 2008-11-27 17:07:11Z adrian at jboss.org $
+-->
+
+<server>
+
+   <!-- ScheduleManager -->
+
+   <mbean code="org.jboss.varia.scheduler.example.SchedulableMBeanExample"
+      name="test:name=SchedulableMBeanExample">
+   </mbean>
+
+   <mbean code="org.jboss.varia.scheduler.ScheduleManager"
+      name="test:service=Scheduler,name=ScheduleManager">
+   </mbean>
+
+   <mbean code="org.jboss.varia.scheduler.SingleScheduleProvider"
+      name="test:service=SingleScheduleProvider">
+      <attribute name="TargetMethod">hit( NOTIFICATION, DATE, REPETITIONS, SCHEDULER_NAME, java.lang.String )</attribute>
+	  <depends optional-attribute-name="ScheduleManagerName">test:service=Scheduler,name=ScheduleManager</depends>
+	  <depends optional-attribute-name="TargetName">test:name=SchedulableMBeanExample</depends>
+      <attribute name="StartDate">NOW</attribute>
+      <attribute name="Repetitions">1</attribute>
+      <attribute name="Period">1</attribute>
+   </mbean>
+
+</server>

Modified: branches/JBPAPP_4_2_0_GA_CP/varia/src/main/org/jboss/varia/scheduler/ScheduleManager.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/varia/src/main/org/jboss/varia/scheduler/ScheduleManager.java	2010-09-21 01:33:58 UTC (rev 108236)
+++ branches/JBPAPP_4_2_0_GA_CP/varia/src/main/org/jboss/varia/scheduler/ScheduleManager.java	2010-09-21 02:22:19 UTC (rev 108237)
@@ -687,8 +687,8 @@
       public int mNotificationID;
       public ObjectName mProvider;
       public ObjectName mTarget;
-      public int mInitialRepetitions;
-      public int mRemainingRepetitions = 0;
+      public long mInitialRepetitions;
+      public long mRemainingRepetitions = 0;
       public Date mStartDate;
       public long mPeriod;
       public String mMethodName;
@@ -769,7 +769,7 @@
          {
             // If then first check if a repetition is in the future
             long lNow = new Date().getTime() + 100;
-            int lSkipRepeats = (int) ((lNow - mStartDate.getTime()) / mPeriod) + 1;
+            long lSkipRepeats = ((lNow - mStartDate.getTime()) / mPeriod) + 1;
             log.debug("Old start date: " + mStartDate + ", now: " + new Date(lNow) + ", Skip repeats: " + lSkipRepeats);
             if (mInitialRepetitions > 0)
             {



More information about the jboss-cvs-commits mailing list