use of co.cask.cdap.api.dataset.DatasetAdmin in project cdap by caskdata.
the class TableTest method testBasicIncrementWriteWithTxSmall.
private void testBasicIncrementWriteWithTxSmall(boolean readless) throws Exception {
DatasetProperties props = TableProperties.builder().setReadlessIncrementSupport(readless).build();
DatasetAdmin admin = getTableAdmin(CONTEXT1, MY_TABLE, props);
admin.create();
Table myTable = getTable(CONTEXT1, MY_TABLE, props);
// start 1st tx
Transaction tx = txClient.startShort();
((TransactionAware) myTable).startTx(tx);
myTable.increment(R1, a(C1), la(-3L));
// we'll use this one to test that we can delete increment and increment again
myTable.increment(R2, a(C2), la(5L));
commitAndAssertSuccess(tx, (TransactionAware) myTable);
// start 2nd tx
tx = txClient.startShort();
((TransactionAware) myTable).startTx(tx);
Assert.assertArrayEquals(Bytes.toBytes(-3L), myTable.get(R1, C1));
myTable.increment(R1, a(C1), la(-3L));
Assert.assertArrayEquals(Bytes.toBytes(-6L), myTable.get(R1, C1));
Assert.assertArrayEquals(Bytes.toBytes(5L), myTable.get(R2, C2));
myTable.delete(R2, C2);
Assert.assertArrayEquals(null, myTable.get(R2, C2));
commitAndAssertSuccess(tx, (TransactionAware) myTable);
// start 3rd tx
tx = txClient.startShort();
((TransactionAware) myTable).startTx(tx);
Assert.assertArrayEquals(Bytes.toBytes(-6L), myTable.get(R1, C1));
Assert.assertArrayEquals(null, myTable.get(R2, C2));
myTable.increment(R2, a(C2), la(7L));
Assert.assertArrayEquals(Bytes.toBytes(7L), myTable.get(R2, C2));
commitAndAssertSuccess(tx, (TransactionAware) myTable);
// start 4rd tx
tx = txClient.startShort();
((TransactionAware) myTable).startTx(tx);
Assert.assertArrayEquals(Bytes.toBytes(7L), myTable.get(R2, C2));
commitAndAssertSuccess(tx, (TransactionAware) myTable);
admin.drop();
}
use of co.cask.cdap.api.dataset.DatasetAdmin in project cdap by caskdata.
the class TableTest method testReadOwnWrite.
@Test
public void testReadOwnWrite() throws Exception {
final String tableName = "readOwnWrite";
DatasetAdmin admin = getTableAdmin(CONTEXT1, tableName);
admin.create();
Table table = getTable(CONTEXT1, tableName);
Transaction tx = txClient.startShort();
try {
((TransactionAware) table).startTx(tx);
// Write some data, then flush it by calling commitTx.
table.put(new Put(R1, C1, V1));
((TransactionAware) table).commitTx();
// Try to read the previous write.
Assert.assertArrayEquals(V1, table.get(new Get(R1, C1)).get(C1));
} finally {
txClient.commit(tx);
}
// drop table
admin.drop();
}
use of co.cask.cdap.api.dataset.DatasetAdmin in project cdap by caskdata.
the class MetadataDatasetTest method after.
@After
public void after() throws Exception {
dataset = null;
DatasetAdmin admin = dsFrameworkUtil.getFramework().getAdmin(datasetInstance, null);
if (admin != null) {
admin.truncate();
}
}
use of co.cask.cdap.api.dataset.DatasetAdmin in project cdap by caskdata.
the class TableTest method testScanWithFuzzyRowFilter.
@Test
public void testScanWithFuzzyRowFilter() throws Exception {
DatasetAdmin admin = getTableAdmin(CONTEXT1, MY_TABLE);
admin.create();
try {
Transaction tx1 = txClient.startShort();
Table table = getTable(CONTEXT1, MY_TABLE);
((TransactionAware) table).startTx(tx1);
// write data
byte[] abc = { 'a', 'b', 'c' };
for (byte b1 : abc) {
for (byte b2 : abc) {
for (byte b3 : abc) {
for (byte b4 : abc) {
table.put(new Put(new byte[] { b1, b2, b3, b4 }).add(C1, V1));
}
}
}
}
// we should have 81 (3^4) rows now
Assert.assertEquals(81, countRows(table));
// check that filter works against data written in same tx
verifyScanWithFuzzyRowFilter(table);
// commit tx, start new and TableAssert.verify scan again against "persisted" data
Assert.assertTrue(txClient.canCommit(tx1, ((TransactionAware) table).getTxChanges()));
Assert.assertTrue(((TransactionAware) table).commitTx());
Assert.assertTrue(txClient.commit(tx1));
((TransactionAware) table).postTxCommit();
Transaction tx2 = txClient.startShort();
((TransactionAware) table).startTx(tx2);
verifyScanWithFuzzyRowFilter(table);
} finally {
admin.drop();
}
}
use of co.cask.cdap.api.dataset.DatasetAdmin in project cdap by caskdata.
the class TableTest method testScanAndDelete.
@Test
public void testScanAndDelete() throws Exception {
DatasetAdmin admin = getTableAdmin(CONTEXT1, MY_TABLE);
admin.create();
try {
//
Transaction tx1 = txClient.startShort();
Table myTable1 = getTable(CONTEXT1, MY_TABLE);
((TransactionAware) myTable1).startTx(tx1);
myTable1.put(Bytes.toBytes("1_09a"), a(C1), a(V1));
Assert.assertTrue(txClient.canCommit(tx1, ((TransactionAware) myTable1).getTxChanges()));
Assert.assertTrue(((TransactionAware) myTable1).commitTx());
Assert.assertTrue(txClient.commit(tx1));
//
Transaction tx2 = txClient.startShort();
((TransactionAware) myTable1).startTx(tx2);
myTable1.delete(Bytes.toBytes("1_09a"));
myTable1.put(Bytes.toBytes("1_08a"), a(C1), a(V1));
myTable1.put(Bytes.toBytes("1_09b"), a(C1), a(V1));
Assert.assertTrue(txClient.canCommit(tx2, ((TransactionAware) myTable1).getTxChanges()));
Assert.assertTrue(((TransactionAware) myTable1).commitTx());
Assert.assertTrue(txClient.commit(tx2));
//
Transaction tx3 = txClient.startShort();
((TransactionAware) myTable1).startTx(tx3);
TableAssert.assertScan(a(Bytes.toBytes("1_08a"), Bytes.toBytes("1_09b")), aa(a(C1, V1), a(C1, V1)), myTable1, new Scan(Bytes.toBytes("1_"), Bytes.toBytes("2_")));
myTable1.delete(Bytes.toBytes("1_08a"));
myTable1.put(Bytes.toBytes("1_07a"), a(C1), a(V1));
myTable1.delete(Bytes.toBytes("1_09b"));
myTable1.put(Bytes.toBytes("1_08b"), a(C1), a(V1));
myTable1.put(Bytes.toBytes("1_09c"), a(C1), a(V1));
Assert.assertTrue(txClient.canCommit(tx3, ((TransactionAware) myTable1).getTxChanges()));
Assert.assertTrue(((TransactionAware) myTable1).commitTx());
Assert.assertTrue(txClient.commit(tx3));
// Now, we will test scans
Transaction tx4 = txClient.startShort();
((TransactionAware) myTable1).startTx(tx4);
TableAssert.assertScan(a(Bytes.toBytes("1_07a"), Bytes.toBytes("1_08b"), Bytes.toBytes("1_09c")), aa(a(C1, V1), a(C1, V1), a(C1, V1)), myTable1, new Scan(Bytes.toBytes("1_"), Bytes.toBytes("2_")));
} finally {
admin.drop();
}
}
Aggregations