use of com.rabbitmq.stream.impl.Utils.ClientFactory in project rabbitmq-stream-java-client by rabbitmq.
the class ProducersCoordinatorTest method shouldGetExactNodeImmediatelyWithAdvertisedHostNameClientFactoryAndExactNodeOnFirstTime.
@Test
void shouldGetExactNodeImmediatelyWithAdvertisedHostNameClientFactoryAndExactNodeOnFirstTime() {
ClientFactory cf = context -> Utils.connectToAdvertisedNodeClientFactory(context.key(), clientFactory, Duration.ofMillis(1)).client(context);
ProducersCoordinator c = new ProducersCoordinator(environment, ProducersCoordinator.MAX_PRODUCERS_PER_CLIENT, ProducersCoordinator.MAX_TRACKING_CONSUMERS_PER_CLIENT, type -> "producer-connection", cf);
when(locator.metadata("stream")).thenReturn(metadata(leader(), replicas()));
when(clientFactory.client(any())).thenReturn(client);
when(client.serverAdvertisedHost()).thenReturn(leader().getHost());
when(client.serverAdvertisedPort()).thenReturn(leader().getPort());
Runnable cleanTask = c.registerProducer(producer, null, "stream");
verify(clientFactory, times(1)).client(any());
verify(producer, times(1)).setClient(client);
cleanTask.run();
}
use of com.rabbitmq.stream.impl.Utils.ClientFactory in project rabbitmq-stream-java-client by rabbitmq.
the class ProducersCoordinatorTest method shouldRetryUntilGettingExactNodeWithAdvertisedHostNameClientFactoryAndNotExactNodeOnFirstTime.
@Test
void shouldRetryUntilGettingExactNodeWithAdvertisedHostNameClientFactoryAndNotExactNodeOnFirstTime() {
ClientFactory cf = context -> Utils.connectToAdvertisedNodeClientFactory(context.key(), clientFactory, Duration.ofMillis(1)).client(context);
ProducersCoordinator c = new ProducersCoordinator(environment, ProducersCoordinator.MAX_PRODUCERS_PER_CLIENT, ProducersCoordinator.MAX_TRACKING_CONSUMERS_PER_CLIENT, type -> "producer-connection", cf);
when(locator.metadata("stream")).thenReturn(metadata(leader(), replicas()));
when(clientFactory.client(any())).thenReturn(client);
when(client.serverAdvertisedHost()).thenReturn("foo").thenReturn(leader().getHost());
when(client.serverAdvertisedPort()).thenReturn(42).thenReturn(leader().getPort());
Runnable cleanTask = c.registerProducer(producer, null, "stream");
verify(clientFactory, times(2)).client(any());
verify(producer, times(1)).setClient(client);
cleanTask.run();
}
use of com.rabbitmq.stream.impl.Utils.ClientFactory 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