Couchbase BucketClosedException in integration tests

Hi All,
I run the below snippet to test couchbase java api,Test is passing when I run individually but when ran as a suite it gives me a BucketClosedException at stub.retrieveMessage(RetrieveMessageRequest.newBuilder().setMessageId(“MessageTest_001”).build()); line.Detailed trace is at below.

Please let me know why Bucketclosure happens in the test case when ran as a suite and passing it individually.

@SpringBootTest(classes = { AeroConnectServerApplication.class })
@TestPropertySource(properties = { “grpc.port: 6560” })
public class MessageTest {
private MessageRepository messageRepository;
private MessageRevisionRepository messageRevisionRepository;
private ApiRepository apiRepository;
private CouchbaseBucketConfig messageBucketConfig;
private Bucket messageBucket;
private Bucket configurationBucket;
private static CouchbaseTemplate sCouchbaseTemplate;
private static CouchbaseTemplate configTemplate;

private int port;

private String host;

public void testARetrieveMessage01() throws Exception {;;;;

    ManagedChannel channel = ManagedChannelBuilder.forAddress(host, port).usePlaintext().build();
    MessageServiceGrpc.MessageServiceBlockingStub stub = MessageServiceGrpc.newBlockingStub(channel);
    RetrieveMessageResponse response = stub.retrieveMessage(RetrieveMessageRequest.newBuilder().setMessageId("MessageTest_001").build());


com.couchbase.client.core.BucketClosedException: message has been closed
at com.couchbase.client.core.RequestHandler.dispatchRequest(
at com.couchbase.client.core.RequestHandler.onEvent(
at com.couchbase.client.core.RequestHandler.onEvent(

My springboot config is as below

public class CouchbaseBucketConfig extends AbstractCouchbaseDataConfiguration {

private CouchbaseClusterConfigurer generalConfigurer;

public Bucket configurationBucket() throws Exception {
	return generalConfigurer.couchbaseClient();

Bucket messageBucket() throws Exception {
	return generalConfigurer.messageBucket();

public CouchbaseTemplate messageConfigTemplate() throws Exception {
	CouchbaseTemplate template = new CouchbaseTemplate(couchbaseConfigurer().couchbaseClusterInfo(),
			generalConfigurer.messageBucket(), mappingCouchbaseConverter(), translationService());
	return template;

Hi All,
It worked when I remove @Bean Bucket definitions.I got the bucket from template .getCouchbaseBucket and it works fine. Nevertheless Can somebody tell me why BucketClosedException went away when direct Bucket injection is removed?


Hi @iisuru,

It would help to see the full stack trace of the BucketClosedException, but suspecting that if you are using RBAC enabled server, the credentials should be stored on the cluster instance before openBucket is called. SDC does add the credentials in the bucket bean creation method.
Probably taking a look here would help for adding custom bucket bean creations.

Hi Subhashini,

Actually cluster creation and authentication is happening in even my @Bucket annotated method through the injecton of generalconfigurer.The injection fails only when I run integration tests as a suite.It is working fine when I execute them sequentially one by one.So it might be related to gradle integration set up also.

Since now I got it working in both integration tests and real code via bucket extraction from template I will take time and check what is going on in this case using your pointers as well.

Thanks for the support.