Package com.yahoo.omid.client

Examples of com.yahoo.omid.client.TransactionalTable


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

   @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);        
        
         int modifiedrows = 0;
         ResultScanner rs = tt.getScanner(t2, new Scan().setStartRow(startrow).setStopRow(stoprow).addColumn(fam, col));
         Result r = rs.next();
         while (r != null) {
            if (Bytes.equals(data2, r.getValue(fam, col))) {
               if (LOG.isTraceEnabled()) {
                  LOG.trace("Modified :" + Bytes.toString(r.getRow()));
               }
               modifiedrows++;
            }
           
            r = rs.next();
         }
        
         assertTrue("Expected 1 row modified, but " + modifiedrows + " are.",
                    modifiedrows == 1);
         tm.abort(t2);
        
         TransactionState tscan = tm.beginTransaction();
         rs = tt.getScanner(tscan, new Scan().setStartRow(startrow).setStopRow(stoprow).addColumn(fam, col));
         r = rs.next();
         while (r != null) {
            if (LOG.isTraceEnabled()) {
               LOG.trace("Scan1 :" + Bytes.toString(r.getRow()) + " => " + Bytes.toString(r.getValue(fam, col)));
            }
View Full Code Here


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

   @Test public void testMultiPutSameRow() throws Exception {
      try{
         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("value"), data);
            table1.put(t,put);
         }
         int key=15;
         Get g=new Get(Bytes.toBytes(key));
         Result r=table1.get(t,g);
        
         assertTrue("Found a row that should not exist", r.isEmpty());

         tm.tryCommit(t);
      } catch (Exception e) {
View Full Code Here

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

   @Test public void testDeleteOld() 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[] col2 = Bytes.toBytes("testdata2");
         byte[] data1 = Bytes.toBytes("testWrite-1");
         byte[] data2 = Bytes.toBytes("testWrite-2verylargedatamuchmoredata than anything ever written to");

         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);
         tm.tryCommit(t2);

         for (int i = 0; i < 500; ++i) {
            t2 = tm.beginTransaction();
            p = new Put(row);
            p.add(fam, col2, data2);
            tt.put(t2, p);
            tm.tryCommit(t2);
         }
        
         HBaseAdmin admin = new HBaseAdmin(hbaseConf);
         admin.flush(TEST_TABLE);
        
         for (int i = 0; i < 500; ++i) {
            t2 = tm.beginTransaction();
            p = new Put(row);
            p.add(fam, col2, data2);
            tt.put(t2, p);
            tm.tryCommit(t2);
         }

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

         admin.compact(TEST_TABLE);
        
         Thread.sleep(2000);
        
         g = new Get(row);
         g.setMaxVersions();
         g.addColumn(fam, col);
         r = tt.get(g);
         assertEquals(1, r.getColumn(fam, col).size());
        
         g = new Get(row);
         g.setMaxVersions();
         g.addColumn(fam, col2);
         r = tt.get(g);
         LOG.info("Size after compaction " + r.getColumn(fam, col2).size());
         assertThat(r.getColumn(fam, col2).size(), is(lessThan(size)));
      } catch (Exception e) {
         LOG.error("Exception occurred", e);
         throw e;
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.