You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2010/10/15 23:25:29 UTC

svn commit: r1023116 - in /openejb/branches/openejb-3.1.x/container/openejb-core/src: main/java/org/apache/openejb/monitoring/Event.java test/java/org/apache/openejb/core/stateless/StatelessPoolStatsTest.java

Author: dblevins
Date: Fri Oct 15 21:25:29 2010
New Revision: 1023116

URL: http://svn.apache.org/viewvc?rev=1023116&view=rev
Log:
Hopefully permanently fixes Sweeps test.
Basically added a "long Sweeps.LatestTime" so we can to the millisecond accuracy off the stat and have a greater guarantee it will always pass.  Previously there was only a formatted date string of the last sweep time so all milliseconds were lost -- more if the default system time shaved off seconds too.

Modified:
    openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/monitoring/Event.java
    openejb/branches/openejb-3.1.x/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/StatelessPoolStatsTest.java

Modified: openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/monitoring/Event.java
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/monitoring/Event.java?rev=1023116&r1=1023115&r2=1023116&view=diff
==============================================================================
--- openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/monitoring/Event.java (original)
+++ openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/monitoring/Event.java Fri Oct 15 21:25:29 2010
@@ -52,4 +52,9 @@ public class Event {
         DateFormat format = SimpleDateFormat.getDateTimeInstance();
         return format.format(new Date(last));
     }
+
+    @Managed
+    public long getLatestTime() {
+        return this.last.get();
+    }
 }

Modified: openejb/branches/openejb-3.1.x/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/StatelessPoolStatsTest.java
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.1.x/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/StatelessPoolStatsTest.java?rev=1023116&r1=1023115&r2=1023116&view=diff
==============================================================================
--- openejb/branches/openejb-3.1.x/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/StatelessPoolStatsTest.java (original)
+++ openejb/branches/openejb-3.1.x/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/StatelessPoolStatsTest.java Fri Oct 15 21:25:29 2010
@@ -31,7 +31,6 @@ import javax.annotation.PreDestroy;
 import javax.annotation.Resource;
 import javax.annotation.PostConstruct;
 import javax.ejb.SessionContext;
-import javax.ejb.ConcurrentAccessTimeoutException;
 import javax.ejb.ConcurrentAccessException;
 import javax.management.AttributeNotFoundException;
 import javax.management.InstanceNotFoundException;
@@ -87,19 +86,25 @@ public class StatelessPoolStatsTest exte
         List<MBeanAttributeInfo> expectedAttributes = new ArrayList<MBeanAttributeInfo>();
         expectedAttributes.add(new MBeanAttributeInfo("AccessTimeouts", "long", "", true, false, false));
         expectedAttributes.add(new MBeanAttributeInfo("AccessTimeouts.Latest", "java.lang.String", "", true, false, false));
+        expectedAttributes.add(new MBeanAttributeInfo("AccessTimeouts.LatestTime", "long", "", true, false, false));
         expectedAttributes.add(new MBeanAttributeInfo("Aged", "long", "", true, false, false));
         expectedAttributes.add(new MBeanAttributeInfo("Aged.Latest", "java.lang.String", "", true, false, false));
+        expectedAttributes.add(new MBeanAttributeInfo("Aged.LatestTime", "long", "", true, false, false));
         expectedAttributes.add(new MBeanAttributeInfo("AvailablePermits", "int", "", true, false, false));
         expectedAttributes.add(new MBeanAttributeInfo("Flushed", "long", "", true, false, false));
         expectedAttributes.add(new MBeanAttributeInfo("Flushed.Latest", "java.lang.String", "", true, false, false));
+        expectedAttributes.add(new MBeanAttributeInfo("Flushed.LatestTime", "long", "", true, false, false));
         expectedAttributes.add(new MBeanAttributeInfo("Flushes", "long", "", true, false, false));
         expectedAttributes.add(new MBeanAttributeInfo("Flushes.Latest", "java.lang.String", "", true, false, false));
+        expectedAttributes.add(new MBeanAttributeInfo("Flushes.LatestTime", "long", "", true, false, false));
         expectedAttributes.add(new MBeanAttributeInfo("GarbageCollected", "long", "", true, false, false));
         expectedAttributes.add(new MBeanAttributeInfo("GarbageCollected.Latest", "java.lang.String", "", true, false, false));
+        expectedAttributes.add(new MBeanAttributeInfo("GarbageCollected.LatestTime", "long", "", true, false, false));
         expectedAttributes.add(new MBeanAttributeInfo("GarbageCollection", "boolean", "", true, false, false));
         expectedAttributes.add(new MBeanAttributeInfo("IdleTimeout", "long", "", true, false, false));
         expectedAttributes.add(new MBeanAttributeInfo("IdleTimeouts", "long", "", true, false, false));
         expectedAttributes.add(new MBeanAttributeInfo("IdleTimeouts.Latest", "java.lang.String", "", true, false, false));
+        expectedAttributes.add(new MBeanAttributeInfo("IdleTimeouts.LatestTime", "long", "", true, false, false));
         expectedAttributes.add(new MBeanAttributeInfo("InstancesActive", "int", "", true, false, false));
         expectedAttributes.add(new MBeanAttributeInfo("InstancesIdle", "int", "", true, false, false));
         expectedAttributes.add(new MBeanAttributeInfo("InstancesInitializing", "int", "", true, false, false));
@@ -111,15 +116,18 @@ public class StatelessPoolStatsTest exte
         expectedAttributes.add(new MBeanAttributeInfo("MinimumInstances", "int", "", true, false, false));
         expectedAttributes.add(new MBeanAttributeInfo("Overdrafts", "long", "", true, false, false));
         expectedAttributes.add(new MBeanAttributeInfo("Overdrafts.Latest", "java.lang.String", "", true, false, false));
+        expectedAttributes.add(new MBeanAttributeInfo("Overdrafts.LatestTime", "long", "", true, false, false));
         expectedAttributes.add(new MBeanAttributeInfo("PoolVersion", "int", "", true, false, false));
         expectedAttributes.add(new MBeanAttributeInfo("ReplaceAged", "boolean", "", true, false, false));
         expectedAttributes.add(new MBeanAttributeInfo("ReplaceFlushed", "boolean", "", true, false, false));
         expectedAttributes.add(new MBeanAttributeInfo("Replaced", "long", "", true, false, false));
         expectedAttributes.add(new MBeanAttributeInfo("Replaced.Latest", "java.lang.String", "", true, false, false));
+        expectedAttributes.add(new MBeanAttributeInfo("Replaced.LatestTime", "long", "", true, false, false));
         expectedAttributes.add(new MBeanAttributeInfo("StrictPooling", "boolean", "", true, false, false));
         expectedAttributes.add(new MBeanAttributeInfo("SweepInterval", "long", "", true, false, false));
         expectedAttributes.add(new MBeanAttributeInfo("Sweeps", "long", "", true, false, false));
         expectedAttributes.add(new MBeanAttributeInfo("Sweeps.Latest", "java.lang.String", "", true, false, false));
+        expectedAttributes.add(new MBeanAttributeInfo("Sweeps.LatestTime", "long", "", true, false, false));
 
 
         // The hardest part, check the values of each, PoolVersion is AtomicaInteger, *.Latest are time-sensitive, so not verified.
@@ -130,7 +138,7 @@ public class StatelessPoolStatsTest exte
         expectedAttributesValue.put("Flushed", (long) 0);
         expectedAttributesValue.put("Flushes", (long) 0);
         expectedAttributesValue.put("GarbageCollected", (long) 0);
-        expectedAttributesValue.put("GarbageCollection", true);
+        expectedAttributesValue.put("GarbageCollection", false);
         expectedAttributesValue.put("IdleTimeout", (long) 0);
         expectedAttributesValue.put("IdleTimeouts", (long) 0);
         expectedAttributesValue.put("InstancesPooled", (int) 3);
@@ -155,7 +163,7 @@ public class StatelessPoolStatsTest exte
         Map<String, Object> actualAttributesValue = new HashMap<String, Object>();
         for (MBeanAttributeInfo info : poolMBeanInfo.getAttributes()) {
             actualAttributes.add(info);
-            if (!info.getName().endsWith(".Latest")) {
+            if (!info.getName().endsWith(".Latest") && !info.getName().endsWith(".LatestTime")) {
                 actualAttributesValue.put(info.getName(), server.getAttribute(objectName, info.getName()));
             }
         }
@@ -479,19 +487,26 @@ public class StatelessPoolStatsTest exte
      */
     public void testSweeps() throws Exception {
     	Properties properties = new Properties();
-    	properties.setProperty("SweepInterval", "1");
+    	properties.setProperty("SweepInterval", "100");
+
+        Date expectedDate = new Date(); // now
 
         deploy("testSweeps", properties);
 
-        assertTrue((Long)(server.getAttribute(objectName, "Sweeps")) >= 1L);
+        Thread.sleep(200);
+
+        final Long sweeps = (Long) (server.getAttribute(objectName, "Sweeps"));
+        assertTrue("sweeps=" + sweeps, sweeps >= 1L);
 
-        //Get current time
-        DateFormat dateFormatter = SimpleDateFormat.getDateTimeInstance();
+        final Object attribute = server.getAttribute(objectName, "Sweeps.LatestTime");
+        final Date actualDate = new Date((Long)attribute);
 
-        Date expected = new Date(System.currentTimeMillis() - 1 * 60 * 1000L);
+        final String message = display("actual", actualDate) + " after " + display("expected", expectedDate);
+        assertTrue(message, actualDate.after(expectedDate));
+    }
 
-        final String latest = (String) (server.getAttribute(objectName, "Sweeps.Latest"));
-        assertTrue(dateFormatter.parse(latest).after(expected));
+    private String display(String name, Date date) {
+        return name + "=" + date.getTime();
     }
 
     /**