felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1626022 - in /felix/trunk/eventadmin/impl: changelog.txt src/test/java/org/apache/felix/eventadmin/ittests/AbstractTest.java src/test/java/org/apache/felix/eventadmin/ittests/StressTestIT.java
Date Thu, 18 Sep 2014 16:33:08 GMT
Author: cziegeler
Date: Thu Sep 18 16:33:07 2014
New Revision: 1626022

URL: http://svn.apache.org/r1626022
Log:
[FELIX-4623] - Add test for thread based ordering. Apply patch from Bob Paulin

Modified:
    felix/trunk/eventadmin/impl/changelog.txt
    felix/trunk/eventadmin/impl/src/test/java/org/apache/felix/eventadmin/ittests/AbstractTest.java
    felix/trunk/eventadmin/impl/src/test/java/org/apache/felix/eventadmin/ittests/StressTestIT.java

Modified: felix/trunk/eventadmin/impl/changelog.txt
URL: http://svn.apache.org/viewvc/felix/trunk/eventadmin/impl/changelog.txt?rev=1626022&r1=1626021&r2=1626022&view=diff
==============================================================================
--- felix/trunk/eventadmin/impl/changelog.txt (original)
+++ felix/trunk/eventadmin/impl/changelog.txt Thu Sep 18 16:33:07 2014
@@ -1,3 +1,9 @@
+Changes from 1.4.2 to 1.4.4
+---------------------------
+** Improvement
+    * [FELIX-4623] - Add test for thread based ordering
+
+
 Changes from 1.4.0 to 1.4.2
 ---------------------------
 ** Improvement

Modified: felix/trunk/eventadmin/impl/src/test/java/org/apache/felix/eventadmin/ittests/AbstractTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/eventadmin/impl/src/test/java/org/apache/felix/eventadmin/ittests/AbstractTest.java?rev=1626022&r1=1626021&r2=1626022&view=diff
==============================================================================
--- felix/trunk/eventadmin/impl/src/test/java/org/apache/felix/eventadmin/ittests/AbstractTest.java
(original)
+++ felix/trunk/eventadmin/impl/src/test/java/org/apache/felix/eventadmin/ittests/AbstractTest.java
Thu Sep 18 16:33:07 2014
@@ -23,11 +23,18 @@ import static org.ops4j.pax.exam.CoreOpt
 import static org.ops4j.pax.exam.CoreOptions.options;
 import static org.ops4j.pax.exam.CoreOptions.provision;
 import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+import static org.ops4j.pax.exam.CoreOptions.vmOption;
 
 import java.io.File;
 import java.util.ArrayList;
 import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Hashtable;
 import java.util.List;
+import java.util.Map;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.CopyOnWriteArrayList;
 
 import javax.inject.Inject;
 
@@ -74,6 +81,8 @@ public abstract class AbstractTest imple
     private volatile String prefix;
 
     private volatile long startTime;
+    
+    private final Queue<Event> eventRecievedList = new ConcurrentLinkedQueue();
 
     /** Wait lock for syncing. */
     private final Object waitLock = new Object();
@@ -87,6 +96,7 @@ public abstract class AbstractTest imple
         if ( this.running ) {
             if ( prefix == null || event.getTopic().startsWith(prefix) ) {
                 incCount();
+                eventRecievedList.offer(event);
             }
         }
     }
@@ -97,8 +107,15 @@ public abstract class AbstractTest imple
      * @param properties
      * @param sync
      */
-    protected void send(String topic, Dictionary<String, Object> properties, boolean
sync) {
-        final Event event = new Event(topic, properties);
+    protected void send(String topic, Dictionary<String, Object> properties, int index,
boolean sync) {
+        
+    	if(properties == null)
+    	{
+    		properties = new Hashtable();
+    	}
+        properties.put("thread", Thread.currentThread().getId());
+        properties.put("index", index);
+    	final Event event = new Event(topic, properties);
         if ( sync ) {
             getEventAdmin().sendEvent(event);
         } else {
@@ -257,6 +274,7 @@ public abstract class AbstractTest imple
              // with build server issue
              new DirectURLJUnitBundlesOption(),
              systemProperty("pax.exam.invoker").value("junit"),
+             //vmOption("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"),

              bundle("link:classpath:META-INF/links/org.ops4j.pax.exam.invoker.junit.link")
         );
     }
@@ -269,6 +287,36 @@ public abstract class AbstractTest imple
         this.waitForFinish();
         this.stop();
         logger.info("Finished eventing test {}", this.getClass().getSimpleName());
+        Event currentEvent = null;
+        Map<Long, Integer> orderVerifyMap = new HashMap<Long, Integer>();
+        while((currentEvent =eventRecievedList.poll()) != null)
+        {
+        	Integer index = (Integer)currentEvent.getProperty("index");
+        	Long threadId = (Long)currentEvent.getProperty("thread");
+        	
+        	if(index != null && threadId != null){
+        		Integer previousIndex = orderVerifyMap.get(threadId);
+        		if(previousIndex == null)
+        		{
+        			if(index != 0)
+        			{
+        				System.out.println("Event " + index + " recieved first for thread " + threadId);
+        			}
+        			orderVerifyMap.put(threadId, index);
+        		}
+        		else
+        		{
+        			if(previousIndex > index)
+        			{
+        				System.out.println("Events for thread " + threadId + " out of order.  Event "
+ previousIndex + " recieved before " + index);
+        			}
+        			else
+        			{
+        				orderVerifyMap.put(threadId, index);
+        			}
+        		}
+        	}
+        }
         try {
             Thread.sleep(15 * 1000);
         } catch (final InterruptedException ie) {

Modified: felix/trunk/eventadmin/impl/src/test/java/org/apache/felix/eventadmin/ittests/StressTestIT.java
URL: http://svn.apache.org/viewvc/felix/trunk/eventadmin/impl/src/test/java/org/apache/felix/eventadmin/ittests/StressTestIT.java?rev=1626022&r1=1626021&r2=1626022&view=diff
==============================================================================
--- felix/trunk/eventadmin/impl/src/test/java/org/apache/felix/eventadmin/ittests/StressTestIT.java
(original)
+++ felix/trunk/eventadmin/impl/src/test/java/org/apache/felix/eventadmin/ittests/StressTestIT.java
Thu Sep 18 16:33:07 2014
@@ -18,6 +18,7 @@ package org.apache.felix.eventadmin.itte
 
 import org.junit.Test;
 
+
 public class StressTestIT extends AbstractTest {
 
     private static final String PREFIX = "org/apache/felix/eventing/test";
@@ -28,7 +29,7 @@ public class StressTestIT extends Abstra
     protected void sendEvent(int index) {
         final String postFix = String.valueOf(index % 10);
         final String topic = PREFIX + '/' + postFix;
-        this.send(topic, null, true);
+        this.send(topic, null, index, false);
     }
 
     @Test



Mime
View raw message