Package com.tinkerpop.blueprints

Examples of com.tinkerpop.blueprints.Graph


        for (Map.Entry<Long, FaunusVertex> entry : graph.entrySet()) {
            edgeMapReduceDriver.withInput(NullWritable.get(), entry.getValue());
        }
        edgeMapReduceDriver.run();

        final Graph tinkerGraph = ((TinkerGraphOutputMapReduce.VertexMap) vertexMapReduceDriver.getMapper()).graph;

        Vertex marko = null;
        Vertex peter = null;
        Vertex josh = null;
        Vertex vadas = null;
        Vertex lop = null;
        Vertex ripple = null;
        Vertex stephen = null;
        int count = 0;
        for (Vertex v : tinkerGraph.getVertices()) {
            count++;
            String name = v.getProperty("name").toString();
            if (name.equals("marko")) {
                marko = v;
            } else if (name.equals("peter")) {
View Full Code Here


        for (Map.Entry<Long, FaunusVertex> entry : graph.entrySet()) {
            edgeMapReduceDriver.withInput(NullWritable.get(), entry.getValue());
        }
        edgeMapReduceDriver.run();

        final Graph tinkerGraph = ((TinkerGraphOutputMapReduce.VertexMap) vertexMapReduceDriver.getMapper()).graph;

        Vertex marko = null;
        Vertex peter = null;
        Vertex josh = null;
        Vertex vadas = null;
        Vertex lop = null;
        Vertex ripple = null;
        int count = 0;
        for (Vertex v : tinkerGraph.getVertices()) {
            count++;
            String name = v.getProperty("name").toString();
            if (name.equals("marko")) {
                marko = v;
            } else if (name.equals("peter")) {
                peter = v;
            } else if (name.equals("josh")) {
                josh = v;
            } else if (name.equals("vadas")) {
                vadas = v;
            } else if (name.equals("lop")) {
                lop = v;
            } else if (name.equals("ripple")) {
                ripple = v;
            } else {
                assertTrue(false);
            }
        }
        assertTrue(null != marko);
        assertTrue(null != peter);
        assertTrue(null != josh);
        assertTrue(null != vadas);
        assertTrue(null != lop);
        assertTrue(null != ripple);
        assertEquals(count, 6);

        count = 0;
        for (Edge edge : tinkerGraph.query().edges()) {
            System.out.println(edge);
            count++;
        }
        assertEquals(count, 6);
View Full Code Here

            assertEquals(entry.getSecond().getProperties().size(), 0);
            assertEquals(entry.getSecond().getIdAsLong(), -1);
        }
        assertEquals(counter, 6);

        final Graph tinkerGraph = ((TinkerGraphOutputMapReduce.VertexMap) vertexMapReduceDriver.getMapper()).graph;

        Vertex marko = null;
        Vertex peter = null;
        Vertex josh = null;
        Vertex vadas = null;
        Vertex lop = null;
        Vertex ripple = null;
        int count = 0;
        for (Vertex v : tinkerGraph.getVertices()) {
            count++;
            String name = v.getProperty("name").toString();
            if (name.equals("marko")) {
                marko = v;
            } else if (name.equals("peter")) {
                peter = v;
            } else if (name.equals("josh")) {
                josh = v;
            } else if (name.equals("vadas")) {
                vadas = v;
            } else if (name.equals("lop")) {
                lop = v;
            } else if (name.equals("ripple")) {
                ripple = v;
            } else {
                assertTrue(false);
            }
        }
        assertEquals(count, 6);
        assertTrue(null != marko);
        assertTrue(null != peter);
        assertTrue(null != josh);
        assertTrue(null != vadas);
        assertTrue(null != lop);
        assertTrue(null != ripple);

        assertEquals(count(tinkerGraph.getEdges()), 6);

        // test marko
        Set<Vertex> vertices = new HashSet<Vertex>();
        assertEquals(marko.getProperty("name"), "marko");
        assertEquals(((Number) marko.getProperty("age")).intValue(), 29);
View Full Code Here

    super(graphTest);
  }

  @Test
  public void testGetEdgesWithTargetVertex() throws Exception {
    Graph graph = graphTest.generateGraph();

    OrientVertex v1 = (OrientVertex) graph.addVertex(null);
    OrientVertex v2 = (OrientVertex) graph.addVertex(null);
    OrientVertex v3 = (OrientVertex) graph.addVertex(null);
    v1.addEdge("targets", v2);
    v1.addEdge("targets", v3);

    Assert.assertEquals(1, count(v1.getEdges(v2, Direction.OUT, "targets")));
    Assert.assertEquals(0, count(v1.getEdges(v2, Direction.IN, "targets")));
    Assert.assertEquals(0, count(v1.getEdges(v2, Direction.OUT, "aaa")));
    Assert.assertEquals(1, count(v1.getEdges(v3, Direction.OUT, "targets")));
    Assert.assertEquals(0, count(v1.getEdges(v3, Direction.OUT, "bbb")));
    Assert.assertEquals(1, count(v1.getEdges(v2, Direction.OUT)));
    Assert.assertEquals(1, count(v1.getEdges(v3, Direction.OUT)));

    Assert.assertEquals(1, count(v2.getEdges(v1, Direction.IN, "targets")));
    Assert.assertEquals(0, count(v2.getEdges(v1, Direction.OUT, "targets")));
    Assert.assertEquals(0, count(v2.getEdges(v1, Direction.IN, "aaa")));
    Assert.assertEquals(1, count(v2.getEdges(v1, Direction.IN, "targets")));
    Assert.assertEquals(0, count(v2.getEdges(v1, Direction.IN, "bbb")));
    Assert.assertEquals(1, count(v2.getEdges(v1, Direction.IN)));

    graph.shutdown();
  }
View Full Code Here

  @Test
  public void testComplexMapProperty() throws Exception {
    // complex map properties have problems when unmarshalled from disk to
    // an OTrackedMap
    Graph graph = graphTest.generateGraph("complex-map");
    final HashMap<String, Object> consignee = new HashMap<String, Object>();
    consignee.put("name", "Company 4");
    final ArrayList consigneeAddress = new ArrayList();
    consigneeAddress.add("Lilla Bommen 6");
    consignee.put("address", consigneeAddress);
    consignee.put("zipCode", "41104");
    consignee.put("city", "G\u00f6teborg");
    final HashMap<String, Object> consigneeCountry = new HashMap<String, Object>();
    consigneeCountry.put("name", "Sverige");
    consigneeCountry.put("code", "SV");
    consignee.put("country", consigneeCountry);
    consignee.put("contactName", "Contact Person 4");
    consignee.put("telephone", "0731123456");
    consignee.put("telefax", null);
    consignee.put("mobileTelephone", "072345678");
    consignee.put("email", "test@company4.com");
    consignee.put("hiflexId", null);

    final HashMap<String, Object> delivery = new HashMap<String, Object>();
    delivery.put("name", "Company 5");
    final ArrayList deliveryAddress = new ArrayList();
    deliveryAddress.add("Stora Enens V\u00e4g 38");
    delivery.put("address", deliveryAddress);
    delivery.put("zipCode", "43931");
    delivery.put("city", "Onsala");
    final HashMap<String, Object> deliveryCountry = new HashMap<String, Object>();
    deliveryCountry.put("name", "Sverige");
    deliveryCountry.put("code", "SV");
    delivery.put("country", deliveryCountry);
    delivery.put("contactName", "Contact Person 5");
    delivery.put("telephone", "030060094");
    delivery.put("telefax", null);
    delivery.put("mobileTelephone", null);
    delivery.put("email", "test@company5.com");
    delivery.put("hiflexId", null);

    final HashMap<String, Object> pickup = new HashMap<String, Object>();
    pickup.put("name", "Pickup Company 2");
    final ArrayList pickupAddress = new ArrayList();
    pickupAddress.add("Drottninggatan 1");
    pickup.put("address", pickupAddress);
    pickup.put("zipCode", "41103");
    pickup.put("city", "G\u00f6teborg");
    final HashMap<String, Object> pickupCountry = new HashMap<String, Object>();
    pickupCountry.put("name", "Sverige");
    pickupCountry.put("code", "SV");
    pickup.put("country", pickupCountry);
    pickup.put("contactName", "Contact Person 6");
    pickup.put("telephone", "071234567");
    pickup.put("telefax", null);
    pickup.put("mobileTelephone", null);
    pickup.put("email", "test@pickupcompany2.com");
    pickup.put("hiflexId", null);

    final Map shipping = new HashMap();
    shipping.put("name", "Posten MyPack");
    shipping.put("code", "postenmypack");
    shipping.put("templateName", "POSTENMYPACK");
    shipping.put("rates", new ArrayList());

    final Vertex v = graph.addVertex(null);
    v.setProperty("weight", 20);
    v.setProperty("height", 20);
    v.setProperty("consigneeAddress", consignee);
    v.setProperty("width", 10);
    v.setProperty("sum", 400);
    v.setProperty("shippingMethod", shipping);
    v.setProperty("type", "shipment");
    v.setProperty("depth", 30);
    v.setProperty("estimatedCost", 200);
    v.setProperty("deliveryAddress", delivery);
    v.setProperty("pickupAddress", pickup);

    ((TransactionalGraph) graph).commit();

    // have to shutdown the graph so that the map will read back out as an
    // OTrackedMap. Maps that exist in memory
    // do not show the problem.
    graph.shutdown();

    graph = graphTest.generateGraph("complex-map");

    final Vertex v1 = graph.getVertex(v.getId());
    assertNotNull(v1);

    // check the delivery address. not sure if there should be other
    // assertions here, but the basic issues
    // is that the keys/values in the OTrackedMap appear like this:
    // mobileTelephone=null:null
    final Map d = v1.getProperty("deliveryAddress");
    assertNotNull(d);
    assertTrue(d.containsKey("telefax"));
    graph.shutdown();
    //graphTest.dropGraph(((OrientGraphTest) graphTest).getWorkingDirectory() + "/complex-map");
  }
View Full Code Here

        }
        batch.shutdown();

        // native neo4j graph load

        final Graph graph = new Neo4jGraph(directory);
        assertEquals(count(graph.getVertices()), 10);

        assertEquals(count(graph.getEdges()), 9);
        for (final Edge edge : graph.getEdges()) {
            long idA = (Long) edge.getVertex(Direction.OUT).getId();
            long idB = (Long) edge.getVertex(Direction.IN).getId();
            assertEquals(idA + 1, idB);
            assertEquals(edge.getLabel(), idA + "-" + idB);
        }

        assertNotNull(graph.getVertex(1L));
        assertNull(graph.getVertex(100L));
        assertNull(graph.getEdge(100L));

        graph.shutdown();
    }
View Full Code Here

        assertNull(batch.getVertex(200000L));
        batch.shutdown();

        // native neo4j graph load

        final Graph graph = new Neo4jGraph(directory);
        assertEquals(count(graph.getVertices()), ids.size());
        for (final Long id : ids) {
            assertNotNull(graph.getVertex(id));
            assertEquals(graph.getVertex(id).getProperty("theKey"), id);
            assertEquals(graph.getVertex(id).getPropertyKeys().size(), 1);
        }
        assertNull(graph.getVertex(1L));
        assertNull(graph.getVertex(2L));
        assertNull(graph.getVertex(200000L));
        graph.shutdown();
    }
View Full Code Here

        assertNull(batch.getVertex(200000L));
        batch.shutdown();

        // native neo4j graph load

        final Graph graph = new Neo4jGraph(directory);
        assertEquals(count(graph.getVertices()), ids.size());
        assertNotNull(graph.getVertex(100l));
        assertNotNull(graph.getVertex(5l));
        assertNotNull(graph.getVertex(10l));
        assertNotNull(graph.getVertex(4l));
        assertNotNull(graph.getVertex(10000));

        graph.shutdown();

    }
View Full Code Here

        super(graphTest);
    }

    public void testSparkseeGraph() throws Exception {
        double totalTime = 0.0d;
        Graph graph = graphTest.generateGraph();
        GraphMLReader.inputGraph(graph, GraphMLReader.class.getResourceAsStream("graph-example-2.xml"));
        graph.shutdown();

        for (int i = 0; i < TOTAL_RUNS; i++) {
            graph = graphTest.generateGraph();
            this.stopWatch();
            int counter = 0;
            CloseableIterable<Vertex> vv = (CloseableIterable<Vertex>) graph.getVertices();
            for (final Vertex vertex : vv) {
                counter++;
                CloseableIterable<Edge> ee = (CloseableIterable<Edge>) vertex.getEdges(Direction.OUT);
                for (final Edge edge : ee) {
                    counter++;
                    final Vertex vertex2 = edge.getVertex(Direction.IN);
                    counter++;
                    CloseableIterable<Edge> ee2 = (CloseableIterable<Edge>) vertex2.getEdges(Direction.OUT);
                    for (final Edge edge2 : ee2) {
                        counter++;
                        final Vertex vertex3 = edge2.getVertex(Direction.IN);
                        counter++;
                        CloseableIterable<Edge> ee3 = (CloseableIterable<Edge>) vertex3.getEdges(Direction.OUT);
                        for (final Edge edge3 : ee3) {
                            counter++;
                            edge3.getVertex(Direction.OUT);
                            counter++;
                        }
                        ee3.close();
                    }
                    ee2.close();
                }
                ee.close();
            }
            vv.close();
            double currentTime = this.stopWatch();
            totalTime = totalTime + currentTime;
            BaseTest.printPerformance(graph.toString(), counter, "SparkseeGraph elements touched (run=" + i + ")", currentTime);
            graph.shutdown();
        }
        BaseTest.printPerformance("SparkseeGraph", 1, "SparkseeGraph experiment average", totalTime / (double) TOTAL_RUNS);
    }
View Full Code Here

    public SparkseeGraphSpecificTestSuite(final GraphTest graphTest) {
        super(graphTest);
    }

    public void testSparkseeVertexLabel() throws Exception {
        Graph graph = graphTest.generateGraph();
        ((SparkseeGraph) graph).typeScope.set(true);
        this.stopWatch();

        assertTrue(graph.addVertex(null).getProperty(StringFactory.LABEL).equals(SparkseeGraph.DEFAULT_SPARKSEE_VERTEX_LABEL));
        ((SparkseeGraph) graph).label.set("people");
        assertTrue(graph.addVertex(null).getProperty(StringFactory.LABEL).equals("people"));
        ((SparkseeGraph) graph).label.set("thing");
        assertTrue(graph.addVertex(null).getProperty(StringFactory.LABEL).equals("thing"));
        assertTrue(graph.addVertex("whatever").getProperty(StringFactory.LABEL).equals("thing"));
        ((SparkseeGraph) graph).label.set(null);
        assertTrue(graph.addVertex(null).getProperty(StringFactory.LABEL).equals(SparkseeGraph.DEFAULT_SPARKSEE_VERTEX_LABEL));

        ((SparkseeGraph) graph).label.set("mylabel");
        Vertex v1 = graph.addVertex("mylabel");
        boolean excep = false;
        try {
            v1.setProperty(StringFactory.LABEL, "otherlabel");
        } catch (IllegalArgumentException e) {
            excep = true;
        } finally {
            assertTrue(excep);
        }

        printPerformance(graph.toString(), null, "testSparkseeVertexLabel", this.stopWatch());
        graph.shutdown();
    }
View Full Code Here

TOP

Related Classes of com.tinkerpop.blueprints.Graph

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.