Search in sources :

Example 1 with IntegerStore

use of co.cask.cdap.api.dataset.lib.IntegerStore in project cdap by caskdata.

the class ObjectStoreDatasetTest method testSubclass.

@Test
public void testSubclass() throws Exception {
    DatasetId intsInstance = DatasetFrameworkTestUtil.NAMESPACE_ID.dataset("ints");
    addIntegerStoreInstance(intsInstance);
    final IntegerStore ints = dsFrameworkUtil.getInstance(intsInstance);
    TransactionExecutor txnl = dsFrameworkUtil.newInMemoryTransactionExecutor(ints);
    txnl.execute(new TransactionExecutor.Subroutine() {

        @Override
        public void apply() throws Exception {
            ints.write(42, 101);
        }
    });
    txnl.execute(new TransactionExecutor.Subroutine() {

        @Override
        public void apply() throws Exception {
            Assert.assertEquals((Integer) 101, ints.read(42));
        }
    });
    // test delete
    txnl.execute(new TransactionExecutor.Subroutine() {

        @Override
        public void apply() throws Exception {
            ints.delete(42);
        }
    });
    txnl.execute(new TransactionExecutor.Subroutine() {

        @Override
        public void apply() throws Exception {
            Assert.assertNull(ints.read(42));
        }
    });
    dsFrameworkUtil.deleteInstance(intsInstance);
}
Also used : IntegerStore(co.cask.cdap.api.dataset.lib.IntegerStore) TransactionExecutor(org.apache.tephra.TransactionExecutor) TransactionFailureException(org.apache.tephra.TransactionFailureException) NoSuchElementException(java.util.NoSuchElementException) DatasetId(co.cask.cdap.proto.id.DatasetId) Test(org.junit.Test)

Aggregations

IntegerStore (co.cask.cdap.api.dataset.lib.IntegerStore)1 DatasetId (co.cask.cdap.proto.id.DatasetId)1 NoSuchElementException (java.util.NoSuchElementException)1 TransactionExecutor (org.apache.tephra.TransactionExecutor)1 TransactionFailureException (org.apache.tephra.TransactionFailureException)1 Test (org.junit.Test)1