use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.
the class LuceneInsertMultithreadTest method testConcurrentInsertWithIndex.
@Test
public void testConcurrentInsertWithIndex() throws Exception {
databaseDocumentTx = new ODatabaseDocumentTx(url);
if (!url.contains("remote:") && databaseDocumentTx.exists()) {
databaseDocumentTx.open("admin", "admin");
databaseDocumentTx.drop();
databaseDocumentTx.create();
} else {
databaseDocumentTx.create();
}
OSchema schema = databaseDocumentTx.getMetadata().getSchema();
if (schema.getClass("City") == null) {
OClass oClass = schema.createClass("City");
oClass.createProperty("name", OType.STRING);
oClass.createIndex("City.name", "FULLTEXT", null, null, "LUCENE", new String[] { "name" });
}
Thread[] threads = new Thread[THREADS + RTHREADS];
for (int i = 0; i < THREADS; ++i) threads[i] = new Thread(new LuceneInsertThread(CYCLE), "ConcurrentWriteTest" + i);
for (int i = THREADS; i < THREADS + RTHREADS; ++i) threads[i] = new Thread(new LuceneReadThread(CYCLE), "ConcurrentReadTest" + i);
for (int i = 0; i < THREADS + RTHREADS; ++i) threads[i].start();
for (int i = 0; i < THREADS + RTHREADS; ++i) threads[i].join();
OIndex idx = schema.getClass("City").getClassIndex("City.name");
Assert.assertEquals(idx.getSize(), THREADS * CYCLE);
databaseDocumentTx.drop();
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.
the class BrowseSpeedTest method browseStorageClusters.
protected void browseStorageClusters() throws IOException {
ODatabaseDocumentTx db = openDatabase();
final long total = db.countClass(CLASS);
final OClass cls = db.getMetadata().getSchema().getClass(CLASS);
final int[] clIds = cls.getPolymorphicClusterIds();
long start = System.currentTimeMillis();
int loaded = 0;
ORecord rec;
for (int clId : clIds) {
OCluster cluster = db.getStorage().getClusterById(clId);
final long clusterRecords = cluster.getEntries();
for (long rid = 0; rid < clusterRecords; ++rid) {
final ORawBuffer buffer = cluster.readRecord(rid, true);
loaded++;
}
}
long end = System.currentTimeMillis();
System.out.println("Browse clusters " + total + " and loaded " + loaded + " took " + (end - start));
db.close();
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.
the class CRUDObjectInheritanceTestSchemaFull method beforeClass.
@BeforeClass
public void beforeClass() throws Exception {
super.beforeClass();
database.close();
database = new OObjectDatabaseTx(url + "_objectschema");
ODatabaseHelper.dropDatabase(database, getStorageType());
ODatabaseHelper.createDatabase(database, url + "_objectschema", getStorageType());
try {
ODatabaseDocumentTx exportDatabase = new ODatabaseDocumentTx(url);
exportDatabase.open("admin", "admin");
OCommandOutputListener listener = new OCommandOutputListener() {
@Override
public void onMessage(String iText) {
}
};
ODatabaseExport export = new ODatabaseExport(exportDatabase, EXPORT_DIR, listener);
export.exportDatabase();
export.close();
exportDatabase.close();
ODatabaseDocumentTx importDatabase = new ODatabaseDocumentTx(url + "_objectschema");
if (url.startsWith("remote")) {
importDatabase.open("root", ODatabaseHelper.getServerRootPassword());
} else {
importDatabase.open("admin", "admin");
}
ODatabaseImport impor = new ODatabaseImport(importDatabase, EXPORT_DIR, listener);
// UNREGISTER ALL THE HOOKS
for (ORecordHook hook : new ArrayList<ORecordHook>(importDatabase.getHooks().keySet())) {
importDatabase.unregisterHook(hook);
}
impor.setDeleteRIDMapping(true);
impor.importDatabase();
impor.close();
importDatabase.close();
final File importDir = new File(EXPORT_DIR);
importDir.delete();
} catch (IOException e) {
Assert.fail("Export import didn't go as expected", e);
}
database.open("admin", "admin");
if (database.getMetadata().getSchema().existsClass("Company"))
database.command(new OCommandSQL("delete from Company")).execute();
if (database.getMetadata().getSchema().existsClass("Account"))
database.command(new OCommandSQL("delete from Account")).execute();
if (database.getMetadata().getSchema().existsClass("JavaComplexTestClass"))
database.command(new OCommandSQL("delete from JavaComplexTestClass")).execute();
if (database.getMetadata().getSchema().existsClass("Profile"))
database.command(new OCommandSQL("delete from Profile")).execute();
if (database.getMetadata().getSchema().existsClass("IdentityChild"))
database.command(new OCommandSQL("delete from IdentityChild")).execute();
database.close();
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.
the class CRUDDocumentPhysicalTest method testPool.
@Test
public void testPool() throws IOException {
OPartitionedDatabasePool pool = new OPartitionedDatabasePool(url, "admin", "admin");
final ODatabaseDocumentTx[] dbs = new ODatabaseDocumentTx[pool.getMaxPartitonSize()];
for (int i = 0; i < 10; ++i) {
for (int db = 0; db < dbs.length; ++db) dbs[db] = pool.acquire();
for (int db = 0; db < dbs.length; ++db) dbs[db].close();
}
pool.close();
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx in project orientdb by orientechnologies.
the class CRUDDocumentPhysicalTest method asynchInsertion.
@Test(dependsOnMethods = "cleanAll")
public void asynchInsertion() {
startRecordNumber = database.countClusterElements("Account");
final AtomicInteger callBackCalled = new AtomicInteger();
final long total = startRecordNumber + TOT_RECORDS;
for (long i = startRecordNumber; i < total; ++i) {
record.reset();
record.setClassName("Account");
record.field("id", i);
record.field("name", "Asynch insertion test");
record.field("location", "Italy");
record.field("salary", (i + 300));
database.save(record, OPERATION_MODE.ASYNCHRONOUS, false, new ORecordCallback<Long>() {
@Override
public void call(ORecordId iRID, Long iParameter) {
callBackCalled.incrementAndGet();
}
}, null);
}
while (callBackCalled.intValue() < total) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
}
Assert.assertEquals(callBackCalled.intValue(), total);
// WAIT UNTIL ALL RECORD ARE INSERTED. USE A NEW DATABASE CONNECTION
// TO AVOID TO ENQUEUE THE COUNT ITSELF
final Thread t = new Thread(new Runnable() {
@Override
public void run() {
final ODatabaseDocumentTx db = new ODatabaseDocumentTx(url).open("admin", "admin");
long tot;
while ((tot = db.countClusterElements("Account")) < startRecordNumber + TOT_RECORDS) {
// + " is reached");
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
}
db.close();
}
});
t.start();
try {
t.join();
} catch (InterruptedException e) {
}
if (database.countClusterElements("Account") > 0)
for (ODocument d : database.browseClass("Account")) {
if (d.field("name").equals("Asynch insertion test"))
d.delete();
}
}
Aggregations