use of com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx in project orientdb by orientechnologies.
the class TestShardingManualSync method executeTest.
@Override
protected void executeTest() throws Exception {
final OrientGraphFactory localFactoryEurope = new OrientGraphFactory("plocal:target/server0/databases/" + getDatabaseName());
OrientGraphFactory localFactoryUsa = new OrientGraphFactory("plocal:target/server1/databases/" + getDatabaseName());
final ORID v1Identity;
OrientGraphNoTx graphNoTxEurope = localFactoryEurope.getNoTx();
try {
final OrientVertexType clientType = graphNoTxEurope.createVertexType("Client-Type");
for (int i = 1; i < serverInstance.size(); ++i) {
final String serverName = serverInstance.get(i).getServerInstance().getDistributedManager().getLocalNodeName();
clientType.addCluster("client_" + serverName);
}
final OrientVertex v1 = graphNoTxEurope.addVertex("class:Client-Type");
v1Identity = v1.getIdentity();
log("Created vertex " + v1Identity + "...");
} finally {
graphNoTxEurope.shutdown();
}
OrientGraphNoTx graphNoTxUsa = localFactoryUsa.getNoTx();
try {
Assert.assertEquals(1, graphNoTxUsa.countVertices());
} finally {
graphNoTxUsa.shutdown();
localFactoryUsa.close();
}
final String clusterName;
graphNoTxEurope = localFactoryEurope.getNoTx();
try {
Assert.assertEquals(1, graphNoTxEurope.countVertices());
// CHANGE THE WRITE QUORUM = 1
final OModifiableDistributedConfiguration dCfg = serverInstance.get(0).server.getDistributedManager().getDatabaseConfiguration(getDatabaseName()).modify();
ODocument newCfg = dCfg.getDocument().field("writeQuorum", 1);
serverInstance.get(0).server.getDistributedManager().updateCachedDatabaseConfiguration(getDatabaseName(), dCfg, true);
// CREATE A NEW RECORD ON SERVER 0 BYPASSING REPLICATION
final ODocument v2 = new ODocument("Client");
((ORecordId) v2.getIdentity()).setClusterId(v1Identity.getClusterId());
((ORecordId) v2.getIdentity()).setClusterPosition(v1Identity.getClusterPosition() + 1);
final Object result = createRemoteRecord(0, v2, new String[] { serverInstance.get(0).getServerInstance().getDistributedManager().getLocalNodeName() });
Assert.assertFalse(result instanceof Throwable);
Assert.assertEquals(2, graphNoTxEurope.countVertices());
clusterName = graphNoTxEurope.getRawGraph().getClusterNameById(v2.getIdentity().getClusterId());
Assert.assertEquals(2, graphNoTxEurope.countVertices());
} finally {
graphNoTxEurope.shutdown();
}
// TEST SECOND VERTEX IS MISSING ON USA NODE
localFactoryUsa = new OrientGraphFactory("plocal:target/server1/databases/" + getDatabaseName());
graphNoTxUsa = localFactoryUsa.getNoTx();
try {
Assert.assertEquals(1, graphNoTxUsa.countVertices());
log("Manually syncing cluster client-type of node USA...");
graphNoTxUsa.command(new OCommandSQL("ha sync cluster `" + clusterName + "`")).execute();
Assert.assertEquals(2, graphNoTxUsa.countVertices());
} finally {
graphNoTxUsa.shutdown();
}
localFactoryEurope.close();
localFactoryUsa.close();
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx in project orientdb by orientechnologies.
the class AsyncIndexRemoteTest method dbClient1.
protected void dbClient1() {
OrientBaseGraph graph = new OrientGraphNoTx(getRemoteURL());
try {
graph.command(new OCommandSQL("create class SMS")).execute();
graph.command(new OCommandSQL("create property SMS.type string")).execute();
graph.command(new OCommandSQL("create property SMS.lang string")).execute();
graph.command(new OCommandSQL("create property SMS.source integer")).execute();
graph.command(new OCommandSQL("create property SMS.content string")).execute();
graph.command(new OCommandSQL("alter property SMS.lang min 2")).execute();
graph.command(new OCommandSQL("alter property SMS.lang max 2")).execute();
graph.command(new OCommandSQL("create index sms_keys ON SMS (type, lang) unique")).execute();
graph.command(new OCommandSQL("insert into sms (type, lang, source, content) values ( 'notify', 'en', 1, 'This is a test')")).execute();
try {
graph.command(new OCommandSQL("insert into sms (type, lang, source, content) values ( 'notify', 'en', 1, 'This is a test')")).execute();
Assert.fail("violated unique index was not raised");
} catch (ORecordDuplicatedException e) {
}
final Iterable<OrientVertex> result = graph.command(new OSQLSynchQuery<OrientVertex>("select count(*) from SMS")).execute();
Assert.assertEquals(1, ((Number) result.iterator().next().getProperty("count")).intValue());
} catch (Throwable e) {
if (exceptionInThread == null) {
exceptionInThread = e;
}
} finally {
OLogManager.instance().info(this, "Shutting down db1");
graph.shutdown();
}
// CHECK ON THE 2ND NODE
OrientBaseGraph graph2 = new OrientGraphNoTx(getRemoteURL2());
try {
try {
graph2.command(new OCommandSQL("insert into sms (type, lang, source, content) values ( 'notify', 'en', 1, 'This is a test')")).execute();
Assert.fail("violated unique index was not raised");
} catch (ORecordDuplicatedException e) {
}
final Iterable<OrientVertex> result = graph2.command(new OSQLSynchQuery<OrientVertex>("select count(*) from SMS")).execute();
Assert.assertEquals(1, ((Number) result.iterator().next().getProperty("count")).intValue());
} catch (Throwable e) {
if (exceptionInThread == null) {
exceptionInThread = e;
}
} finally {
OLogManager.instance().info(this, "Shutting down db2");
graph2.shutdown();
}
// CHECK ON THE 2ND NODE
OrientBaseGraph graph3 = new OrientGraphNoTx(getRemoteURL3());
try {
try {
graph3.command(new OCommandSQL("insert into sms (type, lang, source, content) values ( 'notify', 'en', 1, 'This is a test')")).execute();
Assert.fail("violated unique index was not raised");
} catch (ORecordDuplicatedException e) {
}
final Iterable<OrientVertex> result = graph3.command(new OSQLSynchQuery<OrientVertex>("select count(*) from SMS")).execute();
Assert.assertEquals(1, ((Number) result.iterator().next().getProperty("count")).intValue());
} catch (Throwable e) {
if (exceptionInThread == null) {
exceptionInThread = e;
}
} finally {
OLogManager.instance().info(this, "Shutting down db3");
graph3.shutdown();
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx in project orientdb by orientechnologies.
the class AsyncIndexTest method dbClient1.
protected void dbClient1() {
OrientBaseGraph graph = new OrientGraphNoTx(getLocalURL());
try {
graph.command(new OCommandSQL("create class SMS")).execute();
graph.command(new OCommandSQL("create property SMS.type string")).execute();
graph.command(new OCommandSQL("create property SMS.lang string")).execute();
graph.command(new OCommandSQL("create property SMS.source integer")).execute();
graph.command(new OCommandSQL("create property SMS.content string")).execute();
graph.command(new OCommandSQL("alter property SMS.lang min 2")).execute();
graph.command(new OCommandSQL("alter property SMS.lang max 2")).execute();
graph.command(new OCommandSQL("create index sms_keys ON SMS (type, lang) unique")).execute();
graph.command(new OCommandSQL("insert into sms (type, lang, source, content) values ( 'notify', 'en', 1, 'This is a test')")).execute();
try {
graph.command(new OCommandSQL("insert into sms (type, lang, source, content) values ( 'notify', 'en', 1, 'This is a test')")).execute();
Assert.fail("violated unique index was not raised");
} catch (ORecordDuplicatedException e) {
}
final Iterable<OrientVertex> result = graph.command(new OSQLSynchQuery<OrientVertex>("select count(*) from SMS")).execute();
Assert.assertEquals(1, ((Number) result.iterator().next().getProperty("count")).intValue());
} catch (Throwable e) {
if (exceptionInThread == null) {
exceptionInThread = e;
}
} finally {
OLogManager.instance().info(this, "Shutting down db1");
graph.shutdown();
}
// CHECK ON THE OTHER NODE
OrientBaseGraph graph2 = new OrientGraphNoTx(getLocalURL2());
try {
try {
graph2.command(new OCommandSQL("insert into sms (type, lang, source, content) values ( 'notify', 'en', 1, 'This is a test')")).execute();
Assert.fail("violated unique index was not raised");
} catch (ORecordDuplicatedException e) {
}
final Iterable<OrientVertex> result = graph2.command(new OSQLSynchQuery<OrientVertex>("select count(*) from SMS")).execute();
Assert.assertEquals(1, ((Number) result.iterator().next().getProperty("count")).intValue());
} catch (Throwable e) {
if (exceptionInThread == null) {
exceptionInThread = e;
}
} finally {
OLogManager.instance().info(this, "Shutting down db2");
graph2.shutdown();
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx in project orientdb by orientechnologies.
the class DistributedSecurityTest method executeTest.
@Override
protected void executeTest() throws Exception {
for (int s = 0; s < SERVERS; ++s) {
OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName(), "reader", "reader");
OrientGraphNoTx g = factory.getNoTx();
try {
try {
// TRY DELETING ALL OUSER VIA COMMAND
Long deleted = g.command(new OCommandSQL("delete from OUser")).execute();
Assert.assertEquals(deleted.longValue(), 0l);
} catch (Exception e) {
Assert.assertTrue(true);
}
try {
// TRY DELETING CURRENT OUSER VIA API
g.getRawGraph().getUser().getIdentity().getRecord().delete();
Assert.assertTrue(false);
} catch (Exception e) {
Assert.assertTrue(true);
}
} finally {
g.shutdown();
}
}
}
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();
}
}
Aggregations