use of com.couchbase.client.core.service.ServiceContext in project couchbase-jvm-clients by couchbase.
the class BaseEndpointTest method beforeEach.
@BeforeEach
void beforeEach() {
eventLoopGroup = new NioEventLoopGroup(1);
eventBus = new SimpleEventBus(true, Collections.singletonList(EndpointStateChangedEvent.class));
environment = CoreEnvironment.builder().eventBus(eventBus).build();
CoreContext coreContext = new CoreContext(mock(Core.class), 1, environment, authenticator);
ctx = new ServiceContext(coreContext, LOCALHOST, 1234, ServiceType.KV, Optional.empty());
}
use of com.couchbase.client.core.service.ServiceContext in project couchbase-jvm-clients by couchbase.
the class BaseEndpointTest method disconnectDuringRetry.
/**
* Make sure that while we are retrying and a disconnect event comes along, we stop
* retrying and end up in the disconnected state right away.
*/
@Test
void disconnectDuringRetry() {
SimpleEventBus eventBus = new SimpleEventBus(true, Collections.singletonList(EndpointStateChangedEvent.class));
CoreEnvironment env = CoreEnvironment.builder().eventBus(eventBus).timeoutConfig(TimeoutConfig.connectTimeout(Duration.ofMillis(10))).build();
CoreContext coreContext = new CoreContext(mock(Core.class), 1, env, authenticator);
ServiceContext ctx = new ServiceContext(coreContext, LOCALHOST, 1234, ServiceType.KV, Optional.empty());
try {
final CompletableFuture<Channel> cf = new CompletableFuture<>();
InstrumentedEndpoint endpoint = InstrumentedEndpoint.create(eventLoopGroup, ctx, () -> Mono.fromFuture(cf));
endpoint.connect();
waitUntilCondition(() -> eventBus.publishedEvents().size() >= 3);
endpoint.disconnect();
waitUntilCondition(() -> endpoint.state() == EndpointState.DISCONNECTED);
waitUntilCondition(() -> eventBus.publishedEvents().size() >= 4);
int warn = 0;
int debug = 0;
for (Event event : eventBus.publishedEvents()) {
if (event.severity() == Event.Severity.WARN) {
warn++;
assertTrue(event instanceof EndpointConnectionFailedEvent);
} else if (event.severity() == Event.Severity.DEBUG) {
debug++;
assertTrue(event instanceof EndpointConnectionAbortedEvent);
} else {
throw new RuntimeException("Unexpected Event: " + event);
}
}
assertEquals(3, warn);
assertEquals(1, debug);
} finally {
environment.shutdown();
}
}
Aggregations