use of com.tinkerpop.blueprints.impls.orient.OrientBaseGraph 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.OrientBaseGraph 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.OrientBaseGraph 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.OrientBaseGraph in project orientdb by orientechnologies.
the class AbstractShardingScenarioTest method executeMultipleWritesOnShards.
/*
* It executes multiple writes using different concurrent writers (as specified by the value writerCount) on all the servers
* present in the collection passed as parameter in a specific cluster-shards. Each write performs a vertex insert and some update
* and check operations on it. Vertex name: <shardName>-s<serverId>-t<threadId>-<recordId>
*/
protected void executeMultipleWritesOnShards(List<ServerRun> executeOnServers, String storageType) throws InterruptedException, ExecutionException {
System.out.println("Creating Writers threads...");
final ExecutorService writerExecutors = Executors.newCachedThreadPool();
runningWriters = new CountDownLatch(executeOnServers.size() * writerCount);
String shardName = "client_";
int serverId = 0;
int threadId = 0;
List<Callable<Void>> writerWorkers = new ArrayList<Callable<Void>>();
for (ServerRun server : executeOnServers) {
if (server.isActive()) {
shardName += server.getServerInstance().getDistributedManager().getLocalNodeName();
for (int j = 0; j < writerCount; j++) {
Callable writer = null;
if (storageType.equals("plocal")) {
writer = new ShardWriter(serverId, shardName, threadId++, getPlocalDatabaseURL(server));
} else if (storageType.equals("remote")) {
writer = new ShardWriter(serverId, shardName, threadId++, getPlocalDatabaseURL(server));
}
writerWorkers.add(writer);
}
}
serverId++;
shardName = "client_";
}
expected = writerCount * count * serverId + baseCount;
List<Future<Void>> futures = writerExecutors.invokeAll(writerWorkers);
System.out.println("Threads started, waiting for the end");
for (Future<Void> future : futures) {
future.get();
}
writerExecutors.shutdown();
assertTrue(writerExecutors.awaitTermination(1, TimeUnit.MINUTES));
System.out.println("All writer threads have finished.");
// checking inserted vertices
OrientBaseGraph graph;
OrientGraphFactory graphFactory;
// checking total amount of records (map-reduce aggregation)
graphFactory = new OrientGraphFactory("plocal:target/server0/databases/" + getDatabaseName());
graph = graphFactory.getNoTx();
try {
OResultSet<ODocument> clients = new OCommandSQL("select from Client").execute();
int total = clients.size();
assertEquals(expected, total);
List<ODocument> result = new OCommandSQL("select count(*) from Client").execute();
total = ((Number) result.get(0).field("count")).intValue();
// assertEquals(expected, total);
} finally {
graph.getRawGraph().close();
}
serverId = 0;
for (ServerRun server : serverInstance) {
if (server.isActive()) {
graphFactory = new OrientGraphFactory("plocal:target/server" + serverId + "/databases/" + getDatabaseName());
graph = graphFactory.getNoTx();
try {
String sqlCommand = "select from cluster:client_" + server.getServerInstance().getDistributedManager().getLocalNodeName();
List<ODocument> result = new OCommandSQL(sqlCommand).execute();
int total = result.size();
// assertEquals(count * writerCount, total);
sqlCommand = "select count(*) from cluster:client_" + server.getServerInstance().getDistributedManager().getLocalNodeName();
result = new OCommandSQL(sqlCommand).execute();
total = ((Number) result.get(0).field("count")).intValue();
// assertEquals(count * writerCount, total);
} catch (Exception e) {
e.printStackTrace();
} finally {
graph.getRawGraph().close();
}
}
serverId++;
}
// checking indexes
// serverId = 0;
// for (ServerRun server : serverInstance) {
// if (server.isActive()) {
// graphFactory = new OrientGraphFactory("plocal:target/server" + serverId + "/databases/" + getDatabaseName());
// graph = graphFactory.getNoTx();
// try {
// final long indexSize = graph.getRawGraph().getMetadata().getIndexManager().getIndex("Client.name").getSize();
//
// if (indexSize != count) {
// // ERROR: DUMP ALL THE RECORDS
// List<ODocument> result = graph.command(new OCommandSQL("select from index:Client.name")).execute();
// int i = 0;
// for (ODocument d : result) {
// System.out.println((i++) + ": " + ((OIdentifiable) d.field("rid")).getRecord());
// }
// }
//
// junit.framework.Assert.assertEquals(count, indexSize);
//
// System.out.println("From metadata: indexes " + indexSize + " items");
//
// List<ODocument> result = graph.command(new OCommandSQL("select count(*) from index:Client.name")).execute();
// junit.framework.Assert.assertEquals(count, ((Long) result.get(0).field("count")).longValue());
//
// System.out.println("From sql: indexes " + indexSize + " items");
// } finally {
// graph.getRawGraph().close();
// }
// }
// serverId++;
// }
}
use of com.tinkerpop.blueprints.impls.orient.OrientBaseGraph in project orientdb by orientechnologies.
the class BareBonesServer method createDB.
public void createDB(String orientUrl) {
OLogManager.instance().info(this, "creating the database:" + orientUrl);
OrientGraphFactory factory = new OrientGraphFactory(orientUrl);
OrientBaseGraph graph = factory.getTx();
graph.executeOutsideTx(new OCallable<Object, OrientBaseGraph>() {
@Override
public Object call(OrientBaseGraph g) {
if (g.getEdgeType("edgetype") == null)
g.createEdgeType("edgetype");
if (g.getVertexType("vertextype") == null)
g.createVertexType("vertextype");
return null;
}
});
graph.shutdown();
factory.close();
}
Aggregations