private static <T> long countInternal(BatchingVisitable<T> visitable, int batchSize) { final long[] count = new long[1]; visitable.batchAccept(batchSize, AbortingVisitors.<T, RuntimeException>batching( item -> { count[0]++; return true; })); return count[0]; }
public static <T> boolean isEmpty(BatchingVisitable<T> v) { return v.batchAccept(1, AbortingVisitors.<T, RuntimeException>batching(AbortingVisitors.<T>alwaysFalse())); }
@Test public void testConcat() { BatchingVisitable<Long> visitor = ListVisitor.create(Lists.newArrayList(0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L)); BatchingVisitableView<Long> limited = BatchingVisitableView.of(visitor).limit(3); BatchingVisitableView<Long> concat = BatchingVisitables.concat(limited, visitor); assertTrue("concatenated batchAccept should be true", concat.batchAccept(2, AbortingVisitors .batching(AbortingVisitors.alwaysTrue()))); }
assertEquals("limit produced unexpected result", ImmutableList.of(0L, 1L, 2L), copy); assertFalse("alwaysFalse should be false", limited.batchAccept(1, AbortingVisitors.alwaysFalse())); assertTrue("alwaysTrue should be true", limited.batchAccept(1, AbortingVisitors.alwaysTrue())); assertTrue("alwaysTrue should be true twice", limited.batchAccept(2, AbortingVisitors.alwaysTrue())); assertTrue("alwaysTrue should be true thrice", limited.batchAccept(3, AbortingVisitors.alwaysTrue())); assertTrue("batchAccept should be true", limited.batchAccept(2, AbortingVisitors.batching(cv))); assertEquals("CountingVisitor had wrong count", 3, cv.count); assertTrue("batchAccept should be true", limited.batchAccept(3, AbortingVisitors.batching(cv))); assertEquals("CountingVisitor had wrong count", 6, cv.count); assertTrue("batchAccept should be true", limited.batchAccept(4, AbortingVisitors.batching(cv))); assertEquals("CountingVisitor had wrong count", 9, cv.count); limited.skip(3).batchAccept(1, AbortingVisitors.alwaysFalse())); assertFalse("batchAccept should be false", limited.batchAccept(1, AbortingVisitors.batching(lv))); lv = new LimitVisitor<>(4); assertTrue("batchAccept should be true", limited.batchAccept(1, AbortingVisitors.batching(lv))); lv = new LimitVisitor<>(2); assertFalse("batchAccept should be false", limited.batchAccept(1, AbortingVisitors.batching(lv))); .batchAccept(1, AbortingVisitors.alwaysFalse())); assertTrue("batchAccept should be trivially true after everything was skipped", limited.hintBatchSize(10).skip(3) .batchAccept(1, AbortingVisitors.alwaysFalse()));
@Test public void testEmpty() { assertTrue("empty batching visitable should be empty!", BatchingVisitables.isEmpty(BatchingVisitables.emptyBatchingVisitable())); assertEquals("empty batching visitable should be empty!", 0, BatchingVisitables.count(BatchingVisitables.emptyBatchingVisitable())); BatchingVisitable<Long> bv = ListVisitor.create(Lists.newArrayList(0L, 1L, 2L, 3L)); assertFalse("non-empty batching visitable should not be empty!", BatchingVisitables.isEmpty(bv)); assertEquals("visitable had wrong size", 4, BatchingVisitables.count(bv)); assertTrue("empty visitable should always be true, even when told to visit an always-false place", BatchingVisitables.emptyBatchingVisitable().batchAccept(1, AbortingVisitors.alwaysFalse())); }
t.getRange(TABLE_SWEPT_THOROUGH, RangeRequest.all()).batchAccept(batchHint, AbortingVisitors.alwaysTrue()); return null; })); BatchColumnRangeSelection.create(new ColumnRangeSelection(null, null), batchHint)) .values(); results.forEach(result -> result.batchAccept(batchHint, AbortingVisitors.alwaysTrue())); return null; }));
@Test public void testBatchWrap() { BatchingVisitable<Long> visitor = ListVisitor.create(Lists.newArrayList(0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L)); final Mutable<Boolean> hasTripped = Mutables.newMutable(); AbortingVisitor<List<Object>, RuntimeException> bv = item -> { hasTripped.set(true); assertEquals("batched item had wrong size", 8, item.size()); return false; }; AbortingVisitor<List<Long>, RuntimeException> wrap = AbortingVisitors.wrapBatching(bv); BatchingVisitableView.of(visitor).batchAccept(1000, wrap); assertTrue("should have been tripped!", hasTripped.get()); }
@Test public void testBatchWrap2() { BatchingVisitable<Long> visitor = ListVisitor.create(Lists.newArrayList(0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L)); final Mutable<Boolean> hasTripped = Mutables.newMutable(); AbortingVisitor<List<? extends Long>, RuntimeException> bv = item -> { hasTripped.set(true); assertEquals("batched item had wrong size", 8, item.size()); return false; }; AbortingVisitor<List<Long>, RuntimeException> wrap = AbortingVisitors.wrapBatching(bv); BatchingVisitableView.of(visitor).batchAccept(1000, wrap); assertTrue("should have been tripped!", hasTripped.get()); }
@Nullable public static <T> T getFirst(BatchingVisitable<T> visitable, @Nullable T defaultElement) { final Mutable<T> ret = Mutables.newMutable(defaultElement); visitable.batchAccept(1, AbortingVisitors.<T, RuntimeException>batching(item -> { ret.set(item); return false; })); return ret.get(); }
public static <T> boolean isEmpty(BatchingVisitable<T> v) { return v.batchAccept(1, AbortingVisitors.<T, RuntimeException>batching(AbortingVisitors.<T>alwaysFalse())); }
@Nullable public static <T> T getLast(BatchingVisitable<T> visitable, @Nullable T defaultElement) { final Mutable<T> ret = Mutables.newMutable(defaultElement); visitable.batchAccept(DEFAULT_BATCH_SIZE, AbortingVisitors.<T, RuntimeException>batching(item -> { ret.set(item); return true; })); return ret.get(); }
v.batchAccept( DEFAULT_BATCH_SIZE, AbortingVisitors.<T, RuntimeException>batching(new AbortingVisitor<T, RuntimeException>() { boolean hasSeenFirst = false; @Override
v.batchAccept( DEFAULT_BATCH_SIZE, AbortingVisitors.<T, RuntimeException>batching(new AbortingVisitor<T, RuntimeException>() { boolean hasSeenFirst = false; @Override
private byte[] internalCopyRange(BatchingVisitable<RowResult<byte[]>> bv, final long maxBytes, final Transaction txn) { final Mutable<byte[]> lastRowName = Mutables.newMutable(null); final MutableLong bytesPut = new MutableLong(0L); bv.batchAccept(readBatchSize, AbortingVisitors.batching( // Replacing this with a lambda results in an unreported exception compile error // even though no exception can be thrown :-( new AbortingVisitor<RowResult<byte[]>, RuntimeException>() { @Override public boolean visit(RowResult<byte[]> rr) throws RuntimeException { return TransactionRangeMigrator.this.internalCopyRow(rr, maxBytes, txn, bytesPut, lastRowName); } })); return lastRowName.get(); }
private byte[] internalCopyRange(BatchingVisitable<RowResult<byte[]>> bv, final long maxBytes, @Output final Map<Cell, byte[]> writeMap) { final Mutable<byte[]> lastRowName = Mutables.newMutable(null); final MutableLong bytesPut = new MutableLong(0L); bv.batchAccept(readBatchSize, AbortingVisitors.batching( // Replacing this with a lambda results in an unreported exception compile error // even though no exception can be thrown :-( new AbortingVisitor<RowResult<byte[]>, RuntimeException>() { @Override public boolean visit(RowResult<byte[]> rr) throws RuntimeException { return KvsRangeMigrator.this.internalCopyRow(rr, maxBytes, writeMap, bytesPut, lastRowName); } })); return lastRowName.get(); }
visitable.batchAccept(100, AbortingVisitors.batching((RowVisitor) item -> { MapEntries.putAll(vals, item.getCells()); if (Arrays.equals(item.getRowName(), "row1".getBytes())) {
final Map<Cell, byte[]> vals = Maps.newHashMap(); try { visitable.batchAccept(1, AbortingVisitors.batching((RowVisitor) item -> { try { latch.countDown();
private static <T> long countInternal(BatchingVisitable<T> visitable, int batchSize) { final long[] count = new long[1]; visitable.batchAccept(batchSize, AbortingVisitors.<T, RuntimeException>batching( item -> { count[0]++; return true; })); return count[0]; }
@Nullable public static <T> T getLast(BatchingVisitable<T> visitable, @Nullable T defaultElement) { final Mutable<T> ret = Mutables.newMutable(defaultElement); visitable.batchAccept(DEFAULT_BATCH_SIZE, AbortingVisitors.<T, RuntimeException>batching(item -> { ret.set(item); return true; })); return ret.get(); }