Package com.yahoo.omid.client

Examples of com.yahoo.omid.client.TransactionalTable


    @Test
    public void testTimestampsOfTwoRowsInstertedAfterCommitOfSingleTransactionAreEquals()
            throws Exception {

        TransactionManager tm = new TransactionManager(hbaseConf);
        TransactionalTable tt = new TransactionalTable(hbaseConf, TEST_TABLE);

        byte[] rowName1 = Bytes.toBytes("row1");
        byte[] rowName2 = Bytes.toBytes("row2");
        byte[] famName1 = Bytes.toBytes(TEST_FAMILY);
        byte[] colName1 = Bytes.toBytes("col1");
        byte[] dataValue1 = Bytes.toBytes("testWrite-1");
        byte[] dataValue2 = Bytes.toBytes("testWrite-2");

        TransactionState tx1 = tm.beginTransaction();

        Put row1 = new Put(rowName1);
        row1.add(famName1, colName1, dataValue1);
        tt.put(tx1, row1);
        Put row2 = new Put(rowName2);
        row2.add(famName1, colName1, dataValue2);
        tt.put(tx1, row2);

        tm.tryCommit(tx1);

        tt.close();

        // Checks
        Get getResultRow1 = new Get(rowName1).setMaxVersions(1);
        Result result1 = tt.get(getResultRow1);
        byte[] val1 = result1.getValue(famName1, colName1);
        assertTrue(
                "Unexpected value for row 1 in col 1: " + Bytes.toString(val1),
                Bytes.equals(dataValue1, result1.getValue(famName1, colName1)));
        long tsRow1 = result1.raw()[0].getTimestamp();

        Get getResultRow2 = new Get(rowName2).setMaxVersions(1);
        Result result2 = tt.get(getResultRow2);
        byte[] val2 = result2.getValue(famName1, colName1);
        assertTrue(
                "Unexpected value for row 2 in col 1: " + Bytes.toString(val2),
                Bytes.equals(dataValue2, result2.getValue(famName1, colName1)));
        long tsRow2 = result2.raw()[0].getTimestamp();
View Full Code Here


    @Test
    public void testTimestampsOfTwoRowsModifiedByTwoSequentialTransactionsAreEqualAndHaveBeenIncreasedMonotonically()
            throws Exception {

        TransactionManager tm = new TransactionManager(hbaseConf);
        TransactionalTable tt = new TransactionalTable(hbaseConf, TEST_TABLE);

        byte[] rowName1 = Bytes.toBytes("row1");
        byte[] rowName2 = Bytes.toBytes("row2");
        byte[] famName1 = Bytes.toBytes(TEST_FAMILY);
        byte[] colName1 = Bytes.toBytes("col1");
        byte[] dataValue1 = Bytes.toBytes("testWrite-1");
        byte[] dataValue2 = Bytes.toBytes("testWrite-2");

        byte[] dataValue3 = Bytes.toBytes("testWrite-3");
        byte[] dataValue4 = Bytes.toBytes("testWrite-4");

        TransactionState tx1 = tm.beginTransaction();

        Put row1 = new Put(rowName1);
        row1.add(famName1, colName1, dataValue1);
        tt.put(tx1, row1);
        Put row2 = new Put(rowName2);
        row2.add(famName1, colName1, dataValue2);
        tt.put(tx1, row2);

        tm.tryCommit(tx1);

        TransactionState tx2 = tm.beginTransaction();

        row1 = new Put(rowName1);
        row1.add(famName1, colName1, dataValue3);
        tt.put(tx2, row1);
        row2 = new Put(rowName2);
        row2.add(famName1, colName1, dataValue4);
        tt.put(tx2, row2);

        tm.tryCommit(tx2);

        tt.close();

        // Checks
        Get getResultRow1 = new Get(rowName1).setMaxVersions(2);
        Result result1 = tt.get(getResultRow1);
        byte[] val1 = result1.getValue(famName1, colName1);
        assertTrue(
                "Unexpected value for row 1 in col 1: " + Bytes.toString(val1),
                Bytes.equals(dataValue3, result1.getValue(famName1, colName1)));

        long lastTsRow1 = result1.raw()[0].getTimestamp();
        long previousTsRow1 = result1.raw()[1].getTimestamp();

        Get getResultRow2 = new Get(rowName2).setMaxVersions(2);
        Result result2 = tt.get(getResultRow2);
        byte[] val2 = result2.getValue(famName1, colName1);
        assertTrue(
                "Unexpected value for row 2 in col 1: " + Bytes.toString(val2),
                Bytes.equals(dataValue4, result2.getValue(famName1, colName1)));
View Full Code Here

   private static final String TEST_COL = "value";

   @Test public void testGet() throws Exception {
      try{
         TransactionManager tm = new TransactionManager(hbaseConf);
         TransactionalTable table = new TransactionalTable(hbaseConf, 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);
      }
   }
View Full Code Here

   }

   @Test public void testScan() throws Exception {
      try{
         TransactionManager tm = new TransactionManager(hbaseConf);
         TransactionalTable table = new TransactionalTable(hbaseConf, 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);
         }
        
         Scan s=new Scan();
         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++;
         }
         assertTrue("Count should be " + lInts.length + " but is " + count,
                    count == lInts.length);
         LOG.info("Rows found " + count);

         tm.tryCommit(t);

         t=tm.beginTransaction();
         res=table.getScanner(t,s);
         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++;
         }
         assertTrue("Count should be " + lInts.length + " but is " + count,
                    count == lInts.length);
         LOG.info("Rows found " + count);
         tm.tryCommit(t);
         table.close();
      } catch (Exception e) {
         LOG.error("Exception in test", e);
      }
   }
View Full Code Here

  

   @Test public void testScanUncommitted() throws Exception {
      try{
         TransactionManager tm = new TransactionManager(hbaseConf);
         TransactionalTable table = new TransactionalTable(hbaseConf, TEST_TABLE);
         TransactionState t=tm.beginTransaction();
         int[] lIntsA=new int[]{100,243,2342,22,1,5,43,56};
         for (int i=0;i<lIntsA.length;i++) {
            byte[]data=Bytes.toBytes(lIntsA[i]);
            Put put=new Put(data);
            put.add(Bytes.toBytes(TEST_FAMILY), Bytes.toBytes(TEST_COL), data);
            table.put(t,put);
         }
         tm.tryCommit(t);
  
         TransactionState tu=tm.beginTransaction();
         int[] lIntsB=new int[]{105,24,4342,32,7,3,30,40};
         for (int i=0;i<lIntsB.length;i++) {
            byte[]data=Bytes.toBytes(lIntsB[i]);
            Put put=new Put(data);
            put.add(Bytes.toBytes(TEST_FAMILY), Bytes.toBytes(TEST_COL), data);
            table.put(tu,put);
         }
  
         t=tm.beginTransaction();
         int[] lIntsC=new int[]{109,224,242,2,16,59,23,26};
         for (int i=0;i<lIntsC.length;i++) {
            byte[]data=Bytes.toBytes(lIntsC[i]);
            Put put=new Put(data);
            put.add(Bytes.toBytes(TEST_FAMILY), Bytes.toBytes(TEST_COL), data);
            table.put(t,put);
         }
         tm.tryCommit(t);
        
         t=tm.beginTransaction();
         Scan s=new Scan();
         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++;
         }
         assertTrue("Count should be " + (lIntsA.length*lIntsC.length) + " but is " + count,
                    count == lIntsA.length + lIntsC.length);
         LOG.info("Rows found " + count);
         tm.tryCommit(t);
         table.close();
      } catch (Exception e) {
         LOG.error("Exception in test", e);
      }
   }
View Full Code Here

   }

   @Test public void testLimitEqualToColumns() throws Exception {
      try {
         TransactionManager tm = new TransactionManager(hbaseConf);
         TransactionalTable tt = new TransactionalTable(hbaseConf, TEST_TABLE);

         TransactionState t1 = tm.beginTransaction();

         byte[] row = Bytes.toBytes("test-simple");
         byte[] row2 = Bytes.toBytes("test-simple2");
         byte[] row3 = Bytes.toBytes("test-simple3");
         byte[] row4 = Bytes.toBytes("test-simple4");
         byte[] fam = Bytes.toBytes(TEST_FAMILY);
         byte[] col = Bytes.toBytes("testdata");
         byte[] col1 = Bytes.add(col, Bytes.toBytes(1));
         byte[] col11 = Bytes.add(col, Bytes.toBytes(11));
         byte[] data = Bytes.toBytes("testWrite-1");
         byte[] data2 = Bytes.toBytes("testWrite-2verylargedatamuchmoredata than anything ever written to");

         Put p = new Put(row);
         for (int i = 0; i < 10; ++i) {
            p.add(fam, Bytes.add(col, Bytes.toBytes(i)), data);
         }
         tt.put(t1, p);
         tm.tryCommit(t1);

         TransactionState t2 = tm.beginTransaction();
         p = new Put(row2);
         for (int i = 0; i < 10; ++i) {
            p.add(fam, Bytes.add(col, Bytes.toBytes(i)), data);
         }
         tt.put(t2, p);
         tm.tryCommit(t2);

         // fill with data
         for (int i = 0; i < 500; ++i) {
            t2 = tm.beginTransaction();
            p = new Put(row4);
            p.add(fam, col11, data2);
            tt.put(t2, p);
            tm.tryCommit(t2);
         }

         HBaseAdmin admin = new HBaseAdmin(hbaseConf);
         admin.flush(TEST_TABLE);

         TransactionState t3 = tm.beginTransaction();
         p = new Put(row3);
         for (int i = 0; i < 10; ++i) {
            p.add(fam, Bytes.add(col, Bytes.toBytes(i)), data);
         }
         tt.put(t3, p);
         tm.tryCommit(t3);

         // fill with data
         for (int i = 0; i < 500; ++i) {
            t2 = tm.beginTransaction();
            p = new Put(row4);
            p.add(fam, col11, data2);
            tt.put(t2, p);
            tm.tryCommit(t2);
         }

         Get g = new Get(row);
         g.setMaxVersions();
         g.addColumn(fam, col1);
         Result r = tt.get(g);
         int size = r.getColumn(fam, col1).size();
         LOG.info("Size before compaction : " + size);

         admin.compact(TEST_TABLE);

         Thread.sleep(2000);

         Scan s = new Scan(row);
         s.setMaxVersions();
         s.addColumn(fam, col1);
         ResultScanner rs = tt.getScanner(s);
         int count = 0;
         while ((r = rs.next()) != null) {
            count += r.getColumn(fam, col1).size();
         }
         assertEquals(3, count);
View Full Code Here

public class TestSingleColumnFamily extends OmidTestBase {
   private static final Log LOG = LogFactory.getLog(TestSingleColumnFamily.class);

   @Test public void testSingleColumnFamily() throws Exception {
      TransactionManager tm = new TransactionManager(hbaseConf);
      TransactionalTable table1 = new TransactionalTable(hbaseConf, 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();
   }
View Full Code Here

      try{
         byte[] family = Bytes.toBytes(TEST_FAMILY);
         byte[] col1 = Bytes.toBytes("value1");
         byte[] col2 = Bytes.toBytes("value2");
         TransactionManager tm = new TransactionManager(hbaseConf);
         TransactionalTable table1 = new TransactionalTable(hbaseConf, TEST_TABLE);
         TransactionState t=tm.beginTransaction();
         int val=1000;
         byte[]data=Bytes.toBytes(val);
         Put put1=new Put(data);
         put1.add(family, col1, data);
         table1.put(t,put1);
         Put put2=new Put(data);
         put2.add(family, col2, data);
         table1.put(t,put2);
         tm.tryCommit(t);
         table1.close();

         assertTrue("Invalid value in table", verifyValue(Bytes.toBytes(TEST_TABLE),
                                                          data, family, col1, data));
         assertTrue("Invalid value in table", verifyValue(Bytes.toBytes(TEST_TABLE),
                                                          data, family, col2, data));
View Full Code Here

      try{
         byte[] family = Bytes.toBytes(TEST_FAMILY);
         byte[] col = Bytes.toBytes("value");

         TransactionManager tm = new TransactionManager(hbaseConf);
         TransactionalTable table1 = new TransactionalTable(hbaseConf, TEST_TABLE);
         TransactionState t=tm.beginTransaction();
         int num=50;
         for(int j=0;j<=num;j++) {
            byte[]data=Bytes.toBytes(j);
            Put put=new Put(data);
            put.add(family, col, data);
            table1.put(t,put);
         }
         tm.tryCommit(t);
         table1.close();

         byte[] data=Bytes.toBytes(0);
         assertTrue("Invalid value in table", verifyValue(Bytes.toBytes(TEST_TABLE),
                                                          data, family, col, data));
         data=Bytes.toBytes(num/2);
View Full Code Here

            admin.createTable(desc, new byte[][]{Bytes.toBytes("3000")});
            LOG.info("created table");
        }

        TransactionManager tm = new TransactionManager(conf);
        TransactionalTable tt = new TransactionalTable(conf, TEST_TABLE);

        TransactionalTable tt2 = new TransactionalTable(conf, TEST_TABLE2);

        TransactionState t1 = tm.beginTransaction();

        Put put = new Put(Bytes.toBytes("2002"));
        put.add(Bytes.toBytes(TEST_FAMILY), Bytes.toBytes("c"), Bytes.toBytes("2002"));
        tt.put(t1, put);

        tt2.put(t1, put);

        ResultScanner rs = tt.getScanner(t1, new Scan());
        Result r = rs.next();
        while (r != null) {
            System.out.println(r);
            r = rs.next();
        }
        tm.tryCommit(t1);

        System.out.println();

        t1 = tm.beginTransaction();

        put = new Put(Bytes.toBytes("2003"));
        put.add(Bytes.toBytes(TEST_FAMILY), Bytes.toBytes("c"), Bytes.toBytes("2003"));
        tt.put(t1, put);
        tt2.put(t1, put);
        tm.abort(t1);

        rs = tt.getScanner(t1, new Scan());
        r = rs.next();
        while (r != null) {
            System.out.print(r);
            r = rs.next();
        }

        System.out.println();

        rs = tt2.getScanner(t1, new Scan());
        r = rs.next();
        while (r != null) {
            System.out.print(r);
            r = rs.next();
        }
       
        System.out.println();
       
       
        put = new Put(Bytes.toBytes("2004"));
        put.add(Bytes.toBytes(TEST_FAMILY), Bytes.toBytes("c"), Bytes.toBytes("2004"));
        tt.put(t1, put);
        tt2.put(t1, put);
        put = new Put(Bytes.toBytes("3001"));
        put.add(Bytes.toBytes(TEST_FAMILY), Bytes.toBytes("c"), Bytes.toBytes("3002"));
        tt.put(t1, put);
        tt2.put(t1, put);
        tm.abort(t1);

        rs = tt.getScanner(t1, new Scan());
        r = rs.next();
        while (r != null) {
            System.out.print(r);
            r = rs.next();
        }

        System.out.println();

        rs = tt2.getScanner(t1, new Scan());
        r = rs.next();
        while (r != null) {
            System.out.print(r);
            r = rs.next();
        }
View Full Code Here

TOP

Related Classes of com.yahoo.omid.client.TransactionalTable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.