use of com.thinkaurelius.titan.core.TitanVertex in project titan by thinkaurelius.
the class TitanGraphTest method testEdgeTTLLimitedByVertexTTL.
@Category({ BrittleTests.class })
@Test
public void testEdgeTTLLimitedByVertexTTL() throws Exception {
if (!features.hasCellTTL()) {
return;
}
Boolean dbCache = config.get("cache.db-cache", Boolean.class);
if (null == dbCache) {
dbCache = false;
}
EdgeLabel likes = mgmt.makeEdgeLabel("likes").make();
// long edge TTL will be overridden by short vertex TTL
mgmt.setTTL(likes, Duration.ofSeconds(42));
EdgeLabel dislikes = mgmt.makeEdgeLabel("dislikes").make();
mgmt.setTTL(dislikes, Duration.ofSeconds(1));
EdgeLabel indifferentTo = mgmt.makeEdgeLabel("indifferentTo").make();
VertexLabel label1 = mgmt.makeVertexLabel("person").setStatic().make();
mgmt.setTTL(label1, Duration.ofSeconds(2));
assertEquals(Duration.ofSeconds(42), mgmt.getTTL(likes));
assertEquals(Duration.ofSeconds(1), mgmt.getTTL(dislikes));
assertEquals(Duration.ZERO, mgmt.getTTL(indifferentTo));
assertEquals(Duration.ofSeconds(2), mgmt.getTTL(label1));
mgmt.commit();
TitanVertex v1 = tx.addVertex("person");
TitanVertex v2 = tx.addVertex();
Edge v1LikesV2 = v1.addEdge("likes", v2);
Edge v1DislikesV2 = v1.addEdge("dislikes", v2);
Edge v1IndifferentToV2 = v1.addEdge("indifferentTo", v2);
tx.commit();
long commitTime = System.currentTimeMillis();
Object v1Id = v1.id();
Object v2id = v2.id();
Object v1LikesV2Id = v1LikesV2.id();
Object v1DislikesV2Id = v1DislikesV2.id();
Object v1IndifferentToV2Id = v1IndifferentToV2.id();
v1 = getV(graph, v1Id);
v2 = getV(graph, v2id);
v1LikesV2 = getE(graph, v1LikesV2Id);
v1DislikesV2 = getE(graph, v1DislikesV2Id);
v1IndifferentToV2 = getE(graph, v1IndifferentToV2Id);
assertNotNull(v1);
assertNotNull(v2);
assertNotNull(v1LikesV2);
assertNotNull(v1DislikesV2);
assertNotNull(v1IndifferentToV2);
assertNotEmpty(v2.query().direction(Direction.IN).labels("likes").edges());
assertNotEmpty(v2.query().direction(Direction.IN).labels("dislikes").edges());
assertNotEmpty(v2.query().direction(Direction.IN).labels("indifferentTo").edges());
Thread.sleep(commitTime + 1001L - System.currentTimeMillis());
graph.tx().rollback();
v1 = getV(graph, v1Id);
v2 = getV(graph, v2id);
v1LikesV2 = getE(graph, v1LikesV2Id);
v1DislikesV2 = getE(graph, v1DislikesV2Id);
v1IndifferentToV2 = getE(graph, v1IndifferentToV2Id);
assertNotNull(v1);
assertNotNull(v2);
assertNotNull(v1LikesV2);
// this edge has expired
assertNull(v1DislikesV2);
assertNotNull(v1IndifferentToV2);
assertNotEmpty(v2.query().direction(Direction.IN).labels("likes").edges());
// expired
assertEmpty(v2.query().direction(Direction.IN).labels("dislikes").edges());
assertNotEmpty(v2.query().direction(Direction.IN).labels("indifferentTo").edges());
Thread.sleep(commitTime + 2001L - System.currentTimeMillis());
graph.tx().rollback();
v1 = getV(graph, v1Id);
v2 = getV(graph, v2id);
v1LikesV2 = getE(graph, v1LikesV2Id);
v1DislikesV2 = getE(graph, v1DislikesV2Id);
v1IndifferentToV2 = getE(graph, v1IndifferentToV2Id);
// the vertex itself has expired
assertNull(v1);
assertNotNull(v2);
// all incident edges have necessarily expired
assertNull(v1LikesV2);
assertNull(v1DislikesV2);
assertNull(v1IndifferentToV2);
if (dbCache) {
/* TODO: uncomment
assertNotEmpty(v2.query().direction(Direction.IN).labels("likes").edges());
assertNotEmpty(v2.query().direction(Direction.IN).labels("dislikes").edges());
assertNotEmpty(v2.query().direction(Direction.IN).labels("indifferentTo").edges());
*/
} else {
assertEmpty(v2.query().direction(Direction.IN).labels("likes").edges());
assertEmpty(v2.query().direction(Direction.IN).labels("dislikes").edges());
assertEmpty(v2.query().direction(Direction.IN).labels("indifferentTo").edges());
}
}
use of com.thinkaurelius.titan.core.TitanVertex in project titan by thinkaurelius.
the class TitanGraphTest method testIndexQueryWithLabelsAndContainsIN.
@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());
}
}
use of com.thinkaurelius.titan.core.TitanVertex in project titan by thinkaurelius.
the class TitanGraphTest method testMultivaluedVertexProperty.
/**
* Tests multi-valued properties with special focus on indexing and incident unidirectional edges
* which is not tested in {@link #testSchemaTypes()}
* <p/>
* -->TODO: split and move this into other test cases: ordering to query, indexing to index
*/
@Test
public <V> void testMultivaluedVertexProperty() {
/*
* Constant test data
*
* The values list below must have at least two elements. The string
* literals were chosen arbitrarily and have no special significance.
*/
final String foo = "foo", bar = "bar", weight = "weight";
final List<String> values = ImmutableList.of("four", "score", "and", "seven");
assertTrue("Values list must have multiple elements for this test to make sense", 2 <= values.size());
// Create property with name pname and a vertex
PropertyKey w = makeKey(weight, Integer.class);
PropertyKey f = ((StandardPropertyKeyMaker) mgmt.makePropertyKey(foo)).dataType(String.class).cardinality(Cardinality.LIST).sortKey(w).sortOrder(Order.DESC).make();
mgmt.buildIndex(foo, Vertex.class).addKey(f).buildCompositeIndex();
PropertyKey b = mgmt.makePropertyKey(bar).dataType(String.class).cardinality(Cardinality.LIST).make();
mgmt.buildIndex(bar, Vertex.class).addKey(b).buildCompositeIndex();
finishSchema();
TitanVertex v = tx.addVertex();
// Insert prop values
int i = 0;
for (String s : values) {
v.property(foo, s, weight, ++i);
v.property(bar, s, weight, i);
}
//Verify correct number of properties
assertCount(values.size(), v.properties(foo));
assertCount(values.size(), v.properties(bar));
//Verify order
for (String prop : new String[] { foo, bar }) {
int sum = 0;
int index = values.size();
for (TitanVertexProperty<String> p : v.query().labels(foo).properties()) {
assertTrue(values.contains(p.value()));
int wint = p.value(weight);
sum += wint;
if (prop == foo)
assertEquals(index, wint);
index--;
}
assertEquals(values.size() * (values.size() + 1) / 2, sum);
}
assertCount(1, tx.query().has(foo, values.get(1)).vertices());
assertCount(1, tx.query().has(foo, values.get(3)).vertices());
assertCount(1, tx.query().has(bar, values.get(1)).vertices());
assertCount(1, tx.query().has(bar, values.get(3)).vertices());
// Check that removing properties works
asStream(v.properties(foo)).forEach(p -> p.remove());
// Check that the properties were actually deleted from v
assertEmpty(v.properties(foo));
// Reopen database
clopen();
assertCount(0, tx.query().has(foo, values.get(1)).vertices());
assertCount(0, tx.query().has(foo, values.get(3)).vertices());
assertCount(1, tx.query().has(bar, values.get(1)).vertices());
assertCount(1, tx.query().has(bar, values.get(3)).vertices());
// Retrieve and check our test vertex
v = getV(tx, v);
assertEmpty(v.properties(foo));
assertCount(values.size(), v.properties(bar));
// Reinsert prop values
for (String s : values) {
v.property(foo, s);
}
assertCount(values.size(), v.properties(foo));
// Check that removing properties works
asStream(v.properties(foo)).forEach(p -> p.remove());
// Check that the properties were actually deleted from v
assertEmpty(v.properties(foo));
}
use of com.thinkaurelius.titan.core.TitanVertex in project titan by thinkaurelius.
the class TitanGraphTest method testBasic.
/**
* Very simple graph operation to ensure minimal functionality and cleanup
*/
@Test
public void testBasic() {
PropertyKey uid = makeVertexIndexedUniqueKey("name", String.class);
finishSchema();
TitanVertex n1 = tx.addVertex();
uid = tx.getPropertyKey("name");
n1.property(uid.name(), "abcd");
clopen();
long nid = n1.longId();
uid = tx.getPropertyKey("name");
assertTrue(getV(tx, nid) != null);
assertTrue(getV(tx, uid.longId()) != null);
assertMissing(tx, nid + 64);
uid = tx.getPropertyKey(uid.name());
n1 = getV(tx, nid);
assertEquals(n1, getOnlyVertex(tx.query().has(uid.name(), "abcd")));
//TODO: how to expose relations?
assertEquals(1, Iterables.size(n1.query().relations()));
assertEquals("abcd", n1.value(uid.name()));
assertCount(1, tx.query().vertices());
close();
TitanCleanup.clear(graph);
open(config);
assertEmpty(tx.query().vertices());
}
use of com.thinkaurelius.titan.core.TitanVertex in project titan by thinkaurelius.
the class TitanGraphTest method testStaleVertex.
@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();
}
Aggregations