use of com.rabbitmq.stream.impl.Utils.ExactNodeRetryClientFactory in project rabbitmq-stream-java-client by rabbitmq.
the class UtilsTest method exactNodeRetryClientFactoryShouldRetryUntilConditionOk.
@Test
@SuppressWarnings("unchecked")
void exactNodeRetryClientFactoryShouldRetryUntilConditionOk() {
Client client = mock(Client.class);
ClientFactory cf = mock(ClientFactory.class);
when(cf.client(any())).thenReturn(client);
Predicate<Client> condition = mock(Predicate.class);
when(condition.test(any())).thenReturn(false).thenReturn(false).thenReturn(true);
Client result = new ExactNodeRetryClientFactory(cf, condition, Duration.ofMillis(1)).client(ClientFactoryContext.fromParameters(new ClientParameters()));
assertThat(result).isEqualTo(client);
verify(cf, times(3)).client(any());
verify(client, times(2)).close();
}
use of com.rabbitmq.stream.impl.Utils.ExactNodeRetryClientFactory in project rabbitmq-stream-java-client by rabbitmq.
the class UtilsTest method exactNodeRetryClientFactoryShouldReturnImmediatelyIfConditionOk.
@Test
void exactNodeRetryClientFactoryShouldReturnImmediatelyIfConditionOk() {
Client client = mock(Client.class);
ClientFactory cf = mock(ClientFactory.class);
when(cf.client(any())).thenReturn(client);
Predicate<Client> condition = c -> true;
Client result = new ExactNodeRetryClientFactory(cf, condition, Duration.ofMillis(1)).client(ClientFactoryContext.fromParameters(new ClientParameters()));
assertThat(result).isEqualTo(client);
verify(cf, times(1)).client(any());
verify(client, never()).close();
}
Aggregations