use of com.tinkerpop.blueprints.impls.orient.OrientGraph in project orientdb by orientechnologies.
the class TestReplicationVersionIncrementedByOne method dbClient1.
protected void dbClient1() {
OrientBaseGraph graph = new OrientGraph(getLocalURL());
try {
Vertex v1 = graph.addVertex("vertextype", (String) null);
graph.commit();
assertEquals(1, ((OrientVertex) v1).getRecord().getVersion());
Vertex v2 = graph.addVertex("vertextype", (String) null);
graph.commit();
assertEquals(1, ((OrientVertex) v2).getRecord().getVersion());
v1.addEdge("edgetype", v2);
graph.commit();
assertEquals(2, ((OrientVertex) v1).getRecord().getVersion());
assertEquals(2, ((OrientVertex) v2).getRecord().getVersion());
} catch (Throwable e) {
if (exceptionInThread == null) {
exceptionInThread = e;
}
} finally {
OLogManager.instance().info(this, "Shutting down");
graph.shutdown();
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraph in project orientdb by orientechnologies.
the class TestAsyncReplMode method dbClient1.
protected void dbClient1() {
sleep(1000);
synchronized (LOCK) {
OrientBaseGraph graph = new OrientGraph(getLocalURL());
try {
// Create 2 parent vertices.
OrientVertex parentV1 = graph.addVertex("vertextype1", (String) null);
graph.commit();
assertEquals(1, parentV1.getRecord().getVersion());
parentV1Id = parentV1.getId();
OrientVertex parentV2 = graph.addVertex("vertextype2", (String) null);
graph.commit();
assertEquals(1, parentV2.getRecord().getVersion());
parentV2Id = parentV2.getId();
// Create vertices.
for (int i = 0; i < NUM_OF_LOOP_ITERATIONS; i++) {
pause();
if (exceptionInThread != null)
break;
// sleep(500);
OrientVertex vertex = graph.addVertex("vertextype3", (String) null);
graph.commit();
assertEquals(1, vertex.getRecord().getVersion());
vertex.setProperty("num", i);
graph.commit();
assertEquals(2, vertex.getRecord().getVersion());
for (int attempt = 0; attempt < NUM_OF_RETRIES; attempt++) {
try {
parentV1.addEdge("edgetype1", vertex);
graph.commit();
assertNotNull(parentV1.getProperty("cnt"));
boolean edge1Exists = false;
for (Edge e : parentV1.getEdges(Direction.OUT, "edgetype1")) {
if (e.getVertex(Direction.IN).equals(vertex)) {
edge1Exists = true;
break;
}
}
assertTrue(edge1Exists);
boolean edge2Exists = false;
for (Edge e : vertex.getEdges(Direction.IN, "edgetype1")) {
if (e.getVertex(Direction.OUT).equals(parentV1)) {
edge2Exists = true;
break;
}
}
assertTrue(edge2Exists);
assertNotNull(vertex.getProperty("num"));
break;
} catch (OConcurrentModificationException c) {
System.out.println("***********ROLLBACK***************");
graph.rollback();
parentV1.reload();
vertex.reload();
}
}
for (int attempt = 0; attempt < NUM_OF_RETRIES; attempt++) {
try {
parentV2.addEdge("edgetype2", vertex);
graph.commit();
assertNotNull(parentV2.getProperty("cnt"));
boolean edge1Exists = false;
for (Edge e : parentV2.getEdges(Direction.OUT, "edgetype2")) {
if (e.getVertex(Direction.IN).equals(vertex)) {
edge1Exists = true;
break;
}
}
assertTrue(edge1Exists);
boolean edge2Exists = false;
for (Edge e : vertex.getEdges(Direction.IN, "edgetype2")) {
if (e.getVertex(Direction.OUT).equals(parentV2)) {
edge2Exists = true;
break;
}
}
assertTrue(edge2Exists);
assertNotNull(vertex.getProperty("num"));
break;
} catch (OConcurrentModificationException c) {
System.out.println("***********ROLLBACK***************");
graph.rollback();
parentV2.reload();
vertex.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.OrientGraph in project orientdb by orientechnologies.
the class TestAsyncReplMode2Servers method dbClient1.
protected void dbClient1() {
OGlobalConfiguration.LOG_CONSOLE_LEVEL.setValue("FINEST");
synchronized (LOCK) {
OrientBaseGraph graph = new OrientGraph(getRemoteURL());
try {
OrientVertex parentV1 = graph.addVertex("vertextype", (String) null);
graph.commit();
assertEquals(1, parentV1.getRecord().getVersion());
parentV1Id = parentV1.getId();
OrientVertex parentV2 = graph.addVertex("vertextype", (String) null);
graph.commit();
assertEquals(1, parentV2.getRecord().getVersion());
parentV2Id = parentV2.getId();
int countPropValue = 0;
for (int i = 0; i < NUM_OF_LOOP_ITERATIONS; i++) {
pause();
if (exceptionInThread != null)
break;
for (int attempt = 0; attempt < NUM_OF_RETRIES; attempt++) {
try {
parentV1.setProperty(CNT_PROP_NAME, ++countPropValue);
graph.commit();
System.out.println("Committing parentV1" + parentV1.getRecord() + "...");
break;
} catch (OConcurrentModificationException c) {
graph.rollback();
parentV1.reload();
}
}
for (int attempt = 0; attempt < NUM_OF_RETRIES; attempt++) {
try {
parentV2.setProperty(CNT_PROP_NAME, countPropValue);
graph.commit();
System.out.println("Committing parentV2" + parentV2.getRecord() + "...");
break;
} 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.OrientGraph in project orientdb by orientechnologies.
the class TestAsyncReplMode2Servers2OpsCommitConcurrent method dbClient1.
protected void dbClient1() {
// OGlobalConfiguration.LOG_CONSOLE_LEVEL.setValue("FINEST");
OrientBaseGraph graph = new OrientGraph(getLocalURL());
OrientVertex vertex1 = graph.addVertex("vertextype", (String) null);
graph.commit();
graph.shutdown();
vertex1Id = vertex1.getIdentity();
exec("client1");
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraph in project orientdb by orientechnologies.
the class TestAsyncReplMode2Servers2OpsCommitConcurrent method exec.
protected void exec(final String iClient) {
counter.countDown();
try {
counter.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
OrientBaseGraph graph = new OrientGraph(getLocalURL());
OrientVertex vertex1 = graph.getVertex(vertex1Id);
try {
int i = 0;
for (; i < TOTAL; ++i) {
for (int retry = 0; retry < 20; ++retry) {
try {
OrientVertex vertex2 = graph.addVertex("vertextype", (String) null);
vertex1.addEdge("edgetype", vertex2);
graph.commit();
System.out.println(iClient + " - successfully committed version: " + vertex1.getRecord().getVersion() + " retry: " + retry);
break;
} catch (ONeedRetryException e) {
System.out.println(iClient + " - caught conflict, reloading vertex. v=" + vertex1.getRecord().getVersion() + " retry: " + retry);
graph.rollback();
vertex1.reload();
}
}
}
// STATISTICALLY HERE AT LEAST ONE CONFLICT HAS BEEN RECEIVED
vertex1.reload();
Assert.assertTrue(vertex1.getRecord().getVersion() > TOTAL + 1);
Assert.assertEquals(TOTAL, i);
} catch (Throwable e) {
if (exceptionInThread == null)
exceptionInThread = e;
} finally {
System.out.println("Shutting down");
graph.shutdown();
}
}
Aggregations