use of com.couchbase.client.core.cnc.SimpleEventBus in project couchbase-jvm-clients by couchbase.
the class MemcacheProtocolVerificationHandlerTest method shouldCloseOnInvalidResponses.
/**
* Verifies that invalid responses are not let through.
*
* @param inputHolder the bad input packets.
*/
@ParameterizedTest(name = "{0}")
@MethodSource
void shouldCloseOnInvalidResponses(final InputHolder inputHolder) {
SimpleEventBus eventBus = new SimpleEventBus(true);
CoreEnvironment env = mock(CoreEnvironment.class);
EndpointContext ctx = mock(EndpointContext.class);
when(ctx.environment()).thenReturn(env);
when(env.eventBus()).thenReturn(eventBus);
final EmbeddedChannel channel = new EmbeddedChannel(new MemcacheProtocolVerificationHandler(ctx));
try {
channel.writeInbound(inputHolder.input);
assertFalse(channel.isOpen());
InvalidPacketDetectedEvent event = (InvalidPacketDetectedEvent) eventBus.publishedEvents().get(0);
assertEquals(Event.Severity.ERROR, event.severity());
assertEquals(Event.Category.IO.path(), event.category());
assertTrue(event.description().contains("Invalid Packet detected:"));
} finally {
channel.finishAndReleaseAll();
}
}
use of com.couchbase.client.core.cnc.SimpleEventBus in project couchbase-jvm-clients by couchbase.
the class SaslListMechanismsHandlerTest method failConnectIfPromiseTimesOut.
/**
* This test makes sure that the timer fires if the connect future is not completed
* otherwise.
*/
@Test
void failConnectIfPromiseTimesOut() throws Exception {
channel = new EmbeddedChannel();
eventBus = new SimpleEventBus(true);
CoreEnvironment env = mock(CoreEnvironment.class);
TimeoutConfig timeoutConfig = mock(TimeoutConfig.class);
when(env.eventBus()).thenReturn(eventBus);
when(env.timeoutConfig()).thenReturn(timeoutConfig);
when(timeoutConfig.connectTimeout()).thenReturn(Duration.ofMillis(100));
CoreContext coreContext = new CoreContext(mock(Core.class), 1, env, mock(Authenticator.class));
EndpointContext endpointContext = new EndpointContext(coreContext, new HostAndPort("127.0.0.1", 1234), null, ServiceType.KV, Optional.empty(), Optional.empty(), Optional.empty());
SaslListMechanismsHandler handler = new SaslListMechanismsHandler(endpointContext);
channel.pipeline().addLast(handler);
final ChannelFuture connect = channel.connect(new InetSocketAddress("1.2.3.4", 1234));
channel.pipeline().fireChannelActive();
Thread.sleep(Duration.ofMillis(100).toMillis() + 5);
channel.runScheduledPendingTasks();
assertTrue(connect.isDone());
assertTrue(connect.cause() instanceof TimeoutException);
assertEquals("SASL Mechanism listing timed out after 100ms", connect.cause().getMessage());
}
use of com.couchbase.client.core.cnc.SimpleEventBus in project couchbase-jvm-clients by couchbase.
the class SelectBucketHandlerTest method setup.
@BeforeEach
void setup() {
channel = new EmbeddedChannel();
SimpleEventBus simpleEventBus = new SimpleEventBus(true);
CoreEnvironment env = mock(CoreEnvironment.class);
TimeoutConfig timeoutConfig = mock(TimeoutConfig.class);
when(env.eventBus()).thenReturn(simpleEventBus);
when(env.timeoutConfig()).thenReturn(timeoutConfig);
when(timeoutConfig.connectTimeout()).thenReturn(Duration.ofMillis(10));
CoreContext coreContext = new CoreContext(mock(Core.class), 1, env, mock(Authenticator.class));
endpointContext = new EndpointContext(coreContext, new HostAndPort("127.0.0.1", 1234), null, ServiceType.KV, Optional.empty(), Optional.empty(), Optional.empty());
}
use of com.couchbase.client.core.cnc.SimpleEventBus in project couchbase-jvm-clients by couchbase.
the class LoggingMeterIntegrationTest method beforeAll.
@BeforeAll
static void beforeAll() {
eventBus = new SimpleEventBus(false);
cluster = createCluster(env -> env.loggingMeterConfig(LoggingMeterConfig.enabled(true).emitInterval(Duration.ofSeconds(2))).eventBus(eventBus));
Bucket bucket = cluster.bucket(config().bucketname());
collection = bucket.defaultCollection();
bucket.waitUntilReady(Duration.ofSeconds(5));
}
use of com.couchbase.client.core.cnc.SimpleEventBus in project couchbase-jvm-clients by couchbase.
the class ThresholdLoggingTracerIntegrationTest method beforeAll.
@BeforeAll
static void beforeAll() {
eventBus = new SimpleEventBus(false);
ThresholdLoggingTracerConfig.Builder config = ThresholdLoggingTracerConfig.enabled(true).kvThreshold(Duration.ofNanos(1)).queryThreshold(Duration.ofNanos(1)).emitInterval(Duration.ofSeconds(2));
cluster = createCluster(env -> env.thresholdLoggingTracerConfig(config).eventBus(eventBus));
Bucket bucket = cluster.bucket(config().bucketname());
collection = bucket.defaultCollection();
bucket.waitUntilReady(Duration.ofSeconds(5));
}
Aggregations