use of com.tinkerpop.blueprints.impls.orient.OrientBaseGraph in project orientdb by orientechnologies.
the class DatabaseConflictStrategyAutoMergeTest method dbClient1.
private void dbClient1() {
sleep(500);
synchronized (LOCK) {
OrientBaseGraph graph = new OrientGraph(CLIENT_ORIENT_URL_MAIN);
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;
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());
parentV1.addEdge("edgetype1", vertex);
graph.commit();
assertNotNull(parentV1.getProperty("cnt"), "record " + parentV1.getIdentity() + " has no 'cnt' property");
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"));
parentV2.addEdge("edgetype2", vertex);
graph.commit();
assertNotNull(parentV2.getProperty("cnt"));
edge1Exists = false;
for (Edge e : parentV2.getEdges(Direction.OUT, "edgetype2")) {
if (e.getVertex(Direction.IN).equals(vertex)) {
edge1Exists = true;
break;
}
}
assertTrue(edge1Exists);
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"));
}
} catch (Throwable e) {
if (exceptionInThread == null) {
exceptionInThread = e;
}
} finally {
graph.shutdown();
LOCK.notifyAll();
}
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientBaseGraph in project orientdb by orientechnologies.
the class DatabaseConflictStrategyAutoMergeTest method testAutoMerge.
@Test
public void testAutoMerge() throws Throwable {
OrientGraphFactory factory = new OrientGraphFactory(CLIENT_ORIENT_URL_MAIN);
OrientBaseGraph graph = factory.getNoTx();
graph.setConflictStrategy(OAutoMergeRecordConflictStrategy.NAME);
graph.createVertexType("vertextype");
graph.createEdgeType("edgetype");
graph.shutdown();
factory.close();
Thread dbClient1 = new Thread() {
@Override
public void run() {
dbClient1();
}
};
dbClient1.start();
// Start the second DB client.
Thread dbClient2 = new Thread() {
@Override
public void run() {
dbClient2();
}
};
dbClient2.start();
dbClient1.join();
dbClient2.join();
if (exceptionInThread != null) {
throw exceptionInThread;
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientBaseGraph in project orientdb by orientechnologies.
the class ConcurrentDistributedUpdateTest method executeTest.
@Override
public void executeTest() throws Exception {
OrientBaseGraph orientGraph = new OrientGraphNoTx(getPlocalDatabaseURL(serverInstance.get(0)));
OClass clazz = orientGraph.getVertexType("Test");
if (clazz == null) {
log("Creating vertex type - " + "Test");
orientGraph.createVertexType("Test");
}
orientGraph.shutdown();
OrientBaseGraph graph = new OrientGraphNoTx(getPlocalDatabaseURL(serverInstance.get(0)));
for (int i = 0; i < 2; i++) {
Vertex vertex = graph.addVertex("class:Test");
vertex.setProperty("prop1", "v1-" + i);
vertex.setProperty("prop2", "v2-1");
vertex.setProperty("prop3", "v3-1");
graph.commit();
if ((i % 100) == 0) {
log("Created " + i + " nodes");
}
}
graph.shutdown();
executeMultipleTest();
}
use of com.tinkerpop.blueprints.impls.orient.OrientBaseGraph 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.OrientBaseGraph 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();
}
}
}
Aggregations