Search in sources :

Example 51 with ODatabaseDocumentTx

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();
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OIndex(com.orientechnologies.orient.core.index.OIndex) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) Test(org.junit.Test)

Example 52 with ODatabaseDocumentTx

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();
}
Also used : ORawBuffer(com.orientechnologies.orient.core.storage.ORawBuffer) ORecord(com.orientechnologies.orient.core.record.ORecord) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OCluster(com.orientechnologies.orient.core.storage.OCluster)

Example 53 with ODatabaseDocumentTx

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();
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ODatabaseImport(com.orientechnologies.orient.core.db.tool.ODatabaseImport) OObjectDatabaseTx(com.orientechnologies.orient.object.db.OObjectDatabaseTx) ArrayList(java.util.ArrayList) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) IOException(java.io.IOException) OCommandOutputListener(com.orientechnologies.orient.core.command.OCommandOutputListener) File(java.io.File) ORecordHook(com.orientechnologies.orient.core.hook.ORecordHook) ODatabaseExport(com.orientechnologies.orient.core.db.tool.ODatabaseExport) BeforeClass(org.testng.annotations.BeforeClass)

Example 54 with ODatabaseDocumentTx

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();
}
Also used : OPartitionedDatabasePool(com.orientechnologies.orient.core.db.OPartitionedDatabasePool) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) Test(org.testng.annotations.Test)

Example 55 with ODatabaseDocumentTx

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();
        }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ORecordId(com.orientechnologies.orient.core.id.ORecordId) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Aggregations

ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)590 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)257 Test (org.testng.annotations.Test)182 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)120 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)81 Test (org.junit.Test)79 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)61 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)47 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)46 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)41 ORID (com.orientechnologies.orient.core.id.ORID)39 ORecordId (com.orientechnologies.orient.core.id.ORecordId)34 Before (org.junit.Before)34 File (java.io.File)33 OProperty (com.orientechnologies.orient.core.metadata.schema.OProperty)25 ArrayList (java.util.ArrayList)25 BeforeClass (org.testng.annotations.BeforeClass)23 BeforeMethod (org.testng.annotations.BeforeMethod)23 OStorage (com.orientechnologies.orient.core.storage.OStorage)21 List (java.util.List)20