Package co.cask.tephra

Examples of co.cask.tephra.TransactionManager$InProgressTx


    this.txMetricsCollector = txMetricsCollector;
  }

  @Override
  public TransactionManager get() {
    return new TransactionManager(conf, storageProvider.get(), txMetricsCollector);
  }
View Full Code Here


    this.txMetricsCollector = txMetricsCollector;
  }

  @Override
  public TransactionManager get() {
    return new TransactionManager(conf, storageProvider.get(), txMetricsCollector);
  }
View Full Code Here

  @Before
  public void setup() throws Exception {
    Configuration conf = HBaseConfiguration.create();
    conf.unset(TxConstants.Persist.CFG_TX_SNAPHOT_CODEC_CLASSES);
    txManager = new TransactionManager(conf);
    txManager.startAndWait();
  }
View Full Code Here

    TransactionStateStorage storage = null;
    TransactionStateStorage storage2 = null;
    TransactionStateStorage storage3 = null;
    try {
      storage = getStorage(conf);
      TransactionManager txManager = new TransactionManager
        (conf, storage, new TxMetricsCollector());
      txManager.startAndWait();

      // TODO: replace with new persistence tests
      final byte[] a = { 'a' };
      final byte[] b = { 'b' };
      // start a tx1, add a change A and commit
      Transaction tx1 = txManager.startShort();
      Assert.assertTrue(txManager.canCommit(tx1, Collections.singleton(a)));
      Assert.assertTrue(txManager.commit(tx1));
      // start a tx2 and add a change B
      Transaction tx2 = txManager.startShort();
      Assert.assertTrue(txManager.canCommit(tx2, Collections.singleton(b)));
      // start a tx3
      Transaction tx3 = txManager.startShort();
      // restart
      txManager.stopAndWait();
      TransactionSnapshot origState = txManager.getCurrentState();
      LOG.info("Orig state: " + origState);

      Thread.sleep(100);
      // starts a new tx manager
      storage2 = getStorage(conf);
      txManager = new TransactionManager(conf, storage2, new TxMetricsCollector());
      txManager.startAndWait();

      // check that the reloaded state matches the old
      TransactionSnapshot newState = txManager.getCurrentState();
      LOG.info("New state: " + newState);
      assertEquals(origState, newState);

      // commit tx2
      Assert.assertTrue(txManager.commit(tx2));
      // start another transaction, must be greater than tx3
      Transaction tx4 = txManager.startShort();
      Assert.assertTrue(tx4.getWritePointer() > tx3.getWritePointer());
      // tx1 must be visble from tx2, but tx3 and tx4 must not
      Assert.assertTrue(tx2.isVisible(tx1.getWritePointer()));
      Assert.assertFalse(tx2.isVisible(tx3.getWritePointer()));
      Assert.assertFalse(tx2.isVisible(tx4.getWritePointer()));
      // add same change for tx3
      Assert.assertFalse(txManager.canCommit(tx3, Collections.singleton(b)));
      // check visibility with new xaction
      Transaction tx5 = txManager.startShort();
      Assert.assertTrue(tx5.isVisible(tx1.getWritePointer()));
      Assert.assertTrue(tx5.isVisible(tx2.getWritePointer()));
      Assert.assertFalse(tx5.isVisible(tx3.getWritePointer()));
      Assert.assertFalse(tx5.isVisible(tx4.getWritePointer()));
      // can commit tx3?
      txManager.abort(tx3);
      txManager.abort(tx4);
      txManager.abort(tx5);
      // start new tx and verify its exclude list is empty
      Transaction tx6 = txManager.startShort();
      Assert.assertFalse(tx6.hasExcludes());
      txManager.abort(tx6);

      // now start 5 x claim size transactions
      Transaction tx = txManager.startShort();
      for (int i = 1; i < 50; i++) {
        tx = txManager.startShort();
      }
      origState = txManager.getCurrentState();

      Thread.sleep(100);
      // simulate crash by starting a new tx manager without a stopAndWait
      storage3 = getStorage(conf);
      txManager = new TransactionManager(conf, storage3, new TxMetricsCollector());
      txManager.startAndWait();

      // verify state again matches (this time should include WAL replay)
      newState = txManager.getCurrentState();
      assertEquals(origState, newState);

      // get a new transaction and verify it is greater
      Transaction txAfter = txManager.startShort();
      Assert.assertTrue(txAfter.getWritePointer() > tx.getWritePointer());
    } finally {
      if (storage != null) {
        storage.stopAndWait();
      }
View Full Code Here

    TransactionStateStorage storage1 = null;
    TransactionStateStorage storage2 = null;
    try {
      storage1 = getStorage(conf);
      TransactionManager txManager = new TransactionManager
        (conf, storage1, new TxMetricsCollector());
      txManager.startAndWait();

      // TODO: replace with new persistence tests
      final byte[] a = { 'a' };
      final byte[] b = { 'b' };
      // start a tx1, add a change A and commit
      Transaction tx1 = txManager.startShort();
      Assert.assertTrue(txManager.canCommit(tx1, Collections.singleton(a)));
      Assert.assertTrue(txManager.commit(tx1));
      // start a tx2 and add a change B
      Transaction tx2 = txManager.startShort();
      Assert.assertTrue(txManager.canCommit(tx2, Collections.singleton(b)));
      // start a tx3
      Transaction tx3 = txManager.startShort();
      TransactionSnapshot origState = txManager.getCurrentState();
      LOG.info("Orig state: " + origState);

      // simulate a failure by starting a new tx manager without stopping first
      storage2 = getStorage(conf);
      txManager = new TransactionManager(conf, storage2, new TxMetricsCollector());
      txManager.startAndWait();

      // check that the reloaded state matches the old
      TransactionSnapshot newState = txManager.getCurrentState();
      LOG.info("New state: " + newState);
      assertEquals(origState, newState);

    } finally {
      if (storage1 != null) {
View Full Code Here

TOP

Related Classes of co.cask.tephra.TransactionManager$InProgressTx

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.