Skip to content

Commit

Permalink
Merge branch 'master' of github.com:tinkerpop/blueprints into SailGra…
Browse files Browse the repository at this point in the history
…ph.loadRDF
  • Loading branch information
juharris committed May 26, 2014
2 parents 8a1fffc + d5a20f9 commit 5373093
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 57 deletions.
4 changes: 2 additions & 2 deletions blueprints-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
<version>1.3.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-json-org</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.2.3</version>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ public static void inputGraph(final Graph inputGraph, final InputStream inputStr

} catch (IOException e) {
throw new IOException("GML malformed line number " + st.lineno() + ": ", e);
} finally {
r.close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import java.util.LinkedList;

/**
* A stateful connection to a BlueprintsSail RDF store interface.
* A stateful connection to a GraphSail RDF store
*
* @author Joshua Shinavier (http://fortytwo.net)
*/
Expand Down Expand Up @@ -260,7 +260,9 @@ private void addStatementInternal(final boolean inferred,
String c = null == context ? GraphSail.NULL_CONTEXT_NATIVE : store.resourceToNative(context);

Vertex out = getOrCreateVertex(subject);
Vertex in = getOrCreateVertex(object);
// object-level identity of subject and object facilitates creation of self-loop edges in some Graph implementations
Vertex in = subject.equals(object) ? out : getOrCreateVertex(object);

Edge edge = store.graph.addEdge(null, out, in, predicate.stringValue());
if (inferred) {
//System.out.println("inferred!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,23 +148,26 @@ public void testGetEdges() {

public void testGetEdgesByLabel() {
Graph graph = graphTest.generateGraph();

if (graph.getFeatures().supportsEdgeIteration) {
Vertex v1 = graph.addVertex(null);
Vertex v2 = graph.addVertex(null);
Vertex v3 = graph.addVertex(null);
Edge e1 = graph.addEdge(null, v1, v2, graphTest.convertLabel("test1"));
Edge e2 = graph.addEdge(null, v2, v3, graphTest.convertLabel("test2"));
Edge e3 = graph.addEdge(null, v3, v1, graphTest.convertLabel("test3"));
assertEquals(e1, getOnlyElement(graph.query().has("label", graphTest.convertLabel("test1")).edges()));
assertEquals(e2, getOnlyElement(graph.query().has("label", graphTest.convertLabel("test2")).edges()));
assertEquals(e3, getOnlyElement(graph.query().has("label", graphTest.convertLabel("test3")).edges()));
assertEquals(e1, getOnlyElement(graph.getEdges("label", graphTest.convertLabel("test1"))));
assertEquals(e2, getOnlyElement(graph.getEdges("label", graphTest.convertLabel("test2"))));
assertEquals(e3, getOnlyElement(graph.getEdges("label", graphTest.convertLabel("test3"))));
Vertex v1 = graph.addVertex(null);
Vertex v2 = graph.addVertex(null);
Vertex v3 = graph.addVertex(null);

Edge e1 = graph.addEdge(null, v1, v2, graphTest.convertLabel("test1"));
Edge e2 = graph.addEdge(null, v2, v3, graphTest.convertLabel("test2"));
Edge e3 = graph.addEdge(null, v3, v1, graphTest.convertLabel("test3"));

assertEquals(e1, getOnlyElement(graph.query().has("label", graphTest.convertLabel("test1")).edges()));
assertEquals(e2, getOnlyElement(graph.query().has("label", graphTest.convertLabel("test2")).edges()));
assertEquals(e3, getOnlyElement(graph.query().has("label", graphTest.convertLabel("test3")).edges()));

assertEquals(e1, getOnlyElement(graph.getEdges("label", graphTest.convertLabel("test1"))));
assertEquals(e2, getOnlyElement(graph.getEdges("label", graphTest.convertLabel("test2"))));
assertEquals(e3, getOnlyElement(graph.getEdges("label", graphTest.convertLabel("test3"))));
}

graph.shutdown();
}

public void testGetNonExistantEdges() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,55 +341,54 @@ public void testSimpleRemovingVerticesEdges() {
graph.shutdown();
}

public void testRemoveNonExistentVertexCausesException() throws Exception{
Graph g = graphTest.generateGraph();
public void testRemoveNonExistentVertexCausesException() throws Exception {
Graph graph = graphTest.generateGraph();

if (!g.getFeatures().isWrapper && !g.getClass().getSimpleName().equals("SailGraph")) {
Vertex v = g.addVertex(null);
if (g.getFeatures().supportsTransactions) {
((TransactionalGraph) g).commit();
if (!graph.getFeatures().isWrapper && !graph.getClass().getSimpleName().equals("SailGraph")) {
Vertex v = graph.addVertex(null);
if (graph.getFeatures().supportsTransactions) {
((TransactionalGraph) graph).commit();
}

boolean exceptionTossed = false;
g.removeVertex(v);
graph.removeVertex(v);
try {
// second call to an already removed vertex should throw an exception
g.removeVertex(v);
graph.removeVertex(v);
} catch (IllegalStateException re) {
exceptionTossed = true;

// rollback the change so the delete can be tried below
if (g.getFeatures().supportsTransactions) {
((TransactionalGraph) g).rollback();
if (graph.getFeatures().supportsTransactions) {
((TransactionalGraph) graph).rollback();
}
}

assertTrue(exceptionTossed);

v = g.addVertex(null);
if (g.getFeatures().supportsTransactions) {
((TransactionalGraph) g).commit();
v = graph.addVertex(null);
if (graph.getFeatures().supportsTransactions) {
((TransactionalGraph) graph).commit();
}
exceptionTossed = false;

// this time commit the tx and then try to remove. both should show illegal state.
g.removeVertex(v);
if (g.getFeatures().supportsTransactions) {
((TransactionalGraph) g).commit();
graph.removeVertex(v);
if (graph.getFeatures().supportsTransactions) {
((TransactionalGraph) graph).commit();
}

try {
// second call to an already removed vertex should throw an exception
g.removeVertex(v);
graph.removeVertex(v);
} catch (IllegalStateException re) {
exceptionTossed = true;
}

assertTrue(exceptionTossed);
}

g.shutdown();

graph.shutdown();
}

public void testRemovingEdges() {
Expand Down Expand Up @@ -427,7 +426,6 @@ public void testRemovingEdges() {
}
printPerformance(graph.toString(), edgeCount, "edges deleted (with size check on each delete)", this.stopWatch());
graph.shutdown();

}

public void testRemovingVertices() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public void testGetIndexedKeysCannotAcceptNullArgumentForClass() {
graph.getIndexedKeys(null);
} catch (IllegalArgumentException iae) {
return;
} finally {
graph.shutdown();
}

fail();
Expand All @@ -31,6 +33,8 @@ public void testCreateKeyIndexCannotAcceptNullArgumentForClass() {
graph.createKeyIndex("test", null);
} catch (IllegalArgumentException iae) {
return;
} finally {
graph.shutdown();
}

fail();
Expand All @@ -42,6 +46,8 @@ public void testRemoveKeyIndexCannotAcceptNullArgumentForClass() {
graph.dropKeyIndex("test", null);
} catch (IllegalArgumentException iae) {
return;
} finally {
graph.shutdown();
}

fail();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public void testAutoStartTransaction() {
vertexCount(graph, 1);
assertEquals(v1.getId(), graph.getVertex(v1.getId()).getId());
graph.shutdown();

}


Expand Down Expand Up @@ -662,28 +661,28 @@ public void testTransactionGraphHelperFireAndForget() {

// first fail the tx
new TransactionRetryHelper.Builder<Vertex>(graph).perform(new TransactionWork<Vertex>() {
@Override
public Vertex execute(final TransactionalGraph graph) throws Exception {
graph.addVertex(null);
throw new Exception("fail");
}
@Override
public Vertex execute(final TransactionalGraph graph) throws Exception {
graph.addVertex(null);
throw new Exception("fail");
}
}).build().fireAndForget();
vertexCount(graph, 0);

// this tx will work
List<Vertex> vin = new ArrayList<Vertex>();
TransactionRetryHelper<Vertex> trh = new TransactionRetryHelper.Builder<Vertex>(graph).perform(new TransactionWork<Vertex>() {
@Override
public Vertex execute(final TransactionalGraph graph) throws Exception{
public Vertex execute(final TransactionalGraph graph) throws Exception {
return graph.addVertex(null);
}
}).build();
vin.add(trh.fireAndForget());



vertexCount(graph, 1);
containsVertices(graph, vin);

graph.shutdown();
}

public void testTransactionGraphHelperOneAndDone() {
Expand All @@ -693,7 +692,7 @@ public void testTransactionGraphHelperOneAndDone() {
try {
new TransactionRetryHelper.Builder<Vertex>(graph).perform(new TransactionWork<Vertex>() {
@Override
public Vertex execute(final TransactionalGraph graph) throws Exception{
public Vertex execute(final TransactionalGraph graph) throws Exception {
graph.addVertex(null);
throw new Exception("fail");
}
Expand All @@ -708,13 +707,15 @@ public Vertex execute(final TransactionalGraph graph) throws Exception{
List<Vertex> vin = new ArrayList<Vertex>();
vin.add(new TransactionRetryHelper.Builder<Vertex>(graph).perform(new TransactionWork<Vertex>() {
@Override
public Vertex execute(final TransactionalGraph graph) throws Exception{
public Vertex execute(final TransactionalGraph graph) throws Exception {
return graph.addVertex(null);
}
}).build().oneAndDone());

vertexCount(graph, 1);
containsVertices(graph, vin);

graph.shutdown();
}

public void testTransactionGraphHelperExponentialBackoff() {
Expand Down Expand Up @@ -743,7 +744,7 @@ public Vertex execute(final TransactionalGraph graph) throws Exception {
List<Vertex> vin = new ArrayList<Vertex>();
vin.add(new TransactionRetryHelper.Builder<Vertex>(graph).perform(new TransactionWork<Vertex>() {
@Override
public Vertex execute(final TransactionalGraph graph) throws Exception{
public Vertex execute(final TransactionalGraph graph) throws Exception {
final int tryNumber = tries.incrementAndGet();
if (tryNumber == TransactionRetryStrategy.DelayedRetry.DEFAULT_TRIES - 2)
return graph.addVertex(null);
Expand All @@ -754,6 +755,8 @@ public Vertex execute(final TransactionalGraph graph) throws Exception{

vertexCount(graph, 1);
containsVertices(graph, vin);

graph.shutdown();
}

public void testTransactionGraphHelperExponentialBackoffWithExceptionChecks() {
Expand Down Expand Up @@ -785,7 +788,7 @@ public Vertex execute(final TransactionalGraph graph) throws Exception {
try {
new TransactionRetryHelper.Builder<Vertex>(graph).perform(new TransactionWork<Vertex>() {
@Override
public Vertex execute(final TransactionalGraph graph) throws Exception{
public Vertex execute(final TransactionalGraph graph) throws Exception {
final int tryNumber = setOfTries.incrementAndGet();
if (tryNumber == TransactionRetryStrategy.DelayedRetry.DEFAULT_TRIES - 2)
throw new Exception("fail");
Expand All @@ -805,7 +808,7 @@ public Vertex execute(final TransactionalGraph graph) throws Exception{
List<Vertex> vin = new ArrayList<Vertex>();
vin.add(new TransactionRetryHelper.Builder<Vertex>(graph).perform(new TransactionWork<Vertex>() {
@Override
public Vertex execute(final TransactionalGraph graph) throws Exception{
public Vertex execute(final TransactionalGraph graph) throws Exception {
final int tryNumber = tries.incrementAndGet();
if (tryNumber == TransactionRetryStrategy.DelayedRetry.DEFAULT_TRIES - 2)
return graph.addVertex(null);
Expand All @@ -816,6 +819,8 @@ public Vertex execute(final TransactionalGraph graph) throws Exception{

vertexCount(graph, 1);
containsVertices(graph, vin);

graph.shutdown();
}

public void testTransactionGraphHelperRetry() {
Expand Down Expand Up @@ -855,6 +860,59 @@ public Vertex execute(final TransactionalGraph graph) throws Exception {

vertexCount(graph, 1);
containsVertices(graph, vin);

graph.shutdown();
}

public void testRemovedElementsInvisibleInTransaction() {
TransactionalGraph graph = (TransactionalGraph) graphTest.generateGraph();
try {
boolean supportsVertexIteration = graph.getFeatures().supportsVertexIteration;
boolean supportsEdgeIteration = graph.getFeatures().supportsEdgeIteration;

if (supportsEdgeIteration) {
assertEquals(0, count(graph.getEdges()));
}
Vertex v1 = graph.addVertex(null);
Vertex v2 = graph.addVertex(null);
Edge e1 = graph.addEdge(null, v1, v2, graphTest.convertLabel("link"));
if (supportsVertexIteration) {
assertEquals(2, count(graph.getVertices()));
}
if (supportsEdgeIteration) {
assertEquals(1, count(graph.getEdges()));
}
graph.commit();
if (supportsVertexIteration) {
assertEquals(2, count(graph.getVertices()));
}
if (supportsEdgeIteration) {
assertEquals(1, count(graph.getEdges()));
}

graph.removeEdge(e1);
// We have removed an edge and not yet committed the change.
// However, the edge should appear to be removed until the end of the transaction.
if (supportsVertexIteration) {
assertEquals(2, count(graph.getVertices()));
}
if (supportsEdgeIteration) {
assertEquals(0, count(graph.getEdges()));
}
graph.removeVertex(v1);
if (supportsVertexIteration) {
assertEquals(1, count(graph.getVertices()));
}
graph.rollback();
if (supportsVertexIteration) {
assertEquals(2, count(graph.getVertices()));
}
if (supportsEdgeIteration) {
assertEquals(1, count(graph.getEdges()));
}
} finally {
graph.shutdown();
}
}

public void untestSimulateRexsterIntegrationTests() throws Exception {
Expand Down Expand Up @@ -1085,6 +1143,7 @@ public void run() {
Set<String> k = v.get().getPropertyKeys();
assertTrue(k.contains("name"));
assertEquals("stephen", v.get().getProperty("name"));
graph.shutdown();
}

public void untestTransactionIsolationWithSeparateThreads() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public void testStreamStaysOpen() throws IOException {
System.out.println("working");
System.setOut(oldStream);

assertTrue(outContent.toString().endsWith("working\n"));
assertTrue(outContent.toString().endsWith("working" + System.getProperty("line.separator")));
}

private int getIterableCount(Iterable<?> elements) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,6 @@ public void testStreamStaysOpen() throws IOException {
System.out.println("working");
System.setOut(oldStream);

assertTrue(outContent.toString().endsWith("working\n"));
assertTrue(outContent.toString().endsWith("working" + System.getProperty("line.separator")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,6 @@ public void streamStaysOpen() throws JSONException, IOException {
System.out.println("working");
System.setOut(oldStream);

Assert.assertTrue(outContent.toString().endsWith("working\n"));
Assert.assertTrue(outContent.toString().endsWith("working" + System.getProperty("line.separator")));
}
}

0 comments on commit 5373093

Please sign in to comment.