BigtableWhileMatchResultScannerAdapter { public ResultScanner adapt(final ResultScanner bigtableResultScanner, final Span span) { return new AbstractClientScanner() { @Override public Result next() throws IOException { Result row = bigtableResultScanner.next(); if (row == null) { span.end(); return null; } Result filteredResult = externalizeResult(row); if (filteredResult == null) { close(); } return filteredResult; } @Override public void close() { try { bigtableResultScanner.close(); } catch (RuntimeException ex) { span.setStatus(Status.UNKNOWN.withDescription(ex.getCause().getMessage())); throw ex; } finally { span.end(); } } public boolean renewLease() { throw new UnsupportedOperationException("renewLease"); } }; }  ResultScanner adapt(final ResultScanner bigtableResultScanner, final Span span);  }
@Test public void adapt_noRow() throws IOException { when(mockBigtableResultScanner.next()).thenReturn(null); ResultScanner scanner = adapter.adapt(mockBigtableResultScanner, mockSpan); assertNull(scanner.next()); verify(mockBigtableResultScanner).next(); verifyNoInteractions(mockRowAdapter); verify(mockSpan, times(1)).end(); }
@Test public void adapt_oneRow() throws IOException { Result expectedResult = Result.create( ImmutableList.<Cell>of( new RowCell( Bytes.toBytes("row"), Bytes.toBytes("family"), Bytes.toBytes("q"), 10000L, Bytes.toBytes("value"), ImmutableList.<String>of()))); when(mockBigtableResultScanner.next()).thenReturn(expectedResult); ResultScanner scanner = adapter.adapt(mockBigtableResultScanner, mockSpan); assertArrayEquals(expectedResult.rawCells(), scanner.next().rawCells()); verify(mockBigtableResultScanner).next(); verify(mockSpan, times(0)).end(); }
@Test public void adapt_oneRow_hasMatchingLabels() throws IOException { Result expectedResult = Result.create( ImmutableList.<Cell>of( new RowCell( Bytes.toBytes("row"), Bytes.toBytes("family"), Bytes.toBytes("q"), 10000L, Bytes.toBytes("value"), ImmutableList.of("a-in")), new RowCell( Bytes.toBytes("row"), Bytes.toBytes("family"), Bytes.toBytes("q"), 10000L, Bytes.toBytes("value"), ImmutableList.of("a-out")))); when(mockBigtableResultScanner.next()).thenReturn(expectedResult); ResultScanner scanner = adapter.adapt(mockBigtableResultScanner, mockSpan); assertEquals(0, scanner.next().size()); verify(mockBigtableResultScanner).next(); verify(mockSpan, times(0)).end(); }
@Test public void adapt_oneRow_hasNoMatchingLabels() throws IOException { Result expectedResult = Result.create( ImmutableList.<Cell>of( new RowCell( Bytes.toBytes("key"), Bytes.toBytes("family"), Bytes.toBytes("q"), 10000L, Bytes.toBytes("value"), ImmutableList.of("a-out")))); when(mockBigtableResultScanner.next()).thenReturn(expectedResult); ResultScanner scanner = adapter.adapt(mockBigtableResultScanner, mockSpan); assertNull(scanner.next()); verify(mockSpan, times(1)).end(); verify(mockBigtableResultScanner).next(); }