public MockMethodInvokerFactory(Supplier<ListenableFuture<Object>> resultsSupplier) { this.methodInvoker = new MockMethodInvoker(resultsSupplier); }
private static DriftMethodInvocation<?> createDriftMethodInvocation( RetryPolicy retryPolicy, TestingMethodInvocationStat stat, MockMethodInvoker invoker, AddressSelector<?> addressSelector, Ticker ticker) { return DriftMethodInvocation.createDriftMethodInvocation( invoker, METHOD_METADATA, ImmutableMap.of(), ImmutableList.of(), retryPolicy, addressSelector, Optional.empty(), stat, ticker); }
@Test(timeOut = 60000) public void testBasicRetriesToNoHosts() throws Exception { RetryPolicy retryPolicy = new RetryPolicy(new DriftClientConfig().setMaxRetries(10), new TestingExceptionClassifier()); TestingMethodInvocationStat stat = new TestingMethodInvocationStat(); AtomicInteger attempts = new AtomicInteger(); int expectedRetries = 3; DriftMethodInvocation<?> methodInvocation = createDriftMethodInvocation( retryPolicy, stat, new MockMethodInvoker(() -> { attempts.getAndIncrement(); return immediateFailedFuture(createClassifiedException(true, NORMAL)); }), new TestingAddressSelector(expectedRetries + 1), systemTicker()); try { methodInvocation.get(); fail("Expected exception"); } catch (ExecutionException e) { assertEquals(attempts.get(), expectedRetries + 1); assertClassifiedException(e.getCause(), new ExceptionClassification(Optional.of(true), NORMAL), expectedRetries); } stat.assertFailure(expectedRetries); }
TestingAddressSelector addressSelector = new TestingAddressSelector(expectedRetries); Set<Address> attemptedAddresses = newConcurrentHashSet(); MockMethodInvoker invoker = new MockMethodInvoker(request -> { attempts.getAndIncrement(); attemptedAddresses.add(request.getAddress());
retryPolicy, stat, new MockMethodInvoker(() -> { attempts.getAndIncrement(); return immediateFailedFuture(createClassifiedException(true, DOWN));
retryPolicy, stat, new MockMethodInvoker(() -> { attempts.getAndIncrement(); return immediateFailedFuture(createClassifiedException(true, NORMAL));
MockMethodInvoker invoker = new MockMethodInvoker(request -> { int tries = attempts.getAndIncrement(); if (tries < expectedInvocationAttempts) {
private static void testBasicRetriesToSuccess(int expectedRetries, boolean wrapWithApplicationException) throws Exception { RetryPolicy retryPolicy = new RetryPolicy( new DriftClientConfig() .setMaxRetries(expectedRetries + 10) .setMinBackoffDelay(new Duration(1, SECONDS)) .setMaxBackoffDelay(new Duration(1, DAYS)) .setBackoffScaleFactor(2.0), new TestingExceptionClassifier()); TestingMethodInvocationStat stat = new TestingMethodInvocationStat(); AtomicInteger attempts = new AtomicInteger(); MockMethodInvoker invoker = new MockMethodInvoker(() -> { int currentAttempts = attempts.getAndIncrement(); if (currentAttempts < expectedRetries) { return immediateFailedFuture(createClassifiedException(true, NORMAL, wrapWithApplicationException)); } return immediateFuture(SUCCESS); }); DriftMethodInvocation<?> methodInvocation = createDriftMethodInvocation(retryPolicy, stat, invoker, new TestingAddressSelector(100), systemTicker()); assertEquals(methodInvocation.get(), SUCCESS); assertEquals(attempts.get(), expectedRetries + 1); stat.assertSuccess(expectedRetries); assertDelays(invoker, retryPolicy, expectedRetries); }
MockMethodInvoker invoker = new MockMethodInvoker( () -> { attempts.getAndIncrement();
MockMethodInvoker invoker = new MockMethodInvoker(() -> { int currentAttempts = attempts.getAndIncrement(); if (currentAttempts < expectedRetries) {