Search in sources :

Example 31 with OrientGraphFactory

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

the class TestShardingManualSync method executeTest.

@Override
protected void executeTest() throws Exception {
    final OrientGraphFactory localFactoryEurope = new OrientGraphFactory("plocal:target/server0/databases/" + getDatabaseName());
    OrientGraphFactory localFactoryUsa = new OrientGraphFactory("plocal:target/server1/databases/" + getDatabaseName());
    final ORID v1Identity;
    OrientGraphNoTx graphNoTxEurope = localFactoryEurope.getNoTx();
    try {
        final OrientVertexType clientType = graphNoTxEurope.createVertexType("Client-Type");
        for (int i = 1; i < serverInstance.size(); ++i) {
            final String serverName = serverInstance.get(i).getServerInstance().getDistributedManager().getLocalNodeName();
            clientType.addCluster("client_" + serverName);
        }
        final OrientVertex v1 = graphNoTxEurope.addVertex("class:Client-Type");
        v1Identity = v1.getIdentity();
        log("Created vertex " + v1Identity + "...");
    } finally {
        graphNoTxEurope.shutdown();
    }
    OrientGraphNoTx graphNoTxUsa = localFactoryUsa.getNoTx();
    try {
        Assert.assertEquals(1, graphNoTxUsa.countVertices());
    } finally {
        graphNoTxUsa.shutdown();
        localFactoryUsa.close();
    }
    final String clusterName;
    graphNoTxEurope = localFactoryEurope.getNoTx();
    try {
        Assert.assertEquals(1, graphNoTxEurope.countVertices());
        // CHANGE THE WRITE QUORUM = 1
        final OModifiableDistributedConfiguration dCfg = serverInstance.get(0).server.getDistributedManager().getDatabaseConfiguration(getDatabaseName()).modify();
        ODocument newCfg = dCfg.getDocument().field("writeQuorum", 1);
        serverInstance.get(0).server.getDistributedManager().updateCachedDatabaseConfiguration(getDatabaseName(), dCfg, true);
        // CREATE A NEW RECORD ON SERVER 0 BYPASSING REPLICATION
        final ODocument v2 = new ODocument("Client");
        ((ORecordId) v2.getIdentity()).setClusterId(v1Identity.getClusterId());
        ((ORecordId) v2.getIdentity()).setClusterPosition(v1Identity.getClusterPosition() + 1);
        final Object result = createRemoteRecord(0, v2, new String[] { serverInstance.get(0).getServerInstance().getDistributedManager().getLocalNodeName() });
        Assert.assertFalse(result instanceof Throwable);
        Assert.assertEquals(2, graphNoTxEurope.countVertices());
        clusterName = graphNoTxEurope.getRawGraph().getClusterNameById(v2.getIdentity().getClusterId());
        Assert.assertEquals(2, graphNoTxEurope.countVertices());
    } finally {
        graphNoTxEurope.shutdown();
    }
    // TEST SECOND VERTEX IS MISSING ON USA NODE
    localFactoryUsa = new OrientGraphFactory("plocal:target/server1/databases/" + getDatabaseName());
    graphNoTxUsa = localFactoryUsa.getNoTx();
    try {
        Assert.assertEquals(1, graphNoTxUsa.countVertices());
        log("Manually syncing cluster client-type of node USA...");
        graphNoTxUsa.command(new OCommandSQL("ha sync cluster `" + clusterName + "`")).execute();
        Assert.assertEquals(2, graphNoTxUsa.countVertices());
    } finally {
        graphNoTxUsa.shutdown();
    }
    localFactoryEurope.close();
    localFactoryUsa.close();
}
Also used : OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) ORecordId(com.orientechnologies.orient.core.id.ORecordId) OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OrientGraphFactory(com.tinkerpop.blueprints.impls.orient.OrientGraphFactory) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) OrientVertexType(com.tinkerpop.blueprints.impls.orient.OrientVertexType) ORID(com.orientechnologies.orient.core.id.ORID) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 32 with OrientGraphFactory

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

the class DbCreationTest method testZipCompression.

public void testZipCompression() {
    if (database == null || !database.getURL().startsWith("plocal:"))
        return;
    OGlobalConfiguration.STORAGE_COMPRESSION_METHOD.setValue("gzip");
    final String buildDirectory = System.getProperty("buildDirectory", ".");
    String dburl = "plocal:" + buildDirectory + "/test-db/" + this.getClass().getSimpleName();
    final OrientGraphFactory factory = new OrientGraphFactory(dburl, "admin", "admin");
    if (factory.exists())
        factory.drop();
    factory.close();
    OrientGraphNoTx db = factory.getNoTx();
    db.drop();
    OGlobalConfiguration.STORAGE_COMPRESSION_METHOD.setValue(OGlobalConfiguration.STORAGE_COMPRESSION_METHOD.getValue());
}
Also used : OrientGraphFactory(com.tinkerpop.blueprints.impls.orient.OrientGraphFactory) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx)

Example 33 with OrientGraphFactory

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

the class GraphTransactionConsistency method testTransactionConsistency.

public void testTransactionConsistency() throws InterruptedException {
    final OrientGraphFactory factory = new OrientGraphFactory("plocal:target/GraphTransactionConsistency", false);
    database = txMode ? factory.getTx() : factory.getNoTx();
    System.out.println("Checking consistency of database...");
    System.out.println("Records found V=" + database.countVertices() + " E=" + database.countEdges());
    final Iterable<OrientVertex> vertices = database.command(new OCommandSQL("select from V")).execute();
    for (OrientVertex v : vertices) {
        final ODocument doc = v.getRecord();
        Assert.assertNotNull(doc);
        final ORidBag out = doc.field("out_");
        if (out != null) {
            for (Iterator<OIdentifiable> it = out.rawIterator(); it.hasNext(); ) {
                final OIdentifiable edge = it.next();
                Assert.assertNotNull(edge);
                final ODocument rec = edge.getRecord();
                Assert.assertNotNull(rec);
                Assert.assertNotNull(rec.field("out"));
                Assert.assertEquals(((ODocument) rec.field("out")).getIdentity(), v.getIdentity());
                Assert.assertNotNull(rec.field("in"));
            }
        }
        final ORidBag in = doc.field("in_");
        if (in != null) {
            for (Iterator<OIdentifiable> it = in.rawIterator(); it.hasNext(); ) {
                final OIdentifiable edge = it.next();
                Assert.assertNotNull(edge);
                final ODocument rec = edge.getRecord();
                Assert.assertNotNull(rec);
                Assert.assertNotNull(rec.field("in"));
                Assert.assertEquals(((ODocument) rec.field("in")).getIdentity(), v.getIdentity());
                Assert.assertNotNull(rec.field("out"));
            }
        }
    }
    System.out.println("Consistency ok.");
    final Thread[] threads = new Thread[THREADS];
    for (int i = 0; i < THREADS; ++i) {
        final int threadNum = i;
        threads[i] = new Thread(new Runnable() {

            @Override
            public void run() {
                OrientBaseGraph graph = txMode ? factory.getTx() : factory.getNoTx();
                try {
                    System.out.println("THREAD " + threadNum + " Start transactions (" + TXNUM + ")");
                    for (int i = 0; i < TXNUM; ++i) {
                        final OrientVertex v1 = graph.addVertex(null, "v", i, "type", "Main", "lastUpdate", new Date());
                        for (int e = 0; e < EDGENUM; ++e) {
                            final OrientVertex v2 = graph.addVertex(null, "v", i, "e", e, "type", "Connected", "lastUpdate", new Date());
                            v1.addEdge("E", v2);
                        }
                        if (i % TXBATCH == 0) {
                            System.out.println("THREAD " + threadNum + " Committing batch of " + TXBATCH + " (i=" + i + ")");
                            System.out.flush();
                            graph.commit();
                            System.out.println("THREAD " + threadNum + " Commit ok - records found V=" + graph.countVertices() + " E=" + graph.countEdges());
                            System.out.flush();
                        }
                    }
                } finally {
                    graph.shutdown();
                }
            }
        });
        Thread.sleep(1000);
        threads[i].start();
    }
    for (int i = 0; i < THREADS; ++i) {
        try {
            threads[i].join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    database.shutdown();
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) Date(java.util.Date) OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OrientGraphFactory(com.tinkerpop.blueprints.impls.orient.OrientGraphFactory) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 34 with OrientGraphFactory

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

the class BackupTest method main.

public static void main(String[] args) throws IOException {
    File backupFile = new File("testbackup.zip");
    OutputStream oS = new FileOutputStream(backupFile);
    OrientGraphFactory factory = new OrientGraphFactory("plocal:backupTest", "admin", "admin");
    OrientGraphNoTx graphNoTx = factory.getNoTx();
    graphNoTx.getRawGraph().backup(oS, null, null, null, 1, 1024);
    ZipFile zipFile = new ZipFile(backupFile);
    Enumeration enumeration = zipFile.entries();
    System.out.format("ZipFile : %s%n", zipFile);
    while (enumeration.hasMoreElements()) {
        Object entry = enumeration.nextElement();
        System.out.format("  Entry : %s%n", entry);
    }
    factory.close();
}
Also used : Enumeration(java.util.Enumeration) ZipFile(java.util.zip.ZipFile) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) OrientGraphFactory(com.tinkerpop.blueprints.impls.orient.OrientGraphFactory) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 35 with OrientGraphFactory

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

the class SuperNodeGraphSpeedTest method init.

@Override
@Test(enabled = false)
public void init() throws Exception {
    String buildDirectory = System.getProperty("buildDirectory", ".");
    if (buildDirectory == null) {
        buildDirectory = ".";
    }
    final OrientGraphFactory factory = new OrientGraphFactory("plocal:" + buildDirectory + "/SuperNodeGraphSpeedTest", "admin", "admin");
    if (factory.exists())
        factory.drop();
    graph = factory.getNoTx();
    superNode = graph.addVertex(null);
    factory.close();
}
Also used : OrientGraphFactory(com.tinkerpop.blueprints.impls.orient.OrientGraphFactory) Test(org.testng.annotations.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