Search in sources :

Example 66 with OrientVertex

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

the class ServerClusterRemoteInsertBalancedTest method testRoundRobinOnConnect.

private void testRoundRobinOnConnect() {
    final OrientGraphFactory factory = new OrientGraphFactory("remote:localhost/" + getDatabaseName());
    factory.setConnectionStrategy(OStorageRemote.CONNECTION_STRATEGY.ROUND_ROBIN_CONNECT.toString());
    OrientGraphNoTx graph = factory.getNoTx();
    graph.createVertexType("Client");
    graph.shutdown();
    Map<Integer, Integer> clusterIds = new HashMap<Integer, Integer>();
    for (int i = 0; i < ITERATIONS; ++i) {
        graph = factory.getNoTx();
        try {
            final OrientVertex v = graph.addVertex("class:Client");
            Integer value = clusterIds.get(v.getIdentity().getClusterId());
            if (value == null)
                value = 1;
            else
                value++;
            clusterIds.put(v.getIdentity().getClusterId(), value);
        } finally {
            graph.shutdown();
        }
    }
    Assert.assertTrue(clusterIds.size() > 1);
}
Also used : HashMap(java.util.HashMap) OrientGraphFactory(com.tinkerpop.blueprints.impls.orient.OrientGraphFactory) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex)

Example 67 with OrientVertex

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

the class ServerClusterSchemaTest 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());
        OrientGraphNoTx g = factory.getNoTx();
        try {
            System.out.println("Creating vertex class Client" + s + " against server " + g + "...");
            OrientVertexType t = g.createVertexType("Client" + s);
            t.createProperty("name", OType.STRING).setMandatory(true);
            System.out.println("Creating vertex class Knows" + s + " against server " + g + "...");
            g.createEdgeType("Knows" + s);
        } finally {
            g.shutdown();
        }
    }
    for (int s = 0; s < SERVERS; ++s) {
        System.out.println("Checking vertices classes on server " + s + "...");
        OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
        OrientGraphNoTx g = factory.getNoTx();
        try {
            for (int i = 0; i < SERVERS; ++i) {
                Assert.assertNotNull(g.getVertexType("Client" + i));
                Assert.assertNotNull(g.getEdgeType("Knows" + i));
            }
        } finally {
            g.shutdown();
        }
    }
    for (int s = 0; s < SERVERS; ++s) {
        System.out.println("Add vertices on server " + s + "...");
        OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
        OrientGraphNoTx g = factory.getNoTx();
        try {
            for (int i = 0; i < SERVERS; ++i) {
                try {
                    final OrientVertex v = g.addVertex("class:" + "Client" + i);
                    Assert.assertTrue(false);
                } catch (OValidationException e) {
                // EXPECTED
                }
            }
        } finally {
            g.shutdown();
        }
    }
    for (int s = 0; s < SERVERS; ++s) {
        System.out.println("Add vertices in TX on server " + s + "...");
        OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
        OrientGraph g = factory.getTx();
        try {
            for (int i = 0; i < SERVERS; ++i) {
                try {
                    final OrientVertex v = g.addVertex("class:" + "Client" + i);
                    g.commit();
                    Assert.assertTrue(false);
                } catch (ONeedRetryException e) {
                // EXPECTED
                } catch (OValidationException e) {
                // EXPECTED
                }
            }
        } finally {
            g.shutdown();
        }
    }
}
Also used : OValidationException(com.orientechnologies.orient.core.exception.OValidationException) OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) ONeedRetryException(com.orientechnologies.common.concur.ONeedRetryException) OrientGraphFactory(com.tinkerpop.blueprints.impls.orient.OrientGraphFactory) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) OrientVertexType(com.tinkerpop.blueprints.impls.orient.OrientVertexType) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex)

Example 68 with OrientVertex

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

the class OrientDbCreationHelper method createWriterAndPosts.

public static void createWriterAndPosts(OrientBaseGraph db, int totAuthors, int totArticles) throws IOException {
    int articleSerial = 0;
    for (int a = 1; a <= totAuthors; ++a) {
        OrientVertex writer = db.addVertex("class:Writer");
        writer.setProperty("uuid", a);
        writer.setProperty("name", "happy writer");
        writer.setProperty("is_active", Boolean.TRUE);
        writer.setProperty("isActive", Boolean.TRUE);
        for (int i = 1; i <= totArticles; ++i) {
            OrientVertex post = db.addVertex("class:Post");
            Calendar instance = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
            Date time = instance.getTime();
            post.setProperty("date", time, OType.DATE);
            post.setProperty("uuid", articleSerial++);
            post.setProperty("title", "the title");
            post.setProperty("content", "the content");
            db.addEdge("class:Writes", writer, post, null);
        }
    }
    //additional wrong data
    OrientVertex writer = db.addVertex("class:Writer");
    writer.setProperty("uuid", totAuthors * 2);
    writer.setProperty("name", "happy writer");
    writer.setProperty("is_active", Boolean.TRUE);
    writer.setProperty("isActive", Boolean.TRUE);
    OrientVertex post = db.addVertex("class:Post");
    //no date!!
    post.setProperty("uuid", articleSerial * 2);
    post.setProperty("title", "the title");
    post.setProperty("content", "the content");
    db.addEdge("class:Writes", writer, post, null);
}
Also used : Calendar(java.util.Calendar) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) Date(java.util.Date)

Example 69 with OrientVertex

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

the class DbListenerTest method testEmbeddedDbListenersGraph.

@Test
public void testEmbeddedDbListenersGraph() throws IOException {
    if (database.getURL().startsWith("remote:"))
        return;
    if (database.exists())
        ODatabaseHelper.deleteDatabase(database, getStorageType());
    ODatabaseHelper.createDatabase(database, url, getStorageType());
    database.open("admin", "admin");
    OrientGraph g = new OrientGraph(database);
    OrientVertex v = g.addVertex(null);
    v.setProperty("name", "Jay");
    g.commit();
    final DocumentChangeListener cl = new DocumentChangeListener(g);
    v.setProperty("surname", "Miner");
    g.shutdown();
    Assert.assertEquals(cl.getChanges().size(), 1);
    ODatabaseHelper.deleteDatabase(database, getStorageType());
    ODatabaseHelper.createDatabase(database, url, getStorageType());
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) Test(org.testng.annotations.Test)

Example 70 with OrientVertex

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

the class GraphDatabaseTest method testDeleteOfVerticesAndEdgesWithDeleteCommandAndUnsafe.

public void testDeleteOfVerticesAndEdgesWithDeleteCommandAndUnsafe() {
    Iterable<OIdentifiable> deletedVertices = database.command(new OCommandSQL("delete from GraphVehicle return before limit 1 unsafe")).execute();
    Assert.assertTrue(deletedVertices.iterator().hasNext());
    OrientVertex v = (OrientVertex) deletedVertices.iterator().next();
    Integer confirmDeleted = database.command(new OCommandSQL("delete from " + v.getIdentity() + " unsafe")).execute();
    Assert.assertFalse(deletedVertices.iterator().hasNext());
    Assert.assertEquals(confirmDeleted.intValue(), 0);
    Iterable<Edge> edges = v.getEdges(Direction.BOTH);
    for (Edge e : edges) {
        Integer deletedEdges = database.command(new OCommandSQL("delete from " + ((OrientEdge) e).getIdentity() + " unsafe")).execute();
        Assert.assertEquals(deletedEdges.intValue(), 1);
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OrientEdge(com.tinkerpop.blueprints.impls.orient.OrientEdge) Edge(com.tinkerpop.blueprints.Edge)

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