use of com.orientechnologies.orient.server.hazelcast.OHazelcastPlugin 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.orientechnologies.orient.server.hazelcast.OHazelcastPlugin in project orientdb by orientechnologies.
the class DeleteAndLazarusScenarioTest method executeTest.
@Override
public void executeTest() throws Exception {
/*
* Test with writeQuorum = majority
*/
banner("Test with writeQuorum = majority");
ODatabaseDocumentTx dbServer1 = poolFactory.get(getDatabaseURL(serverInstance.get(0)), "admin", "admin").acquire();
// changing configuration: readQuorum=2, autoDeploy=false
System.out.print("\nChanging configuration (autoDeploy=false)...");
ODocument cfg = null;
ServerRun server = serverInstance.get(2);
OHazelcastPlugin manager = (OHazelcastPlugin) server.getServerInstance().getDistributedManager();
ODistributedConfiguration databaseConfiguration = manager.getDatabaseConfiguration(getDatabaseName());
cfg = databaseConfiguration.getDocument();
System.out.println("\nConfiguration updated.");
// inserting record r1 and checking consistency on all the servers
try {
ODatabaseRecordThreadLocal.INSTANCE.set(dbServer1);
System.out.print("Inserting record r1...");
new ODocument("Person").fields("id", "R001", "firstName", "Luke", "lastName", "Skywalker").save();
System.out.println("Done.");
} catch (Exception e) {
e.printStackTrace();
fail("Record r1 not inserted!.");
}
waitForInsertedRecordPropagation("R001");
System.out.print("Checking consistency for record r1...");
ODocument r1onServer1 = retrieveRecord(getDatabaseURL(serverInstance.get(0)), "R001");
ODocument r1onServer2 = retrieveRecord(getDatabaseURL(serverInstance.get(1)), "R001");
ODocument r1onServer3 = retrieveRecord(getDatabaseURL(serverInstance.get(2)), "R001");
final ORecordId r1Rid = (ORecordId) r1onServer1.getIdentity();
assertEquals(r1onServer1.field("@version"), r1onServer2.field("@version"));
assertEquals(r1onServer1.field("id"), r1onServer2.field("id"));
assertEquals(r1onServer1.field("firstName"), r1onServer2.field("firstName"));
assertEquals(r1onServer1.field("lastName"), r1onServer2.field("lastName"));
assertEquals(r1onServer2.field("@version"), r1onServer3.field("@version"));
assertEquals(r1onServer2.field("id"), r1onServer3.field("id"));
assertEquals(r1onServer2.field("firstName"), r1onServer3.field("firstName"));
assertEquals(r1onServer2.field("lastName"), r1onServer3.field("lastName"));
System.out.println("\tDone.");
// initial version of the record r1
int initialVersion = r1onServer1.field("@version");
// isolating server3
System.out.println("Network fault on server3.\n");
simulateServerFault(serverInstance.get(2), "net-fault");
assertFalse(serverInstance.get(2).isActive());
// updating r1 in r1* on server3
banner("Updating r1* on server3 (isolated from the the cluster)");
ODatabaseDocumentTx dbServer3 = null;
try {
r1onServer3 = retrieveRecord(getPlocalDatabaseURL(serverInstance.get(2)), "R001");
dbServer3 = new ODatabaseDocumentTx(getPlocalDatabaseURL(serverInstance.get(2))).open("admin", "admin");
r1onServer3.field("firstName", "Darth");
r1onServer3.field("lastName", "Vader");
r1onServer3.save();
System.out.println(r1onServer3.getRecord().toString());
} 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());
// reading r1* on server3
dbServer3 = poolFactory.get(getDatabaseURL(serverInstance.get(2)), "admin", "admin").acquire();
try {
r1onServer3 = retrieveRecord(getPlocalDatabaseURL(serverInstance.get(2)), "R001");
} catch (Exception e) {
e.printStackTrace();
} finally {
dbServer3.close();
}
// r1 was not modified both on server1 and server2
r1onServer1 = retrieveRecord(getDatabaseURL(serverInstance.get(0)), "R001");
r1onServer2 = retrieveRecord(getDatabaseURL(serverInstance.get(1)), "R001");
assertEquals(1, r1onServer1.field("@version"));
assertEquals("R001", r1onServer1.field("id"));
assertEquals("Luke", r1onServer1.field("firstName"));
assertEquals("Skywalker", r1onServer1.field("lastName"));
assertEquals(r1onServer1.field("@version"), r1onServer2.field("@version"));
assertEquals(r1onServer1.field("id"), r1onServer2.field("id"));
assertEquals(r1onServer1.field("firstName"), r1onServer2.field("firstName"));
assertEquals(r1onServer1.field("lastName"), r1onServer2.field("lastName"));
// checking we have different values for r1* on server3
assertEquals("R001", r1onServer3.field("id"));
assertEquals("Darth", r1onServer3.field("firstName"));
assertEquals("Vader", r1onServer3.field("lastName"));
assertEquals(initialVersion + 1, r1onServer3.field("@version"));
// shutdown server1
System.out.println("Network fault on server1.\n");
simulateServerFault(serverInstance.get(0), "net-fault");
assertFalse(serverInstance.get(0).isActive());
// delete request on server3 for r1*
dbServer3 = poolFactory.get(getDatabaseURL(serverInstance.get(2)), "admin", "admin").acquire();
try {
dbServer3.command(new OCommandSQL("delete from Person where @rid=#27:0")).execute();
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
dbServer3.close();
}
// restarting server1
serverInstance.get(0).startServer(getDistributedServerConfiguration(serverInstance.get(0)));
System.out.println("Server 1 restarted.");
assertTrue(serverInstance.get(0).isActive());
// r1 is still present both on server1 and server2
r1onServer1 = retrieveRecord(getDatabaseURL(serverInstance.get(0)), "R001");
r1onServer2 = retrieveRecord(getDatabaseURL(serverInstance.get(1)), "R001");
assertEquals(1, r1onServer1.field("@version"));
assertEquals("R001", r1onServer1.field("id"));
assertEquals("Luke", r1onServer1.field("firstName"));
assertEquals("Skywalker", r1onServer1.field("lastName"));
assertEquals(r1onServer1.field("@version"), r1onServer2.field("@version"));
assertEquals(r1onServer1.field("id"), r1onServer2.field("id"));
assertEquals(r1onServer1.field("firstName"), r1onServer2.field("firstName"));
assertEquals(r1onServer1.field("lastName"), r1onServer2.field("lastName"));
// r1* is still present on server3
r1onServer3 = retrieveRecord(getDatabaseURL(serverInstance.get(2)), "R001");
assertEquals(2, r1onServer3.field("@version"));
assertEquals("R001", r1onServer3.field("id"));
assertEquals("Darth", r1onServer3.field("firstName"));
assertEquals("Vader", r1onServer3.field("lastName"));
// delete request on server1 for r1
dbServer1 = poolFactory.get(getRemoteDatabaseURL(serverInstance.get(0)), "admin", "admin").acquire();
try {
Integer result = dbServer1.command(new OCommandSQL("delete from " + r1Rid)).execute();
} catch (Exception e) {
e.printStackTrace();
} finally {
dbServer1.close();
}
// r1 is no more present neither on server1, server2 nor server3
r1onServer1 = retrieveRecord(getDatabaseURL(serverInstance.get(0)), "R001", true, new OCallable<ODocument, ODocument>() {
@Override
public ODocument call(ODocument doc) {
assertEquals(MISSING_DOCUMENT, doc);
return null;
}
});
r1onServer2 = retrieveRecord(getDatabaseURL(serverInstance.get(1)), "R001", true, new OCallable<ODocument, ODocument>() {
@Override
public ODocument call(ODocument doc) {
assertEquals(MISSING_DOCUMENT, doc);
return null;
}
});
r1onServer3 = retrieveRecord(getDatabaseURL(serverInstance.get(2)), "R001", true, new OCallable<ODocument, ODocument>() {
@Override
public ODocument call(ODocument doc) {
assertEquals(MISSING_DOCUMENT, doc);
return null;
}
});
}
use of com.orientechnologies.orient.server.hazelcast.OHazelcastPlugin in project orientdb by orientechnologies.
the class IsolatedNodeRejoinScenarioTest method executeTest.
@Override
public void executeTest() throws Exception {
/*
* Test with quorum = 1
*/
banner("Test with quorum = 2");
System.out.print("\nChanging configuration (writeQuorum=2, autoDeploy=false)...");
ODocument cfg = null;
ServerRun server = serverInstance.get(2);
OHazelcastPlugin manager = (OHazelcastPlugin) server.getServerInstance().getDistributedManager();
OModifiableDistributedConfiguration databaseConfiguration = manager.getDatabaseConfiguration(getDatabaseName()).modify();
cfg = databaseConfiguration.getDocument();
cfg.field("writeQuorum", 2);
cfg.field("autoDeploy", true);
cfg.field("version", (Integer) cfg.field("version") + 1);
manager.updateCachedDatabaseConfiguration(getDatabaseName(), databaseConfiguration, true);
System.out.println("\nConfiguration updated.");
// isolating server3
System.out.println("Network fault on server3.\n");
simulateServerFault(serverInstance.get(2), "net-fault");
assertFalse(serverInstance.get(2).isActive());
// execute writes on server1 and server2
executeMultipleWrites(super.executeTestsOnServers, "plocal");
// server3 joins the cluster
System.out.println("Restart server3.\n");
try {
serverInstance.get(2).startServer(getDistributedServerConfiguration(server));
} catch (Exception e) {
fail();
}
// waiting for propagation
waitForMultipleInsertsInClassPropagation(1000L, "Person", 5000L);
// check consistency
super.checkWritesAboveCluster(serverInstance, executeTestsOnServers);
}
use of com.orientechnologies.orient.server.hazelcast.OHazelcastPlugin in project orientdb by orientechnologies.
the class Quorum1ScenarioTest method executeTest.
@Override
public void executeTest() throws Exception {
/*
* Test with quorum = 1
*/
banner("Test with quorum = 1");
System.out.print("\nChanging configuration (writeQuorum=1, autoDeploy=false)...");
ODocument cfg = null;
ServerRun server = serverInstance.get(0);
OHazelcastPlugin manager = (OHazelcastPlugin) server.getServerInstance().getDistributedManager();
OModifiableDistributedConfiguration databaseConfiguration = manager.getDatabaseConfiguration(getDatabaseName()).modify();
cfg = databaseConfiguration.getDocument();
cfg.field("writeQuorum", 1);
cfg.field("autoDeploy", true);
cfg.field("version", (Integer) cfg.field("version") + 1);
manager.updateCachedDatabaseConfiguration(getDatabaseName(), databaseConfiguration, true);
System.out.println("\nConfiguration updated.");
// execute writes on server1 and server2
executeMultipleWrites(super.executeTestsOnServers, "plocal");
// waiting for propagation
waitForMultipleInsertsInClassPropagation(executeTestsOnServers.size() * writerCount * count, "Person", 5000L);
// check consistency
super.checkWritesAboveCluster(serverInstance, executeTestsOnServers);
}
use of com.orientechnologies.orient.server.hazelcast.OHazelcastPlugin in project orientdb by orientechnologies.
the class TwoClientsRecordUpdateTxOnTwoServersWithQuorum2ScenarioTest method setWriteQuorum.
private void setWriteQuorum(int quorum) throws InterruptedException {
OHazelcastPlugin manager = (OHazelcastPlugin) serverInstance.get(0).getServerInstance().getDistributedManager();
OModifiableDistributedConfiguration databaseConfiguration = manager.getDatabaseConfiguration(getDatabaseName()).modify();
ODocument cfg = databaseConfiguration.getDocument();
cfg.field("writeQuorum", quorum);
manager.updateCachedDatabaseConfiguration(getDatabaseName(), databaseConfiguration, true);
Thread.sleep(100);
}
Aggregations