Search in sources :

Example 41 with OrientVertex

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

the class TestAsyncReplMode2ServersOverflow method exec.

protected void exec(final String iClient) {
    counter.countDown();
    try {
        counter.await();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    OrientBaseGraph graph = new OrientGraphNoTx(getLocalURL());
    try {
        int i = 0;
        for (; i < TOTAL; ++i) {
            final OrientVertex v = graph.addVertex(null);
            Assert.assertTrue(v.getIdentity().isPersistent());
        }
    } catch (Throwable e) {
        if (exceptionInThread == null)
            exceptionInThread = e;
    } finally {
        System.out.println("Shutting down");
        graph.shutdown();
    }
}
Also used : OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)

Example 42 with OrientVertex

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

the class TestDistributedDatabaseRepair method testNoWinner.

private void testNoWinner(OrientGraphFactory localFactory0, OrientGraphFactory localFactory1, OrientGraphFactory localFactory2) throws Exception {
    OrientBaseGraph graph = localFactory0.getTx();
    OrientVertex product;
    try {
        product = graph.addVertex("class:ProductType");
        product.setProperty("status", "ok");
    } finally {
        graph.shutdown();
    }
    banner("CORRUPT A RECORD IN SERVER 0");
    graph = localFactory0.getNoTx();
    try {
        final OrientVertex product2 = graph.getVertex(product.getIdentity());
        product2.getRecord().field("status", "corrupted0");
        final ODistributedResponse result = updateRemoteRecord(0, product2.getRecord(), new String[] { serverInstance.get(0).getServerInstance().getDistributedManager().getLocalNodeName() });
        Assert.assertFalse(result.getPayload() instanceof Throwable);
    } finally {
        graph.shutdown();
    }
    banner("CORRUPT A RECORD IN SERVER 1");
    graph = localFactory1.getNoTx();
    try {
        final OrientVertex product2 = graph.getVertex(product.getIdentity());
        product2.getRecord().field("status", "corrupted1");
        ODistributedResponse result = updateRemoteRecord(1, product2.getRecord(), new String[] { serverInstance.get(1).getServerInstance().getDistributedManager().getLocalNodeName() });
        Assert.assertFalse(result.getPayload() instanceof Throwable);
    } finally {
        graph.shutdown();
    }
    serverInstance.get(0).getServerInstance().getDistributedManager().getMessageService().getDatabase(getDatabaseName()).getDatabaseRepairer().enqueueRepairRecord((ORecordId) product.getIdentity());
    Thread.sleep(3000);
    // TEST NOTHING IS CHANGED
    graph = localFactory0.getNoTx();
    try {
        final OrientVertex product2 = graph.getVertex(product.getIdentity());
        Assert.assertEquals("corrupted0", product2.getProperty("status"));
    } finally {
        graph.shutdown();
    }
    graph = localFactory1.getNoTx();
    try {
        final OrientVertex product2 = graph.getVertex(product.getIdentity());
        Assert.assertEquals("corrupted1", product2.getProperty("status"));
    } finally {
        graph.shutdown();
    }
    graph = localFactory2.getNoTx();
    try {
        final OrientVertex product2 = graph.getVertex(product.getIdentity());
        Assert.assertEquals("ok", product2.getProperty("status"));
    } finally {
        graph.shutdown();
    }
}
Also used : OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)

Example 43 with OrientVertex

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

the class TestDistributedDatabaseRepair method testRepairClusters.

/**
   * Breaks a cluster by creating new records only on certain servers
   */
private void testRepairClusters(OrientGraphFactory localFactory0, OrientGraphFactory localFactory1, OrientGraphFactory localFactory2) throws Exception {
    Thread.sleep(2000);
    OrientBaseGraph graph = localFactory0.getNoTx();
    graph.createVertexType("Employee");
    graph.shutdown();
    final ODistributedConfiguration cfg = serverInstance.get(1).getServerInstance().getDistributedManager().getDatabaseConfiguration(getDatabaseName());
    // FIND THE LOCAL CLUSTER
    String localCluster = null;
    final Set<String> owner = cfg.getClustersOwnedByServer(serverInstance.get(1).getServerInstance().getDistributedManager().getLocalNodeName());
    for (String s : owner) {
        if (s.toLowerCase().startsWith("employee")) {
            localCluster = s;
            break;
        }
    }
    graph = localFactory1.getTx();
    OrientVertex employee;
    try {
        employee = graph.addVertex("Employee", localCluster);
        employee.setProperty("status", "ok");
    } finally {
        graph.shutdown();
    }
    banner("CREATE 10 RECORDS ONLY ON local (1) SERVER and 0");
    graph = localFactory1.getTx();
    try {
        for (int i = 0; i < 10; ++i) {
            OrientVertex v = graph.addVertex("Employee", localCluster);
            v.setProperty("status", "onlyServer0and1");
            graph.getRawGraph().getStorage().getUnderlying().createRecord((ORecordId) v.getRecord().getIdentity(), v.getRecord().toStream(), v.getRecord().getVersion(), ODocument.RECORD_TYPE, 0, null);
            final ODistributedResponse result = createRemoteRecord(0, v.getRecord(), new String[] { serverInstance.get(0).getServerInstance().getDistributedManager().getLocalNodeName() });
            Assert.assertFalse(result.getPayload() instanceof Throwable);
        }
    } finally {
        graph.rollback();
    }
    banner("CREATE 10 RECORDS ONLY ON SERVER 0");
    graph = localFactory1.getTx();
    try {
        for (int i = 0; i < 10; ++i) {
            OrientVertex v = graph.addVertex("Employee", localCluster);
            v.setProperty("status", "onlyServer0and1");
            graph.getRawGraph().getStorage().getUnderlying().createRecord((ORecordId) v.getRecord().getIdentity(), v.getRecord().toStream(), v.getRecord().getVersion(), ODocument.RECORD_TYPE, 0, null);
        }
    } finally {
        graph.rollback();
    }
    // TRY TO CREATE A RECORD TO START THE REPAIR
    graph = localFactory1.getTx();
    try {
        OrientVertex v = graph.addVertex("Employee", localCluster);
        v.setProperty("status", "check");
        graph.commit();
    } catch (ODistributedOperationException e) {
        Assert.assertTrue(true);
    } finally {
        graph.shutdown();
    }
    Thread.sleep(5000);
    banner("CHECK RECORDS...");
    graph = localFactory0.getNoTx();
    try {
        Assert.assertEquals(21, graph.countVertices("Employee"));
    } finally {
        graph.shutdown();
    }
    graph = localFactory1.getNoTx();
    try {
        Assert.assertEquals(21, graph.countVertices("Employee"));
    } finally {
        graph.shutdown();
    }
    graph = localFactory2.getNoTx();
    try {
        Assert.assertEquals(21, graph.countVertices("Employee"));
    } finally {
        graph.shutdown();
    }
}
Also used : OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph) ODistributedOperationException(com.orientechnologies.orient.server.distributed.task.ODistributedOperationException)

Example 44 with OrientVertex

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

the class TestDistributedDatabaseRepair method testWinnerIsMajorityPlusVersion.

private void testWinnerIsMajorityPlusVersion(OrientGraphFactory localFactory0, OrientGraphFactory localFactory1, OrientGraphFactory localFactory2) throws Exception {
    OrientBaseGraph graph = localFactory0.getTx();
    OrientVertex product;
    try {
        product = graph.addVertex("class:ProductType");
        product.setProperty("status", "ok");
    } finally {
        graph.shutdown();
    }
    banner("CORRUPT A RECORD IN SERVER 0");
    graph = localFactory0.getNoTx();
    try {
        final OrientVertex product2 = graph.getVertex(product.getIdentity());
        product2.getRecord().field("status", "corrupted0");
        final ODistributedResponse result = updateRemoteRecord(0, product2.getRecord(), new String[] { serverInstance.get(0).getServerInstance().getDistributedManager().getLocalNodeName() });
        Assert.assertFalse(result.getPayload() instanceof Throwable);
    } finally {
        graph.shutdown();
    }
    banner("CORRUPT A RECORD IN SERVER 1 WITH THE HIGHEST VERSION (=WINNER)");
    graph = localFactory1.getNoTx();
    try {
        final OrientVertex product2 = graph.getVertex(product.getIdentity());
        product2.getRecord().field("status", "thisIsTheMostRecent");
        ORecordInternal.setVersion(product2.getRecord(), ORecordVersionHelper.setRollbackMode(1000));
        ODistributedResponse result = updateRemoteRecord(1, product2.getRecord(), new String[] { serverInstance.get(1).getServerInstance().getDistributedManager().getLocalNodeName() });
        Assert.assertFalse(result.getPayload() instanceof Throwable);
    } finally {
        graph.shutdown();
    }
    serverInstance.get(0).getServerInstance().getDistributedManager().getMessageService().getDatabase(getDatabaseName()).getDatabaseRepairer().enqueueRepairRecord((ORecordId) product.getIdentity());
    Thread.sleep(3000);
    banner("EXPECTING AUTO RECOVER ON ALL NODES...");
    // TEST RECOVER IS CHANGED
    graph = localFactory0.getNoTx();
    try {
        final OrientVertex product2 = graph.getVertex(product.getIdentity());
        Assert.assertEquals("thisIsTheMostRecent", product2.getProperty("status"));
        Assert.assertEquals(1000, product2.getRecord().getVersion());
    } finally {
        graph.shutdown();
    }
    graph = localFactory1.getNoTx();
    try {
        final OrientVertex product2 = graph.getVertex(product.getIdentity());
        Assert.assertEquals("thisIsTheMostRecent", product2.getProperty("status"));
        Assert.assertEquals(1000, product2.getRecord().getVersion());
    } finally {
        graph.shutdown();
    }
    graph = localFactory2.getNoTx();
    try {
        final OrientVertex product2 = graph.getVertex(product.getIdentity());
        Assert.assertEquals("thisIsTheMostRecent", product2.getProperty("status"));
        Assert.assertEquals(1000, product2.getRecord().getVersion());
    } finally {
        graph.shutdown();
    }
}
Also used : OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)

Example 45 with OrientVertex

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

the class TestDistributedDatabaseRepair method testWinnerIsMajority.

private void testWinnerIsMajority(OrientGraphFactory localFactory0, OrientGraphFactory localFactory1, OrientGraphFactory localFactory2) throws Exception {
    OrientBaseGraph graph = localFactory0.getTx();
    OrientVertex product;
    try {
        product = graph.addVertex("class:ProductType");
        product.setProperty("status", "ok");
    } finally {
        graph.shutdown();
    }
    banner("CORRUPT ONLY 1 RECORD IN SERVER 0");
    graph = localFactory0.getNoTx();
    try {
        final OrientVertex product2 = graph.getVertex(product.getIdentity());
        product2.getRecord().field("status", "corrupted0");
        final ODistributedResponse result = updateRemoteRecord(0, product2.getRecord(), new String[] { serverInstance.get(0).getServerInstance().getDistributedManager().getLocalNodeName() });
        Assert.assertFalse(result.getPayload() instanceof Throwable);
    } finally {
        graph.shutdown();
    }
    serverInstance.get(0).getServerInstance().getDistributedManager().getMessageService().getDatabase(getDatabaseName()).getDatabaseRepairer().enqueueRepairRecord((ORecordId) product.getIdentity());
    Thread.sleep(3000);
    banner("EXPECTING AUTO RECOVER ON ALL NODES...");
    // TEST RECORD IS CHANGED
    graph = localFactory0.getNoTx();
    try {
        final OrientVertex product2 = graph.getVertex(product.getIdentity());
        Assert.assertEquals("ok", product2.getProperty("status"));
    } finally {
        graph.shutdown();
    }
    graph = localFactory1.getNoTx();
    try {
        final OrientVertex product2 = graph.getVertex(product.getIdentity());
        Assert.assertEquals("ok", product2.getProperty("status"));
    } finally {
        graph.shutdown();
    }
    graph = localFactory2.getNoTx();
    try {
        final OrientVertex product2 = graph.getVertex(product.getIdentity());
        Assert.assertEquals("ok", product2.getProperty("status"));
    } finally {
        graph.shutdown();
    }
}
Also used : OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)

Aggregations

OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)155 Test (org.junit.Test)73 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)42 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)40 OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)37 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)35 OrientGraphNoTx (com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx)26 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)25 OrientEdge (com.tinkerpop.blueprints.impls.orient.OrientEdge)25 Vertex (com.tinkerpop.blueprints.Vertex)24 HashMap (java.util.HashMap)20 OBasicCommandContext (com.orientechnologies.orient.core.command.OBasicCommandContext)13 OrientGraphFactory (com.tinkerpop.blueprints.impls.orient.OrientGraphFactory)13 OrientVertexType (com.tinkerpop.blueprints.impls.orient.OrientVertexType)13 Edge (com.tinkerpop.blueprints.Edge)12 OConcurrentModificationException (com.orientechnologies.orient.core.exception.OConcurrentModificationException)10 GraphNoTxAbstractTest (com.orientechnologies.orient.graph.GraphNoTxAbstractTest)9 ORID (com.orientechnologies.orient.core.id.ORID)7 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)7 GraphTxAbstractTest (com.orientechnologies.orient.graph.GraphTxAbstractTest)7