Search in sources :

Example 16 with FeatureFlag

use of org.janusgraph.testutil.FeatureFlag in project janusgraph by JanusGraph.

the class KeyColumnValueStoreTest method testGetKeysColumnSlicesOnLowerTriangular.

/**
 * Test {@code getKeys} with columns slice values chosen to trigger
 * potential fencepost bugs.
 * <p>
 * Description of data generated for and queried by this test:
 * <p>
 * Generate a sequence of keys as unsigned integers, starting at zero. Each
 * row has as many columns as the key value. The columns are generated in
 * the same way as the keys. This results in a sort of "lower triangular"
 * data space, with no values above the diagonal.
 *
 * @throws BackendException shouldn't happen
 * @throws IOException      shouldn't happen
 */
@Test
@FeatureFlag(feature = JanusGraphFeature.Scan)
public void testGetKeysColumnSlicesOnLowerTriangular() throws BackendException, IOException {
    // should be greater than or equal to 1
    final int offset = 10;
    // should be greater than or equal to 4
    final int size = 10;
    final int midpoint = size / 2 + offset;
    final int upper = offset + size;
    final int step = 1;
    loadLowerTriangularValues(size, offset);
    boolean executed = false;
    if (manager.getFeatures().hasUnorderedScan()) {
        final Collection<StaticBuffer> expected = new HashSet<>(size);
        for (int start = midpoint; start >= offset - step; start -= step) {
            for (int end = midpoint + 1; end <= upper + step; end += step) {
                Preconditions.checkArgument(start < end);
                // Set column bounds
                StaticBuffer startCol = BufferUtil.getIntBuffer(start);
                StaticBuffer endCol = BufferUtil.getIntBuffer(end);
                SliceQuery sq = new SliceQuery(startCol, endCol);
                // Compute expectation
                expected.clear();
                for (long l = Math.max(start, offset); l < upper; l++) {
                    expected.add(BufferUtil.getLongBuffer(l));
                }
                // Compute actual
                KeyIterator i = store.getKeys(sq, tx);
                Collection<StaticBuffer> actual = Sets.newHashSet(i);
                // Check
                log.debug("Checking bounds [{}, {}) (expect {} keys)", startCol, endCol, expected.size());
                assertEquals(expected, actual);
                i.close();
                executed = true;
            }
        }
    } else if (manager.getFeatures().hasOrderedScan()) {
        final Collection<StaticBuffer> expected = new ArrayList<>(size);
        for (int start = midpoint; start >= offset - step; start -= step) {
            for (int end = midpoint + 1; end <= upper + step; end += step) {
                Preconditions.checkArgument(start < end);
                // Set column bounds
                StaticBuffer startCol = BufferUtil.getIntBuffer(start);
                StaticBuffer endCol = BufferUtil.getIntBuffer(end);
                SliceQuery sq = new SliceQuery(startCol, endCol);
                // Set key bounds
                StaticBuffer keyStart = BufferUtil.getLongBuffer(start);
                StaticBuffer keyEnd = BufferUtil.getLongBuffer(end);
                KeyRangeQuery krq = new KeyRangeQuery(keyStart, keyEnd, sq);
                // Compute expectation
                expected.clear();
                for (long l = Math.max(start, offset); l < Math.min(upper, end); l++) {
                    expected.add(BufferUtil.getLongBuffer(l));
                }
                // Compute actual
                KeyIterator i = store.getKeys(krq, tx);
                Collection<StaticBuffer> actual = Lists.newArrayList(i);
                log.debug("Checking bounds key:[{}, {}) & col:[{}, {}) (expect {} keys)", keyStart, keyEnd, startCol, endCol, expected.size());
                assertEquals(expected, actual);
                i.close();
                executed = true;
            }
        }
    } else {
        throw new UnsupportedOperationException("Illegal store configuration: supportsScan()=true but supportsOrderedScan()=supportsUnorderedScan()=false");
    }
    Preconditions.checkArgument(executed);
}
Also used : KeyRangeQuery(org.janusgraph.diskstorage.keycolumnvalue.KeyRangeQuery) KeyIterator(org.janusgraph.diskstorage.keycolumnvalue.KeyIterator) Collection(java.util.Collection) SliceQuery(org.janusgraph.diskstorage.keycolumnvalue.SliceQuery) KeySliceQuery(org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) JanusGraphBaseStoreFeaturesTest(org.janusgraph.JanusGraphBaseStoreFeaturesTest) FeatureFlag(org.janusgraph.testutil.FeatureFlag)

Example 17 with FeatureFlag

use of org.janusgraph.testutil.FeatureFlag in project janusgraph by JanusGraph.

the class JanusGraphTest method testGetTTLFromUnsupportedType.

@Test
@FeatureFlag(feature = JanusGraphFeature.CellTtl)
public void testGetTTLFromUnsupportedType() {
    assertThrows(IllegalArgumentException.class, () -> {
        JanusGraphSchemaType type = ImplicitKey.ID;
        mgmt.getTTL(type);
    });
}
Also used : JanusGraphSchemaType(org.janusgraph.core.schema.JanusGraphSchemaType) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test) FeatureFlag(org.janusgraph.testutil.FeatureFlag)

Example 18 with FeatureFlag

use of org.janusgraph.testutil.FeatureFlag in project janusgraph by JanusGraph.

the class JanusGraphTest method testSettingTTLOnUnsupportedType.

@Test
@FeatureFlag(feature = JanusGraphFeature.CellTtl)
public void testSettingTTLOnUnsupportedType() {
    assertThrows(IllegalArgumentException.class, () -> {
        JanusGraphSchemaType type = ImplicitKey.ID;
        mgmt.setTTL(type, Duration.ZERO);
    });
}
Also used : JanusGraphSchemaType(org.janusgraph.core.schema.JanusGraphSchemaType) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test) FeatureFlag(org.janusgraph.testutil.FeatureFlag)

Example 19 with FeatureFlag

use of org.janusgraph.testutil.FeatureFlag in project janusgraph by JanusGraph.

the class JanusGraphTest method testEdgeTTLLimitedByVertexTTL.

@Test
@Tag(TestCategory.BRITTLE_TESTS)
@FeatureFlag(feature = JanusGraphFeature.CellTtl)
public void testEdgeTTLLimitedByVertexTTL() throws Exception {
    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();
    JanusGraphVertex v1 = tx.addVertex("person");
    JanusGraphVertex 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());
    }
}
Also used : VertexLabel(org.janusgraph.core.VertexLabel) BaseVertexLabel(org.janusgraph.graphdb.types.system.BaseVertexLabel) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) EdgeLabel(org.janusgraph.core.EdgeLabel) AbstractEdge(org.janusgraph.graphdb.relations.AbstractEdge) JanusGraphEdge(org.janusgraph.core.JanusGraphEdge) Edge(org.apache.tinkerpop.gremlin.structure.Edge) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test) FeatureFlag(org.janusgraph.testutil.FeatureFlag) Tag(org.junit.jupiter.api.Tag)

Example 20 with FeatureFlag

use of org.janusgraph.testutil.FeatureFlag in project janusgraph by JanusGraph.

the class JanusGraphTest method testVertexTTLImplicitKey.

@Test
@FeatureFlag(feature = JanusGraphFeature.CellTtl)
public void testVertexTTLImplicitKey() throws Exception {
    Duration d;
    clopen(option(GraphDatabaseConfiguration.STORE_META_TTL, "edgestore"), true);
    int ttl1 = 1;
    VertexLabel label1 = mgmt.makeVertexLabel("event").setStatic().make();
    mgmt.setTTL(label1, Duration.ofSeconds(ttl1));
    assertEquals(Duration.ofSeconds(ttl1), mgmt.getTTL(label1));
    mgmt.commit();
    JanusGraphVertex v1 = tx.addVertex("event");
    JanusGraphVertex v2 = tx.addVertex();
    tx.commit();
    /* TODO: this fails
        d = v1.getProperty("~ttl");
        assertEquals(1, d);
        d = v2.getProperty("~ttl");
        assertEquals(0, d);
        */
    Object v1id = v1.id();
    Object v2id = v2.id();
    v1 = getV(graph, v1id);
    v2 = getV(graph, v2id);
    d = v1.value("~ttl");
    assertEquals(Duration.ofSeconds(1), d);
    d = v2.value("~ttl");
    assertEquals(Duration.ZERO, d);
}
Also used : VertexLabel(org.janusgraph.core.VertexLabel) BaseVertexLabel(org.janusgraph.graphdb.types.system.BaseVertexLabel) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) Duration(java.time.Duration) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test) FeatureFlag(org.janusgraph.testutil.FeatureFlag)

Aggregations

FeatureFlag (org.janusgraph.testutil.FeatureFlag)22 Test (org.junit.jupiter.api.Test)22 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)16 JanusGraphVertex (org.janusgraph.core.JanusGraphVertex)9 JanusGraphBaseStoreFeaturesTest (org.janusgraph.JanusGraphBaseStoreFeaturesTest)6 EdgeLabel (org.janusgraph.core.EdgeLabel)6 VertexLabel (org.janusgraph.core.VertexLabel)5 KeyIterator (org.janusgraph.diskstorage.keycolumnvalue.KeyIterator)5 KeyRangeQuery (org.janusgraph.diskstorage.keycolumnvalue.KeyRangeQuery)5 SliceQuery (org.janusgraph.diskstorage.keycolumnvalue.SliceQuery)5 BaseVertexLabel (org.janusgraph.graphdb.types.system.BaseVertexLabel)5 KeyColumnValueStoreTest (org.janusgraph.diskstorage.KeyColumnValueStoreTest)4 KeySliceQuery (org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery)4 Tag (org.junit.jupiter.api.Tag)4 PropertyKey (org.janusgraph.core.PropertyKey)3 Field (java.lang.reflect.Field)2 Duration (java.time.Duration)2 Edge (org.apache.tinkerpop.gremlin.structure.Edge)2 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)2 JanusGraphEdge (org.janusgraph.core.JanusGraphEdge)2