Search in sources :

Example 1 with DefaultTransactionExecutor

use of org.apache.tephra.DefaultTransactionExecutor in project cdap by caskdata.

the class TableConcurrentTest method before.

@Before
public void before() {
    super.before();
    txExecutorFactory = new TransactionExecutorFactory() {

        @Override
        public TransactionExecutor createExecutor(Iterable<TransactionAware> txAwares) {
            return new DefaultTransactionExecutor(txClient, txAwares);
        }
    };
}
Also used : TransactionAware(org.apache.tephra.TransactionAware) DefaultTransactionExecutor(org.apache.tephra.DefaultTransactionExecutor) TransactionExecutor(org.apache.tephra.TransactionExecutor) DefaultTransactionExecutor(org.apache.tephra.DefaultTransactionExecutor) TransactionExecutorFactory(org.apache.tephra.TransactionExecutorFactory) Before(org.junit.Before)

Example 2 with DefaultTransactionExecutor

use of org.apache.tephra.DefaultTransactionExecutor in project cdap by caskdata.

the class DatasetOpExecutorServiceTest method testRest.

@Test
public void testRest() throws Exception {
    // check non-existence with 404
    testAdminOp(bob, "exists", 404, null);
    // add instance, should automatically create an instance
    dsFramework.addInstance("table", bob, DatasetProperties.EMPTY);
    testAdminOp(bob, "exists", 200, true);
    testAdminOp("bob", "exists", 404, null);
    // check truncate
    final Table table = dsFramework.getDataset(bob, DatasetDefinition.NO_ARGUMENTS, null);
    Assert.assertNotNull(table);
    TransactionExecutor txExecutor = new DefaultTransactionExecutor(new InMemoryTxSystemClient(txManager), ImmutableList.of((TransactionAware) table));
    // writing smth to table
    txExecutor.execute(new TransactionExecutor.Subroutine() {

        @Override
        public void apply() throws Exception {
            table.put(new Put("key1", "col1", "val1"));
        }
    });
    // verify that we can read the data
    txExecutor.execute(new TransactionExecutor.Subroutine() {

        @Override
        public void apply() throws Exception {
            Assert.assertEquals("val1", table.get(new Get("key1", "col1")).getString("col1"));
        }
    });
    testAdminOp(bob, "truncate", 200, null);
    // verify that data is no longer there
    txExecutor.execute(new TransactionExecutor.Subroutine() {

        @Override
        public void apply() throws Exception {
            Assert.assertTrue(table.get(new Get("key1", "col1")).isEmpty());
        }
    });
    // check upgrade
    testAdminOp(bob, "upgrade", 200, null);
    // drop and check non-existence
    dsFramework.deleteInstance(bob);
    testAdminOp(bob, "exists", 404, null);
}
Also used : Table(co.cask.cdap.api.dataset.table.Table) TransactionAware(org.apache.tephra.TransactionAware) Get(co.cask.cdap.api.dataset.table.Get) DefaultTransactionExecutor(org.apache.tephra.DefaultTransactionExecutor) TransactionExecutor(org.apache.tephra.TransactionExecutor) DefaultTransactionExecutor(org.apache.tephra.DefaultTransactionExecutor) InMemoryTxSystemClient(org.apache.tephra.inmemory.InMemoryTxSystemClient) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) Put(co.cask.cdap.api.dataset.table.Put) Test(org.junit.Test)

Example 3 with DefaultTransactionExecutor

use of org.apache.tephra.DefaultTransactionExecutor in project cdap by caskdata.

the class HBaseTableTest method testColumnFamily.

@Test
public void testColumnFamily() throws Exception {
    DatasetProperties props = TableProperties.builder().setColumnFamily("t").build();
    String tableName = "testcf";
    DatasetAdmin admin = getTableAdmin(CONTEXT1, tableName, props);
    admin.create();
    final BufferingTable table = getTable(CONTEXT1, tableName, props);
    TransactionSystemClient txClient = new DetachedTxSystemClient();
    TransactionExecutor executor = new DefaultTransactionExecutor(txClient, table);
    executor.execute(new TransactionExecutor.Subroutine() {

        @Override
        public void apply() throws Exception {
            table.put(new Put("row", "column", "testValue"));
        }
    });
    final BufferingTable table2 = getTable(CONTEXT1, tableName, props);
    executor = new DefaultTransactionExecutor(txClient, table2);
    executor.execute(new TransactionExecutor.Subroutine() {

        @Override
        public void apply() throws Exception {
            Assert.assertEquals("testValue", table2.get(new Get("row", "column")).getString("column"));
        }
    });
    // Verify the column family name
    TableId hTableId = hBaseTableUtil.createHTableId(new NamespaceId(CONTEXT1.getNamespaceId()), tableName);
    HTableDescriptor htd = hBaseTableUtil.getHTableDescriptor(TEST_HBASE.getHBaseAdmin(), hTableId);
    HColumnDescriptor hcd = htd.getFamily(Bytes.toBytes("t"));
    Assert.assertNotNull(hcd);
    Assert.assertEquals("t", hcd.getNameAsString());
}
Also used : TableId(co.cask.cdap.data2.util.TableId) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) DatasetProperties(co.cask.cdap.api.dataset.DatasetProperties) DatasetAdmin(co.cask.cdap.api.dataset.DatasetAdmin) TransactionExecutor(org.apache.tephra.TransactionExecutor) DefaultTransactionExecutor(org.apache.tephra.DefaultTransactionExecutor) ScannerTimeoutException(org.apache.hadoop.hbase.client.ScannerTimeoutException) RetriesExhaustedWithDetailsException(org.apache.hadoop.hbase.client.RetriesExhaustedWithDetailsException) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) Put(co.cask.cdap.api.dataset.table.Put) BufferingTable(co.cask.cdap.data2.dataset2.lib.table.BufferingTable) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) TransactionSystemClient(org.apache.tephra.TransactionSystemClient) Get(co.cask.cdap.api.dataset.table.Get) DefaultTransactionExecutor(org.apache.tephra.DefaultTransactionExecutor) DetachedTxSystemClient(org.apache.tephra.inmemory.DetachedTxSystemClient) NamespaceId(co.cask.cdap.proto.id.NamespaceId) BufferingTableTest(co.cask.cdap.data2.dataset2.lib.table.BufferingTableTest) Test(org.junit.Test)

Example 4 with DefaultTransactionExecutor

use of org.apache.tephra.DefaultTransactionExecutor in project cdap by caskdata.

the class HiveExploreServiceFileSetTestRun method doTransaction.

private void doTransaction(Dataset dataset, final Runnable runnable) throws Exception {
    TransactionExecutor executor = new DefaultTransactionExecutor(transactionSystemClient, (TransactionAware) dataset);
    executor.execute(new TransactionExecutor.Subroutine() {

        @Override
        public void apply() throws Exception {
            runnable.run();
        }
    });
}
Also used : DefaultTransactionExecutor(org.apache.tephra.DefaultTransactionExecutor) TransactionExecutor(org.apache.tephra.TransactionExecutor) DefaultTransactionExecutor(org.apache.tephra.DefaultTransactionExecutor) TransactionFailureException(org.apache.tephra.TransactionFailureException) DataSetException(co.cask.cdap.api.dataset.DataSetException)

Example 5 with DefaultTransactionExecutor

use of org.apache.tephra.DefaultTransactionExecutor in project cdap by caskdata.

the class DatasetInstanceHandlerTest method testCreateDelete.

@Test
public void testCreateDelete() throws Exception {
    try {
        deployModule("default-table", InMemoryTableModule.class);
        deployModule("default-core", CoreDatasetsModule.class);
        // cannot create instance with same name again
        Assert.assertEquals(HttpStatus.SC_OK, createInstance("myTable1", "table", DatasetProperties.EMPTY).getResponseCode());
        Assert.assertEquals(HttpStatus.SC_OK, createInstance("myTable2", "table", DatasetProperties.EMPTY).getResponseCode());
        Assert.assertEquals(2, getInstances().getResponseObject().size());
        // we want to verify that data is also gone, so we write smth to tables first
        final Table table1 = dsFramework.getDataset(NamespaceId.DEFAULT.dataset("myTable1"), DatasetDefinition.NO_ARGUMENTS, null);
        final Table table2 = dsFramework.getDataset(NamespaceId.DEFAULT.dataset("myTable2"), DatasetDefinition.NO_ARGUMENTS, null);
        Assert.assertNotNull(table1);
        Assert.assertNotNull(table2);
        TransactionExecutor txExecutor = new DefaultTransactionExecutor(new InMemoryTxSystemClient(txManager), ImmutableList.of((TransactionAware) table1, (TransactionAware) table2));
        txExecutor.execute(new TransactionExecutor.Subroutine() {

            @Override
            public void apply() throws Exception {
                table1.put(new Put("key1", "col1", "val1"));
                table2.put(new Put("key2", "col2", "val2"));
            }
        });
        // verify that we can read the data
        txExecutor.execute(new TransactionExecutor.Subroutine() {

            @Override
            public void apply() throws Exception {
                Assert.assertEquals("val1", table1.get(new Get("key1", "col1")).getString("col1"));
                Assert.assertEquals("val2", table2.get(new Get("key2", "col2")).getString("col2"));
            }
        });
        // delete table, check that it is deleted, create again and verify that it is empty
        Assert.assertEquals(HttpStatus.SC_OK, deleteInstance("myTable1").getResponseCode());
        ObjectResponse<List<DatasetSpecificationSummary>> instances = getInstances();
        Assert.assertEquals(1, instances.getResponseObject().size());
        Assert.assertEquals("myTable2", instances.getResponseObject().get(0).getName());
        Assert.assertEquals(HttpStatus.SC_OK, createInstance("myTable1", "table", DatasetProperties.EMPTY).getResponseCode());
        Assert.assertEquals(2, getInstances().getResponseObject().size());
        // verify that table1 is empty. Note: it is ok for test purpose to re-use the table clients
        txExecutor.execute(new TransactionExecutor.Subroutine() {

            @Override
            public void apply() throws Exception {
                Assert.assertTrue(table1.get(new Get("key1", "col1")).isEmpty());
                Assert.assertEquals("val2", table2.get(new Get("key2", "col2")).getString("col2"));
                // writing smth to table1 for subsequent test
                table1.put(new Put("key3", "col3", "val3"));
            }
        });
        // delete all tables, check that they deleted, create again and verify that they are empty
        deleteInstances();
        Assert.assertEquals(0, getInstances().getResponseObject().size());
        Assert.assertEquals(HttpStatus.SC_OK, createInstance("myTable1", "table", DatasetProperties.EMPTY).getResponseCode());
        Assert.assertEquals(HttpStatus.SC_OK, createInstance("myTable2", "table", DatasetProperties.EMPTY).getResponseCode());
        Assert.assertEquals(2, getInstances().getResponseObject().size());
        // verify that tables are empty. Note: it is ok for test purpose to re-use the table clients
        txExecutor.execute(new TransactionExecutor.Subroutine() {

            @Override
            public void apply() throws Exception {
                Assert.assertTrue(table1.get(new Get("key3", "col3")).isEmpty());
                Assert.assertTrue(table2.get(new Get("key2", "col2")).isEmpty());
            }
        });
    } finally {
        // cleanup
        deleteInstances();
        Assert.assertEquals(HttpStatus.SC_OK, deleteModules().getResponseCode());
    }
}
Also used : Table(co.cask.cdap.api.dataset.table.Table) TransactionAware(org.apache.tephra.TransactionAware) Get(co.cask.cdap.api.dataset.table.Get) DefaultTransactionExecutor(org.apache.tephra.DefaultTransactionExecutor) TransactionExecutor(org.apache.tephra.TransactionExecutor) DefaultTransactionExecutor(org.apache.tephra.DefaultTransactionExecutor) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) InMemoryTxSystemClient(org.apache.tephra.inmemory.InMemoryTxSystemClient) IOException(java.io.IOException) Put(co.cask.cdap.api.dataset.table.Put) Test(org.junit.Test)

Aggregations

DefaultTransactionExecutor (org.apache.tephra.DefaultTransactionExecutor)9 TransactionExecutor (org.apache.tephra.TransactionExecutor)9 IOException (java.io.IOException)6 Test (org.junit.Test)6 Table (co.cask.cdap.api.dataset.table.Table)5 TransactionAware (org.apache.tephra.TransactionAware)5 DatasetAdmin (co.cask.cdap.api.dataset.DatasetAdmin)3 DatasetManagementException (co.cask.cdap.api.dataset.DatasetManagementException)3 InstanceConflictException (co.cask.cdap.api.dataset.InstanceConflictException)3 Get (co.cask.cdap.api.dataset.table.Get)3 Put (co.cask.cdap.api.dataset.table.Put)3 MinimalTxSystemClient (org.apache.tephra.inmemory.MinimalTxSystemClient)3 LineageWriterDatasetFramework (co.cask.cdap.data2.metadata.writer.LineageWriterDatasetFramework)2 NamespaceId (co.cask.cdap.proto.id.NamespaceId)2 TransactionSystemClient (org.apache.tephra.TransactionSystemClient)2 DataSetException (co.cask.cdap.api.dataset.DataSetException)1 DatasetProperties (co.cask.cdap.api.dataset.DatasetProperties)1 CConfiguration (co.cask.cdap.common.conf.CConfiguration)1 ConfigModule (co.cask.cdap.common.guice.ConfigModule)1 DiscoveryRuntimeModule (co.cask.cdap.common.guice.DiscoveryRuntimeModule)1