Author: rhauch
Date: 2008-05-08 15:06:57 -0400 (Thu, 08 May 2008)
New Revision: 128
Modified:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencingService.java
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/MockSequencerA.java
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/SequencingServiceTest.java
Log:
Corrected a concurrency problem in SequencingService.awaitTermination(...) that sometimes
caused a deadlock.
Modified:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencingService.java
===================================================================
---
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencingService.java 2008-05-08
19:05:58 UTC (rev 127)
+++
trunk/dna-repository/src/main/java/org/jboss/dna/repository/sequencers/SequencingService.java 2008-05-08
19:06:57 UTC (rev 128)
@@ -387,7 +387,7 @@
}
protected boolean doAwaitTermination( long timeout, TimeUnit unit ) throws
InterruptedException {
- if (this.executorService.isShutdown()) return true;
+ if (this.executorService == null || this.executorService.isTerminated()) return
true;
return this.executorService.awaitTermination(timeout, unit);
}
Modified:
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/MockSequencerA.java
===================================================================
---
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/MockSequencerA.java 2008-05-08
19:05:58 UTC (rev 127)
+++
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/MockSequencerA.java 2008-05-08
19:06:57 UTC (rev 128)
@@ -43,7 +43,7 @@
private SequencerConfig config;
private AtomicInteger counter = new AtomicInteger();
- private CountDownLatch latch = new CountDownLatch(0);
+ private volatile CountDownLatch latch = new CountDownLatch(0);
public void setExpectedCount( int numExpected ) {
this.latch = new CountDownLatch(numExpected);
Modified:
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/SequencingServiceTest.java
===================================================================
---
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/SequencingServiceTest.java 2008-05-08
19:05:58 UTC (rev 127)
+++
trunk/dna-repository/src/test/java/org/jboss/dna/repository/sequencers/SequencingServiceTest.java 2008-05-08
19:06:57 UTC (rev 128)
@@ -22,21 +22,18 @@
package org.jboss.dna.repository.sequencers;
-import java.util.concurrent.TimeUnit;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.hamcrest.core.IsNull.nullValue;
import static org.hamcrest.core.IsSame.sameInstance;
import static org.junit.Assert.assertThat;
import static org.junit.matchers.JUnitMatchers.hasItem;
+import java.util.concurrent.TimeUnit;
import javax.jcr.Node;
import javax.jcr.Session;
import javax.jcr.observation.Event;
import org.jboss.dna.common.jcr.AbstractJcrRepositoryTest;
import org.jboss.dna.repository.observation.ObservationService;
-import org.jboss.dna.repository.sequencers.Sequencer;
-import org.jboss.dna.repository.sequencers.SequencerConfig;
-import org.jboss.dna.repository.sequencers.SequencingService;
import org.jboss.dna.repository.services.ServiceAdministrator;
import org.jboss.dna.repository.util.ExecutionContext;
import org.jboss.dna.repository.util.MockExecutionContext;
@@ -67,9 +64,11 @@
@After
public void afterEach() throws Exception {
- super.shutdownRepository();
- this.sequencingService.getAdministrator().shutdown();
this.observationService.getAdministrator().shutdown();
+ this.observationService.getAdministrator().awaitTermination(5,
TimeUnit.SECONDS);
+ this.sequencingService.getAdministrator().shutdown();
+ this.sequencingService.getAdministrator().awaitTermination(5, TimeUnit.SECONDS);
+ super.shutdownRepository();
}
@Test
@@ -303,6 +302,7 @@
MockSequencerA sequencerA =
(MockSequencerA)sequencingService.getSequencerLibrary().getInstances().get(0);
assertThat(sequencerA, is(notNullValue()));
assertThat(sequencerA.getCounter(), is(0));
+ sequencerA.setExpectedCount(1);
assertThat(sequencingService.getSequencerLibrary().getInstances(),
hasItem((Sequencer)sequencerA));
// Cause an event, but not one that the sequencer cares about ...
@@ -320,7 +320,6 @@
assertThat(sequencingService.getSequencerLibrary().getInstances(),
hasItem((Sequencer)sequencerA));
// Now set the property that the sequencer DOES care about ...
- sequencerA.setExpectedCount(1);
nodeD.setProperty("description", "This is the value");
session.save();