Search in sources :

Example 1 with ReadWriteUpdateTable

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);
}
Also used : ReadWriteUpdateTable(org.apache.samza.table.ReadWriteUpdateTable) Test(org.junit.Test)

Example 2 with ReadWriteUpdateTable

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);
}
Also used : ReadWriteUpdateTable(org.apache.samza.table.ReadWriteUpdateTable) Test(org.junit.Test)

Example 3 with ReadWriteUpdateTable

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);
}
Also used : ReadWriteUpdateTable(org.apache.samza.table.ReadWriteUpdateTable) Test(org.junit.Test)

Example 4 with ReadWriteUpdateTable

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;
}
Also used : ReadWriteUpdateTable(org.apache.samza.table.ReadWriteUpdateTable)

Example 5 with ReadWriteUpdateTable

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;
}
Also used : ReadWriteUpdateTable(org.apache.samza.table.ReadWriteUpdateTable) JavaTableConfig(org.apache.samza.config.JavaTableConfig)

Aggregations

ReadWriteUpdateTable (org.apache.samza.table.ReadWriteUpdateTable)16 Test (org.junit.Test)11 Context (org.apache.samza.context.Context)3 MockContext (org.apache.samza.context.MockContext)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 JavaTableConfig (org.apache.samza.config.JavaTableConfig)2 KV (org.apache.samza.operators.KV)2 StreamTableJoinOperatorSpec (org.apache.samza.operators.spec.StreamTableJoinOperatorSpec)2 MessageCollector (org.apache.samza.task.MessageCollector)2 TaskCoordinator (org.apache.samza.task.TaskCoordinator)2 Matchers.anyString (org.mockito.Matchers.anyString)2 Preconditions (com.google.common.base.Preconditions)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors (java.util.concurrent.Executors)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 SamzaException (org.apache.samza.SamzaException)1