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);
}
};
}
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);
}
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());
}
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();
}
});
}
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());
}
}
Aggregations