use of org.janusgraph.core.JanusGraphVertex in project janusgraph by JanusGraph.
the class JanusGraphTest method testTransactionIsolation.
/**
* Verifies transactional isolation and internal vertex existence checking
*/
@Test
public void testTransactionIsolation() {
// Create edge label before attempting to write it from concurrent transactions
makeLabel("knows");
finishSchema();
JanusGraphTransaction tx1 = graph.newTransaction();
JanusGraphTransaction tx2 = graph.newTransaction();
// Verify that using vertices across transactions is prohibited
JanusGraphVertex v11 = tx1.addVertex();
JanusGraphVertex v12 = tx1.addVertex();
v11.addEdge("knows", v12);
JanusGraphVertex v21 = tx2.addVertex();
try {
v21.addEdge("knows", v11);
fail();
} catch (IllegalStateException ignored) {
}
JanusGraphVertex v22 = tx2.addVertex();
v21.addEdge("knows", v22);
tx2.commit();
try {
v22.addEdge("knows", v21);
fail();
} catch (IllegalStateException ignored) {
}
tx1.rollback();
try {
v11.property(VertexProperty.Cardinality.single, "test", 5);
fail();
} catch (IllegalStateException ignored) {
}
// Test unidirected edge with and without internal existence check
newTx();
v21 = getV(tx, v21);
tx.makeEdgeLabel("link").unidirected().make();
JanusGraphVertex v3 = tx.addVertex();
v21.addEdge("link", v3);
newTx();
v21 = getV(tx, v21);
v3 = Iterables.getOnlyElement(v21.query().direction(Direction.OUT).labels("link").vertices());
assertFalse(v3.isRemoved());
v3.remove();
newTx();
v21 = getV(tx, v21);
v3 = Iterables.getOnlyElement(v21.query().direction(Direction.OUT).labels("link").vertices());
assertFalse(v3.isRemoved());
newTx();
JanusGraphTransaction tx3 = graph.buildTransaction().checkInternalVertexExistence(true).start();
v21 = getV(tx3, v21);
v3 = Iterables.getOnlyElement(v21.query().direction(Direction.OUT).labels("link").vertices());
assertTrue(v3.isRemoved());
tx3.commit();
}
use of org.janusgraph.core.JanusGraphVertex in project janusgraph by JanusGraph.
the class JanusGraphTest method testSelfLoop.
/**
* Tests that self-loop edges are handled and counted correctly
*/
@Test
public void testSelfLoop() {
JanusGraphVertex v = tx.addVertex();
v.addEdge("self", v);
assertCount(1, v.query().direction(Direction.OUT).labels("self").edges());
assertCount(1, v.query().direction(Direction.IN).labels("self").edges());
assertCount(2, v.query().direction(Direction.BOTH).labels("self").edges());
clopen();
v = getV(tx, v);
assertNotNull(v);
assertCount(1, v.query().direction(Direction.IN).labels("self").edges());
assertCount(1, v.query().direction(Direction.OUT).labels("self").edges());
assertCount(1, v.query().direction(Direction.IN).labels("self").edges());
assertCount(2, v.query().direction(Direction.BOTH).labels("self").edges());
}
use of org.janusgraph.core.JanusGraphVertex in project janusgraph by JanusGraph.
the class JanusGraphTest method testArrayEqualityUsingImplicitKey.
@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()));
}
use of org.janusgraph.core.JanusGraphVertex in project janusgraph by JanusGraph.
the class JanusGraphTest method testDataTypes.
/**
* Test the different data types that JanusGraph supports natively and ensure that invalid data types aren't allowed
*/
@Test
public void testDataTypes() {
clopen(option(CUSTOM_ATTRIBUTE_CLASS, "attribute10"), SpecialInt.class.getCanonicalName(), option(CUSTOM_SERIALIZER_CLASS, "attribute10"), SpecialIntSerializer.class.getCanonicalName());
PropertyKey num = makeKey("num", SpecialInt.class);
PropertyKey barr = makeKey("barr", byte[].class);
PropertyKey booleanValue = makeKey("boolval", Boolean.class);
PropertyKey birthday = makeKey("birthday", Instant.class);
PropertyKey location = makeKey("location", Geoshape.class);
PropertyKey boundary = makeKey("boundary", Geoshape.class);
PropertyKey precise = makeKey("precise", Double.class);
PropertyKey any = mgmt.makePropertyKey("any").cardinality(Cardinality.LIST).dataType(Object.class).make();
try {
// Not a valid data type - primitive
makeKey("pint", int.class);
fail();
} catch (IllegalArgumentException ignored) {
}
try {
// Not a valid data type - interface
makeKey("number", Number.class);
fail();
} catch (IllegalArgumentException ignored) {
}
finishSchema();
clopen();
booleanValue = tx.getPropertyKey("boolval");
num = tx.getPropertyKey("num");
barr = tx.getPropertyKey("barr");
birthday = tx.getPropertyKey("birthday");
location = tx.getPropertyKey("location");
boundary = tx.getPropertyKey("boundary");
precise = tx.getPropertyKey("precise");
any = tx.getPropertyKey("any");
assertEquals(Boolean.class, booleanValue.dataType());
assertEquals(byte[].class, barr.dataType());
assertEquals(Object.class, any.dataType());
final Instant c = Instant.ofEpochSecond(1429225756);
final Geoshape point = Geoshape.point(10.0, 10.0);
final Geoshape shape = Geoshape.box(10.0, 10.0, 20.0, 20.0);
JanusGraphVertex v = tx.addVertex();
v.property(n(booleanValue), true);
v.property(VertexProperty.Cardinality.single, n(birthday), c);
v.property(VertexProperty.Cardinality.single, n(num), new SpecialInt(10));
v.property(VertexProperty.Cardinality.single, n(barr), new byte[] { 1, 2, 3, 4 });
v.property(VertexProperty.Cardinality.single, n(location), point);
v.property(VertexProperty.Cardinality.single, n(boundary), shape);
v.property(VertexProperty.Cardinality.single, n(precise), 10.12345);
v.property(n(any), "Hello");
v.property(n(any), 10L);
int[] testArray = { 5, 6, 7 };
v.property(n(any), testArray);
// ######## VERIFICATION ##########
assertTrue(v.<Boolean>value("boolval"));
assertEquals(10, v.<SpecialInt>value("num").getValue());
assertEquals(c, v.value("birthday"));
assertEquals(4, v.<byte[]>value("barr").length);
assertEquals(point, v.<Geoshape>value("location"));
assertEquals(shape, v.<Geoshape>value("boundary"));
assertEquals(10.12345, v.<Double>value("precise"), 0.000001);
assertCount(3, v.properties("any"));
for (Object prop : v.query().labels("any").properties()) {
Object value = ((JanusGraphVertexProperty<?>) prop).value();
if (value instanceof String)
assertEquals("Hello", value);
else if (value instanceof Long)
assertEquals(10L, value);
else if (value.getClass().isArray()) {
assertTrue(Arrays.equals(testArray, (int[]) value));
} else
fail();
}
clopen();
v = getV(tx, v);
// ######## VERIFICATION (copied from above) ##########
assertTrue(v.<Boolean>value("boolval"));
assertEquals(10, v.<SpecialInt>value("num").getValue());
assertEquals(c, v.value("birthday"));
assertEquals(4, v.<byte[]>value("barr").length);
assertEquals(point, v.<Geoshape>value("location"));
assertEquals(shape, v.<Geoshape>value("boundary"));
assertEquals(10.12345, v.<Double>value("precise"), 0.000001);
assertCount(3, v.properties("any"));
for (Object prop : v.query().labels("any").properties()) {
Object value = ((JanusGraphVertexProperty<?>) prop).value();
if (value instanceof String)
assertEquals("Hello", value);
else if (value instanceof Long)
assertEquals(10L, value);
else if (value.getClass().isArray()) {
assertTrue(Arrays.equals(testArray, (int[]) value));
} else
fail();
}
}
use of org.janusgraph.core.JanusGraphVertex in project janusgraph by JanusGraph.
the class JanusGraphTest method testCreateDelete.
// Add more removal operations, different transaction contexts
@Test
public void testCreateDelete() {
makeKey("weight", Double.class);
PropertyKey uid = makeVertexIndexedUniqueKey("uid", Integer.class);
((StandardEdgeLabelMaker) mgmt.makeEdgeLabel("knows")).sortKey(uid).sortOrder(Order.DESC).directed().make();
mgmt.makeEdgeLabel("father").multiplicity(Multiplicity.MANY2ONE).make();
finishSchema();
JanusGraphVertex v1 = graph.addVertex(), v3 = graph.addVertex("uid", 445);
Edge e = v3.addEdge("knows", v1, "uid", 111);
Edge e2 = v1.addEdge("friend", v3);
assertEquals(111, e.<Integer>value("uid").intValue());
graph.tx().commit();
v3 = getV(graph, v3);
assertEquals(445, v3.<Integer>value("uid").intValue());
e = Iterables.getOnlyElement(v3.query().direction(Direction.OUT).labels("knows").edges());
assertEquals(111, e.<Integer>value("uid").intValue());
assertEquals(e, getE(graph, e.id()));
assertEquals(e, getE(graph, e.id().toString()));
VertexProperty p = getOnlyElement(v3.properties("uid"));
p.remove();
v3.property("uid", 353);
e = Iterables.getOnlyElement(v3.query().direction(Direction.OUT).labels("knows").edges());
e.property("uid", 222);
e2 = Iterables.getOnlyElement(v1.query().direction(Direction.OUT).labels("friend").edges());
e2.property("uid", 1);
e2.property("weight", 2.0);
assertEquals(1, e2.<Integer>value("uid").intValue());
assertEquals(2.0, e2.<Double>value("weight"), 0.0001);
clopen();
v3 = getV(graph, v3.id());
assertEquals(353, v3.<Integer>value("uid").intValue());
e = Iterables.getOnlyElement(v3.query().direction(Direction.OUT).labels("knows").edges());
assertEquals(222, e.<Integer>value("uid").intValue());
}
Aggregations