Package com.yahoo.omid.client

Examples of com.yahoo.omid.client.TransactionManager


  
    @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);
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);
View Full Code Here

    }

   @Test public void runTestSimple() throws Exception {
      try {
         TransactionManager tm = new TransactionManager(hbaseConf);
         TransactionalTable tt = new TransactionalTable(hbaseConf, TEST_TABLE);
        
         TransactionState t1 = tm.beginTransaction();
         LOG.info("Transaction created " + t1);
        
         byte[] row = Bytes.toBytes("test-simple");
         byte[] fam = Bytes.toBytes(TEST_FAMILY);
         byte[] col = Bytes.toBytes("testdata");
         byte[] data1 = Bytes.toBytes("testWrite-1");
         byte[] data2 = Bytes.toBytes("testWrite-2");

         Put p = new Put(row);
         p.add(fam, col, data1);
         tt.put(t1, p);
         tm.tryCommit(t1);

         TransactionState tread = tm.beginTransaction();
         TransactionState t2 = tm.beginTransaction();
         p = new Put(row);
         p.add(fam, col, data2);
         tt.put(t2, p);
         tm.tryCommit(t2);

         Get g = new Get(row).setMaxVersions(1);
         Result r = tt.get(g);
         assertTrue("Unexpected value for read: " + Bytes.toString(r.getValue(fam, col)),
                    Bytes.equals(data2, r.getValue(fam, col)));
View Full Code Here

      }
   }

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

         TransactionState t1 = tm.beginTransaction();
         LOG.info("Transaction created " + t1);

         byte[] row = Bytes.toBytes("test-simple");
         byte[] fam = Bytes.toBytes(TEST_FAMILY);
         byte[] col = Bytes.toBytes("testdata");
         byte[] data1 = Bytes.toBytes("testWrite-1");
         byte[] data2 = Bytes.toBytes("testWrite-2");

         Put p = new Put(row);
         p.add(fam, col, data1);
         tt.put(t1, p);
         tm.tryCommit(t1);

         for (int i = 0; i < 5; ++i) {
            TransactionState t2 = tm.beginTransaction();
            p = new Put(row);
            p.add(fam, col, data2);
            tt.put(t2, p);
         }
         TransactionState tread = tm.beginTransaction();

         Get g = new Get(row).setMaxVersions(1);
         Result r = tt.get(g);
         assertTrue("Unexpected value for read: " + Bytes.toString(r.getValue(fam, col)),
               Bytes.equals(data2, r.getValue(fam, col)));
View Full Code Here

      }
   }

   @Test public void runTestInterleave() throws Exception {
      try {
         TransactionManager tm = new TransactionManager(hbaseConf);
         TransactionalTable tt = new TransactionalTable(hbaseConf, TEST_TABLE);
       
         TransactionState t1 = tm.beginTransaction();
         LOG.info("Transaction created " + t1);
        
         byte[] row = Bytes.toBytes("test-interleave");
         byte[] fam = Bytes.toBytes(TEST_FAMILY);
         byte[] col = Bytes.toBytes("testdata");
         byte[] data1 = Bytes.toBytes("testWrite-1");
         byte[] data2 = Bytes.toBytes("testWrite-2");

         Put p = new Put(row);
         p.add(fam, col, data1);
         tt.put(t1, p);
         tm.tryCommit(t1);

         TransactionState t2 = tm.beginTransaction();
         p = new Put(row);
         p.add(fam, col, data2);
         tt.put(t2, p);

         TransactionState tread = tm.beginTransaction();
         Get g = new Get(row).setMaxVersions(1);
         Result r = tt.get(tread, g);
         assertTrue("Unexpected value for SI read " + tread + ": " + Bytes.toString(r.getValue(fam, col)),
                    Bytes.equals(data1, r.getValue(fam, col)));
         tm.tryCommit(t2);

         r = tt.get(g);
         assertTrue("Unexpected value for read: " + Bytes.toString(r.getValue(fam, col)),
                    Bytes.equals(data2, r.getValue(fam, col)));
View Full Code Here

      }
   }

   @Test public void runTestInterleaveScan() throws Exception {
      try {
         TransactionManager tm = new TransactionManager(hbaseConf);
         TransactionalTable tt = new TransactionalTable(hbaseConf, TEST_TABLE);
        
         TransactionState t1 = tm.beginTransaction();
         LOG.info("Transaction created " + t1);
        
         byte[] fam = Bytes.toBytes(TEST_FAMILY);
         byte[] col = Bytes.toBytes("testdata");
         byte[] data1 = Bytes.toBytes("testWrite-1");
         byte[] data2 = Bytes.toBytes("testWrite-2");
        
         byte[] startrow = Bytes.toBytes("test-scan" + 0);
         byte[] stoprow = Bytes.toBytes("test-scan" + 9);
         byte[] modrow = Bytes.toBytes("test-scan" + 3);
         for (int i = 0; i < 10; i++) {
            byte[] row = Bytes.toBytes("test-scan" + i);
           
            Put p = new Put(row);
            p.add(fam, col, data1);
            tt.put(t1, p);
         }
         tm.tryCommit(t1);

         TransactionState t2 = tm.beginTransaction();
         Put p = new Put(modrow);
         p.add(fam, col, data2);
         tt.put(t2, p);
        
         TransactionState tscan = tm.beginTransaction();
         ResultScanner rs = tt.getScanner(tscan, new Scan().setStartRow(startrow).setStopRow(stoprow));
         Result r = rs.next();
         int i = 0;
         while (r != null) {
            if (LOG.isTraceEnabled()) {
               LOG.trace("Scan1 :" + Bytes.toString(r.getRow()) + " => " + Bytes.toString(r.getValue(fam, col)));
            }
            System.out.println(++i);

            assertTrue("Unexpected value for SI scan " + tscan + ": " + Bytes.toString(r.getValue(fam, col)),
                       Bytes.equals(data1, r.getValue(fam, col)));
            r = rs.next();
         }
         tm.tryCommit(t2);

         int modifiedrows = 0;
         tscan = tm.beginTransaction();
         rs = tt.getScanner(tscan, new Scan().setStartRow(startrow).setStopRow(stoprow));
         r = rs.next();
         while (r != null) {
            if (Bytes.equals(data2, r.getValue(fam, col))) {
               if (LOG.isTraceEnabled()) {
View Full Code Here

      }
   }
  
   @Test public void runTestDeleteCol() throws Exception {
      try {
         TransactionManager tm = new TransactionManager(hbaseConf);
         TransactionalTable tt = new TransactionalTable(hbaseConf, TEST_TABLE);
        
         TransactionState t1 = tm.beginTransaction();
         LOG.info("Transaction created " + t1);
        
         int rowcount = 10;
         int colAcount = 0;
         int colBcount = 0;

         byte[] fam = Bytes.toBytes(TEST_FAMILY);
         byte[] colA = Bytes.toBytes("testdataA");
         byte[] colB = Bytes.toBytes("testdataB");
         byte[] data1 = Bytes.toBytes("testWrite-1");
         byte[] data2 = Bytes.toBytes("testWrite-2");
        
         byte[] modrow = Bytes.toBytes("test-del" + 3);
         for (int i = 0; i < rowcount; i++) {
            byte[] row = Bytes.toBytes("test-del" + i);
           
            Put p = new Put(row);
            p.add(fam, colA, data1);
            p.add(fam, colB, data2);
            tt.put(t1, p);
         }
         tm.tryCommit(t1);

         TransactionState t2 = tm.beginTransaction();
         Delete d = new Delete(modrow);
         d.deleteColumn(fam, colA);
         tt.delete(t2, d);
        
         TransactionState tscan = tm.beginTransaction();
         ResultScanner rs = tt.getScanner(tscan, new Scan());
         Result r = rs.next();
         colAcount = 0;
         colBcount = 0;
         while (r != null) {
            if (r.containsColumn(fam, colA)) {
               colAcount++;
            }
            if (r.containsColumn(fam, colB)) {
               colBcount++;
            }

            LOG.trace("row: " + Bytes.toString(r.getRow()) + " countA: " + colAcount + " countB: " + colBcount);
            r = rs.next();
         }
         assertTrue("Expected all these numbers to be the same "
                    + colAcount + "," + colBcount + "," + rowcount,
                    (colAcount == colBcount) && (colAcount == rowcount));
         tm.tryCommit(t2);

         tscan = tm.beginTransaction();
         rs = tt.getScanner(tscan, new Scan());
         r = rs.next();

         colAcount = 0;
         colBcount = 0;
View Full Code Here

      }
   }
  
   @Test public void runTestDeleteRow() throws Exception {
      try {
         TransactionManager tm = new TransactionManager(hbaseConf);
         TransactionalTable tt = new TransactionalTable(hbaseConf, TEST_TABLE);
        
         TransactionState t1 = tm.beginTransaction();
         LOG.info("Transaction created " + t1);
        
         int rowcount = 10;
         int count = 0;

         byte[] fam = Bytes.toBytes(TEST_FAMILY);
         byte[] col = Bytes.toBytes("testdata");
         byte[] data1 = Bytes.toBytes("testWrite-1");
        
         byte[] modrow = Bytes.toBytes("test-del" + 3);
         for (int i = 0; i < rowcount; i++) {
            byte[] row = Bytes.toBytes("test-del" + i);
           
            Put p = new Put(row);
            p.add(fam, col, data1);
            tt.put(t1, p);
         }
         tm.tryCommit(t1);

         TransactionState t2 = tm.beginTransaction();
         Delete d = new Delete(modrow);
         tt.delete(t2, d);
        
         TransactionState tscan = tm.beginTransaction();
         ResultScanner rs = tt.getScanner(tscan, new Scan());
         Result r = rs.next();
         count = 0;
         while (r != null) {
            count++;
            LOG.trace("row: " + Bytes.toString(r.getRow()) + " count: " + count);
            r = rs.next();
         }
         assertTrue("Expected " + rowcount + " rows but " + count + " found",
                    count == rowcount);

         tm.tryCommit(t2);
        
         tscan = tm.beginTransaction();
         rs = tt.getScanner(tscan, new Scan());
         r = rs.next();
         count = 0;
         while (r != null) {
            count++;           
View Full Code Here

   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(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

TOP

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

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.