ldoguin / couchbase-test-docker

How to test Couchbase with a Docker container
Apache License 2.0
5 stars 6 forks source link

Getting design documents fails when couchbase is running on docker #1

Open ricardojoaoreis opened 7 years ago

ricardojoaoreis commented 7 years ago

Hello,

Running the BucketManager.getDesignDocuments() fails with an InvocationTargetException

The message is java.lang.RuntimeException: java.net.ConnectException: Connection refused: localhost/127.0.0.1:8091

It seems that the client is still trying to connect to port 8091 somewhere...

I've tried with client versions 2.2.8 and 2.3.6

Here's a JUnit test demonstrating the problem:

package com.couchbase;

import com.couchbase.client.java.Bucket;
import com.couchbase.client.java.CouchbaseCluster;
import com.couchbase.client.java.view.DesignDocument;
import org.junit.Assert;
import org.junit.ClassRule;
import org.junit.Test;

import java.util.List;

public class CouchbaseDesignDocumentsTest {

    @ClassRule
    public static CouchbaseContainer couchbase = new CouchbaseContainer()
        .withBeerSample(true)
        .withFTS(true)
        .withIndex(true)
        .withQuery(true)
        .withKeyValue(true)
        .withClusterUsername("Administrator")
        .withClusterPassword("password");

    @Test
    public void testDesignDocuments() throws Exception {
        CouchbaseCluster cc = couchbase.geCouchbaseCluster();
        Bucket bucket = cc.openBucket("beer-sample");
        List<DesignDocument> designDocuments = bucket.bucketManager().getDesignDocuments();
        Assert.assertNotNull(designDocuments);
    }
}
ldoguin commented 7 years ago

I don't have issue on the spring data version I worked on today https://github.com/ldoguin/testcontainers-spring-data-couchbase I'll give it a shot tomorrow. Out of curiosity have you tried with bucket.bucketManager("Administrator","password") ?

ricardojoaoreis commented 7 years ago

Version 2.3.6 doesn't seem to have that method...

Trying openBucket("beer-samples", "password") also doesn't work because the bucket was created without a password...

Also, I was performing some more testing today and I actually get a ConnectionRefused exception on with the above code somewhere along the stack and it mentions port 8091 which seems strange to me, since it should connect to the mapped port... Someone mentioned I could edit the static_config file after setting up the cluster but I had no luck with that...

Regarding spring-data is that if you annotate a Repository with @ViewIndexed (to be able to use count() and findAll()) and have the IndexManager take care of the views for you like this:

@Bean(name = BeanNames.COUCHBASE_INDEX_MANAGER)
public IndexManager indexManager() {
    return new IndexManager(true, true, true);
}

On IndexManager.java there's this line DesignDocument doc = manager.getDesignDocument(config.designDoc()); where the execution hangs...

I tried it on the other repo you linked by having the IndexManager like I told you and the UserRepository annotated with @ViewIndexed(designDoc = "userRepository" and I got the same problems that I have in my application... So maybe it's just a spring-data issue?

ldoguin commented 7 years ago

Version 2.3.6 doesn't seem to have that method...

I mixed up things with couchbaseCluster.clusterManager(clusterUser, clusterPassword), sorry. I also experienced timeout with Spring Data and I am looking into this.