Created
November 21, 2013 15:12
-
-
Save andrii0lomakin/7583253 to your computer and use it in GitHub Desktop.
Test fix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.orientechnologies.orient.graph.blueprints; | |
import com.orientechnologies.orient.core.db.record.OIdentifiable; | |
import com.orientechnologies.orient.core.id.ORID; | |
import org.testng.annotations.Test; | |
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentPool; | |
import com.tinkerpop.blueprints.Edge; | |
import com.tinkerpop.blueprints.Vertex; | |
import com.tinkerpop.blueprints.impls.orient.OrientGraph; | |
import static org.testng.Assert.assertTrue; | |
/** | |
* @author Andrey Lomakin <a href="mailto:[email protected]">Andrey Lomakin</a> | |
* @since 11/21/13 | |
*/ | |
@Test | |
public class PoolAndAddEdgeTest { | |
public void testAddEdge() { | |
// Database properties | |
String url = "remote:localhost/e-soa_graph-test"; | |
String user = "admin"; | |
String password = "admin"; | |
// Get the pool | |
ODatabaseDocumentPool aPool = new ODatabaseDocumentPool(url, user, password); | |
// Create vertex | |
Vertex v1 = this.createVertex(aPool, "Jack"); | |
Vertex v2 = this.createVertex(aPool, "Nick"); | |
// Create edge | |
Edge e1 = this.createEdge(aPool, (ORID)v1.getId(), (ORID)v2.getId(), "friend"); | |
// This line is not reached | |
assertTrue(e1 != null); | |
} | |
private Vertex createVertex(ODatabaseDocumentPool aPool, String aName) { | |
Vertex aVertex = null; | |
// Get the graph instance | |
OrientGraph graph = new OrientGraph(aPool.acquire()); | |
try { | |
// Add the vertex | |
aVertex = graph.addVertex(null); | |
aVertex.setProperty("name", aName); | |
} finally { | |
graph.shutdown(); | |
} | |
return aVertex; | |
} | |
private Edge createEdge(ODatabaseDocumentPool aPool, ORID v_out, ORID v_in, String label) { | |
Edge anEdge = null; | |
// Get the graph instance | |
OrientGraph graph = new OrientGraph(aPool.acquire()); | |
try { | |
// Add the edge | |
// The line below throws an exception : | |
// java.lang.IllegalStateException: Database is closed | |
// at com.tinkerpop.blueprints.impls.orient.OrientBaseGraph.openOrCreate(OrientBaseGraph.java:870) | |
// at com.tinkerpop.blueprints.impls.orient.OrientBaseGraph.getContext(OrientBaseGraph.java:863) | |
// at com.tinkerpop.blueprints.impls.orient.OrientTransactionalGraph.autoStartTransaction(OrientTransactionalGraph.java:93) | |
// at com.tinkerpop.blueprints.impls.orient.OrientVertex.addEdge(OrientVertex.java:223) | |
// at com.tinkerpop.blueprints.impls.orient.OrientBaseGraph.addEdge(OrientBaseGraph.java:397) | |
// | |
anEdge = graph.addEdge(null, graph.getVertex(v_out), graph.getVertex(v_in), label); // This code throws an exception | |
} finally { | |
graph.shutdown(); | |
} | |
return anEdge; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment