/** * {@inheritDoc} * * @see java.lang.Object#toString() */ @Override public String toString() { String workspaceName = this.workspaceName != null ? "'" + this.workspaceName + "'" : "default"; return "read " + printable(at()) + " (in " + workspaceName + " workspace)"; }
/** * {@inheritDoc} * * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals( Object obj ) { if (obj == this) return true; if (this.getClass().isInstance(obj)) { ReadNodeRequest that = (ReadNodeRequest)obj; if (!this.at().isSame(that.at())) return false; if (!this.inWorkspace().equals(that.inWorkspace())) return false; return true; } return false; }
protected void assertNextRequestReadNode( Location at ) { Request request = executedRequests.poll(); assertThat(request, is(instanceOf(ReadNodeRequest.class))); ReadNodeRequest read = (ReadNodeRequest)request; assertThat(read.at(), is(at)); }
@Override public void process( ReadNodeRequest request ) { PathWorkspace workspace = getWorkspace(request, request.inWorkspace()); if (workspace == null) return; PathNode node = getTargetNode(workspace, request, request.at()); if (node == null) { request.setError(new PathNotFoundException(request.at(), workspace.getLowestExistingPath(request.at().getPath()))); return; } // Get the names of the children ... for (Path.Segment childSegment : node.getChildSegments()) { request.addChild(Location.create(pathFactory.create(node.getPath(), childSegment))); } // Get the properties of the node ... request.addProperties(node.getProperties().values()); request.setActualLocationOfNode(Location.create(node.getPath(), node.getUuid())); setCacheableInfo(request); }
/** * {@inheritDoc} * * @see org.modeshape.graph.request.processor.RequestProcessor#process(org.modeshape.graph.request.ReadNodeRequest) */ @Override public void process( ReadNodeRequest request ) { WorkspaceType workspace = getWorkspace(request, request.inWorkspace()); NodeType node = getTargetNode(workspace, request, request.at()); if (node == null) { assert request.hasError(); return; } Location actualLocation = getActualLocation(workspace, request.at(), node); assert actualLocation != null; // Get the locations of the children ... List<Location> childLocations = txn.getChildrenLocations(workspace, node); request.addChildren(childLocations); // Get the properties of the node ... request.addProperty(propertyFactory.create(ModeShapeLexicon.UUID, node.getUuid())); request.addProperties(node.getProperties().values()); request.setActualLocationOfNode(actualLocation); setCacheableInfo(request); }
@Test public void shouldCreateValidRequestWithValidLocation() { request = new ReadNodeRequest(validPathLocation1, workspace1); assertThat(request.at(), is(sameInstance(validPathLocation1))); assertThat(request.inWorkspace(), is(sameInstance(workspace1))); assertThat(request.hasError(), is(false)); assertThat(request.getError(), is(nullValue())); }
@Test public void shouldSubmitSingleSourceRequestWhenProcessingSingleReadNodeRequest() throws Exception { // Stub the workspace to have a projection ... Location locationInFed = location("/a/x/y"); Location locationInSource = location("/x/y"); ProjectedNode projectedNode = new ProxyNode(projectionA, locationInSource, locationInFed, false); when(workspace.project(context, locationInFed, false)).thenReturn(projectedNode); ReadNodeRequest request = new ReadNodeRequest(locationInFed, workspaceName); processor.process(request); assertThat(request.hasError(), is(false)); // Check that the federated request has the right information ... FederatedRequest fedRequest = federatedRequests.poll(); ReadNodeRequest projectedRequest = (ReadNodeRequest)fedRequest.getFirstProjectedRequest().getRequest(); assertThat(projectedRequest.at(), is(locationInSource)); assertThat(fedRequest.getFirstProjectedRequest().hasNext(), is(false)); // Close the processor ... processor.close(); processor.await(); // Verify the source saw the expected read ... ReadNodeRequest sourceRequest = (ReadNodeRequest)connectionForSourceA.getProcessedRequests().poll(); assertThat(sourceRequest.at().getPath(), is(locationInSource.getPath())); assertThat(connectionForSourceB.getProcessedRequests().isEmpty(), is(true)); assertThat(connectionForSourceC.getProcessedRequests().isEmpty(), is(true)); }
if (request == null) return; ReadAllPropertiesRequest readProperties = new ReadAllPropertiesRequest(request.at(), request.inWorkspace()); process(readProperties); if (readProperties.hasError()) { ReadAllChildrenRequest readChildren = new ReadAllChildrenRequest(request.at(), request.inWorkspace()); process(readChildren); if (readChildren.hasError()) {
assertThat(projectedRequest.at(), is(locationInFed)); List<Location> expectedChildren = new ArrayList<Location>(); for (ProjectedNode child : children) {
Path federatedPath = request.at().getPath(); Map<Name, Property> properties = request.getPropertiesByName(); Map<Name, Integer> childSnsIndexes = new HashMap<Name, Integer>(); Location actualLocation = request.at(); int numMerged = 0; while (projectedRequest != null) { setPathNotFound(request, request.at(), federatedRequest.getFirstProjectedRequest()); } else { if (!actualLocation.hasPath()) {
public void process( ReadNodeRequest request ) { ProjectedNode projectedNode = project(request.at(), request.inWorkspace(), request, false);
@Test public void shouldCancelFederatedRequestIfOneOfSeveralMultipleReadNodeRequestIsCancelled() { // Create the original read node request ... final ReadNodeRequest original = new ReadNodeRequest(location("/a/b/c"), "workspaceM"); // Create a single federated request using the mirror projection... final FederatedRequest request = new FederatedRequest(original); // And "fork" the original request into the first source request ... final ReadNodeRequest projected1 = new ReadNodeRequest(location("/b/c"), "workspaceM"); projected1.setActualLocationOfNode(Location.create(projected1.at().getPath(), UUID.randomUUID())); projected1.addProperty(property("propA", "valueA")); projected1.addProperty(property("propB", "valueB")); projected1.addChild(child(projected1.getActualLocationOfNode(), "child1")); projected1.addChild(child(projected1.getActualLocationOfNode(), "child2")); request.add(projected1, false, false, projectionA); // And a second source request (that was cancelled)... final ReadNodeRequest projected2 = new ReadNodeRequest(location("/a/b/c"), "workspaceM"); projected2.cancel(); request.add(projected2, true, false, mirrorProjection); request.freeze(); request.getLatch().countDown(); request.getLatch().countDown(); joinQueue.add(request); // Add a terminating request and join the request... joinQueue.add(new NoMoreFederatedRequests()); joinProcessor.process(joinQueue); // Check the results of the original has the same results of the projected... assertThat(original.getProperties().isEmpty(), is(true)); assertThat(original.getChildren().isEmpty(), is(true)); assertThat(original.isCancelled(), is(true)); }
@Test public void shouldJoinSingleOffsetReadNodeRequest() { // Create the original read node request ... final ReadNodeRequest original = new ReadNodeRequest(location("/a/b/c"), "workspaceM"); // Create a single federated request using the mirror projection... final FederatedRequest request = new FederatedRequest(original); // And "fork" the original request by creating a mirror final ReadNodeRequest projected = new ReadNodeRequest(location("/b/c"), "workspaceM"); projected.setActualLocationOfNode(Location.create(projected.at().getPath(), UUID.randomUUID())); projected.addProperty(property("propA", "valueA")); projected.addProperty(property("propB", "valueB")); projected.addChild(child(projected.getActualLocationOfNode(), "child1")); projected.addChild(child(projected.getActualLocationOfNode(), "child2")); request.add(projected, false, false, projectionA); request.freeze(); request.getLatch().countDown(); joinQueue.add(request); // Add a terminating request and join the request... joinQueue.add(new NoMoreFederatedRequests()); joinProcessor.process(joinQueue); // Check the results of the original has the same results of the projected... assertThat(original.getPropertiesByName(), is(projected.getPropertiesByName())); assertThat(original.getActualLocationOfNode().getPath(), is(path("/a/b/c"))); assertThat(original.getChildren().get(0).getPath(), is(path("/a/b/c/child1"))); assertThat(original.getChildren().get(1).getPath(), is(path("/a/b/c/child2"))); }
@Test public void shouldJoinSingleMirroredReadNodeRequest() { // Create the original read node request ... final ReadNodeRequest original = new ReadNodeRequest(location("/a/b/c"), "workspaceM"); // Create a single federated request... final FederatedRequest request = new FederatedRequest(original); // And "fork" the original request ... final ReadNodeRequest projected = new ReadNodeRequest(location("/a/b/c"), "workspaceM"); projected.setActualLocationOfNode(Location.create(projected.at().getPath(), UUID.randomUUID())); projected.addProperty(property("propA", "valueA")); projected.addProperty(property("propB", "valueB")); projected.addChild(child(projected.getActualLocationOfNode(), "child1")); projected.addChild(child(projected.getActualLocationOfNode(), "child2")); request.add(projected, true, false, mirrorProjection); request.freeze(); request.getLatch().countDown(); joinQueue.add(request); // Add a terminating request and join the request... joinQueue.add(new NoMoreFederatedRequests()); joinProcessor.process(joinQueue); // Check the results of the original has the same results of the projected... assertThat(original.getChildren(), is(projected.getChildren())); assertThat(original.getPropertiesByName(), is(projected.getPropertiesByName())); assertThat(original.getActualLocationOfNode(), is(projected.getActualLocationOfNode())); }
projected1.setActualLocationOfNode(Location.create(projected1.at().getPath(), UUID.randomUUID())); projected1.addProperty(property("propA", "valueA")); projected1.addProperty(property("propB", "valueB")); projected2.setActualLocationOfNode(Location.create(projected2.at().getPath(), UUID.randomUUID())); projected2.addProperty(property("propC", "valueC")); projected2.addProperty(property("propD", "valueD"));