Search in sources :

Example 16 with SimpleEventBus

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();
    }
}
Also used : CoreEnvironment(com.couchbase.client.core.env.CoreEnvironment) EndpointContext(com.couchbase.client.core.endpoint.EndpointContext) SimpleEventBus(com.couchbase.client.core.cnc.SimpleEventBus) EmbeddedChannel(com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel) InvalidPacketDetectedEvent(com.couchbase.client.core.cnc.events.io.InvalidPacketDetectedEvent) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 17 with SimpleEventBus

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());
}
Also used : ChannelFuture(com.couchbase.client.core.deps.io.netty.channel.ChannelFuture) TimeoutConfig(com.couchbase.client.core.env.TimeoutConfig) CoreContext(com.couchbase.client.core.CoreContext) CoreEnvironment(com.couchbase.client.core.env.CoreEnvironment) EndpointContext(com.couchbase.client.core.endpoint.EndpointContext) InetSocketAddress(java.net.InetSocketAddress) EmbeddedChannel(com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel) HostAndPort(com.couchbase.client.core.util.HostAndPort) SimpleEventBus(com.couchbase.client.core.cnc.SimpleEventBus) Authenticator(com.couchbase.client.core.env.Authenticator) Core(com.couchbase.client.core.Core) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.jupiter.api.Test)

Example 18 with SimpleEventBus

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());
}
Also used : HostAndPort(com.couchbase.client.core.util.HostAndPort) TimeoutConfig(com.couchbase.client.core.env.TimeoutConfig) CoreContext(com.couchbase.client.core.CoreContext) CoreEnvironment(com.couchbase.client.core.env.CoreEnvironment) EndpointContext(com.couchbase.client.core.endpoint.EndpointContext) SimpleEventBus(com.couchbase.client.core.cnc.SimpleEventBus) EmbeddedChannel(com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel) Authenticator(com.couchbase.client.core.env.Authenticator) Core(com.couchbase.client.core.Core) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 19 with SimpleEventBus

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));
}
Also used : JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Util.waitUntilCondition(com.couchbase.client.test.Util.waitUntilCondition) LatencyMetricsAggregatedEvent(com.couchbase.client.core.cnc.events.metrics.LatencyMetricsAggregatedEvent) Event(com.couchbase.client.core.cnc.Event) LoggingMeterConfig(com.couchbase.client.core.env.LoggingMeterConfig) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) SimpleEventBus(com.couchbase.client.core.cnc.SimpleEventBus) Collection(com.couchbase.client.java.Collection) Bucket(com.couchbase.client.java.Bucket) List(java.util.List) BeforeAll(org.junit.jupiter.api.BeforeAll) Cluster(com.couchbase.client.java.Cluster) Duration(java.time.Duration) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) JsonObject(com.couchbase.client.java.json.JsonObject) Bucket(com.couchbase.client.java.Bucket) SimpleEventBus(com.couchbase.client.core.cnc.SimpleEventBus) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 20 with SimpleEventBus

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));
}
Also used : JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Util.waitUntilCondition(com.couchbase.client.test.Util.waitUntilCondition) Capabilities(com.couchbase.client.test.Capabilities) OverThresholdRequestsRecordedEvent(com.couchbase.client.core.cnc.events.tracing.OverThresholdRequestsRecordedEvent) Event(com.couchbase.client.core.cnc.Event) ClusterType(com.couchbase.client.test.ClusterType) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) SimpleEventBus(com.couchbase.client.core.cnc.SimpleEventBus) Collection(com.couchbase.client.java.Collection) Bucket(com.couchbase.client.java.Bucket) AfterEach(org.junit.jupiter.api.AfterEach) List(java.util.List) ThresholdLoggingTracerConfig(com.couchbase.client.core.env.ThresholdLoggingTracerConfig) BeforeAll(org.junit.jupiter.api.BeforeAll) Cluster(com.couchbase.client.java.Cluster) Duration(java.time.Duration) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) JsonObject(com.couchbase.client.java.json.JsonObject) Bucket(com.couchbase.client.java.Bucket) SimpleEventBus(com.couchbase.client.core.cnc.SimpleEventBus) ThresholdLoggingTracerConfig(com.couchbase.client.core.env.ThresholdLoggingTracerConfig) BeforeAll(org.junit.jupiter.api.BeforeAll)

Aggregations

SimpleEventBus (com.couchbase.client.core.cnc.SimpleEventBus)25 Core (com.couchbase.client.core.Core)16 Test (org.junit.jupiter.api.Test)14 CoreContext (com.couchbase.client.core.CoreContext)13 CoreEnvironment (com.couchbase.client.core.env.CoreEnvironment)12 Event (com.couchbase.client.core.cnc.Event)9 EmbeddedChannel (com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel)7 Authenticator (com.couchbase.client.core.env.Authenticator)7 EndpointConnectionFailedEvent (com.couchbase.client.core.cnc.events.endpoint.EndpointConnectionFailedEvent)6 TimeoutConfig (com.couchbase.client.core.env.TimeoutConfig)6 EndpointContext (com.couchbase.client.core.endpoint.EndpointContext)5 CoreIntegrationTest (com.couchbase.client.core.util.CoreIntegrationTest)4 HostAndPort (com.couchbase.client.core.util.HostAndPort)4 ClusterType (com.couchbase.client.test.ClusterType)4 IgnoreWhen (com.couchbase.client.test.IgnoreWhen)4 Util.waitUntilCondition (com.couchbase.client.test.Util.waitUntilCondition)4 Duration (java.time.Duration)4 List (java.util.List)4 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)4 BeforeAll (org.junit.jupiter.api.BeforeAll)4