/** * Tests the {@link com.thinkaurelius.titan.example.GraphOfTheGodsFactory#load(com.thinkaurelius.titan.core.TitanGraph)} * method used as the standard example that ships with Titan. */ @Test public void testGraphOfTheGods() { GraphOfTheGodsFactory.load(graph); assertGraphOfTheGods(graph); }
PropertyKey name = makeKey("name", String.class); PropertyKey time = makeKey("time", Long.class); PropertyKey text = makeKey("text", String.class); addKey(name, getStringMapping()).addKey(time).buildMixedIndex(INDEX); mgmt.buildIndex("index2", Vertex.class).indexOnly(event). addKey(text, getTextMapping()).buildMixedIndex(INDEX); finishSchema(); ElementCategory.VERTEX, 1, new boolean[]{true, true}, "index2"); clopen(); ElementCategory.VERTEX, 1, new boolean[]{true, true}, "index2"); v1 = getV(tx, v1Id); v2 = getV(tx, v1Id); assertNotNull(v1); assertNotNull(v2); clopen(); v1 = getV(tx, v1Id); v2 = getV(tx, v2Id); assertNull(v1); assertNull(v2);
final TimestampProvider times = graph.getConfiguration().getTimestampProvider(); final Instant startTime = times.getTime(); clopen(option(SYSTEM_LOG_TRANSACTIONS), true , option(KCVSLog.LOG_READ_LAG_TIME, TRANSACTION_LOG), Duration.ofMillis(50) , option(LOG_READ_INTERVAL, TRANSACTION_LOG), Duration.ofMillis(250) , option(MAX_COMMIT_TIME), Duration.ofSeconds(1) , option(STORAGE_WRITE_WAITTIME), Duration.ofMillis(300) , option(TestMockIndexProvider.INDEX_BACKEND_PROXY, INDEX), readConfig.get(INDEX_BACKEND, INDEX) , option(INDEX_BACKEND, INDEX), TestMockIndexProvider.class.getName() , option(TestMockIndexProvider.INDEX_MOCK_FAILADD, INDEX), true ); mgmt.buildIndex("mi", Vertex.class).addKey(name, getTextMapping()).addKey(age).buildMixedIndex(INDEX); finishSchema(); Vertex vs[] = new TitanVertex[4]; newTx(); vs[1] = tx.addVertex("name", "Long Little Lewis", "age", 35); vs[2] = tx.addVertex("name", "Tall Long Tiger", "age", 75); vs[3] = tx.addVertex("name", "Long John Don", "age", 15); newTx(); vs[2] = getV(tx, vs[2]); vs[2].remove(); vs[3] = getV(tx, vs[3]); vs[3].property(VertexProperty.Cardinality.single, "name", "Bad Boy Badsy"); vs[3].property("age").remove(); newTx(); vs[0] = getV(tx, vs[0]); vs[0].property(VertexProperty.Cardinality.single, "age", 66);
private void setupChainGraph(int numV, String[] strs, boolean sameNameMapping) { clopen(option(INDEX_NAME_MAPPING, INDEX), sameNameMapping); TitanGraphIndex vindex = getExternalIndex(Vertex.class, INDEX); TitanGraphIndex eindex = getExternalIndex(Edge.class, INDEX); TitanGraphIndex pindex = getExternalIndex(TitanVertexProperty.class, INDEX); PropertyKey name = makeKey("name", String.class); mgmt.addIndexKey(vindex, name, getStringMapping()); mgmt.addIndexKey(eindex, name, getStringMapping()); mgmt.addIndexKey(pindex, name, getStringMapping(), Parameter.of("mapped-name", "xstr")); PropertyKey text = makeKey("text", String.class); mgmt.addIndexKey(vindex, text, getTextMapping(), Parameter.of("mapped-name", "xtext")); mgmt.addIndexKey(eindex, text, getTextMapping()); mgmt.addIndexKey(pindex, text, getTextMapping()); mgmt.makeEdgeLabel("knows").signature(name).make(); mgmt.makePropertyKey("uid").dataType(String.class).signature(text).make(); finishSchema(); TitanVertex previous = null; for (int i = 0; i < numV; i++) { TitanVertex v = graph.addVertex("name", strs[i % strs.length], "text", strs[i % strs.length]); Edge e = v.addEdge("knows", previous == null ? v : previous, "name", strs[i % strs.length], "text", strs[i % strs.length]); VertexProperty p = v.property("uid", "v" + i, "name", strs[i % strs.length], "text", strs[i % strs.length]); previous = v; } }
/** * Tests indexing using _all virtual field */ @Test public void testWidcardQuery() { if (supportsWildcardQuery()) { PropertyKey p1 = makeKey("p1", String.class); PropertyKey p2 = makeKey("p2", String.class); mgmt.buildIndex("mixedIndex", Vertex.class).addKey(p1).addKey(p2).buildMixedIndex(INDEX); finishSchema(); clopen(); TitanVertex v1 = graph.addVertex(); v1.property("p1", "test1"); v1.property("p2", "test2"); clopen();//Flush the index assertEquals(v1, graph.indexQuery("mixedIndex", "v.*:\"test1\"").vertices().iterator().next().getElement()); assertEquals(v1, graph.indexQuery("mixedIndex", "v.*:\"test2\"").vertices().iterator().next().getElement()); } }
PropertyKey name = makeKey("instant", Instant.class); mgmt.buildIndex("instantIndex", Vertex.class). addKey(name).buildMixedIndex(INDEX); finishSchema(); clopen(); Instant firstTimestamp = Instant.ofEpochMilli(1); Instant secondTimestamp = Instant.ofEpochMilli(2000); v2.property("instant", secondTimestamp); testInstant(firstTimestamp, secondTimestamp, v1, v2); v1.property("instant", firstTimestamp); if (indexFeatures.supportsNanoseconds()) { testInstant(firstTimestamp, secondTimestamp, v1, v2); } else { clopen();//Flush the index try { assertEquals(v1, getOnlyVertex(graph.query().has("instant", Cmp.EQUAL, firstTimestamp))); Assert.fail("Should have failed to update the index"); } catch (Exception e) {
PropertyKey text = makeKey("text", String.class); createExternalVertexIndex(text, INDEX); createExternalEdgeIndex(text, INDEX); PropertyKey location = makeKey("location", Geoshape.class); createExternalVertexIndex(location, INDEX); createExternalEdgeIndex(location, INDEX); PropertyKey time = makeKey("time", Long.class); createExternalVertexIndex(time, INDEX); createExternalEdgeIndex(time, INDEX); PropertyKey category = makeKey("category", Integer.class); mgmt.buildIndex("vcategory", Vertex.class).addKey(category).buildCompositeIndex(); mgmt.buildIndex("ecategory", Edge.class).addKey(category).buildCompositeIndex(); PropertyKey group = makeKey("group", Byte.class); createExternalVertexIndex(group, INDEX); createExternalEdgeIndex(group, INDEX); PropertyKey id = makeVertexIndexedKey("uid", Integer.class); EdgeLabel knows = ((StandardEdgeLabelMaker) mgmt.makeEdgeLabel("knows")).sortKey(time).signature(location).make(); finishSchema(); clopen(); String[] words = {"world", "aurelius", "titan", "graph"}; int numCategories = 5; Edge e = v.addEdge("knows", getVertex("uid", Math.max(0, i - 1)));
@Test public void testIndexUpdatesWithoutReindex() throws InterruptedException, ExecutionException { Object[] settings = new Object[]{option(LOG_SEND_DELAY, MANAGEMENT_LOG), Duration.ofMillis(0), option(KCVSLog.LOG_READ_LAG_TIME, MANAGEMENT_LOG), Duration.ofMillis(50), option(LOG_READ_INTERVAL, MANAGEMENT_LOG), Duration.ofMillis(250) }; clopen(settings); final String defText = "Mountain rocks are great friends"; final int defTime = 5; mgmt.buildIndex("theIndex", Vertex.class).addKey(text, getTextMapping(), getFieldMap(text)).buildMixedIndex(INDEX); finishSchema(); addVertex(defTime, defText, defHeight, defPhones); clopen(settings); evaluateQuery(tx.query().has("text", Text.CONTAINS, "rocks"), ElementCategory.VERTEX, 1, new boolean[]{true, true}, "theIndex"); newTx(); finishSchema(); PropertyKey time = mgmt.getPropertyKey("time"); mgmt.addIndexKey(mgmt.getGraphIndex("theIndex"), time, getFieldMap(time)); finishSchema(); newTx(); addVertex(defTime, defText, defHeight, defPhones); tx.commit();
if (!supportsLuceneStyleQueries()) return; setupChainGraph(numV, strs, true); clopen();
@Test public void testSimpleUpdate() { PropertyKey name = makeKey("name", String.class); EdgeLabel knows = makeLabel("knows"); mgmt.buildIndex("namev", Vertex.class).addKey(name).buildMixedIndex(INDEX); mgmt.buildIndex("namee", Edge.class).addKey(name).buildMixedIndex(INDEX); finishSchema(); TitanVertex v = tx.addVertex("name", "Marko Rodriguez"); Edge e = v.addEdge("knows", v, "name", "Hulu Bubab"); assertCount(1, tx.query().has("name", Text.CONTAINS, "marko").vertices()); assertCount(1, tx.query().has("name", Text.CONTAINS, "Hulu").edges()); for (Vertex u : tx.getVertices()) assertEquals("Marko Rodriguez", u.value("name")); clopen(); assertCount(1, tx.query().has("name", Text.CONTAINS, "marko").vertices()); assertCount(1, tx.query().has("name", Text.CONTAINS, "Hulu").edges()); for (Vertex u : tx.getVertices()) assertEquals("Marko Rodriguez", u.value("name")); v = getOnlyVertex(tx.query().has("name", Text.CONTAINS, "marko")); v.property(VertexProperty.Cardinality.single, "name", "Marko"); e = getOnlyEdge(v.query().direction(Direction.OUT)); e.property("name", "Tubu Rubu"); assertCount(1, tx.query().has("name", Text.CONTAINS, "marko").vertices()); assertCount(1, tx.query().has("name", Text.CONTAINS, "Rubu").edges()); assertCount(0, tx.query().has("name", Text.CONTAINS, "Hulu").edges()); for (Vertex u : tx.getVertices()) assertEquals("Marko", u.value("name")); clopen(); assertCount(1, tx.query().has("name", Text.CONTAINS, "marko").vertices()); assertCount(1, tx.query().has("name", Text.CONTAINS, "Rubu").edges()); assertCount(0, tx.query().has("name", Text.CONTAINS, "Hulu").edges()); for (Vertex u : tx.getVertices()) assertEquals("Marko", u.value("name")); }
if (!indexFeatures.supportsStringMapping(Mapping.TEXTSTRING)) return; PropertyKey name = makeKey("name", String.class); TitanGraphIndex mixed = mgmt.buildIndex("mixed", Vertex.class).addKey(name, Mapping.TEXTSTRING.asParameter()).buildMixedIndex(INDEX); mixed.name(); finishSchema(); tx.addVertex("name", "Middle Sister Mabel"); clopen(); evaluateQuery(tx.query().has("name", Cmp.EQUAL, "Long John Don"), ElementCategory.VERTEX, 1, new boolean[]{true, true}, "mixed"); clopen();
@Test public void testSimpleUpdate() { PropertyKey name = makeKey("name",String.class); EdgeLabel knows = makeLabel("knows"); mgmt.buildIndex("namev",Vertex.class).addKey(name).buildMixedIndex(INDEX); mgmt.buildIndex("namee",Edge.class).addKey(name).buildMixedIndex(INDEX); finishSchema(); assertEquals(1, Iterables.size(tx.query().has("name", Text.CONTAINS, "Hulu").edges())); for (Vertex u : tx.getVertices()) assertEquals("Marko Rodriguez",u.getProperty("name")); clopen(); assertEquals(1, Iterables.size(tx.query().has("name", Text.CONTAINS, "marko").vertices())); assertEquals(1, Iterables.size(tx.query().has("name", Text.CONTAINS, "Hulu").edges())); assertEquals(0, Iterables.size(tx.query().has("name", Text.CONTAINS, "Hulu").edges())); for (Vertex u : tx.getVertices()) assertEquals("Marko",u.getProperty("name")); clopen(); assertEquals(1, Iterables.size(tx.query().has("name", Text.CONTAINS, "marko").vertices())); assertEquals(1, Iterables.size(tx.query().has("name", Text.CONTAINS, "Rubu").edges()));
PropertyKey prop = makeKey(propName, String.class); createExternalVertexIndex(prop, INDEX); finishSchema(); TitanTransaction propDeleter = graph.newTransaction(); getV(vertexDeleter, id).remove(); if (null == updatedValue) getV(propDeleter, id).property(propName).remove(); else getV(propDeleter, id).property(VertexProperty.Cardinality.single, propName, updatedValue); assertEquals(null, getV(graph, id)); assertEmpty(graph.query().has(propName).vertices()); if (null != updatedValue)
private void testIndexing(Cardinality cardinality) { if (supportsCollections()) { PropertyKey stringProperty = mgmt.makePropertyKey("name").dataType(String.class).cardinality(cardinality).make(); PropertyKey intProperty = mgmt.makePropertyKey("age").dataType(Integer.class).cardinality(cardinality).make(); PropertyKey longProperty = mgmt.makePropertyKey("long").dataType(Long.class).cardinality(cardinality).make(); PropertyKey uuidProperty = mgmt.makePropertyKey("uuid").dataType(UUID.class).cardinality(cardinality).make(); PropertyKey geoProperty = mgmt.makePropertyKey("geo").dataType(Geoshape.class).cardinality(cardinality).make(); mgmt.buildIndex("collectionIndex", Vertex.class).addKey(stringProperty, getStringMapping()).addKey(intProperty).addKey(longProperty).addKey(uuidProperty).addKey(geoProperty).buildMixedIndex(INDEX); finishSchema(); testCollection(cardinality, "name", "Totoro", "Hiro"); testCollection(cardinality, "age", 1, 2); testCollection(cardinality, "long", 1L, 2L); testCollection(cardinality, "uuid", UUID.randomUUID(), UUID.randomUUID()); testCollection(cardinality, "geo", Geoshape.point(1.0, 1.0), Geoshape.point(2.0, 2.0)); } else { try { PropertyKey stringProperty = mgmt.makePropertyKey("name").dataType(String.class).cardinality(cardinality).make(); //This should throw an exception mgmt.buildIndex("collectionIndex", Vertex.class).addKey(stringProperty, getStringMapping()).buildMixedIndex(INDEX); Assert.fail("Should have thrown an exception"); } catch (TitanException e) { } } }
private void testCollection(Cardinality cardinality, String property, Object value1, Object value2) { clopen(); clopen();//Flush the index assertEquals(v1, getOnlyElement(graph.query().has(property, value1).vertices())); v1 = getV(graph, v1.id()); v1.property(property, value2); assertEquals(v1, getOnlyElement(graph.query().has(property, value1).vertices())); assertEquals(v1, getOnlyElement(graph.query().has(property, value2).vertices())); clopen();//Flush the index assertEquals(v1, getOnlyElement(graph.query().has(property, value1).vertices())); assertEquals(v1, getOnlyElement(graph.query().has(property, value2).vertices())); v1 = getV(graph, v1.id()); v1.properties(property).forEachRemaining(p -> { if (p.value().equals(value1)) { assertEquals(v1, getOnlyElement(graph.query().has(property, value2).vertices())); clopen();//Flush the index assertEquals(v1, getOnlyElement(graph.query().has(property, value2).vertices())); assertFalse(graph.query().has(property, value1).vertices().iterator().hasNext()); v1 = getV(graph, v1.id()); v1.property(property, value1); assertEquals(v1, getOnlyElement(graph.query().has(property, value1).vertices())); assertEquals(v1, getOnlyElement(graph.query().has(property, value2).vertices())); clopen();//Flush the index assertEquals(v1, getOnlyElement(graph.query().has(property, value1).vertices()));
PropertyKey prop = makeKey(propName, String.class); createExternalVertexIndex(prop, INDEX); finishSchema(); TitanVertex v = graph.addVertex(null); if (null != initialValue)
int numV = 1000; String[] strs = {"Uncle Berry has a farm","and on his farm he has five ducks","ducks are beautiful animals","the sky is very blue today"}; setupChainGraph(numV,strs); clopen();
private void testInstant(Instant firstTimestamp, Instant secondTimestamp, TitanVertex v1, TitanVertex v2) { assertEquals(v1, getOnlyVertex(graph.query().has("instant", Cmp.EQUAL, firstTimestamp))); assertEquals(v2, getOnlyVertex(graph.query().has("instant", Cmp.GREATER_THAN, firstTimestamp))); assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("instant", Cmp.GREATER_THAN_EQUAL, firstTimestamp).vertices())); assertEquals(v1, getOnlyVertex(graph.query().has("instant", Cmp.LESS_THAN, secondTimestamp))); assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("instant", Cmp.LESS_THAN_EQUAL, secondTimestamp).vertices())); assertEquals(v2, getOnlyVertex(graph.query().has("instant", Cmp.NOT_EQUAL, firstTimestamp))); clopen();//Flush the index assertEquals(v1, getOnlyVertex(graph.query().has("instant", Cmp.EQUAL, firstTimestamp))); assertEquals(v2, getOnlyVertex(graph.query().has("instant", Cmp.GREATER_THAN, firstTimestamp))); assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("instant", Cmp.GREATER_THAN_EQUAL, firstTimestamp).vertices())); assertEquals(v1, getOnlyVertex(graph.query().has("instant", Cmp.LESS_THAN, secondTimestamp))); assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("instant", Cmp.LESS_THAN_EQUAL, secondTimestamp).vertices())); assertEquals(v2, getOnlyVertex(graph.query().has("instant", Cmp.NOT_EQUAL, firstTimestamp))); }