use of com.tinkerpop.blueprints.impls.orient.OrientVertex in project orientdb by orientechnologies.
the class AbstractShardingScenarioTest method loadVertex.
protected OrientVertex loadVertex(OrientBaseGraph graph, String shardName, int serverId, int threadId, int i) {
List<OrientVertex> result = null;
try {
final String uniqueId = shardName + "-s" + serverId + "-t" + threadId + "-v" + i;
Iterable<Vertex> it = graph.command(new OCommandSQL("select from Client where name = '" + uniqueId + "'")).execute();
result = new LinkedList<OrientVertex>();
for (Vertex v : it) {
result.add((OrientVertex) v);
}
if (result.size() == 0)
fail("No record found with name = '" + uniqueId + "'!");
else if (result.size() > 1)
fail(result.size() + " records found with name = '" + uniqueId + "'!");
if (result.size() > 0)
return result.get(0);
} catch (Exception e) {
e.printStackTrace();
Assert.fail("Error in loadVertex(): " + e.toString());
}
return null;
}
use of com.tinkerpop.blueprints.impls.orient.OrientVertex 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.OrientVertex in project orientdb by orientechnologies.
the class TestAsyncReplMode method dbClient2.
protected void dbClient2() {
synchronized (LOCK) {
OrientBaseGraph graph = new OrientGraph(getRemoteURL());
OrientVertex parentV1 = null;
OrientVertex parentV2 = null;
int countPropValue = 0;
try {
for (int i = 0; i < NUM_OF_LOOP_ITERATIONS; i++) {
pause();
if (exceptionInThread != null)
break;
// Let's give it some time for asynchronous replication.
// sleep(500);
countPropValue++;
if (parentV1 == null) {
parentV1 = graph.getVertex(parentV1Id);
}
for (int attempt = 0; attempt < NUM_OF_RETRIES; attempt++) {
try {
parentV1.setProperty("cnt", countPropValue);
graph.commit();
} catch (OConcurrentModificationException c) {
graph.rollback();
parentV1.reload();
}
}
if (parentV2 == null) {
parentV2 = graph.getVertex(parentV2Id);
}
for (int attempt = 0; attempt < NUM_OF_RETRIES; attempt++) {
try {
parentV2.setProperty("cnt", countPropValue);
graph.commit();
} catch (OConcurrentModificationException c) {
graph.rollback();
parentV2.reload();
}
}
}
} catch (Throwable e) {
if (exceptionInThread == null) {
exceptionInThread = e;
}
} finally {
System.out.println("Shutting down");
graph.shutdown();
LOCK.notifyAll();
}
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientVertex in project orientdb by orientechnologies.
the class TestAsyncReplMode2Servers method dbClient2.
protected void dbClient2() {
sleep(1000);
synchronized (LOCK) {
OrientBaseGraph graph = new OrientGraph(getLocalURL2());
try {
OrientVertex parentV1 = graph.getVertex(parentV1Id);
assertEquals(1, parentV1.getRecord().getVersion());
OrientVertex parentV2 = graph.getVertex(parentV2Id);
assertEquals(1, parentV2.getRecord().getVersion());
int countPropValue = 0;
for (int i = 0; i < NUM_OF_LOOP_ITERATIONS; i++) {
pause();
if (exceptionInThread != null)
break;
sleep(500);
parentV1.reload();
parentV2.reload();
assertEquals("parentV1 (" + parentV1.getRecord() + ")", ++countPropValue, parentV1.getProperty(CNT_PROP_NAME));
assertEquals("parentV2 (" + parentV2.getRecord() + ")", countPropValue, parentV2.getProperty(CNT_PROP_NAME));
}
} catch (Throwable e) {
if (exceptionInThread == null) {
exceptionInThread = e;
}
} finally {
System.out.println("Shutting down");
graph.shutdown();
LOCK.notifyAll();
}
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientVertex in project orientdb by orientechnologies.
the class TestAsyncReplMode2ServersAddEdge method dbClient2.
protected void dbClient2() {
sleep(500);
synchronized (LOCK) {
OrientBaseGraph graph = new OrientGraph(getLocalURL2());
try {
sleep(500);
OrientVertex parentV1 = graph.getVertex(parentV1Id);
assertEquals(NUM_OF_LOOP_ITERATIONS + 1, parentV1.getRecord().getVersion());
} catch (Throwable e) {
if (exceptionInThread == null) {
exceptionInThread = e;
}
} finally {
System.out.println("Shutting down");
graph.shutdown();
LOCK.notifyAll();
}
}
}
Aggregations