Search in sources :

Example 36 with OrientGraphFactory

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

the class OrientTestsManualTx method setUpGraph.

@Before
public void setUpGraph() {
    graphFactory = new OrientGraphFactory(DATABASE_URL);
    graphFactory.setAutoStartTx(false);
    graph = graphFactory.getTx();
}
Also used : OrientGraphFactory(com.tinkerpop.blueprints.impls.orient.OrientGraphFactory) Before(org.junit.Before)

Example 37 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 38 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 39 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 40 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