Search in sources :

Example 91 with TransactionAware

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

the class UnitTestManager method getDataset.

@Override
public <T> DataSetManager<T> getDataset(DatasetId datasetInstanceId) throws Exception {
    @SuppressWarnings("unchecked") final T dataSet = datasetFramework.getDataset(datasetInstanceId, new HashMap<String, String>(), null);
    try {
        final TransactionContext txContext;
        // not every dataset is TransactionAware. FileSets for example, are not transactional.
        if (dataSet instanceof TransactionAware) {
            TransactionAware txAwareDataset = (TransactionAware) dataSet;
            txContext = new TransactionContext(txSystemClient, Lists.newArrayList(txAwareDataset));
            txContext.start();
        } else {
            txContext = null;
        }
        return new UnitTestDatasetManager<>(dataSet, txContext);
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : TransactionContext(org.apache.tephra.TransactionContext) TransactionAware(org.apache.tephra.TransactionAware) TransactionFailureException(org.apache.tephra.TransactionFailureException) IOException(java.io.IOException)

Aggregations

TransactionAware (org.apache.tephra.TransactionAware)91 Test (org.junit.Test)64 TransactionExecutor (org.apache.tephra.TransactionExecutor)47 Table (co.cask.cdap.api.dataset.table.Table)37 Transaction (org.apache.tephra.Transaction)30 IOException (java.io.IOException)27 DatasetAdmin (co.cask.cdap.api.dataset.DatasetAdmin)22 PartitionedFileSet (co.cask.cdap.api.dataset.lib.PartitionedFileSet)22 HBaseTable (co.cask.cdap.data2.dataset2.lib.table.hbase.HBaseTable)21 PartitionKey (co.cask.cdap.api.dataset.lib.PartitionKey)17 DataSetException (co.cask.cdap.api.dataset.DataSetException)16 TransactionFailureException (org.apache.tephra.TransactionFailureException)15 List (java.util.List)13 ArrayList (java.util.ArrayList)11 HashSet (java.util.HashSet)11 DatasetManagementException (co.cask.cdap.api.dataset.DatasetManagementException)10 PartitionNotFoundException (co.cask.cdap.api.dataset.PartitionNotFoundException)10 TimePartitionedFileSet (co.cask.cdap.api.dataset.lib.TimePartitionedFileSet)10 ConcurrentPartitionConsumer (co.cask.cdap.api.dataset.lib.partitioned.ConcurrentPartitionConsumer)10 PartitionConsumer (co.cask.cdap.api.dataset.lib.partitioned.PartitionConsumer)10