Author: rhauch
Date: 2009-07-20 23:17:04 -0400 (Mon, 20 Jul 2009)
New Revision: 1119
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/Graph.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/federation/FederatedRepositoryConnection.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/federation/FederatedRequest.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/federation/ForkRequestProcessor.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/federation/JoinRequestProcessor.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/federation/NoMoreFederatedRequests.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/federation/Projection.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/Request.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/processor/RequestProcessor.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/federation/AbstractFederatedRepositorySourceIntegrationTest.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/federation/FederatedRepositorySourceUsingMirrorAndBranchProjectionsTest.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/federation/FederatedRequestTest.java
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/federation/ForkRequestProcessorChannelTest.java
Log:
DNA-392 All sessions in a repository should share the same /jcr:system content
A number of issues/bugs were found in the federated connector. These were fixed, and
several tests were added. (Subsequent commits will make additional use of the federated
connector in the JCR implementation, and these also put the federated connector through
additional tests.)
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/Graph.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/Graph.java 2009-07-21 03:14:59 UTC
(rev 1118)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/Graph.java 2009-07-21 03:17:04 UTC
(rev 1119)
@@ -5451,23 +5451,14 @@
if (request instanceof ReadAllPropertiesRequest) {
ReadAllPropertiesRequest read = (ReadAllPropertiesRequest)request;
DateTime expires = computeExpirationTime(read);
- if (read.getActualLocationOfNode() == null) {
- int x = 0;
- }
getOrCreateNode(read.getActualLocationOfNode(),
expires).setProperties(read.getPropertiesByName());
} else if (request instanceof ReadPropertyRequest) {
ReadPropertyRequest read = (ReadPropertyRequest)request;
DateTime expires = computeExpirationTime(read);
- if (read.getActualLocationOfNode() == null) {
- int x = 0;
- }
getOrCreateNode(read.getActualLocationOfNode(),
expires).addProperty(read.getProperty());
} else if (request instanceof ReadNodeRequest) {
ReadNodeRequest read = (ReadNodeRequest)request;
DateTime expires = computeExpirationTime(read);
- if (read.getActualLocationOfNode() == null) {
- int x = 0;
- }
BatchResultsNode node =
getOrCreateNode(read.getActualLocationOfNode(), expires);
node.setProperties(read.getPropertiesByName());
node.setChildren(read.getChildren());
@@ -5476,17 +5467,11 @@
} else if (request instanceof ReadAllChildrenRequest) {
ReadAllChildrenRequest read = (ReadAllChildrenRequest)request;
DateTime expires = computeExpirationTime(read);
- if (read.getActualLocationOfNode() == null) {
- int x = 0;
- }
getOrCreateNode(read.getActualLocationOfNode(),
expires).setChildren(read.getChildren());
} else if (request instanceof ReadBranchRequest) {
ReadBranchRequest read = (ReadBranchRequest)request;
DateTime expires = computeExpirationTime(read);
for (Location location : read) {
- if (location == null) {
- int x = 0;
- }
BatchResultsNode node = getOrCreateNode(location, expires);
node.setProperties(read.getPropertiesFor(location));
node.setChildren(read.getChildren(location));
@@ -5512,9 +5497,6 @@
} else if (request instanceof ReadNodeRequest) {
ReadNodeRequest read = (ReadNodeRequest)request;
DateTime expires = computeExpirationTime(read);
- if (read.getActualLocationOfNode() == null) {
- int x = 0;
- }
BatchResultsNode node = getOrCreateNode(read.getActualLocationOfNode(),
expires);
node.setProperties(read.getPropertiesByName());
node.setChildren(read.getChildren());
@@ -5555,9 +5537,6 @@
DateTime expirationTime ) {
BatchResultsNode node = nodes.get(location);
if (node == null) {
- if (location == null) {
- int x = 0;
- }
node = new BatchResultsNode(location, expirationTime);
assert location != null;
assert location.getPath() != null;
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/federation/FederatedRepositoryConnection.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/federation/FederatedRepositoryConnection.java 2009-07-21
03:14:59 UTC (rev 1118)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/federation/FederatedRepositoryConnection.java 2009-07-21
03:17:04 UTC (rev 1119)
@@ -226,6 +226,12 @@
} finally {
join.close();
}
+ if (request instanceof CompositeRequest) {
+ // The composite request will not have any errors set, since the
fork/join approach puts the
+ // contained requests into a separate CompositeRequest object for
processing.
+ // So, look at the requests for any errors
+ ((CompositeRequest)request).checkForErrors();
+ }
} catch (InterruptedException e) {
abort = true;
request.setError(e);
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/federation/FederatedRequest.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/federation/FederatedRequest.java 2009-07-21
03:14:59 UTC (rev 1118)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/federation/FederatedRequest.java 2009-07-21
03:17:04 UTC (rev 1119)
@@ -33,6 +33,8 @@
*/
@NotThreadSafe
class FederatedRequest {
+ static final CountDownLatch CLOSED_LATCH = new CountDownLatch(0);
+
private final Request original;
private CountDownLatch forkLatch;
private int incompleteCount;
@@ -51,6 +53,7 @@
boolean isComplete,
Projection projection,
Projection secondProjection ) {
+ assert forkLatch == null;
if (!isComplete) ++incompleteCount;
if (first == null) {
if (isSameLocationAsOriginal) {
@@ -72,8 +75,8 @@
}
public void freeze() {
- if (incompleteCount > 0 && forkLatch == null) {
- forkLatch = new CountDownLatch(incompleteCount);
+ if (forkLatch == null) {
+ forkLatch = incompleteCount > 0 ? new CountDownLatch(incompleteCount) :
CLOSED_LATCH;
}
}
@@ -86,6 +89,7 @@
}
public CountDownLatch getLatch() {
+ freeze();
return forkLatch;
}
@@ -102,7 +106,6 @@
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("Federated request:
").append(original).append("\n");
- sb.append(" projected to: ").append("\n");
ProjectedRequest projected = first;
while (projected != null) {
sb.append(" - ").append(projected).append("\n");
@@ -128,19 +131,19 @@
this.projection2 = secondProjection;
}
- public Projection getProjection() {
+ public final Projection getProjection() {
return projection;
}
- public Projection getSecondProjection() {
+ public final Projection getSecondProjection() {
return projection2;
}
- public Request getRequest() {
+ public final Request getRequest() {
return request;
}
- public boolean isComplete() {
+ public final boolean isComplete() {
return isComplete;
}
@@ -148,11 +151,11 @@
return false;
}
- public ProjectedRequest next() {
+ public final ProjectedRequest next() {
return next;
}
- public boolean hasNext() {
+ public final boolean hasNext() {
return next != null;
}
@@ -173,6 +176,30 @@
Projection projection ) {
return addNext(request, isComplete, projection, null);
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("Projects to: ");
+ sb.append(request);
+ if (projection != null) {
+ sb.append(" using ");
+ sb.append(projection);
+ if (projection2 != null) {
+ sb.append(" and ");
+ sb.append(projection2);
+ }
+ }
+ if (isComplete) {
+ sb.append(" (complete)");
+ }
+ return sb.toString();
+ }
}
class MirrorRequest extends ProjectedRequest {
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/federation/ForkRequestProcessor.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/federation/ForkRequestProcessor.java 2009-07-21
03:14:59 UTC (rev 1118)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/federation/ForkRequestProcessor.java 2009-07-21
03:17:04 UTC (rev 1119)
@@ -117,58 +117,6 @@
}
/**
- * A pseudo Request that allows addition of a request that, when processed, will
decrement a latch. Since the latch is
- * supplied by the submitter, this is useful when the submitter wishes to block until
a particular request is processed. The
- * submitter merely creates a {@link CountDownLatch}, submits their real request
wrapped by a BlockedRequest, and calls
- * {@link CountDownLatch#await()} on the latch. When <code>await()</code>
returns, the request has been completed.
- *
- * @see ForkRequestProcessor#submit(Request, String, CountDownLatch)
- * @see ForkRequestProcessor#submitAndAwait(Request, String)
- */
- protected static class BlockedRequest extends Request {
- private static final long serialVersionUID = 1L;
- protected final Request original;
- protected final transient CountDownLatch latch;
-
- protected BlockedRequest( Request original,
- CountDownLatch latch ) {
- this.original = original;
- this.latch = latch;
- }
-
- @Override
- public boolean isReadOnly() {
- return original.isReadOnly();
- }
-
- @Override
- public boolean isCancelled() {
- return original.isCancelled();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.request.Request#setError(java.lang.Throwable)
- */
- @Override
- public void setError( Throwable error ) {
- original.setError(error);
- if (this.latch != null) this.latch.countDown();
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.jboss.dna.graph.request.Request#hasError()
- */
- @Override
- public boolean hasError() {
- return original.hasError();
- }
- }
-
- /**
* Represents the channel for a specific source into which this processor submits the
requests for that source. To use, create
* a Channel, {@link Channel#start(ExecutorService, ExecutionContext,
RepositoryConnectionFactory) start it}, and then
* {@link Channel#add(Request) add} requests (optionally with a {@link
Channel#add(Request, CountDownLatch) latch} or via a
@@ -281,15 +229,9 @@
protected Iterator<Request> createIterator() {
final BlockingQueue<Request> queue = this.queue;
return new Iterator<Request>() {
- private BlockedRequest previousBlocked;
private Request next;
public boolean hasNext() {
- // If the previous request was a blocked request, then we need to
decrement its latch ...
- if (previousBlocked != null && previousBlocked.latch != null)
{
- previousBlocked.latch.countDown();
- }
-
// If next still has a request, then 'hasNext()' has been
called multiple times in a row
if (next != null) return true;
@@ -331,19 +273,12 @@
}
}
}
- // If this request is a blocked request, we need to return the
wrapped request and record the blocked request
- if (next instanceof BlockedRequest) {
- previousBlocked = (BlockedRequest)next;
- next = null;
- return previousBlocked.original;
+ if (next == null) {
+ throw new NoSuchElementException();
}
- previousBlocked = null;
- if (next != null) {
- Request result = next;
- next = null;
- return result;
- }
- throw new NoSuchElementException();
+ Request result = next;
+ next = null;
+ return result;
}
public void remove() {
@@ -424,7 +359,8 @@
assert latch != null;
// Submit the request for processing ...
this.allRequests.add(request);
- this.queue.add(new BlockedRequest(request, latch));
+ request.setLatchForFreezing(latch);
+ this.queue.add(request);
return latch;
}
@@ -707,12 +643,13 @@
ProjectedRequest projected = request.getFirstProjectedRequest();
while (projected != null) {
if (!projected.isComplete()) {
+ // Submit to the appropriate source channel for execution ...
submit(projected.getRequest(),
projected.getProjection().getSourceName(), request.getLatch());
}
projected = projected.next();
}
}
- // Record this federated request ...
+ // Record this federated request, ready for the join processor ...
this.federatedRequestQueue.add(request);
}
@@ -723,7 +660,7 @@
*/
@Override
protected void completeRequest( Request request ) {
- // Do nothing here, as this is the federated request
+ // Do nothing here, since this is the federated request which will be frozen in
the join processor
}
/**
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/federation/JoinRequestProcessor.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/federation/JoinRequestProcessor.java 2009-07-21
03:14:59 UTC (rev 1118)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/federation/JoinRequestProcessor.java 2009-07-21
03:17:04 UTC (rev 1119)
@@ -47,7 +47,6 @@
import org.jboss.dna.graph.request.CacheableRequest;
import org.jboss.dna.graph.request.CloneBranchRequest;
import org.jboss.dna.graph.request.CloneWorkspaceRequest;
-import org.jboss.dna.graph.request.CompositeRequest;
import org.jboss.dna.graph.request.CopyBranchRequest;
import org.jboss.dna.graph.request.CreateNodeRequest;
import org.jboss.dna.graph.request.CreateWorkspaceRequest;
@@ -107,19 +106,13 @@
*
* @param completedFederatedRequests the collection of {@link FederatedRequest} whose
projected requests have already been
* processed; may not be null
- * @return the exception that occurred while processing these requests (analogous to
{@link CompositeRequest#getError()} where
- * the composite's requests are these errors), or null if there was none
* @see FederatedRepositoryConnection#execute(ExecutionContext,
org.jboss.dna.graph.request.Request)
*/
- public Throwable process( final Iterable<FederatedRequest>
completedFederatedRequests ) {
+ public void process( final Iterable<FederatedRequest>
completedFederatedRequests ) {
for (FederatedRequest federatedRequest : completedFederatedRequests) {
// No need to await for the forked request, since it will be done
process(federatedRequest);
- if (federatedRequest.original().hasError()) {
- return federatedRequest.original().getError();
- }
}
- return null;
}
/**
@@ -137,6 +130,7 @@
for (;;) {
forked = federatedRequestQueue.take();
if (forked instanceof NoMoreFederatedRequests) return;
+ // Block until this forked request has completed
forked.await();
// Now process ...
process(forked);
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/federation/NoMoreFederatedRequests.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/federation/NoMoreFederatedRequests.java 2009-07-21
03:14:59 UTC (rev 1118)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/federation/NoMoreFederatedRequests.java 2009-07-21
03:17:04 UTC (rev 1119)
@@ -35,6 +35,7 @@
*/
NoMoreFederatedRequests() {
super(null);
+ freeze();
}
}
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/federation/Projection.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/federation/Projection.java 2009-07-21
03:14:59 UTC (rev 1118)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/federation/Projection.java 2009-07-21
03:17:04 UTC (rev 1119)
@@ -475,9 +475,9 @@
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
+ sb.append(this.workspaceName);
+ sb.append('@');
sb.append(this.sourceName);
- sb.append("::");
- sb.append(this.workspaceName);
sb.append(" { ");
boolean first = true;
for (Rule rule : this.getRules()) {
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/Request.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/Request.java 2009-07-21
03:14:59 UTC (rev 1118)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/Request.java 2009-07-21
03:17:04 UTC (rev 1119)
@@ -24,6 +24,7 @@
package org.jboss.dna.graph.request;
import java.io.Serializable;
+import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;
import org.jboss.dna.graph.GraphI18n;
import org.jboss.dna.graph.connector.RepositoryConnection;
@@ -40,10 +41,16 @@
private Throwable error;
private AtomicBoolean cancelled = new AtomicBoolean(false);
private final AtomicBoolean frozen = new AtomicBoolean(false);
+ private transient CountDownLatch freezingLatch = null;
protected Request() {
}
+ public void setLatchForFreezing( CountDownLatch latch ) {
+ checkNotFrozen();
+ this.freezingLatch = latch;
+ }
+
/**
* Set the error for this request.
*
@@ -148,7 +155,11 @@
* Freeze this request to prevent any further modification. This method does nothing
if the request is already frozen.
*/
public void freeze() {
- frozen.set(true);
+ if (frozen.compareAndSet(false, true)) {
+ // Was not already frozen, so decrement the latch (atomically)
+ CountDownLatch latch = this.freezingLatch;
+ if (latch != null) latch.countDown();
+ }
}
/**
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/processor/RequestProcessor.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/processor/RequestProcessor.java 2009-07-21
03:14:59 UTC (rev 1118)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/processor/RequestProcessor.java 2009-07-21
03:17:04 UTC (rev 1119)
@@ -262,6 +262,8 @@
} else {
processUnknownRequest(request);
}
+ } catch (RuntimeException e) {
+ request.setError(e);
} finally {
completeRequest(request);
}
@@ -710,9 +712,6 @@
request.setError(update.getError());
}
// Set the actual location ...
- if (update.getActualLocationOfNode() == null) {
- int x = 0;
- }
request.setActualLocationOfNode(update.getActualLocationOfNode());
}
Modified:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/federation/AbstractFederatedRepositorySourceIntegrationTest.java
===================================================================
---
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/federation/AbstractFederatedRepositorySourceIntegrationTest.java 2009-07-21
03:14:59 UTC (rev 1118)
+++
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/federation/AbstractFederatedRepositorySourceIntegrationTest.java 2009-07-21
03:17:04 UTC (rev 1119)
@@ -32,6 +32,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.UUID;
import org.jboss.dna.common.statistic.Stopwatch;
import org.jboss.dna.common.util.CheckArg;
import org.jboss.dna.graph.DnaLexicon;
@@ -289,6 +290,12 @@
.getLastSegment()
.getName()));
}
+
+ // The UUID should match ...
+ UUID fedUuid = fedNode.getLocation().getUuid();
+ UUID sourceUuid = sourceNode.getLocation().getUuid();
+ assertThat(fedUuid, is(sourceUuid));
+
// The children should match ...
List<Path.Segment> fedChildren = new ArrayList<Path.Segment>();
List<Path.Segment> sourceChildren = new ArrayList<Path.Segment>();
Modified:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/federation/FederatedRepositorySourceUsingMirrorAndBranchProjectionsTest.java
===================================================================
---
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/federation/FederatedRepositorySourceUsingMirrorAndBranchProjectionsTest.java 2009-07-21
03:14:59 UTC (rev 1118)
+++
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/federation/FederatedRepositorySourceUsingMirrorAndBranchProjectionsTest.java 2009-07-21
03:17:04 UTC (rev 1119)
@@ -24,9 +24,12 @@
package org.jboss.dna.graph.connector.federation;
import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
import static org.junit.Assert.assertThat;
import java.util.Set;
import org.jboss.dna.graph.Graph;
+import org.jboss.dna.graph.Location;
+import org.jboss.dna.graph.Node;
import org.junit.Before;
import org.junit.Test;
@@ -105,6 +108,44 @@
}
@Test
+ public void shouldReturnRootNodeInMirrorProjection() {
+ // Get the root node of the mirror projection using the actual graph ...
+ Graph mirrorGraph = graphFor(mirrorSourceName, mirrorWorkspaceName);
+ Node mirrorRoot = mirrorGraph.getNodeAt("/");
+ Location mirrorRootLocation = mirrorRoot.getLocation();
+ assertThat(mirrorRootLocation.hasIdProperties(), is(true));
+ assertThat(mirrorRootLocation.getUuid(), is(notNullValue()));
+
+ // Get the same node through the federation source ...
+ Node fedRoot = federated.getNodeAt("/");
+ Location fedRootLocation = fedRoot.getLocation();
+ assertThat(fedRootLocation.hasIdProperties(), is(true));
+ assertThat(fedRootLocation.getUuid(), is(notNullValue()));
+
+ // The UUIDs of the nodes must be the same ...
+ assertThat(fedRootLocation.getUuid(), is(mirrorRootLocation.getUuid()));
+ }
+
+ @Test
+ public void shouldReturnRootNodeInBranchProjection() {
+ // Get the top node of the branch projection using the actual graph ...
+ Graph branchGraph = graphFor(branchSourceName, branchWorkspaceName);
+ Node branchNode = branchGraph.getNodeAt("/Aircraft");
+ Location branchNodeLocation = branchNode.getLocation();
+ assertThat(branchNodeLocation.hasIdProperties(), is(true));
+ assertThat(branchNodeLocation.getUuid(), is(notNullValue()));
+
+ // Get the same node through the federation source ...
+ Node fedNode = federated.getNodeAt("/Aircraft");
+ Location fedNodeLocation = fedNode.getLocation();
+ assertThat(fedNodeLocation.hasIdProperties(), is(true));
+ assertThat(fedNodeLocation.getUuid(), is(notNullValue()));
+
+ // The UUIDs of the nodes must be the same ...
+ assertThat(fedNodeLocation.getUuid(), is(branchNodeLocation.getUuid()));
+ }
+
+ @Test
public void shouldFederateRootNodeFromMirrorAndBranch() {
// The root of the federated repository should have the content from the mirror
but should have
// an additional child that is the root of the branch ...
Modified:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/federation/FederatedRequestTest.java
===================================================================
---
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/federation/FederatedRequestTest.java 2009-07-21
03:14:59 UTC (rev 1118)
+++
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/federation/FederatedRequestTest.java 2009-07-21
03:17:04 UTC (rev 1119)
@@ -103,10 +103,9 @@
@Test
public void shouldAddMultipleProjectedRequestsAddedInMethodChain() {
- request.add(projectedRequest[0], false, false,
projection[0]).add(projectedRequest[1], false, true,
projection[1]).add(projectedRequest[2],
-
false,
-
false,
-
projection[2]);
+ request.add(projectedRequest[0], false, false, projection[0])
+ .add(projectedRequest[1], false, true, projection[1])
+ .add(projectedRequest[2], false, false, projection[2]);
assertThat(request.hasIncompleteRequests(), is(true));
ProjectedRequest first = request.getFirstProjectedRequest();
@@ -134,7 +133,6 @@
@Test
public void
shouldCreateCountDownLatchUponFreezeIfNumberOfIncompleteProjectedRequestsIsNonZero() {
request.add(projectedRequest[0], false, false, projection[0]);
- assertThat(request.getLatch(), is(nullValue()));
request.freeze();
assertThat(request.getLatch(), is(notNullValue()));
assertThat(request.getLatch().getCount(), is(1L));
@@ -142,11 +140,10 @@
}
@Test
- public void
shouldNotCreateCountDownLatchUponFreezeIfNumberOfIncompleteProjectedRequestsIsZero() {
+ public void
shouldUseClosedLatchUponFreezeIfNumberOfIncompleteProjectedRequestsIsZero() {
request.add(projectedRequest[0], false, true, projection[0]);
- assertThat(request.getLatch(), is(nullValue()));
request.freeze();
- assertThat(request.getLatch(), is(nullValue()));
+ assertThat(request.getLatch(), is(sameInstance(FederatedRequest.CLOSED_LATCH)));
assertThat(request.hasIncompleteRequests(), is(false));
}
Modified:
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/federation/ForkRequestProcessorChannelTest.java
===================================================================
---
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/federation/ForkRequestProcessorChannelTest.java 2009-07-21
03:14:59 UTC (rev 1118)
+++
trunk/dna-graph/src/test/java/org/jboss/dna/graph/connector/federation/ForkRequestProcessorChannelTest.java 2009-07-21
03:17:04 UTC (rev 1119)
@@ -27,7 +27,6 @@
import static org.hamcrest.core.IsSame.sameInstance;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
-import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.stub;
import java.util.ArrayList;
import java.util.Iterator;
@@ -69,10 +68,10 @@
sourceName = "SourceA";
channel = new ForkRequestProcessor.Channel(sourceName);
requests = new ArrayList<Request>();
- requests.add(mock(Request.class));
- requests.add(mock(Request.class));
- requests.add(mock(Request.class));
- requests.add(mock(Request.class));
+ requests.add(new MockRequest());
+ requests.add(new MockRequest());
+ requests.add(new MockRequest());
+ requests.add(new MockRequest());
// Create the mock connection ...
executedRequests = new LinkedList<Request>(); // this is where requests
submitted to the connection will go
@@ -85,6 +84,15 @@
executor = Executors.newSingleThreadExecutor();
}
+ protected static class MockRequest extends Request {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public boolean isReadOnly() {
+ return false;
+ }
+ }
+
@Test
public void shouldCreateEmptyIteratorIfDoneCalledBeforeObtainingIterator() {
channel.done();