Search in sources :

Example 16 with OrientGraphFactory

use of com.tinkerpop.blueprints.impls.orient.OrientGraphFactory in project orientdb by orientechnologies.

the class NestedTxTest method testNestedTx.

@Test
public void testNestedTx() throws InterruptedException, ExecutionException {
    final ExecutorService executorService = Executors.newSingleThreadExecutor();
    final OrientGraphFactory factory = new OrientGraphFactory("memory:NestedTxTest.testNestedTx", "admin", "admin").setupPool(2, 10);
    factory.setAutoStartTx(false);
    final OrientGraph graph = factory.getTx();
    graph.createVertexType("A");
    graph.createVertexType("B");
    executorService.submit(new Runnable() {

        @Override
        public void run() {
            final OrientGraph graph = getGraph(factory);
            graph.begin();
            graph.addVertex("class:A");
        }
    }).get();
    Assert.assertTrue("vertex A should not exist before top-level commit", !vertexExists(graph, "A"));
    executorService.submit(new Runnable() {

        @Override
        public void run() {
            final OrientGraph graph = getGraph(factory);
            graph.begin();
            graph.addVertex("class:B");
        }
    }).get();
    Assert.assertTrue("vertex B should not exist before top-level commit", !vertexExists(graph, "B"));
    executorService.submit(new Runnable() {

        @Override
        public void run() {
            final OrientGraph graph = getGraph(factory);
            graph.commit();
        }
    }).get();
    Assert.assertTrue("vertex A should not exist before top-level commit", !vertexExists(graph, "A"));
    Assert.assertTrue("vertex B should not exist before top-level commit", !vertexExists(graph, "B"));
    executorService.submit(new Runnable() {

        @Override
        public void run() {
            final OrientGraph graph = getGraph(factory);
            graph.commit();
        }
    }).get();
    Assert.assertTrue("vertex A should exist after top-level commit", vertexExists(graph, "A"));
    Assert.assertTrue("vertex B should exist after top-level commit", vertexExists(graph, "B"));
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OrientGraphFactory(com.tinkerpop.blueprints.impls.orient.OrientGraphFactory) Test(org.junit.Test)

Example 17 with OrientGraphFactory

use of com.tinkerpop.blueprints.impls.orient.OrientGraphFactory in project orientdb by orientechnologies.

the class LocalCreateVertexSpeedTest method init.

@Override
@Test(enabled = false)
public void init() {
    final OrientGraphFactory factory = new OrientGraphFactory(System.getProperty("url"));
    factory.setStandardElementConstraints(false);
    if (factory.exists())
        factory.drop();
    database = factory.getNoTx();
    database.createVertexType("Account");
    database.getRawGraph().declareIntent(new OIntentMassiveInsert());
}
Also used : OrientGraphFactory(com.tinkerpop.blueprints.impls.orient.OrientGraphFactory) OIntentMassiveInsert(com.orientechnologies.orient.core.intent.OIntentMassiveInsert) OrientMonoThreadTest(com.orientechnologies.orient.test.database.base.OrientMonoThreadTest) Test(org.testng.annotations.Test)

Example 18 with OrientGraphFactory

use of com.tinkerpop.blueprints.impls.orient.OrientGraphFactory in project orientdb by orientechnologies.

the class DistributedHookTest method executeTest.

@Override
protected void executeTest() throws Exception {
    for (int s = 1; s <= SERVERS; ++s) {
        OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
        OrientGraphNoTx g = factory.getNoTx();
        g.getRawGraph().registerHook(new TestHookSourceNode(), ORecordHook.HOOK_POSITION.REGULAR);
        try {
            // CREATE (VIA COMMAND)
            OIdentifiable inserted = g.command(new OCommandSQL("insert into OUser (name, password, status) values ('novo" + s + "','teste','ACTIVE') RETURN @rid")).execute();
            Assert.assertNotNull(inserted);
            Assert.assertEquals(beforeCreate.get(), s);
            Assert.assertEquals(afterCreate.get(), s);
            ODocument loadedDoc = inserted.getIdentity().copy().getRecord();
            // UPDATE
            loadedDoc.field("additionalProperty", "test");
            loadedDoc.save();
            Assert.assertEquals(beforeUpdate.get(), s);
            Assert.assertEquals(afterUpdate.get(), s);
            // DELETE
            loadedDoc.delete();
            Assert.assertEquals(beforeDelete.get(), s);
            Assert.assertEquals(afterDelete.get(), s);
        } finally {
            g.shutdown();
        }
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OrientGraphFactory(com.tinkerpop.blueprints.impls.orient.OrientGraphFactory) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 19 with OrientGraphFactory

use of com.tinkerpop.blueprints.impls.orient.OrientGraphFactory in project orientdb by orientechnologies.

the class DistributedSecurityTest method executeTest.

@Override
protected void executeTest() throws Exception {
    for (int s = 0; s < SERVERS; ++s) {
        OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName(), "reader", "reader");
        OrientGraphNoTx g = factory.getNoTx();
        try {
            try {
                // TRY DELETING ALL OUSER VIA COMMAND
                Long deleted = g.command(new OCommandSQL("delete from OUser")).execute();
                Assert.assertEquals(deleted.longValue(), 0l);
            } catch (Exception e) {
                Assert.assertTrue(true);
            }
            try {
                // TRY DELETING CURRENT OUSER VIA API
                g.getRawGraph().getUser().getIdentity().getRecord().delete();
                Assert.assertTrue(false);
            } catch (Exception e) {
                Assert.assertTrue(true);
            }
        } finally {
            g.shutdown();
        }
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OrientGraphFactory(com.tinkerpop.blueprints.impls.orient.OrientGraphFactory) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx)

Example 20 with OrientGraphFactory

use of com.tinkerpop.blueprints.impls.orient.OrientGraphFactory in project orientdb by orientechnologies.

the class OrientdbEdgeTest method getGraphFactory.

protected static OrientGraphFactory getGraphFactory() throws Exception {
    Map<String, Object> conf = new HashMap<String, Object>();
    conf.put("storage.url", "remote:localhost/test");
    conf.put("storage.pool-min", 1);
    conf.put("storage.pool-max", 10);
    conf.put("storage.user", "root");
    conf.put("storage.password", "root");
    OGlobalConfiguration.CLIENT_CONNECT_POOL_WAIT_TIMEOUT.setValue(15000);
    verifyDatabaseExists(conf);
    return new OrientGraphFactory((String) conf.get("storage.url"), (String) conf.get("storage.user"), (String) conf.get("storage.password")).setupPool((Integer) conf.get("storage.pool-min"), (Integer) conf.get("storage.pool-max"));
}
Also used : HashMap(java.util.HashMap) OrientGraphFactory(com.tinkerpop.blueprints.impls.orient.OrientGraphFactory)

Aggregations

OrientGraphFactory (com.tinkerpop.blueprints.impls.orient.OrientGraphFactory)40 OrientGraphNoTx (com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx)19 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)13 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)13 OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)8 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)7 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)5 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)4 OrientVertexType (com.tinkerpop.blueprints.impls.orient.OrientVertexType)4 Before (org.junit.Before)4 Test (org.junit.Test)4 File (java.io.File)3 HashMap (java.util.HashMap)3 Test (org.testng.annotations.Test)3 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)2 ORecordNotFoundException (com.orientechnologies.orient.core.exception.ORecordNotFoundException)2 OValidationException (com.orientechnologies.orient.core.exception.OValidationException)2 OIntentMassiveInsert (com.orientechnologies.orient.core.intent.OIntentMassiveInsert)2 ORecordDuplicatedException (com.orientechnologies.orient.core.storage.ORecordDuplicatedException)2 ODistributedException (com.orientechnologies.orient.server.distributed.ODistributedException)2