use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.
the class OSequenceTest method shouldSequenceMTTx.
@Test
@Ignore
public void shouldSequenceMTTx() throws Exception {
OSequence.CreateParams params = new OSequence.CreateParams().setStart(0L);
OSequence mtSeq = sequences.createSequence("mtSeq", OSequence.SEQUENCE_TYPE.ORDERED, params);
final int count = 1000;
final int threads = 2;
final CountDownLatch latch = new CountDownLatch(count);
final AtomicInteger errors = new AtomicInteger(0);
final AtomicInteger success = new AtomicInteger(0);
ExecutorService service = Executors.newFixedThreadPool(threads);
for (int i = 0; i < threads; i++) {
service.execute(new Runnable() {
@Override
public void run() {
ODatabaseDocument databaseDocument = new ODatabaseDocumentTx("memory:" + OSequenceTest.class.getName());
databaseDocument.open("admin", "admin");
OSequence mtSeq1 = databaseDocument.getMetadata().getSequenceLibrary().getSequence("mtSeq");
for (int j = 0; j < count / threads; j++) {
for (int retry = 0; retry < 10; ++retry) {
try {
databaseDocument.begin();
mtSeq1.next();
databaseDocument.commit();
success.incrementAndGet();
break;
} catch (OConcurrentModificationException e) {
if (retry >= 10) {
e.printStackTrace();
errors.incrementAndGet();
break;
}
// RETRY
try {
Thread.sleep(10 + new Random().nextInt(100));
} catch (InterruptedException e1) {
}
mtSeq1.reloadSequence();
continue;
} catch (Exception e) {
e.printStackTrace();
errors.incrementAndGet();
}
}
latch.countDown();
}
}
});
}
latch.await();
assertThat(errors.get()).isEqualTo(0);
assertThat(success.get()).isEqualTo(1000);
mtSeq.reloadSequence();
assertThat(mtSeq.getDocument().getVersion()).isEqualTo(1001);
assertThat(mtSeq.current()).isEqualTo(1000);
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.
the class ClassIteratorTest method initializeDatabase.
private static void initializeDatabase() {
db = new ODatabaseDocumentTx("memory:" + ClassIteratorTest.class.getSimpleName());
if (db.exists() && RECREATE_DATABASE) {
db.open("admin", "admin");
db.drop();
System.out.println("Dropped database.");
}
if (!db.exists()) {
db.create();
System.out.println("Created database.");
final OSchema schema = db.getMetadata().getSchema();
// Create Person class
final OClass personClass = schema.createClass("Person");
personClass.createProperty("First", OType.STRING).setMandatory(true).setNotNull(true).setMin("1");
System.out.println("Created schema.");
} else {
db.open("admin", "admin");
}
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.
the class OFunctionLibraryTest method before.
@BeforeMethod
public void before() {
db = new ODatabaseDocumentTx("memory:" + OFunctionLibraryTest.class.getSimpleName());
db.create();
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.
the class ODocumentSchemafullSerializationTest method before.
@BeforeMethod
public void before() {
ODatabaseDocumentTx.setDefaultSerializer(serializer);
databaseDocument = new ODatabaseDocumentTx("memory:" + ODocumentSchemafullSerializationTest.class.getSimpleName()).create();
// databaseDocument.getMetadata().
OSchema schema = databaseDocument.getMetadata().getSchema();
address = schema.createClass("Address");
address.createProperty(NAME, OType.STRING);
address.createProperty(NUMBER, OType.INTEGER);
address.createProperty(CITY, OType.STRING);
simple = schema.createClass("Simple");
simple.createProperty(STRING_FIELD, OType.STRING);
simple.createProperty(INT_FIELD, OType.INTEGER);
simple.createProperty(SHORT_FIELD, OType.SHORT);
simple.createProperty(LONG_FIELD, OType.LONG);
simple.createProperty(FLOAT_NUMBER, OType.FLOAT);
simple.createProperty(DOUBLE_NUMBER, OType.DOUBLE);
simple.createProperty(BYTE_FIELD, OType.BYTE);
simple.createProperty(BOOLEAN_FIELD, OType.BOOLEAN);
simple.createProperty(DATE_FIELD, OType.DATETIME);
simple.createProperty(RECORDID_FIELD, OType.LINK);
simple.createProperty(EMBEDDED_FIELD, OType.EMBEDDED, address);
simple.createProperty(ANY_FIELD, OType.ANY);
embSimp = schema.createClass("EmbeddedCollectionSimple");
embSimp.createProperty(LIST_BOOLEANS, OType.EMBEDDEDLIST);
embSimp.createProperty(LIST_BYTES, OType.EMBEDDEDLIST);
embSimp.createProperty(LIST_DATES, OType.EMBEDDEDLIST);
embSimp.createProperty(LIST_DOUBLES, OType.EMBEDDEDLIST);
embSimp.createProperty(LIST_FLOATS, OType.EMBEDDEDLIST);
embSimp.createProperty(LIST_INTEGERS, OType.EMBEDDEDLIST);
embSimp.createProperty(LIST_LONGS, OType.EMBEDDEDLIST);
embSimp.createProperty(LIST_SHORTS, OType.EMBEDDEDLIST);
embSimp.createProperty(LIST_STRINGS, OType.EMBEDDEDLIST);
embSimp.createProperty(LIST_MIXED, OType.EMBEDDEDLIST);
embMapSimple = schema.createClass("EmbeddedMapSimple");
embMapSimple.createProperty(MAP_BYTES, OType.EMBEDDEDMAP);
embMapSimple.createProperty(MAP_DATE, OType.EMBEDDEDMAP);
embMapSimple.createProperty(MAP_DOUBLE, OType.EMBEDDEDMAP);
embMapSimple.createProperty(MAP_FLOAT, OType.EMBEDDEDMAP);
embMapSimple.createProperty(MAP_INT, OType.EMBEDDEDMAP);
embMapSimple.createProperty(MAP_LONG, OType.EMBEDDEDMAP);
embMapSimple.createProperty(MAP_SHORT, OType.EMBEDDEDMAP);
embMapSimple.createProperty(MAP_STRING, OType.EMBEDDEDMAP);
OClass clazzEmbComp = schema.createClass("EmbeddedComplex");
clazzEmbComp.createProperty("addresses", OType.EMBEDDEDLIST, address);
clazzEmbComp.createProperty("uniqueAddresses", OType.EMBEDDEDSET, address);
clazzEmbComp.createProperty("addressByStreet", OType.EMBEDDEDMAP, address);
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.
the class ODocumentSchemalessBinarySerializationTest method testLinkCollections.
@Test
public void testLinkCollections() {
ODatabaseDocument db = new ODatabaseDocumentTx("memory:ODocumentSchemalessBinarySerializationTest").create();
try {
ODocument document = new ODocument();
Set<ORecordId> linkSet = new HashSet<ORecordId>();
linkSet.add(new ORecordId(10, 20));
linkSet.add(new ORecordId(10, 21));
linkSet.add(new ORecordId(10, 22));
linkSet.add(new ORecordId(11, 22));
document.field("linkSet", linkSet, OType.LINKSET);
List<ORecordId> linkList = new ArrayList<ORecordId>();
linkList.add(new ORecordId(10, 20));
linkList.add(new ORecordId(10, 21));
linkList.add(new ORecordId(10, 22));
linkList.add(new ORecordId(11, 22));
document.field("linkList", linkList, OType.LINKLIST);
byte[] res = serializer.toStream(document, false);
ODocument extr = (ODocument) serializer.fromStream(res, new ODocument(), new String[] {});
assertEquals(extr.fields(), document.fields());
assertEquals(((Set<?>) extr.field("linkSet")).size(), ((Set<?>) document.field("linkSet")).size());
assertTrue(((Set<?>) extr.field("linkSet")).containsAll((Set<?>) document.field("linkSet")));
assertEquals(extr.field("linkList"), document.field("linkList"));
} finally {
db.drop();
}
}
Aggregations