use of com.tinkerpop.blueprints.impls.orient.OrientGraphFactory in project orientdb by orientechnologies.
the class ServerClusterGraphTest method executeTest.
@Override
protected void executeTest() throws Exception {
{
OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server0/databases/" + getDatabaseName());
OrientGraphNoTx g = factory.getNoTx();
try {
g.createVertexType("Post");
g.createVertexType("User");
g.createEdgeType("Own");
g.addVertex("class:User");
g.command(new OCommandSQL("insert into Post (content, timestamp) values('test', 1)")).execute();
} finally {
g.shutdown();
}
}
// CHECK VERTEX CREATION ON ALL THE SERVERS
for (int s = 0; s < SERVERS; ++s) {
OrientGraphFactory factory2 = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
OrientGraphNoTx g2 = factory2.getNoTx();
try {
Iterable<OrientVertex> result = g2.command(new OCommandSQL("select from Post")).execute();
Assert.assertTrue(result.iterator().hasNext());
Assert.assertNotNull(result.iterator().next());
} finally {
g2.shutdown();
}
}
{
OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server0/databases/" + getDatabaseName());
OrientGraphNoTx g = factory.getNoTx();
try {
g.command(new OCommandSQL("create edge Own from (select from User) to (select from Post)")).execute();
} finally {
g.shutdown();
}
}
// CHECK VERTEX CREATION ON ALL THE SERVERS
for (int s = 0; s < SERVERS; ++s) {
OrientGraphFactory factory2 = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
OrientGraphNoTx g2 = factory2.getNoTx();
try {
Iterable<OrientVertex> result = g2.command(new OCommandSQL("select from Own")).execute();
Assert.assertTrue(result.iterator().hasNext());
Assert.assertNotNull(result.iterator().next());
result = g2.command(new OCommandSQL("select from Post")).execute();
Assert.assertTrue(result.iterator().hasNext());
final OrientVertex v = result.iterator().next();
Assert.assertNotNull(v);
final Iterable<Edge> inEdges = v.getEdges(Direction.IN);
Assert.assertTrue(inEdges.iterator().hasNext());
Assert.assertNotNull(inEdges.iterator().next());
result = g2.command(new OCommandSQL("select from User")).execute();
Assert.assertTrue(result.iterator().hasNext());
final OrientVertex v2 = result.iterator().next();
Assert.assertNotNull(v2);
final Iterable<Edge> outEdges = v2.getEdges(Direction.OUT);
Assert.assertTrue(outEdges.iterator().hasNext());
Assert.assertNotNull(outEdges.iterator().next());
} finally {
g2.shutdown();
}
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraphFactory in project orientdb by orientechnologies.
the class ServerClusterQueryTest method checkSum.
private void checkSum() {
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 sum(amount) as total from v")).execute(v2.getIdentity());
final Iterator<OrientVertex> it = result.iterator();
Assert.assertTrue(it.hasNext());
final OrientVertex r1 = it.next();
Assert.assertEquals(r1.getProperty("total"), 46);
} finally {
g.shutdown();
}
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraphFactory 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.OrientGraphFactory 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.OrientGraphFactory 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);
}
Aggregations