[jboss-cvs] JBossAS SVN: r109190 - in branches/JBPAPP_5_1: testsuite/src/main/org/jboss/test/util/test and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sun Nov 7 08:10:52 EST 2010


Author: tkobayas at redhat.com
Date: 2010-11-07 08:10:51 -0500 (Sun, 07 Nov 2010)
New Revision: 109190

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

Modified: branches/JBPAPP_5_1/testsuite/imports/sections/util.xml
===================================================================
--- branches/JBPAPP_5_1/testsuite/imports/sections/util.xml	2010-11-07 00:22:45 UTC (rev 109189)
+++ branches/JBPAPP_5_1/testsuite/imports/sections/util.xml	2010-11-07 13:10:51 UTC (rev 109190)
@@ -37,5 +37,6 @@
       </jar>      
       <!-- The service -->
       <copy tofile="${build.lib}/test-default-scheduler-service.xml" file="${build.resources}/util/test-default-scheduler-service.xml"/>
+      <copy tofile="${build.lib}/test-jbas8382-scheduler-service.xml" file="${build.resources}/util/test-jbas8382-scheduler-service.xml"/>
    </target>
 </project>

Added: branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/util/test/jbas8382/JBAS8382UnitTestCase.java
===================================================================
--- branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/util/test/jbas8382/JBAS8382UnitTestCase.java	                        (rev 0)
+++ branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/util/test/jbas8382/JBAS8382UnitTestCase.java	2010-11-07 13:10:51 UTC (rev 109190)
@@ -0,0 +1,136 @@
+/*
+ * 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.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;
+
+/**
+ * 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
+{
+   private String file = "test-jbas8382-scheduler-service.xml";
+
+   /**
+    * 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));
+   }
+
+   private SchedulableMBeanExampleMBean get(ObjectName on) throws Exception
+   {
+	  SchedulableMBeanExampleMBean ex = (SchedulableMBeanExampleMBean)
+		 MBeanServerInvocationHandler.newProxyInstance(getServer(), on,
+			   SchedulableMBeanExampleMBean.class, false);
+	  return ex;
+   }
+
+   private void check(ObjectName on, int hits, long remaining) throws Exception
+   {
+	  SchedulableMBeanExampleMBean ex = get(on);
+	  assertNotNull("name " + on, ex);
+
+	  assertEquals("hits", hits, ex.getHitCount());
+
+	  Date hd = ex.getHitDate();
+	  if (hits > 0)
+	  {
+		 Date now = new Date();
+		 assertNotNull("hit date", hd); 
+		 assertTrue("date " + hd + " " + now, !hd.after(now));
+		 assertTrue("note", ex.getHitNotification() != null);
+		 assertTrue("sched", ex.getSchedulerName() != null);
+		 assertEquals("remaining", remaining, ex.getRemainingRepetitions());
+	  }
+	  assertEquals(null, ex.getTestString());
+   }
+
+   /**
+    * Tests ScheduleManager when (now - startDate) > Integer.MAX_VALUE and period == 1
+    */
+   public void testScheduleManagerWithIntegerOverflow()
+      throws Exception
+   {
+	  ObjectName ex = new ObjectName("test:name=SchedulableMBeanExample");
+	  ObjectName manager = new ObjectName("test:service=Scheduler,name=ScheduleManager");
+          ObjectName provider = new ObjectName("test:service=SingleScheduleProvider");
+
+	  deploy(file);
+      try
+      {
+		 registered(new ObjectName(ScheduleManager.DEFAULT_TIMER_NAME));
+		 registered(ex);
+		 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();
+
+		 Thread.sleep(1000); // just wait for a while
+		 check(ex, 0, 0); // No repetitions left because start date is in the past and could not be reached by Initial Repetitions * Schedule Period 
+		 
+      }
+      finally
+      {
+         undeploy(file);
+      }
+   }
+
+}

Added: branches/JBPAPP_5_1/testsuite/src/resources/util/test-jbas8382-scheduler-service.xml
===================================================================
--- branches/JBPAPP_5_1/testsuite/src/resources/util/test-jbas8382-scheduler-service.xml	                        (rev 0)
+++ branches/JBPAPP_5_1/testsuite/src/resources/util/test-jbas8382-scheduler-service.xml	2010-11-07 13:10:51 UTC (rev 109190)
@@ -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_5_1/varia/src/main/org/jboss/varia/scheduler/ScheduleManager.java
===================================================================
--- branches/JBPAPP_5_1/varia/src/main/org/jboss/varia/scheduler/ScheduleManager.java	2010-11-07 00:22:45 UTC (rev 109189)
+++ branches/JBPAPP_5_1/varia/src/main/org/jboss/varia/scheduler/ScheduleManager.java	2010-11-07 13:10:51 UTC (rev 109190)
@@ -704,8 +704,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;
@@ -786,7 +786,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