use of com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx in project orientdb by orientechnologies.
the class OneNodeBackupTest method onServerStarted.
@Override
protected void onServerStarted(ServerRun server) {
super.onServerStarted(server);
if (serverStarted == 0) {
// INSTALL ON FIRST SERVER ONLY THE SERVER MONITOR TO CHECK IF HAS BEEN RESTARTED
server.server.getDistributedManager().registerLifecycleListener(new ODistributedLifecycleListener() {
@Override
public boolean onNodeJoining(String iNode) {
return true;
}
@Override
public void onNodeJoined(String iNode) {
}
@Override
public void onNodeLeft(String iNode) {
nodeLefts.incrementAndGet();
}
@Override
public void onDatabaseChangeStatus(String iNode, String iDatabaseName, ODistributedServerManager.DB_STATUS iNewStatus) {
}
});
}
if (serverStarted++ == (SERVERS - 1)) {
// BACKUP LAST SERVER, RUN ASYNCHRONOUSLY
new Thread(new Runnable() {
@Override
public void run() {
try {
executeWhen(new Callable<Boolean>() {
// CONDITION
@Override
public Boolean call() throws Exception {
final ODatabaseDocumentTx database = poolFactory.get(getDatabaseURL(serverInstance.get(0)), "admin", "admin").acquire();
try {
return database.countClass("Person") > (count * SERVERS) * 1 / 3;
} finally {
database.close();
}
}
}, // ACTION
new Callable() {
@Override
public Object call() throws Exception {
Assert.assertTrue("Insert was too fast", inserting);
banner("STARTING BACKUP SERVER " + (SERVERS - 1));
OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server" + (SERVERS - 1) + "/databases/" + getDatabaseName(), false);
OrientGraphNoTx g = factory.getNoTx();
backupInProgress.set(true);
File file = null;
try {
file = File.createTempFile("orientdb_test_backup", ".zip");
if (file.exists())
Assert.assertTrue(file.delete());
verticesBeforeBackup = g.countVertices("Person");
g.getRawGraph().backup(new FileOutputStream(file), null, new Callable<Object>() {
@Override
public Object call() throws Exception {
// SIMULATE LONG BACKUP
for (int i = 0; i < 10; ++i) {
banner("SIMULATING LONG BACKUP... ELAPSED SECOND " + i);
Thread.sleep(1000);
}
return null;
}
}, null, 9, 1000000);
final long verticesAfterBackup = g.countVertices("Person");
Assert.assertTrue(verticesAfterBackup > verticesBeforeBackup);
} finally {
banner("COMPLETED BACKUP SERVER " + (SERVERS - 1));
backupInProgress.set(false);
if (file != null)
file.delete();
}
return null;
}
});
} catch (Exception e) {
e.printStackTrace();
Assert.fail("Error on execution flow");
}
}
}).start();
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx 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.OrientGraphNoTx 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.OrientGraphNoTx 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.OrientGraphNoTx 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();
}
}
}
Aggregations