felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From uiter...@apache.org
Subject svn commit: r1565759 - /felix/sandbox/marrs/dependencymanager-prototype/dm/test/test/ConcurrencyTest.java
Date Fri, 07 Feb 2014 18:47:03 GMT
Author: uiterlix
Date: Fri Feb  7 18:47:03 2014
New Revision: 1565759

URL: http://svn.apache.org/r1565759
Log:
Added comments explaining the test.

Modified:
    felix/sandbox/marrs/dependencymanager-prototype/dm/test/test/ConcurrencyTest.java

Modified: felix/sandbox/marrs/dependencymanager-prototype/dm/test/test/ConcurrencyTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/marrs/dependencymanager-prototype/dm/test/test/ConcurrencyTest.java?rev=1565759&r1=1565758&r2=1565759&view=diff
==============================================================================
--- felix/sandbox/marrs/dependencymanager-prototype/dm/test/test/ConcurrencyTest.java (original)
+++ felix/sandbox/marrs/dependencymanager-prototype/dm/test/test/ConcurrencyTest.java Fri
Feb  7 18:47:03 2014
@@ -14,6 +14,11 @@ import dm.impl.DependencyImpl;
 import dm.impl.EventImpl;
 
 public class ConcurrencyTest {
+	
+	/**
+	 * Ensure actions from another thread than the current thread executing in the SerialExecutor
are being
+	 * scheduled (added to the queue) rather than being executed immediately.  
+	 */
 	@Test
 	public void createComponentAddDependencyAndListenerAndAddAnotherDependencyInAParallelThread()
{
 		final Semaphore s = new Semaphore(0);
@@ -31,9 +36,13 @@ public class ConcurrencyTest {
 			public void changed(State state) {
 				try {
 					c.remove(this);
+					// launch a second thread interacting with our component and block this thread until
the
+					// second thread finished its interaction with our component. We want to ensure the
work of 
+					// the second thread is scheduled after our current job in the serial executor and does
not
+					// get executed immediately.
 					t.start();
 					s.acquire();
-					Assert.assertEquals(1, c.getDependencies().size());
+					Assert.assertEquals("dependency count should be 1", 1, c.getDependencies().size());
 				}
 				catch (InterruptedException e) {
 					e.printStackTrace();
@@ -41,22 +50,24 @@ public class ConcurrencyTest {
 			}
 		};
 		
-		
 		c.start();
 		c.add(d);
 		c.add(l);
-		Assert.assertEquals(false, c.isAvailable());
-		d.changed(new EventImpl(true));
+		Assert.assertEquals("component should not be available", false, c.isAvailable());
+		d.changed(new EventImpl(true)); // sets dependency d to available and triggers our ComponentStateListener
 		
-		Assert.assertEquals(false, c.isAvailable());
+		// due to the dependency added by the second thread in the serial executor we still expect
our component
+		// to be unavailable. This work was scheduled in the serial executor and will be executed
by the current
+		// thread after it finished handling the job for handling the changed() method.
+		Assert.assertEquals("component should not be available", false, c.isAvailable());
 		c.remove(l);
-		Assert.assertEquals(false, c.isAvailable());
+		Assert.assertEquals("component should not be available", false, c.isAvailable());
 		c.remove(d);
-		Assert.assertEquals(false, c.isAvailable());
+		Assert.assertEquals("component should not be available", false, c.isAvailable());
 		c.remove(d2);
-		Assert.assertEquals(true, c.isAvailable());
+		Assert.assertEquals("component should be available", true, c.isAvailable());
 		c.stop();
-		Assert.assertEquals(false, c.isAvailable());
+		Assert.assertEquals("component should not be available", false, c.isAvailable());
 	}
 
 }



Mime
View raw message