use of org.apache.phoenix.hbase.index.scanner.Scanner in project phoenix by apache.
the class LocalTableStateTest method testOnlyLoadsRequestedColumns.
@SuppressWarnings("unchecked")
@Test
public void testOnlyLoadsRequestedColumns() throws Exception {
// setup mocks
RegionCoprocessorEnvironment env = Mockito.mock(RegionCoprocessorEnvironment.class);
Region region = Mockito.mock(Region.class);
Mockito.when(env.getRegion()).thenReturn(region);
final KeyValue storedKv = new KeyValue(row, fam, qual, ts, Type.Put, Bytes.toBytes("stored-value"));
storedKv.setSequenceId(2);
Put pendingUpdate = new Put(row);
pendingUpdate.addColumn(fam, qual, ts, val);
HashMap<ImmutableBytesPtr, List<Cell>> rowKeyPtrToCells = new HashMap<ImmutableBytesPtr, List<Cell>>();
rowKeyPtrToCells.put(new ImmutableBytesPtr(row), Collections.singletonList((Cell) storedKv));
CachedLocalTable cachedLocalTable = CachedLocalTable.build(rowKeyPtrToCells);
LocalTableState table = new LocalTableState(cachedLocalTable, pendingUpdate);
// do the lookup for the given column
ColumnReference col = new ColumnReference(fam, qual);
table.setCurrentTimestamp(ts);
// check that the value is there
Pair<CoveredDeleteScanner, IndexUpdate> p = table.getIndexedColumnsTableState(Arrays.asList(col), false, false, indexMetaData);
Scanner s = p.getFirst();
// make sure it read the table the one time
assertEquals("Didn't get the stored keyvalue!", storedKv, s.next());
// on the second lookup it shouldn't access the underlying table again - the cached columns
// should know they are done
p = table.getIndexedColumnsTableState(Arrays.asList(col), false, false, indexMetaData);
s = p.getFirst();
assertEquals("Lost already loaded update!", storedKv, s.next());
}
Aggregations