use of com.couchbase.client.core.cnc.events.service.ServiceConnectInitiatedEvent in project couchbase-jvm-clients by couchbase.
the class PooledService method connect.
@Override
public synchronized void connect() {
if (state() == ServiceState.DISCONNECTED && !disconnected.get()) {
serviceContext.environment().eventBus().publish(new ServiceConnectInitiatedEvent(serviceContext, serviceConfig.minEndpoints()));
for (int i = 0; i < serviceConfig.minEndpoints(); i++) {
Endpoint endpoint = createEndpoint();
endpointStates.register(endpoint, endpoint);
endpoint.connect();
endpoints.add(endpoint);
}
}
}
use of com.couchbase.client.core.cnc.events.service.ServiceConnectInitiatedEvent in project couchbase-jvm-clients by couchbase.
the class PooledServiceTest method tracksMinEndpointStateAfterConnect.
/**
* After a connect call, the minimum number of endpoints should be created
* and the overall state of the service should track their state.
*/
@Test
void tracksMinEndpointStateAfterConnect() {
int minEndpoints = 2;
Endpoint mock1 = mock(Endpoint.class);
when(mock1.state()).thenReturn(EndpointState.CONNECTING);
when(mock1.states()).thenReturn(DirectProcessor.create());
Endpoint mock2 = mock(Endpoint.class);
when(mock2.state()).thenReturn(EndpointState.CONNECTING);
when(mock2.states()).thenReturn(DirectProcessor.create());
final List<Endpoint> mocks = Arrays.asList(mock1, mock2);
final AtomicInteger invocation = new AtomicInteger();
MockedService service = new MockedService(new MockedServiceConfig(minEndpoints, 10), () -> mocks.get(invocation.getAndIncrement()));
service.connect();
assertEquals(minEndpoints, service.trackedEndpoints().size());
assertEquals(ServiceState.CONNECTING, service.state());
verify(mock1, times(1)).connect();
verify(mock2, times(1)).connect();
ServiceConnectInitiatedEvent event = (ServiceConnectInitiatedEvent) eventBus.publishedEvents().get(0);
assertEquals(2, event.minimumEndpoints());
assertEquals("Starting to connect service with 2 minimum endpoints", event.description());
}
Aggregations