use of com.couchbase.client.core.endpoint.EndpointContext in project couchbase-jvm-clients by couchbase.
the class ManagerMessageHandlerTest method returnsNewConfigsWhenChunked.
/**
* Configs can come in all shapes and sizes chunked, but only after the 4 newlines are pushed by the cluster
* the config should be propagated into the flux.
*/
@Test
void returnsNewConfigsWhenChunked() throws Exception {
CoreContext ctx = new CoreContext(mock(Core.class), 1, ENV, PasswordAuthenticator.create(USER, PASS));
BaseEndpoint endpoint = mock(BaseEndpoint.class);
EndpointContext endpointContext = mock(EndpointContext.class);
when(endpointContext.environment()).thenReturn(ENV);
when(endpoint.context()).thenReturn(endpointContext);
EmbeddedChannel channel = new EmbeddedChannel(new ManagerMessageHandler(endpoint, ctx));
BucketConfigStreamingRequest request = new BucketConfigStreamingRequest(Duration.ofSeconds(1), ctx, BestEffortRetryStrategy.INSTANCE, "bucket", ctx.authenticator());
channel.write(request);
HttpRequest outboundHeader = channel.readOutbound();
assertEquals(HttpMethod.GET, outboundHeader.method());
assertEquals("/pools/default/bs/bucket", outboundHeader.uri());
assertEquals(HttpVersion.HTTP_1_1, outboundHeader.protocolVersion());
CompletableFuture<BucketConfigStreamingResponse> response = request.response();
assertFalse(response.isDone());
HttpResponse inboundResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
channel.writeInbound(inboundResponse);
BucketConfigStreamingResponse completedResponse = request.response().get();
final List<String> configsPushed = Collections.synchronizedList(new ArrayList<>());
final AtomicBoolean terminated = new AtomicBoolean(false);
Thread listener = new Thread(() -> completedResponse.configs().subscribe(configsPushed::add, (e) -> {
}, () -> terminated.set(true)));
listener.setDaemon(true);
listener.start();
ByteBuf fullContent = Unpooled.copiedBuffer(readResource("terse_stream_two_configs.json", ManagerMessageHandlerTest.class), StandardCharsets.UTF_8);
while (fullContent.readableBytes() > 0) {
int len = new Random().nextInt(fullContent.readableBytes() + 1);
if (len == 0) {
continue;
}
channel.writeInbound(new DefaultHttpContent(fullContent.readBytes(len)));
}
waitUntilCondition(() -> configsPushed.size() >= 1);
for (String config : configsPushed) {
assertTrue(config.startsWith("{"));
assertTrue(config.endsWith("}"));
}
assertFalse(terminated.get());
channel.writeInbound(new DefaultLastHttpContent());
waitUntilCondition(terminated::get);
ReferenceCountUtil.release(fullContent);
channel.close().awaitUninterruptibly();
}
use of com.couchbase.client.core.endpoint.EndpointContext in project couchbase-jvm-clients by couchbase.
the class QueryMessageHandlerBackpressureTest method requestRecordsExplicitly.
/**
* This test makes sure that even if the server returns a good bunch of data, each individual
* chunk is requested by the caller explicitly.
*/
@Test
void requestRecordsExplicitly() throws Exception {
EndpointContext endpointContext = new EndpointContext(core.context(), new HostAndPort("127.0.0.1", 1234), NoopCircuitBreaker.INSTANCE, ServiceType.QUERY, Optional.empty(), Optional.empty(), Optional.empty());
BaseEndpoint endpoint = mock(BaseEndpoint.class);
when(endpoint.pipelined()).thenReturn(false);
Bootstrap client = new Bootstrap().channel(LocalChannel.class).group(new DefaultEventLoopGroup()).remoteAddress(new LocalAddress("s1")).handler(new ChannelInitializer<LocalChannel>() {
@Override
protected void initChannel(LocalChannel ch) {
ch.pipeline().addLast(new HttpClientCodec()).addLast(new QueryMessageHandler(endpoint, endpointContext));
}
});
Channel channel = client.connect().awaitUninterruptibly().channel();
final List<byte[]> rows = Collections.synchronizedList(new ArrayList<>());
QueryRequest request = new QueryRequest(Duration.ofSeconds(1), endpointContext, BestEffortRetryStrategy.INSTANCE, endpointContext.authenticator(), "select 1=1", "myquery".getBytes(UTF_8), true, null, null, null, null, null);
channel.writeAndFlush(request);
final QueryResponse response = request.response().get();
assertEquals(0, rows.size());
StepVerifier.create(response.rows().map(v -> new String(v.data(), UTF_8)), 0).thenRequest(1).expectNext("{\"foo\":1}").thenRequest(1).expectNext("{\"bar\":1}").thenRequest(2).expectNext("{\"faz\":1}", "{\"baz\":1}").thenRequest(4).expectNext("{\"fazz\":1}", "{\"bazz\":1}", "{\"fizz\":1}", "{\"bizz\":1}").expectComplete().verify();
}
use of com.couchbase.client.core.endpoint.EndpointContext in project couchbase-jvm-clients by couchbase.
the class QueryMessageHandlerTest method setup.
@BeforeAll
static void setup() {
ENV = CoreEnvironment.create();
CORE_CTX = new CoreContext(mock(Core.class), 1, ENV, PasswordAuthenticator.create("user", "pass"));
ENDPOINT_CTX = new EndpointContext(CORE_CTX, new HostAndPort("127.0.0.1", 1234), NoopCircuitBreaker.INSTANCE, ServiceType.QUERY, Optional.empty(), Optional.empty(), Optional.empty());
}
use of com.couchbase.client.core.endpoint.EndpointContext in project couchbase-jvm-clients by couchbase.
the class ErrorMapLoadingHandlerTest method beforeEach.
@BeforeEach
@Override
protected void beforeEach() {
super.beforeEach();
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(1000));
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.endpoint.EndpointContext in project couchbase-jvm-clients by couchbase.
the class PasswordAuthenticatorTest method shouldNotNegotiatePlainWithNonTlsByDefault.
@Test
void shouldNotNegotiatePlainWithNonTlsByDefault() {
PasswordAuthenticator authenticator = PasswordAuthenticator.create("user", "pass");
EndpointContext ctx = mock(EndpointContext.class);
when(ctx.environment()).thenReturn(ENV);
EmbeddedChannel channel = new EmbeddedChannel();
authenticator.authKeyValueConnection(ctx, channel.pipeline());
SaslAuthenticationHandler handler = channel.pipeline().get(SaslAuthenticationHandler.class);
assertFalse(handler.allowedMechanisms().contains(SaslMechanism.PLAIN));
}
Aggregations