use of com.tinkerpop.blueprints.impls.orient.OrientVertex in project orientdb by orientechnologies.
the class ServerClusterQueryTest method checkShardedOrderBy.
private void checkShardedOrderBy() {
for (int s = 0; s < SERVERS; ++s) {
OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
OrientGraphNoTx g = factory.getNoTx();
try {
Iterable<OrientVertex> result = g.command(new OCommandSQL("select amount from v order by amount asc")).execute(v2.getIdentity());
Iterator<OrientVertex> it = result.iterator();
Assert.assertTrue(it.hasNext());
OrientVertex r1 = it.next();
Assert.assertTrue(it.hasNext());
OrientVertex r2 = it.next();
Assert.assertTrue(it.hasNext());
OrientVertex r3 = it.next();
Assert.assertFalse(it.hasNext());
Assert.assertEquals(10, r1.getProperty("amount"));
Assert.assertEquals(15, r2.getProperty("amount"));
Assert.assertEquals(21, r3.getProperty("amount"));
result = g.command(new OCommandSQL("select amount from v order by amount desc")).execute(v2.getIdentity());
it = result.iterator();
Assert.assertTrue(it.hasNext());
r1 = it.next();
Assert.assertTrue(it.hasNext());
r2 = it.next();
Assert.assertTrue(it.hasNext());
r3 = it.next();
Assert.assertFalse(it.hasNext());
Assert.assertEquals(21, r1.getProperty("amount"));
Assert.assertEquals(15, r2.getProperty("amount"));
Assert.assertEquals(10, r3.getProperty("amount"));
} finally {
g.shutdown();
}
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientVertex in project orientdb by orientechnologies.
the class ServerClusterQueryTest method checkNestedQueryContext.
private void checkNestedQueryContext() {
for (int s = 0; s < SERVERS; ++s) {
OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
OrientGraphNoTx g = factory.getNoTx();
try {
final Iterable<OrientVertex> result = g.command(new OCommandSQL("select *, $depth as d from (traverse in('E1') from ?)")).execute(v2.getIdentity());
final Iterator<OrientVertex> it = result.iterator();
Assert.assertTrue(it.hasNext());
final OrientVertex r1 = it.next();
Assert.assertTrue(it.hasNext());
final OrientVertex r2 = it.next();
Assert.assertFalse(it.hasNext());
Assert.assertEquals(r1.getProperty("d"), 0);
Assert.assertEquals(r2.getProperty("d"), 1);
} finally {
g.shutdown();
}
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientVertex in project orientdb by orientechnologies.
the class ServerClusterRemoteInsertBalancedTest method testRoundRobinOnRequest.
private void testRoundRobinOnRequest() {
final OrientGraphFactory factory = new OrientGraphFactory("remote:localhost/" + getDatabaseName());
factory.setConnectionStrategy(OStorageRemote.CONNECTION_STRATEGY.ROUND_ROBIN_REQUEST.toString());
OrientGraphNoTx graph = factory.getNoTx();
Map<Integer, Integer> clusterIds = new HashMap<Integer, Integer>();
try {
for (int i = 0; i < ITERATIONS; ++i) {
final OrientVertex v = graph.addVertex("class:Client");
Integer value = clusterIds.get(v.getIdentity().getClusterId());
if (value == null)
value = 1;
else
value++;
clusterIds.put(v.getIdentity().getClusterId(), value);
}
} finally {
graph.shutdown();
}
Assert.assertTrue(clusterIds.size() > 1);
}
use of com.tinkerpop.blueprints.impls.orient.OrientVertex in project orientdb by orientechnologies.
the class BasicShardingNoReplicaScenarioTest method executeTest.
@Override
public void executeTest() throws Exception {
OHazelcastPlugin manager1 = (OHazelcastPlugin) serverInstance.get(0).getServerInstance().getDistributedManager();
final OModifiableDistributedConfiguration databaseConfiguration = manager1.getDatabaseConfiguration(this.getDatabaseName()).modify();
ODocument cfg = databaseConfiguration.getDocument();
OrientGraphFactory localFactory = new OrientGraphFactory("plocal:target/server0/databases/" + getDatabaseName());
OrientGraphNoTx graphNoTx = null;
try {
graphNoTx = localFactory.getNoTx();
final OrientVertexType clientType = graphNoTx.createVertexType("Client", 1);
OModifiableDistributedConfiguration dCfg = new OModifiableDistributedConfiguration(cfg);
for (int i = 0; i < serverInstance.size(); ++i) {
final String serverName = serverInstance.get(i).getServerInstance().getDistributedManager().getLocalNodeName();
clientType.addCluster("client_" + serverName);
dCfg.setServerOwner("client_" + serverName, serverName);
}
manager1.updateCachedDatabaseConfiguration(this.getDatabaseName(), dCfg, true);
final OrientVertexType.OrientVertexProperty prop = clientType.createProperty("name", OType.STRING);
prop.createIndex(OClass.INDEX_TYPE.NOTUNIQUE);
assertTrue(graphNoTx.getRawGraph().getMetadata().getIndexManager().existsIndex("Client.name"));
Thread.sleep(500);
graphNoTx.getRawGraph().close();
// writes on the three clusters
executeMultipleWritesOnShards(executeTestsOnServers, "plocal");
// check consistency (no-replica)
checkAvailabilityOnShardsNoReplica(serverInstance, executeTestsOnServers);
// network fault on server3
System.out.println("Shutdown on server3.\n");
simulateServerFault(serverInstance.get(2), "shutdown");
assertFalse(serverInstance.get(2).isActive());
waitForDatabaseIsOffline(executeTestsOnServers.get(2).getServerInstance().getDistributedManager().getLocalNodeName(), getDatabaseName(), 10000);
// check consistency (no-replica)
executeTestsOnServers.remove(2);
checkAvailabilityOnShardsNoReplica(executeTestsOnServers, executeTestsOnServers);
// this query doesn't return any result
try {
System.out.print("Checking that records on server3 are not available in the cluster...");
graphNoTx = localFactory.getNoTx();
ODatabaseRecordThreadLocal.INSTANCE.set(graphNoTx.getRawGraph());
final String uniqueId = "client_asia-s2-t10-v0";
Iterable<Vertex> it = graphNoTx.command(new OCommandSQL("select from Client where name = '" + uniqueId + "'")).execute();
List<OrientVertex> result = new LinkedList<OrientVertex>();
for (Vertex v : it) {
result.add((OrientVertex) v);
}
assertEquals(0, result.size());
System.out.println("Done");
graphNoTx.getRawGraph().close();
ODatabaseRecordThreadLocal.INSTANCE.set(null);
} catch (Exception e) {
e.printStackTrace();
fail();
}
// restarting server3
serverInstance.get(2).startServer(getDistributedServerConfiguration(serverInstance.get(SERVERS - 1)));
System.out.println("Server 3 restarted.");
assertTrue(serverInstance.get(2).isActive());
waitForDatabaseIsOnline(0, serverInstance.get(2).getServerInstance().getDistributedManager().getLocalNodeName(), getDatabaseName(), 10000);
// checking server3 status by querying a record inserted on it
try {
System.out.print("Checking server3 status by querying a record inserted on it...");
localFactory = new OrientGraphFactory("plocal:target/server2/databases/" + getDatabaseName());
graphNoTx = localFactory.getNoTx();
ODatabaseRecordThreadLocal.INSTANCE.set(graphNoTx.getRawGraph());
final String uniqueId = "client_asia-s2-t10-v0";
Iterable<Vertex> it = graphNoTx.command(new OCommandSQL("select from Client where name = '" + uniqueId + "'")).execute();
List<OrientVertex> result = new LinkedList<OrientVertex>();
for (Vertex v : it) {
result.add((OrientVertex) v);
}
assertEquals(1, result.size());
graphNoTx.getRawGraph().close();
ODatabaseRecordThreadLocal.INSTANCE.set(null);
} catch (Exception e) {
e.printStackTrace();
fail(e.toString());
}
// check consistency (no-replica)
executeTestsOnServers.add(serverInstance.get(2));
checkAvailabilityOnShardsNoReplica(serverInstance, executeTestsOnServers);
} catch (Exception e) {
e.printStackTrace();
fail(e.toString());
} finally {
if (!graphNoTx.getRawGraph().isClosed()) {
ODatabaseRecordThreadLocal.INSTANCE.set(graphNoTx.getRawGraph());
graphNoTx.getRawGraph().close();
ODatabaseRecordThreadLocal.INSTANCE.set(null);
}
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientVertex in project orientdb by orientechnologies.
the class ConcurrentDistributedUpdateTest method createWriter.
protected Callable<Void> createWriter(final int serverId, final int threadId, final String databaseURL) {
return new Callable<Void>() {
@Override
public Void call() throws Exception {
final String id = serverId + "." + threadId;
boolean isRunning = true;
final OrientBaseGraph graph = new OrientGraph(databaseURL);
try {
String query = "select from Test where prop2='v2-1'";
for (int i = 0; i < 100 && isRunning; i++) {
if ((i % 25) == 0) {
log("[" + id + "] Records Processed: [" + i + "]");
}
Iterable<Vertex> vtxs = graph.command(new OCommandSQL(query)).execute();
boolean update = true;
for (Vertex vtx : vtxs) {
if (update) {
update = true;
for (int k = 0; k < 10 && update; k++) {
OrientVertex vtx1 = (OrientVertex) vtx;
try {
vtx1.setProperty("prop5", "prop55");
graph.commit();
// log("[" + id + "/" + i + "/" + k + "] OK!\n");
break;
} catch (OConcurrentModificationException ex) {
vtx1.reload();
} catch (ODistributedRecordLockedException ex) {
log("[" + id + "/" + i + "/" + k + "] Distributed lock Exception " + ex + " for vertex " + vtx1 + " \n");
// ex.printStackTrace();
update = false;
// isRunning = false;
break;
} catch (Exception ex) {
log("[" + id + "/" + i + "/" + k + "] Exception " + ex + " for vertex " + vtx1 + "\n\n");
ex.printStackTrace();
isRunning = false;
break;
}
}
if (!isRunning)
break;
}
}
}
} catch (Exception ex) {
System.out.println("ID: [" + id + "]********** Exception " + ex + " \n\n");
ex.printStackTrace();
} finally {
log("[" + id + "] Done................>>>>>>>>>>>>>>>>>>");
graph.shutdown();
runningWriters.countDown();
}
Assert.assertTrue(isRunning);
return null;
}
};
}
Aggregations