use of org.apache.accumulo.iteratortest.environments.SimpleIteratorEnvironment in project accumulo by apache.
the class ReSeekTestCase method test.
@Override
public IteratorTestOutput test(IteratorTestInput testInput) {
final SortedKeyValueIterator<Key, Value> skvi = IteratorTestUtil.instantiateIterator(testInput);
final SortedKeyValueIterator<Key, Value> source = IteratorTestUtil.createSource(testInput);
try {
skvi.init(source, testInput.getIteratorOptions(), new SimpleIteratorEnvironment());
skvi.seek(testInput.getRange(), testInput.getFamilies(), testInput.isInclusive());
return new IteratorTestOutput(consume(skvi, testInput));
} catch (IOException e) {
return new IteratorTestOutput(e);
}
}
use of org.apache.accumulo.iteratortest.environments.SimpleIteratorEnvironment in project accumulo by apache.
the class ReSeekTestCase method consume.
TreeMap<Key, Value> consume(SortedKeyValueIterator<Key, Value> skvi, IteratorTestInput testInput) throws IOException {
final TreeMap<Key, Value> data = new TreeMap<>();
final Range origRange = testInput.getRange();
final Collection<ByteSequence> origFamilies = testInput.getFamilies();
final boolean origInclusive = testInput.isInclusive();
int reseekCount = random.nextInt(RESEEK_INTERVAL);
int i = 0;
while (skvi.hasTop()) {
data.put(new Key(skvi.getTopKey()), new Value(skvi.getTopValue()));
/*
* One of the trickiest cases in writing iterators: After any result is returned from a TabletServer to the client, the Iterator in the TabletServer's
* memory may be torn down. To preserve the state and guarantee that all records are received, the TabletServer does remember the last Key it returned to
* the client. It will recreate the Iterator (stack), and seek it using an updated Range. This range's start key is set to the last Key returned,
* non-inclusive.
*/
if (i % RESEEK_INTERVAL == reseekCount) {
// Last key
Key reSeekStartKey = skvi.getTopKey();
// Make a new instance of the iterator
skvi = IteratorTestUtil.instantiateIterator(testInput);
final SortedKeyValueIterator<Key, Value> sourceCopy = IteratorTestUtil.createSource(testInput);
skvi.init(sourceCopy, testInput.getIteratorOptions(), new SimpleIteratorEnvironment());
// The new range, resume where we left off (non-inclusive), with same families filter
final Range newRange = new Range(reSeekStartKey, false, origRange.getEndKey(), origRange.isEndKeyInclusive());
log.debug("Re-seeking to {}", newRange);
// Seek there
skvi.seek(newRange, origFamilies, origInclusive);
} else {
// Every other time, it's a simple call to next()
skvi.next();
}
i++;
}
return data;
}
use of org.apache.accumulo.iteratortest.environments.SimpleIteratorEnvironment in project accumulo by apache.
the class YieldingTestCase method test.
@Override
public IteratorTestOutput test(IteratorTestInput testInput) {
final SortedKeyValueIterator<Key, Value> skvi = IteratorTestUtil.instantiateIterator(testInput);
final SortedKeyValueIterator<Key, Value> source = IteratorTestUtil.createSource(testInput);
try {
skvi.init(source, testInput.getIteratorOptions(), new SimpleIteratorEnvironment());
YieldCallback<Key> yield = new YieldCallback<>();
skvi.enableYielding(yield);
skvi.seek(testInput.getRange(), testInput.getFamilies(), testInput.isInclusive());
return new IteratorTestOutput(consume(testInput, skvi, yield));
} catch (IOException e) {
return new IteratorTestOutput(e);
}
}
use of org.apache.accumulo.iteratortest.environments.SimpleIteratorEnvironment in project accumulo by apache.
the class DeepCopyTestCase method test.
@Override
public IteratorTestOutput test(IteratorTestInput testInput) {
final SortedKeyValueIterator<Key, Value> skvi = IteratorTestUtil.instantiateIterator(testInput);
final SortedKeyValueIterator<Key, Value> source = IteratorTestUtil.createSource(testInput);
try {
skvi.init(source, testInput.getIteratorOptions(), new SimpleIteratorEnvironment());
SortedKeyValueIterator<Key, Value> copy = skvi.deepCopy(new SimpleIteratorEnvironment());
copy.seek(testInput.getRange(), testInput.getFamilies(), testInput.isInclusive());
return new IteratorTestOutput(consume(copy));
} catch (IOException e) {
return new IteratorTestOutput(e);
}
}
use of org.apache.accumulo.iteratortest.environments.SimpleIteratorEnvironment in project accumulo by apache.
the class IsolatedDeepCopiesTestCase method test.
@Override
public IteratorTestOutput test(IteratorTestInput testInput) {
final SortedKeyValueIterator<Key, Value> skvi = IteratorTestUtil.instantiateIterator(testInput);
final SortedKeyValueIterator<Key, Value> source = IteratorTestUtil.createSource(testInput);
try {
skvi.init(source, testInput.getIteratorOptions(), new SimpleIteratorEnvironment());
SortedKeyValueIterator<Key, Value> copy1 = skvi.deepCopy(new SimpleIteratorEnvironment());
SortedKeyValueIterator<Key, Value> copy2 = copy1.deepCopy(new SimpleIteratorEnvironment());
Range seekRange = testInput.getRange();
Collection<ByteSequence> seekColumnFamilies = testInput.getFamilies();
boolean seekInclusive = testInput.isInclusive();
skvi.seek(testInput.getRange(), seekColumnFamilies, seekInclusive);
copy1.seek(testInput.getRange(), seekColumnFamilies, seekInclusive);
copy2.seek(testInput.getRange(), seekColumnFamilies, seekInclusive);
TreeMap<Key, Value> output = consumeMany(new ArrayList<>(Arrays.asList(skvi, copy1, copy2)), seekRange, seekColumnFamilies, seekInclusive);
return new IteratorTestOutput(output);
} catch (IOException e) {
return new IteratorTestOutput(e);
}
}
Aggregations