@Test(expected = ExecutionException.class) public void testDeleteAsyncError() throws Exception { doTestDelete(false, true); }
@Test public void testDeleteAll() throws Exception { doTestDeleteAll(true, false); }
@Test public void testGet() throws Exception { doTestGet(true, false, false); }
public TableMetricsUtil getMetricsUtil(String tableId) { Table table = mock(Table.class); Context context = TestRemoteTable.getMockContext(); return new TableMetricsUtil(context, table, tableId); }
private <K, V, T extends RemoteTable<K, V>> T getTable(String tableId, TableReadFunction<K, V> readFn, TableWriteFunction<K, V> writeFn, boolean retry) { return getTable(tableId, readFn, writeFn, null, retry); }
@Test public void testPut() throws Exception { doTestPut(true, false, false, false); }
@Test public void testPutAllAsyncHasDelete() throws Exception { doTestPutAll(false, false, true); }
@Test public void testGetAll() throws Exception { doTestGetAll(true, false, false); }
private <K, V, T extends RemoteTable<K, V>> T getTable(String tableId, TableReadFunction<K, V> readFn, TableWriteFunction<K, V> writeFn, ExecutorService cbExecutor, boolean retry) { TableRateLimiter<K, V> readRateLimiter = mock(TableRateLimiter.class); TableRateLimiter<K, V> writeRateLimiter = mock(TableRateLimiter.class); TableRetryPolicy readPolicy = retry ? new TableRetryPolicy() : null; TableRetryPolicy writePolicy = retry ? new TableRetryPolicy() : null; ExecutorService rateLimitingExecutor = Executors.newSingleThreadExecutor(); ScheduledExecutorService retryExecutor = Executors.newSingleThreadScheduledExecutor(); RemoteTable<K, V> table = new RemoteTable(tableId, readFn, writeFn, readRateLimiter, writeRateLimiter, rateLimitingExecutor, readPolicy, writePolicy, retryExecutor, cbExecutor); table.init(getMockContext()); return (T) table; }
@Test public void testFlush() { TableWriteFunction<String, String> writeFn = mock(TableWriteFunction.class); RemoteTable<String, String> table = getTable("testFlush", mock(TableReadFunction.class), writeFn, false); table.flush(); verify(writeFn, times(1)).flush(); }
@Test public void testPutAsyncErrorRetried() throws Exception { doTestPut(false, true, false, true); }
@Test public void testPutAll() throws Exception { doTestPutAll(true, false, false); }
@Test(expected = ExecutionException.class) public void testGetAllAsyncError() throws Exception { doTestGetAll(false, true, false); }
@Test public void testFlushAndClose() { TableRateLimiter readRateLimiter = mock(TableRateLimiter.class); TableRateLimiter writeRateLimiter = mock(TableRateLimiter.class); TableReadFunction<String, String> readFn = mock(TableReadFunction.class); TableWriteFunction<String, String> writeFn = mock(TableWriteFunction.class); AsyncReadWriteTable delegate = new AsyncRemoteTable(readFn, writeFn); AsyncRateLimitedTable table = new AsyncRateLimitedTable("t1", delegate, readRateLimiter, 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(); }
@Test public void testGetWithCallbackExecutor() throws Exception { TableReadFunction<String, String> readFn = mock(TableReadFunction.class); // Sync is backed by async so needs to mock the async method doReturn(CompletableFuture.completedFuture("bar")).when(readFn).getAsync(anyString()); RemoteTable<String, String> table = getTable("testGetWithCallbackExecutor", readFn, null, Executors.newSingleThreadExecutor(), false); Thread testThread = Thread.currentThread(); table.getAsync("foo").thenAccept(result -> { Assert.assertEquals("bar", result); // Must be executed on the executor thread Assert.assertNotSame(testThread, Thread.currentThread()); }); } }
@Test public void testPutDelete() throws Exception { doTestPut(true, false, true, false); }
@Test(expected = ExecutionException.class) public void testPutAllAsyncError() throws Exception { doTestPutAll(false, true, false); }
@Test public void testGetAllAsync() throws Exception { doTestGetAll(false, false, false); }
@Test public void testGetAsync() throws Exception { doTestGet(false, false, false); }
@Test public void testDeleteAsync() throws Exception { doTestDelete(false, false); }