Refine search
@Test public void testArrayEqualityUsingImplicitKey() { TitanVertex v = graph.addVertex(); byte singleDimension[] = new byte[]{127, 0, 0, 1}; byte singleDimensionCopy[] = new byte[]{127, 0, 0, 1}; final String singlePropName = "single"; v.property(singlePropName, singleDimension); assertEquals(1, Iterables.size(graph.query().has(singlePropName, singleDimension).vertices())); assertEquals(1, Iterables.size(graph.query().has(singlePropName, singleDimensionCopy).vertices())); graph.tx().commit(); assertEquals(1, Iterables.size(graph.query().has(singlePropName, singleDimension).vertices())); assertEquals(1, Iterables.size(graph.query().has(singlePropName, singleDimensionCopy).vertices())); }
@Test public void testStaleVertex() { PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make(); PropertyKey age = mgmt.makePropertyKey("age").dataType(Integer.class).make(); mgmt.buildIndex("byName", Vertex.class).addKey(name).unique().buildCompositeIndex(); finishSchema(); TitanVertex cartman = graph.addVertex("name", "cartman", "age", 10); TitanVertex stan = graph.addVertex("name", "stan", "age", 8); graph.tx().commit(); cartman = getOnlyElement(graph.query().has("name", "cartman").vertices()); graph.tx().commit(); TitanVertexProperty p = (TitanVertexProperty) cartman.properties().next(); assertTrue(((Long) p.longId()) > 0); graph.tx().commit(); }
@Test public void testStaleVertex() { PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make(); mgmt.makePropertyKey("age").dataType(Integer.class).make(); mgmt.buildIndex("byName", Vertex.class).addKey(name).unique().buildCompositeIndex(); finishSchema(); JanusGraphVertex cartman = graph.addVertex("name", "cartman", "age", 10); graph.addVertex("name", "stan", "age", 8); graph.tx().commit(); cartman = Iterables.getOnlyElement(graph.query().has("name", "cartman").vertices()); graph.tx().commit(); JanusGraphVertexProperty p = (JanusGraphVertexProperty) cartman.properties().next(); assertTrue((p.longId()) > 0); graph.tx().commit(); }
@Test public void testArrayEqualityUsingImplicitKey() { JanusGraphVertex v = graph.addVertex(); byte singleDimension[] = new byte[]{127, 0, 0, 1}; byte singleDimensionCopy[] = new byte[]{127, 0, 0, 1}; final String singlePropName = "single"; v.property(singlePropName, singleDimension); assertEquals(1, Iterables.size(graph.query().has(singlePropName, singleDimension).vertices())); assertEquals(1, Iterables.size(graph.query().has(singlePropName, singleDimensionCopy).vertices())); graph.tx().commit(); assertEquals(1, Iterables.size(graph.query().has(singlePropName, singleDimension).vertices())); assertEquals(1, Iterables.size(graph.query().has(singlePropName, singleDimensionCopy).vertices())); }
@Test public void testVLabelOnOrderedStorage() { final String label = "pl"; mgmt.makeVertexLabel(label).partition().make(); mgmt.commit(); graph.tx().rollback(); graph.addVertex(label); graph.tx().commit(); mgmt = graph.openManagement(); VertexLabel vl = mgmt.getVertexLabel(label); assertTrue(vl.isPartitioned()); mgmt.rollback(); }
@Test public void testVLabelOnOrderedStorage() { final String label = "pl"; mgmt.makeVertexLabel(label).partition().make(); mgmt.commit(); graph.tx().rollback(); graph.addVertex(label); graph.tx().commit(); mgmt = graph.openManagement(); VertexLabel vl = mgmt.getVertexLabel(label); assertTrue(vl.isPartitioned()); mgmt.rollback(); }
@Test public void testPartitionedVertexScan() throws Exception { tearDown(); clearGraph(getConfiguration()); WriteConfiguration partConf = getConfiguration(); open(partConf); mgmt.makeVertexLabel("part").partition().make(); finishSchema(); TitanVertex supernode = graph.addVertex("part"); for (int i = 0; i < 128; i++) { TitanVertex v = graph.addVertex("part"); v.addEdge("default", supernode); if (0 < i && 0 == i % 4) graph.tx().commit(); } graph.tx().commit(); org.apache.hadoop.conf.Configuration c = new org.apache.hadoop.conf.Configuration(); c.set(ConfigElement.getPath(TitanHadoopConfiguration.GRAPH_CONFIG_KEYS, true) + "." + "storage.cassandra.keyspace", getClass().getSimpleName()); c.set(ConfigElement.getPath(TitanHadoopConfiguration.GRAPH_CONFIG_KEYS, true) + "." + "storage.backend", "cassandrathrift"); c.set("cassandra.input.partitioner.class", "org.apache.cassandra.dht.Murmur3Partitioner"); Job job = getVertexJobWithDefaultMapper(c); // Should throw an exception since filter-partitioned-vertices wasn't enabled assertFalse(job.waitForCompletion(true)); }
@Test public void testPartitionedVertexFilteredScan() throws Exception { tearDown(); clearGraph(getConfiguration()); WriteConfiguration partConf = getConfiguration(); open(partConf); mgmt.makeVertexLabel("part").partition().make(); finishSchema(); TitanVertex supernode = graph.addVertex("part"); for (int i = 0; i < 128; i++) { TitanVertex v = graph.addVertex("part"); v.addEdge("default", supernode); if (0 < i && 0 == i % 4) graph.tx().commit(); } graph.tx().commit(); org.apache.hadoop.conf.Configuration c = new org.apache.hadoop.conf.Configuration(); c.set(ConfigElement.getPath(TitanHadoopConfiguration.GRAPH_CONFIG_KEYS, true) + "." + "storage.cassandra.keyspace", getClass().getSimpleName()); c.set(ConfigElement.getPath(TitanHadoopConfiguration.GRAPH_CONFIG_KEYS, true) + "." + "storage.backend", "cassandrathrift"); c.set(ConfigElement.getPath(TitanHadoopConfiguration.FILTER_PARTITIONED_VERTICES), "true"); c.set("cassandra.input.partitioner.class", "org.apache.cassandra.dht.Murmur3Partitioner"); Job job = getVertexJobWithDefaultMapper(c); // Should succeed assertTrue(job.waitForCompletion(true)); }
@Test public void testEdgesExceedCacheSize() { // Add a vertex with as many edges as the tx-cache-size. (20000 by default) int numEdges = graph.getConfiguration().getTxVertexCacheSize(); TitanVertex parentVertex = graph.addVertex(); for (int i = 0; i < numEdges; i++) { TitanVertex childVertex = graph.addVertex(); parentVertex.addEdge("friend", childVertex); } graph.tx().commit(); assertCount(numEdges, parentVertex.query().direction(Direction.OUT).edges()); // Remove an edge. parentVertex.query().direction(OUT).edges().iterator().next().remove(); // Check that getEdges returns one fewer. assertCount(numEdges - 1, parentVertex.query().direction(Direction.OUT).edges()); // Run the same check one more time. // This fails! (Expected: 19999. Actual: 20000.) assertCount(numEdges - 1, parentVertex.query().direction(Direction.OUT).edges()); }
@Test public void testCacheSpeedup() { Object[] newConfig = {option(GraphDatabaseConfiguration.DB_CACHE),true, previous = v; graph.tx().commit(); long vertexId = getId(previous); assertCount(numV, graph.query().vertices()); double timehot = 0; for (int i = 0;i<innerRepeat;i++) { graph.tx().commit(); timewarm += testAllVertices(vertexId,numV); for (int j=0;j<innerRepeat;j++) {
@Test public void testEdgesExceedCacheSize() { // Add a vertex with as many edges as the tx-cache-size. (20000 by default) int numEdges = graph.getConfiguration().getTxVertexCacheSize(); JanusGraphVertex parentVertex = graph.addVertex(); for (int i = 0; i < numEdges; i++) { JanusGraphVertex childVertex = graph.addVertex(); parentVertex.addEdge("friend", childVertex); } graph.tx().commit(); assertCount(numEdges, parentVertex.query().direction(Direction.OUT).edges()); // Remove an edge. parentVertex.query().direction(OUT).edges().iterator().next().remove(); // Check that getEdges returns one fewer. assertCount(numEdges - 1, parentVertex.query().direction(Direction.OUT).edges()); // Run the same check one more time. // This fails! (Expected: 19999. Actual: 20000.) assertCount(numEdges - 1, parentVertex.query().direction(Direction.OUT).edges()); }
@Test public void testIndexQueryWithLabelsAndContainsIN() { // This test is based on the steps to reproduce #882 String labelName = "labelName"; VertexLabel label = mgmt.makeVertexLabel(labelName).make(); PropertyKey uid = mgmt.makePropertyKey("uid").dataType(String.class).make(); TitanGraphIndex uidCompositeIndex = mgmt.buildIndex("uidIndex", Vertex.class).indexOnly(label).addKey(uid).unique().buildCompositeIndex(); mgmt.setConsistency(uidCompositeIndex, ConsistencyModifier.LOCK); finishSchema(); TitanVertex foo = graph.addVertex(labelName); TitanVertex bar = graph.addVertex(labelName); foo.property("uid", "foo"); bar.property("uid", "bar"); graph.tx().commit(); Iterable<TitanVertex> vertexes = graph.query() .has("uid", Contain.IN, ImmutableList.of("foo", "bar")) .has(LABEL_NAME, labelName) .vertices(); assertEquals(2, Iterables.size(vertexes)); for (TitanVertex v : vertexes) { assertEquals(labelName, v.vertexLabel().name()); } }
@Test public void testEdgeTTLWithTransactions() throws Exception { if (!features.hasCellTTL()) { return; } EdgeLabel label1 = mgmt.makeEdgeLabel("likes").make(); mgmt.setTTL(label1, Duration.ofSeconds(1)); assertEquals(Duration.ofSeconds(1), mgmt.getTTL(label1)); mgmt.commit(); TitanVertex v1 = graph.addVertex(), v2 = graph.addVertex(); v1.addEdge("likes", v2); // pre-commit state of the edge. It is not yet subject to TTL assertNotEmpty(v1.query().direction(Direction.OUT).vertices()); Thread.sleep(1001); // the edge should have expired by now, but only if it had been committed assertNotEmpty(v1.query().direction(Direction.OUT).vertices()); graph.tx().commit(); // still here, because we have just committed the edge. Its countdown starts at the commit assertNotEmpty(v1.query().direction(Direction.OUT).vertices()); Thread.sleep(1001); // the edge has expired in Cassandra, but still appears alive in this transaction assertNotEmpty(v1.query().direction(Direction.OUT).vertices()); // syncing with the data store, we see that the edge has expired graph.tx().rollback(); assertEmpty(v1.query().direction(Direction.OUT).vertices()); }
@Test public void testEdgeTTLWithTransactions() throws Exception { if (!features.hasCellTTL()) { return; } EdgeLabel label1 = mgmt.makeEdgeLabel("likes").make(); mgmt.setTTL(label1, Duration.ofSeconds(1)); assertEquals(Duration.ofSeconds(1), mgmt.getTTL(label1)); mgmt.commit(); JanusGraphVertex v1 = graph.addVertex(), v2 = graph.addVertex(); v1.addEdge("likes", v2); // pre-commit state of the edge. It is not yet subject to TTL assertNotEmpty(v1.query().direction(Direction.OUT).vertices()); Thread.sleep(1001); // the edge should have expired by now, but only if it had been committed assertNotEmpty(v1.query().direction(Direction.OUT).vertices()); graph.tx().commit(); // still here, because we have just committed the edge. Its countdown starts at the commit assertNotEmpty(v1.query().direction(Direction.OUT).vertices()); Thread.sleep(1001); // the edge has expired in Cassandra, but still appears alive in this transaction assertNotEmpty(v1.query().direction(Direction.OUT).vertices()); // syncing with the data store, we see that the edge has expired graph.tx().rollback(); assertEmpty(v1.query().direction(Direction.OUT).vertices()); }
@Test public void testIndexQueryWithLabelsAndContainsIN() { // This test is based on the steps to reproduce #882 String labelName = "labelName"; VertexLabel label = mgmt.makeVertexLabel(labelName).make(); PropertyKey uid = mgmt.makePropertyKey("uid").dataType(String.class).make(); JanusGraphIndex uidCompositeIndex = mgmt.buildIndex("uidIndex", Vertex.class) .indexOnly(label).addKey(uid).unique().buildCompositeIndex(); mgmt.setConsistency(uidCompositeIndex, ConsistencyModifier.LOCK); finishSchema(); JanusGraphVertex foo = graph.addVertex(labelName); JanusGraphVertex bar = graph.addVertex(labelName); foo.property("uid", "foo"); bar.property("uid", "bar"); graph.tx().commit(); Iterable<JanusGraphVertex> vertexes = graph.query() .has("uid", Contain.IN, ImmutableList.of("foo", "bar")) .has(LABEL_NAME, labelName) .vertices(); assertEquals(2, Iterables.size(vertexes)); for (JanusGraphVertex v : vertexes) { assertEquals(labelName, v.vertexLabel().name()); } }