use of com.tinkerpop.blueprints.impls.orient.OrientVertex in project orientdb by orientechnologies.
the class TestRemoteDelete method dbClient1.
@Override
protected void dbClient1() {
OrientBaseGraph graph = new OrientGraph(getRemoteURL());
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());
Edge e = v1.addEdge("edgetype", v2);
graph.commit();
assertEquals(2, ((OrientVertex) v1).getRecord().getVersion());
assertEquals(2, ((OrientVertex) v2).getRecord().getVersion());
e.remove();
graph.commit();
assertFalse(((OrientVertex) v1).getVertices(Direction.OUT, "edgetype").iterator().hasNext());
assertFalse(((OrientVertex) v2).getVertices(Direction.IN, "edgetype").iterator().hasNext());
} catch (Throwable e) {
if (exceptionInThread == null) {
exceptionInThread = e;
}
} finally {
OLogManager.instance().info(this, "Shutting down");
graph.shutdown();
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientVertex 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.OrientVertex in project orientdb by orientechnologies.
the class AbstractShardingScenarioTest method checkAvailabilityOnShardsNoReplica.
// checks the consistency in the cluster after the writes in a no-replica sharding scenario
protected void checkAvailabilityOnShardsNoReplica(List<ServerRun> checkConsistencyOnServers, List<ServerRun> writerServer) {
String checkOnServer = "";
for (ServerRun server : checkConsistencyOnServers) {
checkOnServer += server.getServerInstance().getDistributedManager().getLocalNodeName() + ",";
}
checkOnServer = checkOnServer.substring(0, checkOnServer.length() - 1);
String writtenServer = "";
for (ServerRun server : writerServer) {
writtenServer += server.getServerInstance().getDistributedManager().getLocalNodeName() + ",";
}
writtenServer = writtenServer.substring(0, writtenServer.length() - 1);
List<OrientBaseGraph> dbs = new LinkedList<OrientBaseGraph>();
OrientGraphFactory localFactory = null;
for (ServerRun server : checkConsistencyOnServers) {
localFactory = new OrientGraphFactory(getPlocalDatabaseURL(server));
dbs.add(localFactory.getNoTx());
}
Map<Integer, Integer> serverIndex2thresholdThread = new LinkedHashMap<Integer, Integer>();
Map<Integer, String> serverIndex2serverName = new LinkedHashMap<Integer, String>();
int lastThread = 0;
int serverIndex = 0;
for (ServerRun server : writerServer) {
serverIndex2thresholdThread.put(serverIndex, lastThread + 5);
serverIndex++;
lastThread += 5;
}
serverIndex = 0;
for (ServerRun server : writerServer) {
serverIndex2serverName.put(serverIndex, server.getServerInstance().getDistributedManager().getLocalNodeName());
serverIndex++;
}
List<OrientVertex> verticesToCheck = new LinkedList<OrientVertex>();
super.banner("Checking consistency among servers...\nChecking on servers {" + checkOnServer + "} that all the vertices written on {" + writtenServer + "} are consistent.");
try {
int index = 0;
String serverName = null;
for (int serverId : serverIndex2thresholdThread.keySet()) {
serverName = serverIndex2serverName.get(serverId);
System.out.println("Checking records originally inserted on server " + serverName + "...");
String clusterName = "client_" + serverName;
// checking records inserted on server0
int i;
if (serverId == 0)
i = 0;
else
i = serverIndex2thresholdThread.get(serverId - 1);
while (i < serverIndex2thresholdThread.get(serverId)) {
for (int j = 0; j < 100; j++) {
// load records to compare
for (OrientBaseGraph db : dbs) {
verticesToCheck.add(loadVertex(db, clusterName, serverId, i, j + baseCount));
}
// checking that record is present on each server db
OrientVertex currentVertex = null;
int k = 0;
while (k < verticesToCheck.size()) {
assertTrue(verticesToCheck.get(k) != null);
k++;
}
// checking that all the records have the same version and values (each record is equal to the next one)
k = 0;
while (k <= verticesToCheck.size() - 2) {
assertEquals(verticesToCheck.get(k).getProperty("@version"), verticesToCheck.get(k + 1).getProperty("@version"));
assertEquals(verticesToCheck.get(k).getProperty("name"), verticesToCheck.get(k + 1).getProperty("name"));
assertEquals(verticesToCheck.get(k).getProperty("updated"), verticesToCheck.get(k + 1).getProperty("updated"));
k++;
}
verticesToCheck.clear();
}
i++;
}
System.out.println("All records originally inserted on server " + serverName + " in the cluster " + clusterName + " available in the shard.");
index++;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
for (OrientBaseGraph db : dbs) {
ODatabaseRecordThreadLocal.INSTANCE.set(db.getRawGraph());
db.getRawGraph().close();
ODatabaseRecordThreadLocal.INSTANCE.set(null);
}
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientVertex 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.OrientVertex 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();
}
}
}
Aggregations