Search in sources :

Example 1 with BucketConfigRequest

use of com.couchbase.client.core.msg.manager.BucketConfigRequest in project couchbase-jvm-clients by couchbase.

the class ClusterManagerBucketLoaderTest method loadsConfigSuccessfully.

@Test
void loadsConfigSuccessfully() {
    byte[] expectedConfig = "config".getBytes(UTF_8);
    BucketConfigResponse response = mock(BucketConfigResponse.class);
    when(response.status()).thenReturn(ResponseStatus.SUCCESS);
    when(response.config()).thenReturn(expectedConfig);
    doAnswer(i -> {
        ((BucketConfigRequest) i.getArgument(0)).succeed(response);
        return null;
    }).when(core).send(any(BucketConfigRequest.class));
    byte[] config = loader.discoverConfig(SEED, BUCKET).block();
    assertArrayEquals(expectedConfig, config);
}
Also used : BucketConfigResponse(com.couchbase.client.core.msg.manager.BucketConfigResponse) BucketConfigRequest(com.couchbase.client.core.msg.manager.BucketConfigRequest) Test(org.junit.jupiter.api.Test)

Example 2 with BucketConfigRequest

use of com.couchbase.client.core.msg.manager.BucketConfigRequest in project couchbase-jvm-clients by couchbase.

the class ClusterManagerBucketLoaderTest method cancelRequestOnceUnsubscribed.

/**
 * Since the client may run many loaders in parallel, once a good config is found the other
 * attempts will be stopped.
 *
 * <p>This test makes sure that if an operation is ongoing but the downstream listener
 * unsubscribes, it gets cancelled so we are not performing any loader ops that are not needed
 * anymore.</p>
 */
@Test
void cancelRequestOnceUnsubscribed() {
    final AtomicReference<BucketConfigRequest> request = new AtomicReference<>();
    doAnswer(i -> {
        request.set(i.getArgument(0));
        return null;
    }).when(core).send(any(BucketConfigRequest.class));
    Disposable disposable = loader.discoverConfig(SEED, BUCKET).subscribe();
    disposable.dispose();
    assertTrue(request.get().completed());
    assertTrue(request.get().cancelled());
    assertEquals(CancellationReason.STOPPED_LISTENING, request.get().cancellationReason());
}
Also used : Disposable(reactor.core.Disposable) AtomicReference(java.util.concurrent.atomic.AtomicReference) BucketConfigRequest(com.couchbase.client.core.msg.manager.BucketConfigRequest) Test(org.junit.jupiter.api.Test)

Example 3 with BucketConfigRequest

use of com.couchbase.client.core.msg.manager.BucketConfigRequest in project couchbase-jvm-clients by couchbase.

the class ManagerEndpointIntegrationTest method fetchTerseConfig.

/**
 * This integration test attempts to load a "terse" bucket config from the cluster manager.
 *
 * <p>Note that the actual response is not checked here, since this handles at the higher levels. We just make sure
 * that the config returned is not empty.</p>
 */
@Test
void fetchTerseConfig() throws Exception {
    TestNodeConfig node = config().nodes().get(0);
    ManagerEndpoint endpoint = new ManagerEndpoint(serviceContext, node.hostname(), node.ports().get(Services.MANAGER));
    endpoint.connect();
    waitUntilCondition(() -> endpoint.state() == EndpointState.CONNECTED);
    BucketConfigRequest request = new BucketConfigRequest(Duration.ofSeconds(1), serviceContext, null, config().bucketname(), serviceContext.authenticator(), null);
    assertTrue(request.id() > 0);
    endpoint.send(request);
    BucketConfigResponse response = request.response().get(1, TimeUnit.SECONDS);
    assertTrue(response.status().success());
    assertTrue(response.config().length > 0);
    endpoint.disconnect();
    waitUntilCondition(() -> endpoint.state() == EndpointState.DISCONNECTED);
}
Also used : TestNodeConfig(com.couchbase.client.test.TestNodeConfig) BucketConfigResponse(com.couchbase.client.core.msg.manager.BucketConfigResponse) BucketConfigRequest(com.couchbase.client.core.msg.manager.BucketConfigRequest) ClusterAwareIntegrationTest(com.couchbase.client.test.ClusterAwareIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 4 with BucketConfigRequest

use of com.couchbase.client.core.msg.manager.BucketConfigRequest in project couchbase-jvm-clients by couchbase.

the class ClusterManagerBucketLoaderTest method errorsIfNonSuccessful.

@Test
void errorsIfNonSuccessful() {
    BucketConfigResponse response = mock(BucketConfigResponse.class);
    when(response.status()).thenReturn(ResponseStatus.UNKNOWN);
    doAnswer(i -> {
        ((BucketConfigRequest) i.getArgument(0)).succeed(response);
        return null;
    }).when(core).send(any(BucketConfigRequest.class));
    assertThrows(ConfigException.class, () -> loader.discoverConfig(SEED, BUCKET).block());
}
Also used : BucketConfigResponse(com.couchbase.client.core.msg.manager.BucketConfigResponse) BucketConfigRequest(com.couchbase.client.core.msg.manager.BucketConfigRequest) Test(org.junit.jupiter.api.Test)

Aggregations

BucketConfigRequest (com.couchbase.client.core.msg.manager.BucketConfigRequest)4 Test (org.junit.jupiter.api.Test)4 BucketConfigResponse (com.couchbase.client.core.msg.manager.BucketConfigResponse)3 ClusterAwareIntegrationTest (com.couchbase.client.test.ClusterAwareIntegrationTest)1 TestNodeConfig (com.couchbase.client.test.TestNodeConfig)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Disposable (reactor.core.Disposable)1