Search in sources :

Example 11 with AsyncRemoteTable

use of org.apache.samza.table.remote.AsyncRemoteTable in project samza by apache.

the class TestAsyncRetriableTable method testGetWithPermFailureOnTimeout.

@Test
public void testGetWithPermFailureOnTimeout() {
    TableRetryPolicy policy = new TableRetryPolicy();
    policy.withFixedBackoff(Duration.ofMillis(5));
    policy.withStopAfterDelay(Duration.ofMillis(100));
    TableReadFunction<String, String> readFn = mock(TableReadFunction.class);
    doReturn(true).when(readFn).isRetriable(any());
    CompletableFuture<String> future = new CompletableFuture();
    future.completeExceptionally(new RuntimeException("test exception"));
    doReturn(future).when(readFn).getAsync(anyString());
    AsyncReadWriteUpdateTable delegate = new AsyncRemoteTable(readFn, null);
    AsyncRetriableTable table = new AsyncRetriableTable("t1", delegate, policy, null, schedExec, readFn, null);
    table.init(TestRemoteTable.getMockContext());
    try {
        table.getAsync("foo").join();
        fail();
    } catch (Throwable t) {
    }
    verify(readFn, atLeast(3)).getAsync(any());
    assertTrue(table.readRetryMetrics.retryCount.getCount() >= 3);
    assertEquals(0, table.readRetryMetrics.successCount.getCount());
    assertEquals(1, table.readRetryMetrics.permFailureCount.getCount());
    assertTrue(table.readRetryMetrics.retryTimer.getSnapshot().getMax() > 0);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) AsyncRemoteTable(org.apache.samza.table.remote.AsyncRemoteTable) AsyncReadWriteUpdateTable(org.apache.samza.table.AsyncReadWriteUpdateTable) Test(org.junit.Test)

Example 12 with AsyncRemoteTable

use of org.apache.samza.table.remote.AsyncRemoteTable in project samza by apache.

the class TestAsyncRetriableTable method testFlushAndClose.

@Test
public void testFlushAndClose() {
    TableRetryPolicy policy = new TableRetryPolicy();
    policy.withFixedBackoff(Duration.ofMillis(100));
    TableReadFunction readFn = mock(TableReadFunction.class);
    TableWriteFunction writeFn = mock(TableWriteFunction.class);
    AsyncReadWriteUpdateTable delegate = new AsyncRemoteTable(readFn, writeFn);
    AsyncRetriableTable table = new AsyncRetriableTable("t1", delegate, null, policy, schedExec, readFn, writeFn);
    table.flush();
    verify(writeFn, times(1)).flush();
    table.close();
    verify(readFn, times(1)).close();
    verify(writeFn, times(1)).close();
}
Also used : TableReadFunction(org.apache.samza.table.remote.TableReadFunction) AsyncRemoteTable(org.apache.samza.table.remote.AsyncRemoteTable) AsyncReadWriteUpdateTable(org.apache.samza.table.AsyncReadWriteUpdateTable) TableWriteFunction(org.apache.samza.table.remote.TableWriteFunction) Test(org.junit.Test)

Example 13 with AsyncRemoteTable

use of org.apache.samza.table.remote.AsyncRemoteTable in project samza by apache.

the class TestAsyncRateLimitedTable method testFlushAndClose.

@Test
public void testFlushAndClose() {
    TableRateLimiter readRateLimiter = mock(TableRateLimiter.class);
    TableRateLimiter writeRateLimiter = mock(TableRateLimiter.class);
    TableReadFunction<String, String> readFn = mock(TableReadFunction.class);
    TableWriteFunction<String, String, String> writeFn = mock(TableWriteFunction.class);
    AsyncReadWriteUpdateTable delegate = new AsyncRemoteTable(readFn, writeFn);
    AsyncRateLimitedTable table = new AsyncRateLimitedTable("t1", delegate, readRateLimiter, writeRateLimiter, writeRateLimiter, schedExec);
    table.init(TestRemoteTable.getMockContext());
    table.flush();
    verify(writeFn, times(1)).flush();
    table.close();
    verify(readFn, times(1)).close();
    verify(writeFn, times(1)).close();
}
Also used : TableRateLimiter(org.apache.samza.table.remote.TableRateLimiter) AsyncRemoteTable(org.apache.samza.table.remote.AsyncRemoteTable) AsyncReadWriteUpdateTable(org.apache.samza.table.AsyncReadWriteUpdateTable) Test(org.junit.Test)

Example 14 with AsyncRemoteTable

use of org.apache.samza.table.remote.AsyncRemoteTable in project samza by apache.

the class TestAsyncRateLimitedTable method prepare.

@Before
public void prepare() {
    // Read part
    readRateLimiter = mock(TableRateLimiter.class);
    readFn = mock(TableReadFunction.class);
    doReturn(CompletableFuture.completedFuture("bar")).when(readFn).getAsync(any());
    doReturn(CompletableFuture.completedFuture("bar")).when(readFn).getAsync(any(), any());
    readMap.put("foo", "bar");
    doReturn(CompletableFuture.completedFuture(readMap)).when(readFn).getAllAsync(any());
    doReturn(CompletableFuture.completedFuture(readMap)).when(readFn).getAllAsync(any(), any());
    doReturn(CompletableFuture.completedFuture(5)).when(readFn).readAsync(anyInt(), any());
    AsyncReadWriteUpdateTable delegate = new AsyncRemoteTable(readFn, null);
    readTable = new AsyncRateLimitedTable("t1", delegate, readRateLimiter, null, null, schedExec);
    readTable.init(TestRemoteTable.getMockContext());
    // Write part
    writeRateLimiter = mock(TableRateLimiter.class);
    writeFn = mock(TableWriteFunction.class);
    doReturn(CompletableFuture.completedFuture(null)).when(writeFn).putAsync(any(), any());
    doReturn(CompletableFuture.completedFuture(null)).when(writeFn).putAsync(any(), any(), any());
    doReturn(CompletableFuture.completedFuture(null)).when(writeFn).putAllAsync(any());
    doReturn(CompletableFuture.completedFuture(null)).when(writeFn).putAllAsync(any(), any());
    doReturn(CompletableFuture.completedFuture(null)).when(writeFn).deleteAsync(any());
    doReturn(CompletableFuture.completedFuture(null)).when(writeFn).deleteAsync(any(), any());
    doReturn(CompletableFuture.completedFuture(null)).when(writeFn).deleteAllAsync(any());
    doReturn(CompletableFuture.completedFuture(null)).when(writeFn).deleteAllAsync(any(), any());
    doReturn(CompletableFuture.completedFuture(5)).when(writeFn).writeAsync(anyInt(), any());
    // update part
    doReturn(CompletableFuture.completedFuture(null)).when(writeFn).updateAsync(any(), any());
    doReturn(CompletableFuture.completedFuture(null)).when(writeFn).updateAllAsync(any());
    delegate = new AsyncRemoteTable(readFn, writeFn);
    writeTable = new AsyncRateLimitedTable("t1", delegate, readRateLimiter, writeRateLimiter, writeRateLimiter, schedExec);
    writeTable.init(TestRemoteTable.getMockContext());
}
Also used : TableRateLimiter(org.apache.samza.table.remote.TableRateLimiter) TableReadFunction(org.apache.samza.table.remote.TableReadFunction) AsyncRemoteTable(org.apache.samza.table.remote.AsyncRemoteTable) AsyncReadWriteUpdateTable(org.apache.samza.table.AsyncReadWriteUpdateTable) TableWriteFunction(org.apache.samza.table.remote.TableWriteFunction) Before(org.junit.Before)

Example 15 with AsyncRemoteTable

use of org.apache.samza.table.remote.AsyncRemoteTable in project samza by apache.

the class TestAsyncRetriableTable method testPutWithoutRetry.

@Test
public void testPutWithoutRetry() {
    TableRetryPolicy policy = new TableRetryPolicy();
    policy.withFixedBackoff(Duration.ofMillis(100));
    TableReadFunction readFn = mock(TableReadFunction.class);
    TableWriteFunction writeFn = mock(TableWriteFunction.class);
    doReturn(true).when(writeFn).isRetriable(any());
    doReturn(CompletableFuture.completedFuture(null)).when(writeFn).putAsync(any(), any());
    doReturn(CompletableFuture.completedFuture(null)).when(writeFn).putAllAsync(any());
    doReturn(CompletableFuture.completedFuture(null)).when(writeFn).deleteAsync(any());
    doReturn(CompletableFuture.completedFuture(null)).when(writeFn).deleteAllAsync(any());
    AsyncReadWriteUpdateTable delegate = new AsyncRemoteTable(readFn, writeFn);
    AsyncRetriableTable table = new AsyncRetriableTable("t1", delegate, null, policy, schedExec, readFn, writeFn);
    int times = 0;
    table.init(TestRemoteTable.getMockContext());
    verify(readFn, times(0)).init(any(), any());
    verify(writeFn, times(0)).init(any(), any());
    table.putAsync("foo", "bar").join();
    verify(writeFn, times(1)).putAsync(any(), any());
    assertEquals(++times, table.writeRetryMetrics.successCount.getCount());
    table.putAllAsync(Arrays.asList(new Entry("1", "2"))).join();
    verify(writeFn, times(1)).putAllAsync(any());
    assertEquals(++times, table.writeRetryMetrics.successCount.getCount());
    table.deleteAsync("1").join();
    verify(writeFn, times(1)).deleteAsync(any());
    assertEquals(++times, table.writeRetryMetrics.successCount.getCount());
    table.deleteAllAsync(Arrays.asList("1", "2")).join();
    verify(writeFn, times(1)).deleteAllAsync(any());
    assertEquals(++times, table.writeRetryMetrics.successCount.getCount());
    assertEquals(0, table.writeRetryMetrics.retryCount.getCount());
    assertEquals(0, table.writeRetryMetrics.retryTimer.getSnapshot().getMax());
    assertEquals(0, table.writeRetryMetrics.permFailureCount.getCount());
    assertNull(table.readRetryMetrics);
}
Also used : TableReadFunction(org.apache.samza.table.remote.TableReadFunction) Entry(org.apache.samza.storage.kv.Entry) AsyncRemoteTable(org.apache.samza.table.remote.AsyncRemoteTable) AsyncReadWriteUpdateTable(org.apache.samza.table.AsyncReadWriteUpdateTable) TableWriteFunction(org.apache.samza.table.remote.TableWriteFunction) Test(org.junit.Test)

Aggregations

AsyncReadWriteUpdateTable (org.apache.samza.table.AsyncReadWriteUpdateTable)21 AsyncRemoteTable (org.apache.samza.table.remote.AsyncRemoteTable)21 Test (org.junit.Test)20 CompletableFuture (java.util.concurrent.CompletableFuture)12 TableReadFunction (org.apache.samza.table.remote.TableReadFunction)8 HashMap (java.util.HashMap)7 TableWriteFunction (org.apache.samza.table.remote.TableWriteFunction)6 Map (java.util.Map)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Entry (org.apache.samza.storage.kv.Entry)4 TableRateLimiter (org.apache.samza.table.remote.TableRateLimiter)3 ImmutableMap (com.google.common.collect.ImmutableMap)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 Config (org.apache.samza.config.Config)1 JavaTableConfig (org.apache.samza.config.JavaTableConfig)1 MapConfig (org.apache.samza.config.MapConfig)1 TaskName (org.apache.samza.container.TaskName)1 ContainerContext (org.apache.samza.context.ContainerContext)1 Context (org.apache.samza.context.Context)1 JobContext (org.apache.samza.context.JobContext)1