@Test public void testReservedNamesRejectedForPropertyKeys() { for (String s : ILLEGAL_USER_DEFINED_NAMES) { TitanManagement tm = graph.openManagement(); try { tm.makePropertyKey(s); Assert.fail("Property key \"" + s + "\" must be rejected"); } catch (IllegalArgumentException e) { log.debug("Caught expected exception", e); } finally { tm.commit(); } } }
@Test public void testReservedNamesRejectedForEdgeLabels() { for (String s : ILLEGAL_USER_DEFINED_NAMES) { TitanManagement tm = graph.openManagement(); try { tm.makeEdgeLabel(s); Assert.fail("Edge label \"" + s + "\" must be rejected"); } catch (IllegalArgumentException e) { log.debug("Caught expected exception", e); } finally { tm.commit(); } } }
@Test public void testReservedNamesRejectedForVertexLabels() { for (String s : ILLEGAL_USER_DEFINED_NAMES) { TitanManagement tm = graph.openManagement(); VertexLabelMaker vlm = null; try { vlm = tm.makeVertexLabel(s); Assert.fail("Vertex label \"" + s + "\" must be rejected"); } catch (IllegalArgumentException e) { log.debug("Caught expected exception", e); } finally { tm.commit(); } } } }
private <T> void setIllegalGraphOption(ConfigOption<T> opt, ConfigOption.Type requiredType, T attemptedValue) { // Sanity check: make sure the Type of the configoption is what we expect final ConfigOption.Type type = opt.getType(); Preconditions.checkState(type.equals(requiredType)); Preconditions.checkArgument(requiredType.equals(ConfigOption.Type.LOCAL) || requiredType.equals(ConfigOption.Type.FIXED)); // Get full string path of config option final String path = ConfigElement.getPath(opt); // Try to read the option try { mgmt.get(path); } catch (Throwable t) { log.debug("Caught expected exception", t); } // Try to modify the option try { mgmt.set(path, attemptedValue); mgmt.commit(); fail("Option " + path + " with type " + type + " should not be modifiable in the persistent graph config"); } catch (Throwable t) { log.debug("Caught expected exception", t); } }
public void finishSchema() { if (mgmt!=null && mgmt.isOpen()) mgmt.commit(); mgmt=graph.openManagement(); newTx(); graph.tx().commit(); }
public void clopen(Object... settings) { config = getConfiguration(); if (mgmt!=null && mgmt.isOpen()) mgmt.rollback(); if (null != tx && tx.isOpen()) tx.commit(); if (settings!=null && settings.length>0) { Map<TestConfigOption,Object> options = validateConfigOptions(settings); TitanManagement gconf = null; ModifiableConfiguration lconf = new ModifiableConfiguration(GraphDatabaseConfiguration.ROOT_NS,config, BasicConfiguration.Restriction.LOCAL); for (Map.Entry<TestConfigOption,Object> option : options.entrySet()) { if (option.getKey().option.isLocal()) { lconf.set(option.getKey().option,option.getValue(),option.getKey().umbrella); } else { if (gconf==null) gconf = graph.openManagement(); gconf.set(ConfigElement.getPath(option.getKey().option,option.getKey().umbrella),option.getValue()); } } if (gconf!=null) gconf.commit(); lconf.close(); } if (null != graph && graph.isOpen()) graph.close(); Preconditions.checkNotNull(config); open(config); }
@Test public void testIndexQueryWithScore() throws InterruptedException { PropertyKey textKey = mgmt.makePropertyKey("text").dataType(String.class).make(); mgmt.buildIndex("store1", Vertex.class).addKey(textKey).buildMixedIndex(INDEX); mgmt.commit(); TitanVertex v1 = tx.addVertex(); TitanVertex v2 = tx.addVertex(); TitanVertex v3 = tx.addVertex(); v1.property("text", "Hello Hello Hello Hello Hello Hello Hello Hello"); v2.property("text", "Hello abab abab fsdfsd sfdfsd sdffs fsdsdf fdf fsdfsd aera fsad abab abab fsdfsd sfdf"); v3.property("text", "Hello"); tx.commit(); Thread.sleep(5000); Set<Double> scores = new HashSet<Double>(); for (TitanIndexQuery.Result<TitanVertex> r : graph.indexQuery("store1", "v.text:(Hello)").vertices()) { scores.add(r.getScore()); } Assert.assertEquals(3, scores.size()); }
@Test // this tests a case when there as AND with a single CONTAINS condition inside AND(name:(was here)) // which (in case of Solr) spans multiple conditions such as AND(AND(name:was, name:here)) // so we need to make sure that we don't apply AND twice. public void testContainsWithMultipleValues() throws Exception { PropertyKey name = makeKey("name", String.class); mgmt.buildIndex("store1", Vertex.class).addKey(name).buildMixedIndex(INDEX); mgmt.commit(); TitanVertex v1 = tx.addVertex(); v1.property("name", "hercules was here"); tx.commit(); Thread.sleep(2000); TitanVertex r = Iterables.<TitanVertex>get(graph.query().has("name", Text.CONTAINS, "hercules here").vertices(), 0); Assert.assertEquals(r.property("name").value(), "hercules was here"); }
@Override public void loadGraphData(final Graph g, final LoadGraphWith loadGraphWith, final Class testClass, final String testName) { if (loadGraphWith != null) { this.createIndices((TitanGraph) g, loadGraphWith.value()); } else { if (TransactionTest.class.equals(testClass) && testName.equalsIgnoreCase("shouldExecuteWithCompetingThreads")) { TitanManagement mgmt = ((TitanGraph) g).openManagement(); mgmt.makePropertyKey("blah").dataType(Double.class).make(); mgmt.makePropertyKey("bloop").dataType(Integer.class).make(); mgmt.makePropertyKey("test").dataType(Object.class).make(); mgmt.makeEdgeLabel("friend").make(); mgmt.commit(); } } super.loadGraphData(g, loadGraphWith, testClass, testName); }
@Test public void testGettingUndefinedEdgeLabelTTL() { if (!features.hasCellTTL()) { return; } // getTTL should return a null duration on an extant type without a TTL mgmt.makeEdgeLabel("likes").make(); mgmt.commit(); graph.tx().rollback(); // Check getTTL on edge label mgmt = graph.openManagement(); assertEquals(Duration.ZERO, mgmt.getTTL(mgmt.getEdgeLabel("likes"))); mgmt.rollback(); }
@Test public void testGettingUndefinedVertexLabelTTL() { if (!features.hasCellTTL()) { return; } // getTTL should return a null duration on an extant type without a TTL mgmt.makeVertexLabel("foo").make(); mgmt.commit(); graph.tx().rollback(); // Check getTTL on vertex label mgmt = graph.openManagement(); assertEquals(Duration.ZERO, mgmt.getTTL(mgmt.getVertexLabel("foo"))); mgmt.rollback(); }
mgmt.setTTL(label1, Duration.ofSeconds(ttl1)); assertEquals(Duration.ofSeconds(ttl1), mgmt.getTTL(label1)); mgmt.commit();
@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 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 testVertexTTLWithCompositeIndex() throws Exception { if (!features.hasCellTTL()) { return; } PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make(); PropertyKey time = mgmt.makePropertyKey("time").dataType(Long.class).make(); TitanGraphIndex index1 = mgmt.buildIndex("index1", Vertex.class).addKey(name).buildCompositeIndex(); TitanGraphIndex index2 = mgmt.buildIndex("index2", Vertex.class).addKey(name).addKey(time).buildCompositeIndex(); VertexLabel label1 = mgmt.makeVertexLabel("event").setStatic().make(); mgmt.setTTL(label1, Duration.ofSeconds(1)); assertEquals(Duration.ZERO, mgmt.getTTL(name)); assertEquals(Duration.ZERO, mgmt.getTTL(time)); assertEquals(Duration.ofSeconds(1), mgmt.getTTL(label1)); mgmt.commit(); TitanVertex v1 = tx.addVertex(T.label, "event", "name", "some event", "time", System.currentTimeMillis()); tx.commit(); Object id = v1.id(); v1 = getV(graph, id); assertNotNull(v1); assertNotEmpty(graph.query().has("name", "some event").vertices()); Thread.sleep(1001); graph.tx().rollback(); v1 = getV(graph, id); assertNull(v1); assertEmpty(graph.query().has("name", "some event").vertices()); }
@Test public void testReadWideVertexWithManyProperties() { int numProps = 1 << 16; long numV = 1; mgmt.makePropertyKey("p").cardinality(Cardinality.LIST).dataType(Integer.class).make(); mgmt.commit(); finishSchema(); for (int j = 0; j < numV; j++) { Vertex v = graph.addVertex(); for (int i = 0; i < numProps; i++) { v.property("p", i); } } graph.tx().commit(); assertEquals(numV, (long) graph.traversal().V().count().next()); Map<String, Object> propertiesOnVertex = graph.traversal().V().valueMap().next(); List<?> valuesOnP = (List)propertiesOnVertex.values().iterator().next(); assertEquals(numProps, valuesOnP.size()); Graph g = GraphFactory.open("target/test-classes/cassandra-read.properties"); GraphTraversalSource t = g.traversal(GraphTraversalSource.computer(SparkGraphComputer.class)); assertEquals(numV, (long) t.V().count().next()); propertiesOnVertex = t.V().valueMap().next(); valuesOnP = (List)propertiesOnVertex.values().iterator().next(); assertEquals(numProps, valuesOnP.size()); }
assertEquals(Duration.ofSeconds(ttl), mgmt.getTTL(likes)); assertEquals(Duration.ZERO, mgmt.getTTL(hasLiked)); mgmt.commit();
@Test public void testRemoveGraphIndex() throws InterruptedException, BackendException, ExecutionException { tx.commit(); mgmt.commit(); // Load the "Graph of the Gods" sample data GraphOfTheGodsFactory.loadWithoutMixedIndex(graph, true); // Disable the "name" composite index TitanManagement m = graph.openManagement(); TitanGraphIndex nameIndex = m.getGraphIndex("name"); m.updateIndex(nameIndex, SchemaAction.DISABLE_INDEX); m.commit(); graph.tx().commit(); // Block until the SchemaStatus transitions to DISABLED assertTrue(ManagementSystem.awaitGraphIndexStatus(graph, "name") .status(SchemaStatus.DISABLED).call().getSucceeded()); // Remove index MapReduceIndexManagement mri = new MapReduceIndexManagement(graph); m = graph.openManagement(); TitanGraphIndex index = m.getGraphIndex("name"); ScanMetrics metrics = mri.updateIndex(index, SchemaAction.REMOVE_INDEX).get(); assertEquals(12, metrics.getCustom(IndexRemoveJob.DELETED_RECORDS_COUNT)); }
@Test public void testRemoveRelationIndex() throws InterruptedException, BackendException, ExecutionException { tx.commit(); mgmt.commit(); // Load the "Graph of the Gods" sample data GraphOfTheGodsFactory.loadWithoutMixedIndex(graph, true); // Disable the "battlesByTime" index TitanManagement m = graph.openManagement(); RelationType battled = m.getRelationType("battled"); RelationTypeIndex battlesByTime = m.getRelationIndex(battled, "battlesByTime"); m.updateIndex(battlesByTime, SchemaAction.DISABLE_INDEX); m.commit(); graph.tx().commit(); // Block until the SchemaStatus transitions to DISABLED assertTrue(ManagementSystem.awaitRelationIndexStatus(graph, "battlesByTime", "battled") .status(SchemaStatus.DISABLED).call().getSucceeded()); // Remove index MapReduceIndexManagement mri = new MapReduceIndexManagement(graph); m = graph.openManagement(); battled = m.getRelationType("battled"); battlesByTime = m.getRelationIndex(battled, "battlesByTime"); ScanMetrics metrics = mri.updateIndex(battlesByTime, SchemaAction.REMOVE_INDEX).get(); assertEquals(6, metrics.getCustom(IndexRemoveJob.DELETED_RECORDS_COUNT)); }
@Test public void testRepairRelationIndex() throws InterruptedException, BackendException, ExecutionException { tx.commit(); mgmt.commit(); EdgeLabel lives = m.getEdgeLabel("lives"); m.buildEdgeIndex(lives, "livesByReason", Direction.BOTH, Order.decr, reason); m.commit(); graph.tx().commit(); RelationTypeIndex index = m.getRelationIndex(m.getRelationType("lives"), "livesByReason"); m.updateIndex(index, SchemaAction.ENABLE_INDEX); m.commit(); graph.tx().commit();