use of org.apache.samza.table.ReadWriteUpdateTable in project samza by apache.
the class TestLocalTableWrite method testFlush.
@Test
public void testFlush() {
ReadWriteUpdateTable table = createTable(false);
table.flush();
table.flush();
// Note: store.flush() is NOT called here
verify(kvStore, times(0)).flush();
Assert.assertEquals(2, numFlushes.getCount());
Assert.assertTrue(flushNs.getSnapshot().getAverage() > 0);
Assert.assertEquals(0, putNs.getSnapshot().getAverage(), 0.001);
Assert.assertEquals(0, putAllNs.getSnapshot().getAverage(), 0.001);
Assert.assertEquals(0, deleteNs.getSnapshot().getAverage(), 0.001);
Assert.assertEquals(0, deleteAllNs.getSnapshot().getAverage(), 0.001);
Assert.assertEquals(0, numPuts.getCount());
Assert.assertEquals(0, numPutAlls.getCount());
Assert.assertEquals(0, numDeletes.getCount());
Assert.assertEquals(0, numDeleteAlls.getCount());
Assert.assertEquals(0, putCallbackNs.getSnapshot().getAverage(), 0.001);
Assert.assertEquals(0, deleteCallbackNs.getSnapshot().getAverage(), 0.001);
}
use of org.apache.samza.table.ReadWriteUpdateTable in project samza by apache.
the class TestLocalTableWrite method testPutAll.
@Test
public void testPutAll() throws Exception {
ReadWriteUpdateTable table = createTable(false);
List<Entry> entries = Arrays.asList(new Entry("k1", "v1"), new Entry("k2", null));
table.putAll(entries);
table.putAllAsync(entries).get();
verify(kvStore, times(2)).putAll(any());
verify(kvStore, times(2)).deleteAll(any());
Assert.assertEquals(2, numPutAlls.getCount());
Assert.assertEquals(2, numDeleteAlls.getCount());
Assert.assertTrue(putAllNs.getSnapshot().getAverage() > 0);
Assert.assertTrue(deleteAllNs.getSnapshot().getAverage() > 0);
Assert.assertEquals(0, putNs.getSnapshot().getAverage(), 0.001);
Assert.assertEquals(0, deleteNs.getSnapshot().getAverage(), 0.001);
Assert.assertEquals(0, flushNs.getSnapshot().getAverage(), 0.001);
Assert.assertEquals(0, numPuts.getCount());
Assert.assertEquals(0, numDeletes.getCount());
Assert.assertEquals(0, numFlushes.getCount());
Assert.assertEquals(0, putCallbackNs.getSnapshot().getAverage(), 0.001);
Assert.assertEquals(0, deleteCallbackNs.getSnapshot().getAverage(), 0.001);
}
use of org.apache.samza.table.ReadWriteUpdateTable in project samza by apache.
the class TestLocalTableWrite method testTimerDisabled.
@Test
public void testTimerDisabled() throws Exception {
ReadWriteUpdateTable table = createTable(true);
table.put("", "");
table.putAsync("", "").get();
table.putAll(Collections.emptyList());
table.putAllAsync(Collections.emptyList()).get();
table.delete("");
table.deleteAsync("").get();
table.deleteAll(Collections.emptyList());
table.deleteAllAsync(Collections.emptyList()).get();
table.flush();
Assert.assertEquals(1, numFlushes.getCount());
Assert.assertEquals(2, numPuts.getCount());
Assert.assertEquals(0, numPutAlls.getCount());
Assert.assertEquals(2, numDeletes.getCount());
Assert.assertEquals(2, numDeleteAlls.getCount());
Assert.assertEquals(0, flushNs.getSnapshot().getAverage(), 0.001);
Assert.assertEquals(0, putNs.getSnapshot().getAverage(), 0.001);
Assert.assertEquals(0, putAllNs.getSnapshot().getAverage(), 0.001);
Assert.assertEquals(0, deleteNs.getSnapshot().getAverage(), 0.001);
Assert.assertEquals(0, deleteAllNs.getSnapshot().getAverage(), 0.001);
Assert.assertEquals(0, putCallbackNs.getSnapshot().getAverage(), 0.001);
Assert.assertEquals(0, deleteCallbackNs.getSnapshot().getAverage(), 0.001);
}
use of org.apache.samza.table.ReadWriteUpdateTable in project samza by apache.
the class LocalTableProvider method getTable.
@Override
public ReadWriteUpdateTable getTable() {
Preconditions.checkNotNull(context, String.format("Table %s not initialized", tableId));
Preconditions.checkNotNull(kvStore, "Store not initialized for table " + tableId);
@SuppressWarnings("unchecked") ReadWriteUpdateTable table = new LocalTable(tableId, kvStore);
table.init(this.context);
return table;
}
use of org.apache.samza.table.ReadWriteUpdateTable in project samza by apache.
the class CachingTableProvider method getTable.
@Override
public ReadWriteUpdateTable getTable() {
Preconditions.checkNotNull(context, String.format("Table %s not initialized", tableId));
JavaTableConfig tableConfig = new JavaTableConfig(context.getJobContext().getConfig());
String realTableId = tableConfig.getForTable(tableId, CachingTableDescriptor.REAL_TABLE_ID);
ReadWriteUpdateTable table = this.context.getTaskContext().getUpdatableTable(realTableId);
String cacheTableId = tableConfig.getForTable(tableId, CachingTableDescriptor.CACHE_TABLE_ID);
ReadWriteUpdateTable cache;
if (cacheTableId != null) {
cache = this.context.getTaskContext().getUpdatableTable(cacheTableId);
} else {
cache = createDefaultCacheTable(realTableId, tableConfig);
defaultCaches.add(cache);
}
boolean isWriteAround = Boolean.parseBoolean(tableConfig.getForTable(tableId, CachingTableDescriptor.WRITE_AROUND));
CachingTable cachingTable = new CachingTable(tableId, table, cache, isWriteAround);
cachingTable.init(this.context);
return cachingTable;
}
Aggregations