Search in sources :

Example 6 with KeyIterator

use of org.janusgraph.diskstorage.keycolumnvalue.KeyIterator in project janusgraph by JanusGraph.

the class KeyColumnValueStoreTest method testGetKeysWithKeyRange.

@Test
@FeatureFlag(feature = JanusGraphFeature.OrderedScan)
public void testGetKeysWithKeyRange(TestInfo testInfo) throws Exception {
    populateDBWith100Keys();
    tx.commit();
    tx = startTx();
    KeyIterator keyIterator = store.getKeys(new KeyRangeQuery(// key start
    KeyColumnValueStoreUtil.longToByteBuffer(10), // key end
    KeyColumnValueStoreUtil.longToByteBuffer(40), // column start
    new ReadArrayBuffer("b".getBytes()), new ReadArrayBuffer("c".getBytes())), tx);
    examineGetKeysResults(keyIterator, 10, 40);
}
Also used : KeyRangeQuery(org.janusgraph.diskstorage.keycolumnvalue.KeyRangeQuery) KeyIterator(org.janusgraph.diskstorage.keycolumnvalue.KeyIterator) ReadArrayBuffer(org.janusgraph.diskstorage.util.ReadArrayBuffer) Test(org.junit.jupiter.api.Test) JanusGraphBaseStoreFeaturesTest(org.janusgraph.JanusGraphBaseStoreFeaturesTest) FeatureFlag(org.janusgraph.testutil.FeatureFlag)

Example 7 with KeyIterator

use of org.janusgraph.diskstorage.keycolumnvalue.KeyIterator 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)

Aggregations

KeyIterator (org.janusgraph.diskstorage.keycolumnvalue.KeyIterator)7 JanusGraphBaseStoreFeaturesTest (org.janusgraph.JanusGraphBaseStoreFeaturesTest)5 FeatureFlag (org.janusgraph.testutil.FeatureFlag)5 Test (org.junit.jupiter.api.Test)5 KeyRangeQuery (org.janusgraph.diskstorage.keycolumnvalue.KeyRangeQuery)4 SliceQuery (org.janusgraph.diskstorage.keycolumnvalue.SliceQuery)4 KeySliceQuery (org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery)3 ReadArrayBuffer (org.janusgraph.diskstorage.util.ReadArrayBuffer)2 Stopwatch (com.google.common.base.Stopwatch)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Entry (org.janusgraph.diskstorage.Entry)1 KeyColumnValueStore (org.janusgraph.diskstorage.keycolumnvalue.KeyColumnValueStore)1 KeyColumnValueStoreManager (org.janusgraph.diskstorage.keycolumnvalue.KeyColumnValueStoreManager)1 StoreTransaction (org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction)1 RecordIterator (org.janusgraph.diskstorage.util.RecordIterator)1 RepeatedTest (org.junit.jupiter.api.RepeatedTest)1