Search in sources :

Example 1 with OrientGraphFactory

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

the class WWConflictAndNodeInDeadlockScenarioTest method onServerStarted.

@Override
protected void onServerStarted(ServerRun server) {
    super.onServerStarted(server);
    if (serverStarted++ == (2)) {
        // startQueueMonitorTask();
        startCountMonitorTask("Person");
        // BACKUP LAST SERVER, RUN ASYNCHRONOUSLY
        new Thread(new Runnable() {

            @Override
            public void run() {
                try {
                    // CRASH LAST SERVER try {
                    executeWhen(new Callable<Boolean>() {

                        // CONDITION
                        @Override
                        public Boolean call() throws Exception {
                            return server3inDeadlock.get();
                        }
                    }, // ACTION
                    new Callable() {

                        @Override
                        public Object call() throws Exception {
                            banner("STARTING BACKUP SERVER " + (2));
                            OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server2/databases/" + getDatabaseName());
                            OrientGraphNoTx g = factory.getNoTx();
                            backupInProgress = true;
                            File file = null;
                            try {
                                file = File.createTempFile("orientdb_test_backup", ".zip");
                                if (file.exists())
                                    Assert.assertTrue(file.delete());
                                g.getRawGraph().backup(new FileOutputStream(file), null, new Callable<Object>() {

                                    @Override
                                    public Object call() throws Exception {
                                        // SIMULATE LONG BACKUP UNTIL SPECIFIED BY VARIABLE 'server3inDeadlock'
                                        while (server3inDeadlock.get()) {
                                            Thread.sleep(1000);
                                        }
                                        return null;
                                    }
                                }, null, 9, 1000000);
                            } catch (IOException e) {
                                e.printStackTrace();
                            } finally {
                                banner("COMPLETED BACKUP SERVER " + (2));
                                backupInProgress = false;
                                g.shutdown();
                                if (file != null)
                                    file.delete();
                            }
                            return null;
                        }
                    });
                } catch (Exception e) {
                    e.printStackTrace();
                    fail("Error on execution flow");
                }
            }
        }).start();
    }
}
Also used : IOException(java.io.IOException) IOException(java.io.IOException) Callable(java.util.concurrent.Callable) FileOutputStream(java.io.FileOutputStream) OrientGraphFactory(com.tinkerpop.blueprints.impls.orient.OrientGraphFactory) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) File(java.io.File)

Example 2 with OrientGraphFactory

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

the class ServerClusterAsyncGraphTest method executeTest.

@Override
protected void executeTest() throws Exception {
    {
        OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server0/databases/" + getDatabaseName());
        OrientGraphNoTx g = factory.getNoTx();
        try {
            g.createVertexType("Post");
            g.createVertexType("User");
            g.createEdgeType("Own");
            g.addVertex("class:User");
            g.command(new OCommandSQL("insert into Post (content, timestamp) values('test', 1)")).execute();
        } finally {
            g.shutdown();
        }
    }
    // CHECK VERTEX CREATION ON ALL THE SERVERS
    for (int s = 0; s < SERVERS; ++s) {
        OrientGraphFactory factory2 = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
        OrientGraphNoTx g2 = factory2.getNoTx();
        try {
            Iterable<OrientVertex> result = g2.command(new OCommandSQL("select from Post")).execute();
            Assert.assertTrue(result.iterator().hasNext());
            Assert.assertNotNull(result.iterator().next());
        } finally {
            g2.shutdown();
        }
    }
    {
        OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server0/databases/" + getDatabaseName());
        OrientGraphNoTx g = factory.getNoTx();
        try {
            g.command(new OCommandSQL("create edge Own from (select from User) to (select from Post)").onAsyncReplicationError(new OAsyncReplicationError() {

                @Override
                public ACTION onAsyncReplicationError(Throwable iException, int iRetry) {
                    return iException instanceof ONeedRetryException && iRetry <= 3 ? ACTION.RETRY : ACTION.IGNORE;
                }
            })).execute();
        } finally {
            g.shutdown();
        }
    }
    Thread.sleep(1000);
    // CHECK VERTEX CREATION ON ALL THE SERVERS
    for (int s = 0; s < SERVERS; ++s) {
        OrientGraphFactory factory2 = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
        OrientGraphNoTx g2 = factory2.getNoTx();
        try {
            Iterable<OrientVertex> result = g2.command(new OCommandSQL("select from Own")).execute();
            Assert.assertTrue(result.iterator().hasNext());
            Assert.assertNotNull(result.iterator().next());
            result = g2.command(new OCommandSQL("select from Post")).execute();
            Assert.assertTrue(result.iterator().hasNext());
            final OrientVertex v = result.iterator().next();
            Assert.assertNotNull(v);
            final Iterable<Edge> inEdges = v.getEdges(Direction.IN);
            Assert.assertTrue(inEdges.iterator().hasNext());
            Assert.assertNotNull(inEdges.iterator().next());
            result = g2.command(new OCommandSQL("select from User")).execute();
            Assert.assertTrue(result.iterator().hasNext());
            final OrientVertex v2 = result.iterator().next();
            Assert.assertNotNull(v2);
            final Iterable<Edge> outEdges = v2.getEdges(Direction.OUT);
            Assert.assertTrue(outEdges.iterator().hasNext());
            Assert.assertNotNull(outEdges.iterator().next());
        } finally {
            g2.shutdown();
        }
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OAsyncReplicationError(com.orientechnologies.orient.core.replication.OAsyncReplicationError) ONeedRetryException(com.orientechnologies.common.concur.ONeedRetryException) OrientGraphFactory(com.tinkerpop.blueprints.impls.orient.OrientGraphFactory) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) Edge(com.tinkerpop.blueprints.Edge)

Example 3 with OrientGraphFactory

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

the class GraphShutdownTest method graphCommitAfterShutdown.

@Test(expected = ODatabaseException.class)
public void graphCommitAfterShutdown() {
    OrientGraphFactory factory = new OrientGraphFactory("memory:graphCommitAfterShutdown");
    OrientGraph graph1 = factory.getTx();
    OrientGraph graph2 = factory.getTx();
    // in 2.2 this will not close the database because graph1 is still active in the pool
    graph2.shutdown(true);
    // this should fail
    graph2.commit();
    factory.drop();
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OrientGraphFactory(com.tinkerpop.blueprints.impls.orient.OrientGraphFactory) Test(org.junit.Test)

Example 4 with OrientGraphFactory

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

the class HAClusterStrategyTest method executeTest.

@Override
public void executeTest() throws Exception {
    final OrientGraphFactory factory = new OrientGraphFactory(getDatabaseURL(serverInstance.get(0)));
    final OrientGraphNoTx g = factory.getNoTx();
    g.createVertexType("Test");
    g.shutdown();
    for (int i = 0; i < 10; ++i) {
        // pressing 'return' 2 to 10 times should trigger the described behavior
        Thread.sleep(100);
        final OrientGraph graph = factory.getTx();
        // should always be 'local', but eventually changes to 'round-robin'
        System.out.println("StrategyClassName: " + graph.getVertexType("Test").getClusterSelection().getClass().getName());
        System.out.println("ClusterSelectionStrategy for " + graph.getRawGraph().getURL() + ": " + graph.getVertexType("Test").getClusterSelection().getName());
        Assert.assertEquals(graph.getVertexType("Test").getClusterSelection().getClass().getName(), OLocalClusterWrapperStrategy.class.getName());
        Assert.assertEquals(graph.getVertexType("Test").getClusterSelection().getName(), "round-robin");
        graph.addVertex("class:Test", "firstName", "Roger", "lastName", "Smith");
        graph.getRawGraph().commit();
        graph.shutdown();
    }
    factory.close();
    factory.drop();
}
Also used : OLocalClusterWrapperStrategy(com.orientechnologies.orient.server.distributed.impl.OLocalClusterWrapperStrategy) OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OrientGraphFactory(com.tinkerpop.blueprints.impls.orient.OrientGraphFactory) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx)

Example 5 with OrientGraphFactory

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

the class OrientdbEdgeTest method testEdges.

@Test
public void testEdges() throws Exception {
    OrientGraphFactory factory = getGraphFactory();
    OrientBaseGraph g = factory.getNoTx();
    try {
        try {
            g.createEdgeType("some-label");
        } catch (OSchemaException ex) {
            if (!ex.getMessage().contains("exists"))
                throw (ex);
            g.command(new OCommandSQL("delete edge some-label")).execute();
        }
        try {
            g.createVertexType("some-v-label");
        } catch (OSchemaException ex) {
            if (!ex.getMessage().contains("exists"))
                throw (ex);
            g.command(new OCommandSQL("delete vertex some-v-label")).execute();
        }
    } finally {
        g.shutdown();
    }
    OrientGraph t = factory.getTx();
    try {
        Vertex v1 = t.addVertex("class:some-v-label");
        Vertex v2 = t.addVertex("class:some-v-label");
        v1.setProperty("_id", "v1");
        v2.setProperty("_id", "v2");
        OrientEdge edge = t.addEdge(null, v1, v2, "some-label");
        edge.setProperty("some", "thing");
        t.commit();
        t.shutdown();
        t = factory.getTx();
        assertEquals(2, t.countVertices("some-v-label"));
        assertEquals(1, t.countEdges());
        assertNotNull(t.getVertices("_id", "v1").iterator().next());
        assertNotNull(t.getVertices("_id", "v2").iterator().next());
        t.commit();
        t.shutdown();
        t = factory.getTx();
        // works
        assertEquals(1, t.getVertices("_id", "v1").iterator().next().query().labels("some-label").count());
        // NoSuchElementException
        assertNotNull(t.getVertices("_id", "v1").iterator().next().query().labels("some-label").edges().iterator().next());
        t.commit();
    } finally {
        t.shutdown();
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) Vertex(com.tinkerpop.blueprints.Vertex) OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OrientGraphFactory(com.tinkerpop.blueprints.impls.orient.OrientGraphFactory) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph) OSchemaException(com.orientechnologies.orient.core.exception.OSchemaException) OrientEdge(com.tinkerpop.blueprints.impls.orient.OrientEdge) Test(org.junit.Test)

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