Search in sources :

Example 11 with OPartitionedDatabasePool

use of com.orientechnologies.orient.core.db.OPartitionedDatabasePool in project orientdb by orientechnologies.

the class OrientDbWriteLotsOfDataTest method testThreaded.

public void testThreaded(int numthreads, TXTYPE txtype) throws InterruptedException {
    // create document pool
    OPartitionedDatabasePool pool = new OPartitionedDatabasePool(DBURI, DBUSR, DBPWD);
    // create the schema for the test class if it doesn't exist
    ODatabaseDocumentTx db = pool.acquire();
    try {
        OSchema schema = db.getMetadata().getSchema();
        if (!schema.existsClass(CLASSNAME)) {
            OClass oc = schema.createClass(CLASSNAME);
            oc.createProperty(PROPKEY, OType.STRING);
            oc.setStrictMode(true);
            schema.save();
        }
    } finally {
        db.close();
    }
    // create threads and execute
    // create threads, put into list
    ArrayList<RunTest> threads = new ArrayList<RunTest>(1000);
    for (int numth = 0; numth < numthreads; numth++) {
        threads.add(new RunTest(pool, txtype));
    }
    // run test: start each thread and wait for all threads to complete with join
    long a = System.currentTimeMillis();
    for (RunTest t : threads) {
        t.start();
    }
    for (RunTest t : threads) {
        t.join();
    }
    long b = System.currentTimeMillis();
    // collect from each thread
    int savesum = 0;
    int txnsum = 0;
    for (RunTest t : threads) {
        t.printStats();
        savesum += t.getTotalSaves();
        txnsum += t.getTotalTxns();
    }
    // print out cummulative stats
    double secs = 1.0E-3D * (b - a);
    System.out.printf("TOTAL: [%4.2f secs %d tx, %d save] %.2f tx/sec %.2f save/sec \n", secs, txnsum, savesum, txnsum / secs, savesum / secs);
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OPartitionedDatabasePool(com.orientechnologies.orient.core.db.OPartitionedDatabasePool) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ArrayList(java.util.ArrayList) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)

Example 12 with OPartitionedDatabasePool

use of com.orientechnologies.orient.core.db.OPartitionedDatabasePool in project orientdb by orientechnologies.

the class ODatabaseDocumentPoolOpenCloseTest method failureOpenPoolDatabase.

@Test(expectedExceptions = ODatabaseException.class)
public void failureOpenPoolDatabase() {
    String url = "memory:" + ODatabaseDocumentPoolOpenCloseTest.class.getSimpleName();
    ODatabaseDocument dbo = new ODatabaseDocumentTx(url).create();
    OPartitionedDatabasePool pool = new OPartitionedDatabasePool(url, "admin", "admin");
    try {
        ODatabaseDocument db = pool.acquire();
        db.open("admin", "admin");
    } finally {
        pool.close();
        dbo.activateOnCurrentThread();
        dbo.drop();
    }
}
Also used : OPartitionedDatabasePool(com.orientechnologies.orient.core.db.OPartitionedDatabasePool) Test(org.testng.annotations.Test)

Example 13 with OPartitionedDatabasePool

use of com.orientechnologies.orient.core.db.OPartitionedDatabasePool in project orientdb by orientechnologies.

the class ODatabaseDocumentPoolOpenCloseTest method openCloseClearThreadLocal.

@Test
public void openCloseClearThreadLocal() {
    String url = "memory:" + ODatabaseDocumentPoolOpenCloseTest.class.getSimpleName();
    ODatabaseDocument dbo = new ODatabaseDocumentTx(url).create();
    OPartitionedDatabasePool pool = new OPartitionedDatabasePool(url, "admin", "admin");
    try {
        ODatabaseDocument db = pool.acquire();
        db.close();
        assertNull(ODatabaseRecordThreadLocal.INSTANCE.getIfDefined());
    } finally {
        pool.close();
        dbo.activateOnCurrentThread();
        dbo.drop();
    }
}
Also used : OPartitionedDatabasePool(com.orientechnologies.orient.core.db.OPartitionedDatabasePool) Test(org.testng.annotations.Test)

Example 14 with OPartitionedDatabasePool

use of com.orientechnologies.orient.core.db.OPartitionedDatabasePool in project orientdb by orientechnologies.

the class ODatabaseDocumentPoolOpenCloseTest method checkSchemaRefresh.

@Test
public void checkSchemaRefresh() throws ExecutionException, InterruptedException {
    String url = "memory:" + ODatabaseDocumentPoolOpenCloseTest.class.getSimpleName();
    ODatabaseDocument dbo = new ODatabaseDocumentTx(url).create();
    final OPartitionedDatabasePool pool = new OPartitionedDatabasePool(url, "admin", "admin");
    try {
        ODatabaseDocument db = pool.acquire();
        ExecutorService exec = Executors.newSingleThreadExecutor();
        Future f = exec.submit(new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                ODatabaseDocument db1 = pool.acquire();
                db1.getMetadata().getSchema().createClass("Test");
                db1.close();
                return null;
            }
        });
        f.get();
        exec.shutdown();
        db.activateOnCurrentThread();
        OClass clazz = db.getMetadata().getSchema().getClass("Test");
        assertNotNull(clazz);
        db.close();
    } finally {
        pool.close();
        dbo.activateOnCurrentThread();
        dbo.drop();
    }
}
Also used : OPartitionedDatabasePool(com.orientechnologies.orient.core.db.OPartitionedDatabasePool) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException) Test(org.testng.annotations.Test)

Example 15 with OPartitionedDatabasePool

use of com.orientechnologies.orient.core.db.OPartitionedDatabasePool in project orientdb by orientechnologies.

the class StorageBackupMTStateTest method testRun.

public void testRun() throws Exception {
    String buildDirectory = System.getProperty("buildDirectory", ".");
    String dbDirectory = buildDirectory + File.separator + StorageBackupMTStateTest.class.getSimpleName();
    System.out.println("Clean up old data");
    OFileUtils.deleteRecursively(new File(dbDirectory));
    final String backedUpDbDirectory = buildDirectory + File.separator + StorageBackupMTStateTest.class.getSimpleName() + "BackUp";
    OFileUtils.deleteRecursively(new File(backedUpDbDirectory));
    backupDir = new File(buildDirectory, StorageBackupMTStateTest.class.getSimpleName() + "BackupDir");
    OFileUtils.deleteRecursively(backupDir);
    if (!backupDir.exists())
        Assert.assertTrue(backupDir.mkdirs());
    dbURL = "plocal:" + dbDirectory;
    System.out.println("Create database");
    ODatabaseDocumentTx databaseDocumentTx = new ODatabaseDocumentTx(dbURL);
    databaseDocumentTx.create();
    System.out.println("Create schema");
    final OSchema schema = databaseDocumentTx.getMetadata().getSchema();
    for (int i = 0; i < 3; i++) {
        createClass(schema);
    }
    databaseDocumentTx.close();
    pool = new OPartitionedDatabasePool(dbURL, "admin", "admin");
    System.out.println("Start data modification");
    final ExecutorService executor = Executors.newFixedThreadPool(5);
    final ScheduledExecutorService backupExecutor = Executors.newSingleThreadScheduledExecutor();
    final ScheduledExecutorService classCreatorExecutor = Executors.newSingleThreadScheduledExecutor();
    final ScheduledExecutorService classDeleterExecutor = Executors.newSingleThreadScheduledExecutor();
    classDeleterExecutor.scheduleWithFixedDelay(new ClassDeleter(), 10, 10, TimeUnit.MINUTES);
    backupExecutor.scheduleWithFixedDelay(new IncrementalBackupThread(), 5, 5, TimeUnit.MINUTES);
    classCreatorExecutor.scheduleWithFixedDelay(new ClassAdder(), 7, 5, TimeUnit.MINUTES);
    List<Future<Void>> futures = new ArrayList<Future<Void>>();
    futures.add(executor.submit(new NonTxInserter()));
    futures.add(executor.submit(new NonTxInserter()));
    futures.add(executor.submit(new TxInserter()));
    futures.add(executor.submit(new TxInserter()));
    futures.add(executor.submit(new RecordsDeleter()));
    int k = 0;
    while (k < 180) {
        Thread.sleep(30 * 1000);
        k++;
        System.out.println(k * 0.5 + " minutes...");
    }
    stop = true;
    System.out.println("Stop backup");
    backupExecutor.shutdown();
    System.out.println("Stop class creation/deletion");
    classCreatorExecutor.shutdown();
    classDeleterExecutor.shutdown();
    backupExecutor.awaitTermination(15, TimeUnit.MINUTES);
    classCreatorExecutor.awaitTermination(15, TimeUnit.MINUTES);
    classDeleterExecutor.awaitTermination(15, TimeUnit.MINUTES);
    System.out.println("Stop data threads");
    for (Future<Void> future : futures) future.get();
    System.out.println("All threads are stopped");
    pool.close();
    System.out.println("Final incremental  backup");
    databaseDocumentTx = new ODatabaseDocumentTx(dbURL);
    databaseDocumentTx.open("admin", "admin");
    databaseDocumentTx.incrementalBackup(backupDir.getAbsolutePath());
    OStorage storage = databaseDocumentTx.getStorage();
    databaseDocumentTx.close();
    storage.close(true, false);
    System.out.println("Create backup database");
    final ODatabaseDocumentTx backedUpDb = new ODatabaseDocumentTx("plocal:" + backedUpDbDirectory);
    backedUpDb.create(backupDir.getAbsolutePath());
    final OStorage backupStorage = backedUpDb.getStorage();
    backedUpDb.close();
    backupStorage.close(true, false);
    System.out.println("Compare databases");
    final ODatabaseCompare compare = new ODatabaseCompare("plocal:" + dbDirectory, "plocal:" + backedUpDbDirectory, "admin", "admin", new OCommandOutputListener() {

        @Override
        public void onMessage(String iText) {
            System.out.println(iText);
        }
    });
    Assert.assertTrue(compare.compare());
    System.out.println("Drop databases and backup directory");
    databaseDocumentTx.open("admin", "admin");
    databaseDocumentTx.drop();
    backedUpDb.open("admin", "admin");
    backedUpDb.drop();
    OFileUtils.deleteRecursively(backupDir);
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) ODatabaseCompare(com.orientechnologies.orient.core.db.tool.ODatabaseCompare) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OStorage(com.orientechnologies.orient.core.storage.OStorage) OPartitionedDatabasePool(com.orientechnologies.orient.core.db.OPartitionedDatabasePool) File(java.io.File) OCommandOutputListener(com.orientechnologies.orient.core.command.OCommandOutputListener)

Aggregations

OPartitionedDatabasePool (com.orientechnologies.orient.core.db.OPartitionedDatabasePool)17 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)11 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)5 Test (org.testng.annotations.Test)5 ORecord (com.orientechnologies.orient.core.record.ORecord)3 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)2 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)2 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)2 ByteIterator (com.yahoo.ycsb.ByteIterator)2 StringByteIterator (com.yahoo.ycsb.StringByteIterator)2 File (java.io.File)2 Test (org.junit.Test)2 OServerAdmin (com.orientechnologies.orient.client.remote.OServerAdmin)1 OCommandOutputListener (com.orientechnologies.orient.core.command.OCommandOutputListener)1 ODatabaseCompare (com.orientechnologies.orient.core.db.tool.ODatabaseCompare)1 OEntityManager (com.orientechnologies.orient.core.entity.OEntityManager)1 OConcurrentModificationException (com.orientechnologies.orient.core.exception.OConcurrentModificationException)1 ODatabaseException (com.orientechnologies.orient.core.exception.ODatabaseException)1 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)1 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)1