use of com.orientechnologies.orient.server.distributed.impl.ODistributedStorage in project orientdb by orientechnologies.
the class ThreeClientsRecordUpdateWithTransactionsOnMultipleServersScenarioTest method executeTest.
@Override
public void executeTest() throws Exception {
ODatabaseDocumentTx dbServer1 = poolFactory.get(getDatabaseURL(serverInstance.get(0)), "admin", "admin").acquire();
ODatabaseDocumentTx dbServer2 = poolFactory.get(getDatabaseURL(serverInstance.get(1)), "admin", "admin").acquire();
ODatabaseDocumentTx dbServer3 = poolFactory.get(getDatabaseURL(serverInstance.get(2)), "admin", "admin").acquire();
// inserts record1
ODatabaseRecordThreadLocal.INSTANCE.set(dbServer1);
ODocument record1Server1 = new ODocument("Person").fromMap(hanFields);
record1Server1.save();
// waits for propagation of the record on all the servers
waitForInsertedRecordPropagation(RECORD_ID);
// retrieves record1 from server2 and server 3 and checks they're equal
ODocument record1Server2 = retrieveRecord(getDatabaseURL(serverInstance.get(1)), RECORD_ID);
assertEquals(record1Server2.getVersion(), record1Server1.getVersion());
assertEquals(record1Server2.field("id"), record1Server1.field("id"));
assertEquals(record1Server2.field("firstName"), record1Server1.field("firstName"));
assertEquals(record1Server2.field("lastName"), record1Server1.field("lastName"));
ODocument record1Server3 = retrieveRecord(getDatabaseURL(serverInstance.get(2)), RECORD_ID);
assertEquals(record1Server3.getVersion(), record1Server1.getVersion());
assertEquals(record1Server3.field("id"), record1Server1.field("id"));
assertEquals(record1Server3.field("firstName"), record1Server1.field("firstName"));
assertEquals(record1Server3.field("lastName"), record1Server1.field("lastName"));
// gets the actual version of the record1
int actualVersion = record1Server1.getVersion();
System.out.println("Actual version: " + actualVersion);
// sets a delay for operations on distributed storage of all servers
((ODistributedStorage) dbServer1.getStorage()).setEventListener(new AfterRecordLockDelayer("server1", DOCUMENT_WRITE_TIMEOUT));
((ODistributedStorage) dbServer2.getStorage()).setEventListener(new AfterRecordLockDelayer("server2", DOCUMENT_WRITE_TIMEOUT / 4));
((ODistributedStorage) dbServer3.getStorage()).setEventListener(new AfterRecordLockDelayer("server3", DOCUMENT_WRITE_TIMEOUT / 2));
// updates the same record from three different clients, each calling a different server
List<Callable<Void>> clients = new LinkedList<Callable<Void>>();
clients.add(new RecordUpdater(getDatabaseURL(serverInstance.get(0)), record1Server1, lukeFields, true));
clients.add(new RecordUpdater(getDatabaseURL(serverInstance.get(1)), record1Server2, darthFields, true));
clients.add(new RecordUpdater(getDatabaseURL(serverInstance.get(2)), record1Server3, leiaFields, true));
List<Future<Void>> futures = Executors.newCachedThreadPool().invokeAll(clients);
executeFutures(futures);
// checks that record on server3 is the one which wins over the others
waitForUpdatedRecordPropagation(RECORD_ID, "firstName", "Leia");
record1Server1 = retrieveRecord(getDatabaseURL(serverInstance.get(0)), RECORD_ID);
record1Server2 = retrieveRecord(getDatabaseURL(serverInstance.get(1)), RECORD_ID);
record1Server3 = retrieveRecord(getDatabaseURL(serverInstance.get(2)), RECORD_ID);
int finalVersionServer1 = record1Server1.getVersion();
int finalVersionServer2 = record1Server2.getVersion();
int finalVersionServer3 = record1Server3.getVersion();
assertEquals(actualVersion + 1, finalVersionServer1);
assertEquals(actualVersion + 1, finalVersionServer2);
assertEquals(actualVersion + 1, finalVersionServer3);
}
use of com.orientechnologies.orient.server.distributed.impl.ODistributedStorage in project orientdb by orientechnologies.
the class TwoClientsRecordUpdateTxOnThreeServersScenarioTest method executeTest.
@Override
public void executeTest() throws Exception {
ODatabaseDocumentTx dbServer0 = poolFactory.get(getDatabaseURL(serverInstance.get(0)), "admin", "admin").acquire();
ODatabaseDocumentTx dbServer1 = poolFactory.get(getDatabaseURL(serverInstance.get(1)), "admin", "admin").acquire();
// inserts record
ODatabaseRecordThreadLocal.INSTANCE.set(dbServer0);
ODocument recordServer0 = new ODocument("Person").fromMap(hanFields);
recordServer0.save();
// waits for propagation of the record on all the servers
waitForInsertedRecordPropagation(RECORD_ID);
// retrieves record from server1 and server2 and checks they're equal
ODocument recordServer1 = retrieveRecord(getDatabaseURL(serverInstance.get(1)), RECORD_ID);
ODocument recordServer2 = retrieveRecord(getDatabaseURL(serverInstance.get(2)), RECORD_ID);
assertTrue(compareRecords(recordServer0, recordServer1));
assertTrue(compareRecords(recordServer0, recordServer2));
// gets the actual version of the record
int actualVersion = recordServer0.getVersion();
OLogManager.instance().error(this, "Actual version: " + actualVersion);
// sets a delay for operations on distributed storage of server0 and server1
((ODistributedStorage) dbServer0.getStorage()).setEventListener(new AfterRecordLockDelayer("server0", DOCUMENT_WRITE_TIMEOUT / 4));
((ODistributedStorage) dbServer1.getStorage()).setEventListener(new AfterRecordLockDelayer("server1", DOCUMENT_WRITE_TIMEOUT / 2));
// updates the same record from two different clients, each calling a different server (server2 is idle)
List<Callable<Void>> clients = new LinkedList<Callable<Void>>();
clients.add(new RecordUpdater(getDatabaseURL(serverInstance.get(0)), recordServer0, darthFields, true));
clients.add(new RecordUpdater(getDatabaseURL(serverInstance.get(1)), recordServer1, leiaFields, true));
List<Future<Void>> futures = Executors.newCachedThreadPool().invokeAll(clients);
executeFutures(futures);
// Thread.sleep(2000);
// recordServer0 = retrieveRecord(getDatabaseURL(serverInstance.get(0)), RECORD_ID);
// recordServer1 = retrieveRecord(getDatabaseURL(serverInstance.get(1)), RECORD_ID);
// recordServer2 = retrieveRecord(getDatabaseURL(serverInstance.get(2)), RECORD_ID);
//
// OLogManager.instance().error(this, "server0: " + recordServer0.toString() + " v" + recordServer0.getVersion());
// OLogManager.instance().error(this, "server1: " + recordServer1.toString() + " v" + recordServer1.getVersion());
// OLogManager.instance().error(this, "server2: " + recordServer2.toString() + " v" + recordServer2.getVersion());
// checks that record on server0 is the one which wins over the others
System.out.println("serverInstance: " + serverInstance);
waitForUpdatedRecordPropagation(RECORD_ID, "firstName", darthFields.get("firstName").toString());
recordServer0 = retrieveRecord(getDatabaseURL(serverInstance.get(0)), RECORD_ID);
recordServer1 = retrieveRecord(getDatabaseURL(serverInstance.get(1)), RECORD_ID);
recordServer2 = retrieveRecord(getDatabaseURL(serverInstance.get(2)), RECORD_ID);
int finalVersionServer0 = recordServer0.getVersion();
int finalVersionServer1 = recordServer1.getVersion();
int finalVersionServer2 = recordServer2.getVersion();
assertEquals(actualVersion + 1, finalVersionServer0);
assertEquals(actualVersion + 1, finalVersionServer1);
assertEquals(actualVersion + 1, finalVersionServer2);
}
use of com.orientechnologies.orient.server.distributed.impl.ODistributedStorage in project orientdb by orientechnologies.
the class ThreeClientsRecordDeleteWithTransactionsOnMultipleServersScenarioTest method executeTest.
@Override
public void executeTest() throws Exception {
ODatabaseDocumentTx dbServer1 = poolFactory.get(getDatabaseURL(serverInstance.get(0)), "admin", "admin").acquire();
ODatabaseDocumentTx dbServer2 = poolFactory.get(getDatabaseURL(serverInstance.get(1)), "admin", "admin").acquire();
ODatabaseDocumentTx dbServer3 = poolFactory.get(getDatabaseURL(serverInstance.get(2)), "admin", "admin").acquire();
// inserts record1
ODatabaseRecordThreadLocal.INSTANCE.set(dbServer1);
ODocument record1Server1 = new ODocument("Person").fromMap(hanFields);
record1Server1.save();
// waits for propagation of the record on all the servers
waitForInsertedRecordPropagation(RECORD_ID);
// sets a delay for operations on distributed storage of all servers
((ODistributedStorage) dbServer1.getStorage()).setEventListener(new AfterRecordLockDelayer("server1", DOCUMENT_WRITE_TIMEOUT));
((ODistributedStorage) dbServer2.getStorage()).setEventListener(new AfterRecordLockDelayer("server2", DOCUMENT_WRITE_TIMEOUT / 4));
((ODistributedStorage) dbServer3.getStorage()).setEventListener(new AfterRecordLockDelayer("server3", DOCUMENT_WRITE_TIMEOUT / 2));
// deletes the same record from three different clients, each calling a different server
List<Callable<Void>> clients = new LinkedList<Callable<Void>>();
clients.add(new RecordDeleter(getDatabaseURL(serverInstance.get(0)), RECORD_ID, true));
clients.add(new RecordDeleter(getDatabaseURL(serverInstance.get(1)), RECORD_ID, true));
clients.add(new RecordDeleter(getDatabaseURL(serverInstance.get(2)), RECORD_ID, true));
List<Future<Void>> futures = Executors.newCachedThreadPool().invokeAll(clients);
executeFutures(futures);
waitForDeletedRecordPropagation(RECORD_ID);
assertTrue(retrieveRecordOrReturnMissing(getDatabaseURL(serverInstance.get(0)), RECORD_ID) == MISSING_DOCUMENT);
assertTrue(retrieveRecordOrReturnMissing(getDatabaseURL(serverInstance.get(1)), RECORD_ID) == MISSING_DOCUMENT);
assertTrue(retrieveRecordOrReturnMissing(getDatabaseURL(serverInstance.get(2)), RECORD_ID) == MISSING_DOCUMENT);
}
use of com.orientechnologies.orient.server.distributed.impl.ODistributedStorage in project orientdb by orientechnologies.
the class TwoClientsRecordUpdateDuringRetryWithTransactionsOnMultipleServersScenarioTest method executeTest.
@Override
public void executeTest() throws Exception {
ODatabaseDocumentTx dbServer1 = poolFactory.get(getDatabaseURL(serverInstance.get(0)), "admin", "admin").acquire();
ODatabaseDocumentTx dbServer2 = poolFactory.get(getDatabaseURL(serverInstance.get(1)), "admin", "admin").acquire();
// inserts record1
ODatabaseRecordThreadLocal.INSTANCE.set(dbServer2);
ODocument record1Server1 = new ODocument("Person").fields("id", RECORD_ID, "firstName", "Han", "lastName", "Solo");
record1Server1.save();
// waits for propagation of the record on all the servers
waitForInsertedRecordPropagation(RECORD_ID);
// gets the actual version of record1
int actualVersion = record1Server1.getVersion();
// sets a delay for operations on distributed storage of server1 and server2
// so that server1 will start to commit after server2 has started the transaction
((ODistributedStorage) dbServer2.getStorage()).setEventListener(new AfterRecordLockDelayer("server2", 1000));
((ODistributedStorage) dbServer1.getStorage()).setEventListener(new AfterRecordLockDelayer("server1", 250));
// updates the same record from two different clients, each calling a different node
ODocument record1Server2 = retrieveRecord(getDatabaseURL(serverInstance.get(1)), RECORD_ID);
List<Callable<Void>> clients = new LinkedList<Callable<Void>>();
clients.add(new RecordUpdater(getDatabaseURL(serverInstance.get(0)), record1Server1, lukeFields, true));
clients.add(new RecordUpdater(getDatabaseURL(serverInstance.get(1)), record1Server2, darthFields, true));
List<Future<Void>> futures = Executors.newCachedThreadPool().invokeAll(clients);
executeFutures(futures);
// checks that record on server1 is discarded in favour of record present on server2
waitForUpdatedRecordPropagation(RECORD_ID, "firstName", "Darth");
record1Server1 = retrieveRecord(getDatabaseURL(serverInstance.get(0)), RECORD_ID);
record1Server2 = retrieveRecord(getDatabaseURL(serverInstance.get(1)), RECORD_ID);
int finalVersionServer1 = record1Server1.field("@version");
int finalVersionServer2 = record1Server2.field("@version");
assertEquals(finalVersionServer1, actualVersion + 1);
assertEquals(finalVersionServer2, actualVersion + 1);
}
use of com.orientechnologies.orient.server.distributed.impl.ODistributedStorage in project orientdb by orientechnologies.
the class TwoClientsRecordUpdateTxOnTwoServersWithQuorum2ScenarioTest method executeTest.
@Override
public void executeTest() throws Exception {
setWriteQuorum(2);
ODatabaseDocumentTx dbServer0 = poolFactory.get(getDatabaseURL(serverInstance.get(0)), "admin", "admin").acquire();
// inserts record
ODatabaseRecordThreadLocal.INSTANCE.set(dbServer0);
ODocument recordServer0 = new ODocument("Person").fields("id", RECORD_ID, "firstName", "Han", "lastName", "Solo");
recordServer0.save();
// waits for propagation of the record on all the servers
waitForInsertedRecordPropagation(RECORD_ID);
// retrieves record from server1 and checks they're equal
ODocument recordServer1 = retrieveRecord(getDatabaseURL(serverInstance.get(1)), RECORD_ID);
assertEquals(recordServer1.getVersion(), recordServer0.getVersion());
assertEquals(recordServer1.field("id"), recordServer0.field("id"));
assertEquals(recordServer1.field("firstName"), recordServer0.field("firstName"));
assertEquals(recordServer1.field("lastName"), recordServer0.field("lastName"));
// gets the actual version of record from server0
int actualVersion = recordServer0.getVersion();
// sets a delay for operations on distributed storage of server0
((ODistributedStorage) dbServer0.getStorage()).setEventListener(new AfterRecordLockDelayer("server0", DOCUMENT_WRITE_TIMEOUT / 4));
// updates the same record from two different clients, each calling a different node
List<Callable<Void>> clients = new LinkedList<Callable<Void>>();
clients.add(new RecordUpdater(getDatabaseURL(serverInstance.get(0)), recordServer0, lukeFields, true));
clients.add(new RecordUpdater(getDatabaseURL(serverInstance.get(1)), recordServer1, darthFields, true));
List<Future<Void>> futures = Executors.newCachedThreadPool().invokeAll(clients);
executeFutures(futures);
// checks that record on server1 is discarded in favour of record present on server0
waitForUpdatedRecordPropagation(RECORD_ID, "firstName", lukeFields.get("firstName").toString());
recordServer0 = retrieveRecord(getDatabaseURL(serverInstance.get(0)), RECORD_ID);
recordServer1 = retrieveRecord(getDatabaseURL(serverInstance.get(1)), RECORD_ID);
int finalVersionServer0 = recordServer0.getVersion();
int finalVersionServer1 = recordServer1.getVersion();
assertEquals(finalVersionServer0, actualVersion + 1);
assertEquals(finalVersionServer1, actualVersion + 1);
}
Aggregations