use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.
the class TransactionIsolationTest method testIsolationReadCommitted.
@Test
public void testIsolationReadCommitted() throws IOException {
ODatabaseDocumentTx db1 = new ODatabaseDocumentTx(url);
db1.open("admin", "admin");
ODocument record1 = new ODocument();
record1.field("name", "This is the first version").save();
db1.begin();
db1.getTransaction().setIsolationLevel(OTransaction.ISOLATION_LEVEL.READ_COMMITTED);
// RE-READ THE RECORD
record1.getIdentity().getRecord();
// CHANGE THE RECORD FROM DB2
ODatabaseDocumentTx db2 = new ODatabaseDocumentTx(url);
db2.open("admin", "admin");
ODocument record2 = db2.load(record1.getIdentity());
record2.field("name", "This is the second version").save();
db1.activateOnCurrentThread();
db1.reload(record1, null, true);
Assert.assertEquals(record1.field("name"), "This is the second version");
db1.close();
db2.activateOnCurrentThread();
db2.close();
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.
the class TransactionIsolationTest method testIsolationRepeatableRead.
@Test
public void testIsolationRepeatableRead() throws IOException {
ODatabaseDocumentTx db1 = new ODatabaseDocumentTx(url);
db1.open("admin", "admin");
ODocument record1 = new ODocument();
record1.field("name", "This is the first version").save();
db1.begin();
try {
db1.getTransaction().setIsolationLevel(OTransaction.ISOLATION_LEVEL.REPEATABLE_READ);
// RE-READ THE RECORD
record1.getIdentity().getRecord();
// CHANGE THE RECORD FROM DB2
ODatabaseDocumentTx db2 = new ODatabaseDocumentTx(url);
db2.open("admin", "admin");
ODocument record2 = db2.load(record1.getIdentity());
record2.field("name", "This is the second version").save();
db2.close();
db1.activateOnCurrentThread();
db1.reload(record1, null, true);
Assert.assertEquals(record1.field("name"), "This is the first version");
} catch (IllegalArgumentException e) {
if (!url.startsWith("remote:"))
// NOT SUPPORTED IN REMOTE MODE
Assert.assertFalse(true);
}
db1.close();
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.
the class TransactionOptimisticTest method testNestedTxRollbackOne.
public void testNestedTxRollbackOne() throws Exception {
final ExecutorService executorService = Executors.newSingleThreadExecutor();
final Callable<Void> assertEmptyRecord = new Callable<Void>() {
@Override
public Void call() throws Exception {
final ODatabaseDocumentTx db = new ODatabaseDocumentTx(database.getURL());
db.open("admin", "admin");
try {
Assert.assertEquals(db.countClass("NestedTxRollbackOne"), 1);
} finally {
db.close();
}
return null;
}
};
final OSchema schema = database.getMetadata().getSchema();
if (!schema.existsClass("NestedTxRollbackOne"))
schema.createClass("NestedTxRollbackOne");
ODocument brokenDocOne = new ODocument("NestedTxRollbackOne");
brokenDocOne.save();
brokenDocOne = database.load(brokenDocOne.getIdentity(), "*:-1", true);
ODocument brokenDocTwo = database.load(brokenDocOne.getIdentity(), "*:-1", true);
brokenDocTwo.setDirty();
brokenDocTwo.field("v", "vstr");
brokenDocTwo.save();
try {
database.begin();
final ODocument externalDocOne = new ODocument("NestedTxRollbackOne");
externalDocOne.field("v", "val1");
externalDocOne.save();
Future assertFuture = executorService.submit(assertEmptyRecord);
assertFuture.get();
database.begin();
ODocument externalDocTwo = new ODocument("NestedTxRollbackOne");
externalDocTwo.field("v", "val2");
externalDocTwo.save();
assertFuture = executorService.submit(assertEmptyRecord);
assertFuture.get();
brokenDocOne.setDirty();
brokenDocOne.save();
database.commit();
assertFuture = executorService.submit(assertEmptyRecord);
assertFuture.get();
final ODocument externalDocThree = new ODocument("NestedTxRollbackOne");
externalDocThree.field("v", "val3");
externalDocThree.save();
database.commit();
Assert.fail();
} catch (OConcurrentModificationException e) {
database.rollback();
}
Assert.assertTrue(!database.getTransaction().isActive());
Assert.assertEquals(database.countClass("NestedTxRollbackOne"), 1);
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.
the class ServerTest method testOpenCloseCreateClass.
@Test
public void testOpenCloseCreateClass() throws IOException {
OServerAdmin admin = new OServerAdmin("remote:localhost/doubleOpenTest");
admin.connect("root", ODatabaseHelper.getServerRootPassword());
admin.createDatabase("document", "memory");
admin.close();
ODatabaseDocument db = new ODatabaseDocumentTx("remote:localhost/doubleOpenTest");
try {
db.open("admin", "admin");
ODocument d = new ODocument("User");
d.save();
} finally {
db.close();
}
try {
db.open("admin", "admin");
ODocument d = new ODocument("User");
d.save();
} finally {
db.close();
}
admin = new OServerAdmin("remote:localhost/doubleOpenTest");
admin.connect("root", ODatabaseHelper.getServerRootPassword());
admin.dropDatabase("memory");
admin.close();
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.
the class LocalCreateAsynchDocumentSpeedTest method init.
@Override
public void init() {
Orient.instance().getProfiler().startRecording();
OGlobalConfiguration.NETWORK_SOCKET_BUFFER_SIZE.setValue(10000000);
database = new ODatabaseDocumentTx(System.getProperty("url")).open("admin", "admin");
record = database.newInstance();
database.declareIntent(new OIntentMassiveInsert());
database.begin(TXTYPE.NOTX);
}
Aggregations