Search in sources :

Example 11 with ReadWriteUpdateTable

use of org.apache.samza.table.ReadWriteUpdateTable in project samza by apache.

the class TestLocalTableWrite method testDeleteAll.

@Test
public void testDeleteAll() throws Exception {
    ReadWriteUpdateTable table = createTable(false);
    table.deleteAll(Collections.emptyList());
    table.deleteAllAsync(Collections.emptyList()).get();
    verify(kvStore, times(2)).deleteAll(any());
    Assert.assertEquals(2, numDeleteAlls.getCount());
    Assert.assertTrue(deleteAllNs.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, flushNs.getSnapshot().getAverage(), 0.001);
    Assert.assertEquals(0, numPuts.getCount());
    Assert.assertEquals(0, numPutAlls.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 12 with ReadWriteUpdateTable

use of org.apache.samza.table.ReadWriteUpdateTable in project samza by apache.

the class TestLocalTableWrite method testPut.

@Test
public void testPut() throws Exception {
    ReadWriteUpdateTable table = createTable(false);
    table.put("k1", "v1");
    table.putAsync("k2", "v2").get();
    table.putAsync("k3", null).get();
    verify(kvStore, times(2)).put(any(), any());
    verify(kvStore, times(1)).delete(any());
    Assert.assertEquals(2, numPuts.getCount());
    Assert.assertEquals(1, numDeletes.getCount());
    Assert.assertTrue(putNs.getSnapshot().getAverage() > 0);
    Assert.assertTrue(deleteNs.getSnapshot().getAverage() > 0);
    Assert.assertEquals(0, putAllNs.getSnapshot().getAverage(), 0.001);
    Assert.assertEquals(0, deleteAllNs.getSnapshot().getAverage(), 0.001);
    Assert.assertEquals(0, flushNs.getSnapshot().getAverage(), 0.001);
    Assert.assertEquals(0, numPutAlls.getCount());
    Assert.assertEquals(0, numDeleteAlls.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 13 with ReadWriteUpdateTable

use of org.apache.samza.table.ReadWriteUpdateTable in project samza by apache.

the class TestLocalTableWrite method testDelete.

@Test
public void testDelete() throws Exception {
    ReadWriteUpdateTable table = createTable(false);
    table.delete("");
    table.deleteAsync("").get();
    verify(kvStore, times(2)).delete(any());
    Assert.assertEquals(2, numDeletes.getCount());
    Assert.assertTrue(deleteNs.getSnapshot().getAverage() > 0);
    Assert.assertEquals(0, putNs.getSnapshot().getAverage(), 0.001);
    Assert.assertEquals(0, putAllNs.getSnapshot().getAverage(), 0.001);
    Assert.assertEquals(0, deleteAllNs.getSnapshot().getAverage(), 0.001);
    Assert.assertEquals(0, flushNs.getSnapshot().getAverage(), 0.001);
    Assert.assertEquals(0, numPuts.getCount());
    Assert.assertEquals(0, numPutAlls.getCount());
    Assert.assertEquals(0, numDeleteAlls.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 14 with ReadWriteUpdateTable

use of org.apache.samza.table.ReadWriteUpdateTable in project samza by apache.

the class TestLocalTableRead method testGet.

@Test
public void testGet() throws Exception {
    ReadWriteUpdateTable table = createTable(false);
    Assert.assertEquals("v1", table.get("k1"));
    Assert.assertEquals("v2", table.getAsync("k2").get());
    Assert.assertNull(table.get("k3"));
    verify(kvStore, times(3)).get(any());
    Assert.assertEquals(3, numGets.getCount());
    Assert.assertEquals(1, numMissedLookups.getCount());
    Assert.assertTrue(getNs.getSnapshot().getAverage() > 0);
    Assert.assertEquals(0, numGetAlls.getCount());
    Assert.assertEquals(0, getAllNs.getSnapshot().getAverage(), 0.001);
    Assert.assertEquals(0, getCallbackNs.getSnapshot().getAverage(), 0.001);
}
Also used : ReadWriteUpdateTable(org.apache.samza.table.ReadWriteUpdateTable) Test(org.junit.Test)

Example 15 with ReadWriteUpdateTable

use of org.apache.samza.table.ReadWriteUpdateTable in project samza by apache.

the class TestLocalTableRead method testGetAll.

@Test
public void testGetAll() throws Exception {
    ReadWriteUpdateTable table = createTable(false);
    Assert.assertEquals(values, table.getAll(keys));
    Assert.assertEquals(values, table.getAllAsync(keys).get());
    verify(kvStore, times(2)).getAll(any());
    Assert.assertEquals(Collections.emptyMap(), table.getAll(Collections.emptyList()));
    Assert.assertEquals(2, numMissedLookups.getCount());
    Assert.assertEquals(3, numGetAlls.getCount());
    Assert.assertTrue(getAllNs.getSnapshot().getAverage() > 0);
    Assert.assertEquals(0, numGets.getCount());
    Assert.assertEquals(0, getNs.getSnapshot().getAverage(), 0.001);
    Assert.assertEquals(0, getCallbackNs.getSnapshot().getAverage(), 0.001);
}
Also used : ReadWriteUpdateTable(org.apache.samza.table.ReadWriteUpdateTable) Test(org.junit.Test)

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