private static final Log LOG = LogFactory.getLog(TestUpdateScan.class);
private static final String TEST_COL = "value";
@Test public void testGet() throws Exception {
try{
TransactionManager tm = new TransactionManager(conf);
TransactionalTable table = new TransactionalTable(conf, TEST_TABLE);
TransactionState t=tm.beginTransaction();
int[] lInts=new int[]{100,243,2342,22,1,5,43,56};
for (int i=0;i<lInts.length;i++) {
byte[]data=Bytes.toBytes(lInts[i]);
Put put=new Put(data);
put.add(Bytes.toBytes(TEST_FAMILY), Bytes.toBytes(TEST_COL), data);
table.put(t,put);
}
int startKeyValue=lInts[3];
int stopKeyValue=lInts[3];
byte[] startKey=Bytes.toBytes(startKeyValue);
byte[] stopKey=Bytes.toBytes(stopKeyValue);
Get g=new Get(startKey);
Result r=table.get(t,g);
if (!r.isEmpty()) {
int tmp=Bytes.toInt(r.getValue(Bytes.toBytes(TEST_FAMILY),
Bytes.toBytes(TEST_COL)));
LOG.info("Result:" + tmp);
assertTrue("Bad value, should be "
+ startKeyValue + " but is " + tmp
, tmp == startKeyValue);
} else {
fail("Bad result");
}
tm.tryCommit(t);
Scan s=new Scan(startKey);
CompareFilter.CompareOp op=CompareFilter.CompareOp.LESS_OR_EQUAL;
RowFilter toFilter = new RowFilter(op, new BinaryPrefixComparator(stopKey));
boolean startInclusive=true;
if (!startInclusive) {
FilterList filters = new FilterList(FilterList.Operator.MUST_PASS_ALL);
filters.addFilter(new RowFilter(CompareFilter.CompareOp.GREATER,
new BinaryPrefixComparator(startKey)));
filters.addFilter(new WhileMatchFilter(toFilter));
s.setFilter(filters);
} else {
s.setFilter(new WhileMatchFilter(toFilter));
}
t=tm.beginTransaction();
ResultScanner res=table.getScanner(t,s);
Result rr;
int count = 0;
while ((rr=res.next())!=null) {
int iTmp=Bytes.toInt(rr.getValue(Bytes.toBytes(TEST_FAMILY),
Bytes.toBytes(TEST_COL)));
LOG.info("Result: "+iTmp);
count++;
}
assertEquals("Count is wrong", 1, count);
LOG.info("Rows found " + count);
tm.tryCommit(t);
table.close();
} catch (Exception e) {
LOG.error("Exception in test", e);
}
}