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.

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

@Value("${test.port}")
private int port;

@Value("${test.host}")
private String host;

@Test
public void testARetrieveMessage01() throws Exception {
    apiRepository.save(api);
    messageRepository.save(message);
     messageRevisionRepository.save(messageRevision_0);
    messageRevisionRepository.save(messageRevision_1);

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

Trace

com.couchbase.client.core.BucketClosedException: message has been closed
at com.couchbase.client.core.RequestHandler.dispatchRequest(RequestHandler.java:241)
at com.couchbase.client.core.RequestHandler.onEvent(RequestHandler.java:208)
at com.couchbase.client.core.RequestHandler.onEvent(RequestHandler.java:79)
at com.couchbase.client.deps.com.lmax.disruptor.BatchEventProcessor.run(BatchEventProcessor.java:150)
at com.couchbase.client.deps.io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:745)

My springboot config is as below

@Configuration
@EnableCouchbaseRepositories
public class CouchbaseBucketConfig extends AbstractCouchbaseDataConfiguration {

@Autowired
private CouchbaseClusterConfigurer generalConfigurer;

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

@Bean
Bucket messageBucket() throws Exception {
	return generalConfigurer.messageBucket();
}

@Bean
public CouchbaseTemplate messageConfigTemplate() throws Exception {
	CouchbaseTemplate template = new CouchbaseTemplate(couchbaseConfigurer().couchbaseClusterInfo(),
			generalConfigurer.messageBucket(), mappingCouchbaseConverter(), translationService());
	template.setDefaultConsistency(getDefaultConsistency());
	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?

Thanks

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.
Regards
Isuru