public class TestSingleColumnFamily extends OmidTestBase {
private static final Log LOG = LogFactory.getLog(TestSingleColumnFamily.class);
@Test public void testSingleColumnFamily() throws Exception {
TransactionManager tm = new TransactionManager(conf);
TransactionalTable table1 = new TransactionalTable(conf, TEST_TABLE);
int num=10;
TransactionState t=tm.beginTransaction();
for(int j=0;j<num;j++) {
byte[]data=Bytes.toBytes(j);
Put put=new Put(data);
put.add(Bytes.toBytes(TEST_FAMILY), Bytes.toBytes("value1"), data);
put.add(Bytes.toBytes(TEST_FAMILY), Bytes.toBytes("value2"), data);
table1.put(t,put);
}
//tm.tryCommit(t);
//t=tm.beginTransaction(); //Visible if in a different transaction
Scan s=new Scan();
ResultScanner res=table1.getScanner(t,s);
Result rr;
int count = 0;
while ((rr=res.next())!=null) {
int tmp1=Bytes.toInt(rr.getValue(Bytes.toBytes(TEST_FAMILY), Bytes.toBytes("value1")));
int tmp2=Bytes.toInt(rr.getValue(Bytes.toBytes(TEST_FAMILY), Bytes.toBytes("value2")));
LOG.info("RES:"+tmp1+";"+tmp2);
count++;
}
assertTrue("Can't see puts. I should see "
+ num + " but I see " + count
, num == count);
tm.tryCommit(t);
t=tm.beginTransaction();
for(int j=0;j<num/2;j++) {
byte[]data=Bytes.toBytes(j);
byte[]ndata=Bytes.toBytes(j*10);
Put put=new Put(data);
put.add(Bytes.toBytes(TEST_FAMILY), Bytes.toBytes("value2"), ndata);
table1.put(t,put);
}
tm.tryCommit(t);
t=tm.beginTransaction();
s=new Scan();
res=table1.getScanner(t,s);
count = 0;
int modified = 0, notmodified = 0;
while ((rr=res.next())!=null) {
int tmp1=Bytes.toInt(rr.getValue(Bytes.toBytes(TEST_FAMILY), Bytes.toBytes("value1")));
int tmp2=Bytes.toInt(rr.getValue(Bytes.toBytes(TEST_FAMILY), Bytes.toBytes("value2")));
LOG.info("RES:"+tmp1+";"+tmp2);
count++;
if (tmp2 == Bytes.toInt(rr.getRow())*10) {
modified++;
} else {
notmodified++;
}
if (count == 8) {
System.out.println("stop");
}
}
assertTrue("Can't see puts. I should see "
+ num + " but I see " + count
, num == count);
assertTrue("Half of rows should equal row id, half not ("
+ modified + ", " + notmodified + ")"
, modified == notmodified && notmodified == (num/2));
tm.tryCommit(t);
LOG.info("End commiting");
table1.close();
}