ApiCommand extends HystrixCommand<T> implements CommandContext { public static <T> Builder<T> builder() { return new Builder<T>(); } ApiCommand(Builder<T> builder); String getCommandName(); Object getCommandAttribute(String key); void setCommandAttribute(String key, Object val); void removeCommandAttribute(String key); static Builder<T> builder(); public String correlationId; }
@Test(expected = IllegalArgumentException.class) public void testMissingUriProvider() { ApiCommand command = ApiCommand.builder() .withRemoteServiceCallback(new SuccessfulRemoteCallback()) .build(); }
@Test(expected = IllegalArgumentException.class) public void testMissingRemoteServiceCallback() { ApiCommand command = ApiCommand.builder() .withUriProvider(new ConstantUriProvider<>("")) .build(); }
@Test public void testUriProviderFailures() { ApiCommand command = ApiCommand.builder() .withUriProvider(new FlakyUriProvider(0.5)) .withRemoteServiceCallback(new SuccessfulRemoteCallback()) .withNumberOfRetries(5) .withBackoffPolicy(createOneSecondBackoffPolicy()) .withCommandTimeoutInMilliseconds(10000) .build(); Object result = command.execute(); assertNotNull(result); }
@Test public void testRemoteCallbackFailuresFailures() { ApiCommand command = ApiCommand.builder() .withUriProvider(new ConstantUriProvider<>("")) .withRemoteServiceCallback(new FlakyRemoteServiceCallback(0.5,true)) .withNumberOfRetries(5) .withBackoffPolicy(createOneSecondBackoffPolicy()) .withCommandTimeoutInMilliseconds(10000) .build(); Object result = command.execute(); assertNotNull(result); }