Package com.yahoo.omid.client

Examples of com.yahoo.omid.client.TransactionalTable


    }

   @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)));

         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)));
      } catch (Exception e) {
         LOG.error("Exception occurred", e);
         throw e;
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)));

         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)));
      } catch (Exception e) {
         LOG.error("Exception occurred", e);
         throw e;
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)));

      } catch (Exception e) {
         LOG.error("Exception occurred", e);
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()) {
                  LOG.trace("Modified :" + Bytes.toString(r.getRow()));
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;
         while (r != null) {
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++;           
            r = rs.next();
View Full Code Here

   private static final Log LOG = LogFactory.getLog(TestTransactionConflict.class);

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

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

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

      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);

      Put p2 = new Put(row);
      p2.add(fam, col, data2);
      tt.put(t2, p2);

      tm.tryCommit(t2);

      boolean aborted = false;
      try {
View Full Code Here

   }

   @Test
   public void runTestMultiTableConflict() throws Exception {
      TransactionManager tm = new TransactionManager(hbaseConf);
      TransactionalTable tt = new TransactionalTable(hbaseConf, TEST_TABLE);
      String table2 = TEST_TABLE + 2;

      HBaseAdmin admin = new HBaseAdmin(hbaseConf);

      if (!admin.tableExists(table2)) {
         HTableDescriptor desc = new HTableDescriptor(table2);
         HColumnDescriptor datafam = new HColumnDescriptor(TEST_FAMILY);
         datafam.setMaxVersions(Integer.MAX_VALUE);
         desc.addFamily(datafam);

         admin.createTable(desc);
      }

      if (admin.isTableDisabled(table2)) {
         admin.enableTable(table2);
      }

      TransactionalTable tt2 = new TransactionalTable(hbaseConf, table2);

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

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

      byte[] row = Bytes.toBytes("test-simple");
      byte[] row2 = Bytes.toBytes("test-simple2");
      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);
      tt2.put(t1, p);

      Put p2 = new Put(row);
      p2.add(fam, col, data2);
      tt.put(t2, p2);
      p2 = new Put(row2);
      p2.add(fam, col, data2);
      tt2.put(t2, p2);

      tm.tryCommit(t2);

      boolean aborted = false;
      try {
         tm.tryCommit(t1);
         assertTrue("Transaction commited successfully", false);
      } catch (CommitUnsuccessfulException e) {
         aborted = true;
      }
      assertTrue("Transaction didn't raise exception", aborted);

      ResultScanner rs = tt2.getScanner(Bytes.toBytes(TEST_FAMILY));
      int count = 0;
      Result r;
      while ((r = rs.next()) != null) {
         count += r.size();
      }
View Full Code Here

   }

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

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

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

      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);

      Get g = new Get(row).setMaxVersions();
      Result r = tt.get(g);
      assertEquals("Unexpected size for read.", 1, r.size());
      assertTrue("Unexpected value for read: " + Bytes.toString(r.getValue(fam, col)),
            Bytes.equals(data1, r.getValue(fam, col)));

      Put p2 = new Put(row);
      p2.add(fam, col, data2);
      tt.put(t2, p2);

      r = tt.get(g);
      assertEquals("Unexpected size for read.", 2, r.size());
      r = tt.get(t2, g);
      assertEquals("Unexpected size for read.", 1, r.size());
      assertTrue("Unexpected value for read: " + Bytes.toString(r.getValue(fam, col)),
            Bytes.equals(data2, r.getValue(fam, col)));

      tm.tryCommit(t1);

      boolean aborted = false;
      try {
         tm.tryCommit(t2);
         assertTrue("Transaction commited successfully", false);
      } catch (CommitUnsuccessfulException e) {
         aborted = true;
      }
      assertTrue("Transaction didn't raise exception", aborted);

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

   @Test
   public void testCleanupWithDeleteRow() 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[] 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, col, data1);
            tt.put(t1, p);
         }
         tm.tryCommit(t1);

         TransactionState t2 = tm.beginTransaction();
         LOG.info("Transaction created " + t2);
         Delete d = new Delete(modrow);
         tt.delete(t2, d);

         ResultScanner rs = tt.getScanner(t2, new Scan());
         Result r = rs.next();
         count = 0;
         while (r != null) {
            count++;
            LOG.trace("row: " + Bytes.toString(r.getRow()) + " count: " + count);
            r = rs.next();
         }
         assertEquals("Wrong count", rowcount - 1, count);

         TransactionState t3 = tm.beginTransaction();
         LOG.info("Transaction created " + t3);
         Put p = new Put(modrow);
         p.add(fam, col, data2);
         tt.put(t3, p);

         tm.tryCommit(t3);

         boolean aborted = false;
         try {
            tm.tryCommit(t2);
            assertTrue("Didn't abort", false);
         } catch (CommitUnsuccessfulException e) {
            aborted = true;
         }
         assertTrue("Didn't raise exception", aborted);

         TransactionState tscan = tm.beginTransaction();
         rs = tt.getScanner(tscan, new Scan());
         r = rs.next();
         count = 0;
         while (r != null) {
            count++;
            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.