use of com.tinkerpop.blueprints.impls.orient.OrientGraphFactory in project orientdb by orientechnologies.
the class WWConflictAndNodeInDeadlockScenarioTest method onServerStarted.
@Override
protected void onServerStarted(ServerRun server) {
super.onServerStarted(server);
if (serverStarted++ == (2)) {
// startQueueMonitorTask();
startCountMonitorTask("Person");
// BACKUP LAST SERVER, RUN ASYNCHRONOUSLY
new Thread(new Runnable() {
@Override
public void run() {
try {
// CRASH LAST SERVER try {
executeWhen(new Callable<Boolean>() {
// CONDITION
@Override
public Boolean call() throws Exception {
return server3inDeadlock.get();
}
}, // ACTION
new Callable() {
@Override
public Object call() throws Exception {
banner("STARTING BACKUP SERVER " + (2));
OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server2/databases/" + getDatabaseName());
OrientGraphNoTx g = factory.getNoTx();
backupInProgress = true;
File file = null;
try {
file = File.createTempFile("orientdb_test_backup", ".zip");
if (file.exists())
Assert.assertTrue(file.delete());
g.getRawGraph().backup(new FileOutputStream(file), null, new Callable<Object>() {
@Override
public Object call() throws Exception {
// SIMULATE LONG BACKUP UNTIL SPECIFIED BY VARIABLE 'server3inDeadlock'
while (server3inDeadlock.get()) {
Thread.sleep(1000);
}
return null;
}
}, null, 9, 1000000);
} catch (IOException e) {
e.printStackTrace();
} finally {
banner("COMPLETED BACKUP SERVER " + (2));
backupInProgress = false;
g.shutdown();
if (file != null)
file.delete();
}
return null;
}
});
} catch (Exception e) {
e.printStackTrace();
fail("Error on execution flow");
}
}
}).start();
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraphFactory in project orientdb by orientechnologies.
the class ServerClusterAsyncGraphTest method executeTest.
@Override
protected void executeTest() throws Exception {
{
OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server0/databases/" + getDatabaseName());
OrientGraphNoTx g = factory.getNoTx();
try {
g.createVertexType("Post");
g.createVertexType("User");
g.createEdgeType("Own");
g.addVertex("class:User");
g.command(new OCommandSQL("insert into Post (content, timestamp) values('test', 1)")).execute();
} finally {
g.shutdown();
}
}
// CHECK VERTEX CREATION ON ALL THE SERVERS
for (int s = 0; s < SERVERS; ++s) {
OrientGraphFactory factory2 = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
OrientGraphNoTx g2 = factory2.getNoTx();
try {
Iterable<OrientVertex> result = g2.command(new OCommandSQL("select from Post")).execute();
Assert.assertTrue(result.iterator().hasNext());
Assert.assertNotNull(result.iterator().next());
} finally {
g2.shutdown();
}
}
{
OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server0/databases/" + getDatabaseName());
OrientGraphNoTx g = factory.getNoTx();
try {
g.command(new OCommandSQL("create edge Own from (select from User) to (select from Post)").onAsyncReplicationError(new OAsyncReplicationError() {
@Override
public ACTION onAsyncReplicationError(Throwable iException, int iRetry) {
return iException instanceof ONeedRetryException && iRetry <= 3 ? ACTION.RETRY : ACTION.IGNORE;
}
})).execute();
} finally {
g.shutdown();
}
}
Thread.sleep(1000);
// CHECK VERTEX CREATION ON ALL THE SERVERS
for (int s = 0; s < SERVERS; ++s) {
OrientGraphFactory factory2 = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
OrientGraphNoTx g2 = factory2.getNoTx();
try {
Iterable<OrientVertex> result = g2.command(new OCommandSQL("select from Own")).execute();
Assert.assertTrue(result.iterator().hasNext());
Assert.assertNotNull(result.iterator().next());
result = g2.command(new OCommandSQL("select from Post")).execute();
Assert.assertTrue(result.iterator().hasNext());
final OrientVertex v = result.iterator().next();
Assert.assertNotNull(v);
final Iterable<Edge> inEdges = v.getEdges(Direction.IN);
Assert.assertTrue(inEdges.iterator().hasNext());
Assert.assertNotNull(inEdges.iterator().next());
result = g2.command(new OCommandSQL("select from User")).execute();
Assert.assertTrue(result.iterator().hasNext());
final OrientVertex v2 = result.iterator().next();
Assert.assertNotNull(v2);
final Iterable<Edge> outEdges = v2.getEdges(Direction.OUT);
Assert.assertTrue(outEdges.iterator().hasNext());
Assert.assertNotNull(outEdges.iterator().next());
} finally {
g2.shutdown();
}
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraphFactory in project orientdb by orientechnologies.
the class GraphShutdownTest method graphCommitAfterShutdown.
@Test(expected = ODatabaseException.class)
public void graphCommitAfterShutdown() {
OrientGraphFactory factory = new OrientGraphFactory("memory:graphCommitAfterShutdown");
OrientGraph graph1 = factory.getTx();
OrientGraph graph2 = factory.getTx();
// in 2.2 this will not close the database because graph1 is still active in the pool
graph2.shutdown(true);
// this should fail
graph2.commit();
factory.drop();
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraphFactory in project orientdb by orientechnologies.
the class HAClusterStrategyTest method executeTest.
@Override
public void executeTest() throws Exception {
final OrientGraphFactory factory = new OrientGraphFactory(getDatabaseURL(serverInstance.get(0)));
final OrientGraphNoTx g = factory.getNoTx();
g.createVertexType("Test");
g.shutdown();
for (int i = 0; i < 10; ++i) {
// pressing 'return' 2 to 10 times should trigger the described behavior
Thread.sleep(100);
final OrientGraph graph = factory.getTx();
// should always be 'local', but eventually changes to 'round-robin'
System.out.println("StrategyClassName: " + graph.getVertexType("Test").getClusterSelection().getClass().getName());
System.out.println("ClusterSelectionStrategy for " + graph.getRawGraph().getURL() + ": " + graph.getVertexType("Test").getClusterSelection().getName());
Assert.assertEquals(graph.getVertexType("Test").getClusterSelection().getClass().getName(), OLocalClusterWrapperStrategy.class.getName());
Assert.assertEquals(graph.getVertexType("Test").getClusterSelection().getName(), "round-robin");
graph.addVertex("class:Test", "firstName", "Roger", "lastName", "Smith");
graph.getRawGraph().commit();
graph.shutdown();
}
factory.close();
factory.drop();
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraphFactory in project orientdb by orientechnologies.
the class OrientdbEdgeTest method testEdges.
@Test
public void testEdges() throws Exception {
OrientGraphFactory factory = getGraphFactory();
OrientBaseGraph g = factory.getNoTx();
try {
try {
g.createEdgeType("some-label");
} catch (OSchemaException ex) {
if (!ex.getMessage().contains("exists"))
throw (ex);
g.command(new OCommandSQL("delete edge some-label")).execute();
}
try {
g.createVertexType("some-v-label");
} catch (OSchemaException ex) {
if (!ex.getMessage().contains("exists"))
throw (ex);
g.command(new OCommandSQL("delete vertex some-v-label")).execute();
}
} finally {
g.shutdown();
}
OrientGraph t = factory.getTx();
try {
Vertex v1 = t.addVertex("class:some-v-label");
Vertex v2 = t.addVertex("class:some-v-label");
v1.setProperty("_id", "v1");
v2.setProperty("_id", "v2");
OrientEdge edge = t.addEdge(null, v1, v2, "some-label");
edge.setProperty("some", "thing");
t.commit();
t.shutdown();
t = factory.getTx();
assertEquals(2, t.countVertices("some-v-label"));
assertEquals(1, t.countEdges());
assertNotNull(t.getVertices("_id", "v1").iterator().next());
assertNotNull(t.getVertices("_id", "v2").iterator().next());
t.commit();
t.shutdown();
t = factory.getTx();
// works
assertEquals(1, t.getVertices("_id", "v1").iterator().next().query().labels("some-label").count());
// NoSuchElementException
assertNotNull(t.getVertices("_id", "v1").iterator().next().query().labels("some-label").edges().iterator().next());
t.commit();
} finally {
t.shutdown();
}
}
Aggregations