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);
}
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);
}
Aggregations