Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for Couchbase #269

Closed
wants to merge 9 commits into from

Conversation

ldoguin
Copy link

@ldoguin ldoguin commented Jan 18, 2017

This PR adds support for the default Couchbase docker image.


@Override
protected void configure() {
addFixedExposedPort(8091, 8091);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I right that these ports are only needed if you use some sub-set of Couchbase APIs?
Fixed ports are dangerous, we were trying to avoid it as much as possible, so maybe we can make it configurable, i.e. "withN1Q(true)" (or whatever uses them), and put a note that it will fix the ports?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that tests on Travis are failing because of it as well :(

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, unfortunately, some of the ports cannot be changed. Bad Couchbase design for some services, but not all of them. Out of consistency concerns, I chose to fix everything.
But yes, it could be problematic in many cases.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If consistency isn't an issue, we can change configureable port.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we can use some free port finder on the host machine and then configure Couchbase with it.

Still flaky, but at least will work for the most of the cases.
WDYT?

BucketSettings bucketSettings = getCouchbaseCluster().clusterManager(clusterUsername, clusterPassword).insertBucket(bucketSetting);
// allow some time for the query service to come up
try {
Thread.sleep(5000);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we somehow continuously check if it's ready?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could not find an answer yet.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

http://docs.couchbase.com/admin/admin/CLI/CBcli/cbcli-bucket-create.html
I see --wait option here - how does it wait?

Also, at least something like Unreliables.retryUntilSuccess(1, TimeUnit.MINUTES, () -> clusterManager.hasBucket(bucketName)) would be better I think

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or actually, just clusterManager.hasBucket(bucketName, 1, TimeUnit.MINUTES) :D

}


public void initCluster() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think public is too open for this method, maybe protected is better?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually even private would be better. I intend people to use start anyway, Will fix this.

callCouchbaseRestAPI(poolURL, poolPayload);
callCouchbaseRestAPI(setupServicesURL, setupServiceContent);
callCouchbaseRestAPI(webSettingsURL, webSettingsContent);
callCouchbaseRestAPI(bucketURL, sampleBucketPayloadBuilder.toString());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestContainers has a lifecycle, you can put this code to containerIsStarting (means that container was created) method, and then, in containerIsStarted (container passed the wait strategy), do

callCouchbaseRestAPI("/settings/indexes", "indexerThreads=0&logLevel=info&maxRollbackPoints=5&storageMode=memory_optimized");

}
}

public void callCouchbaseRestAPI(String url, String payload) throws IOException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO should be protected as well

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed

"application/x-www-form-urlencoded");
String encoded = Base64.encode((clusterUsername + ":" + clusterPassword).getBytes("UTF-8"));
httpConnection.setRequestProperty("Authorization", "Basic " + encoded);
DataOutputStream out = new DataOutputStream(httpConnection.getOutputStream());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add @lombok.Cleanup DataOutputStream out to automatically close the stream (no need to call out.close(), which should be called in try {} finally {})


<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>selenium</artifactId>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I doubt we need Selenium here :)

@bsideup bsideup added this to the 1.1.8 milestone Jan 18, 2017

protected void initCluster() {
@Override
protected void containerIsStarted(InspectContainerResponse containerInfo) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this code should go to "containerIsStarting", and only the part after waitStrategy - to containerIsStarted. Then you can just define setWaitStrategy() as usual

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ports don't seem to be accessible yet during containerIsStarting.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so you perform some setups only after wait strategy has passed? Got it 👍

<dependency>
<groupId>com.couchbase.client</groupId>
<artifactId>java-client</artifactId>
<version>2.4.0</version>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since TestContainers is a library for testing, we probably should use provided scope here, because users will have Couchbase client library already in their app. Right?

private String urlBase;

public CouchbaseContainer() {
super("couchbase/server:latest");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please lock the version? We try to avoid ":latest" everywhere. Thanks!

@rnorth
Copy link
Member

rnorth commented Jan 22, 2017

@ldoguin @bsideup how would you feel about aiming to include this in a 1.1.9 release next week? I'm keen to wrap up 1.1.8 and release tonight, as it includes a bunch of bug fixes that people are probably awaiting. 1.1.9 can follow next week.
Please let me know if there's anything I can do to help with this PR, too!
Richard

@bsideup
Copy link
Member

bsideup commented Jan 22, 2017

@rnorth I don't mind! Given a critical hotfix for the Docker 1.1.3 in 1.1.8 we should release it ASAP; everything else we can release as a follow-up release

@rnorth rnorth modified the milestones: 1.1.9, 1.1.8 Jan 22, 2017
@rnorth rnorth modified the milestones: 1.1.9, 1.1.10 Feb 12, 2017
@bsideup bsideup removed this from the 1.1.10 milestone Mar 8, 2017
@bsideup
Copy link
Member

bsideup commented May 29, 2017

Hey @ldoguin,

Do you still want to deliver this PR? :)

@ldoguin
Copy link
Author

ldoguin commented May 29, 2017

I would be happy to but there are some things that are not in my powers. In particular the hardcoded port in Couchbase :(
Maybe @benofben could help?

@tchlyah
Copy link
Contributor

tchlyah commented Jul 27, 2017

Hello @ldoguin,

I've extracted and completed your version in an external module differentway/testcontainers-java-module-couchbase.

@bsideup propose to transfer it under http://github.com/testcontainers, Since I was widely inspired by your version, maybe I need your confirmation?

Thank you.

@benofben
Copy link

Is there something I can help out with here?

@ldoguin
Copy link
Author

ldoguin commented Jul 30, 2017

@tchlyah it looks great! You don't need my permission, please go ahead and do whatever you want with it.

@benofben There were some discussions about Couchbase's fixed port. It would be great if they could all be customized. I believe the Travis tests fail because of this.

And while we are on the customization topic, being able to pass a configuration file as argument to autoconfigure couchbase upon start would be awesome. The asynchronousity of most config changes make it a little bit harder than I would like :) Happy to talk more about this by email :)

@benofben
Copy link

@ldoguin Are you referring to 8091 or a different port?

@ldoguin
Copy link
Author

ldoguin commented Jul 31, 2017

@benofben different ports. All the one that are hardcoded in the CouchbaseContainer case.

    // Non configurable ports
    addFixedExposedPort(8092, 8092);
    addFixedExposedPort(8093, 8093);
    addFixedExposedPort(8094, 8094);
    addFixedExposedPort(8095, 8095);
    addFixedExposedPort(18092, 18092);
    addFixedExposedPort(18093, 18093);

@benofben
Copy link

I'm not sure I have enough context here to understand. I believe those ports are configurable in the product. It seems like the container isn't exposing that. Maybe mail me at ben.lackey at couchbase.com and you can explain a bit more what you need.

@kiview
Copy link
Member

kiview commented Aug 21, 2017

Since the module is now developed in it's own repo, it's okay to close the PR, isn't it?

@rnorth
Copy link
Member

rnorth commented Mar 13, 2018

What's the best way to proceed with this. I agree that the existence of differentway/testcontainers-java-module-couchbase means we don't need both.

@tchlyah, would you care to join forces and merge your module into the main testcontainers-java repository? This is an effort we're undertaking for #564.

@tchlyah
Copy link
Contributor

tchlyah commented Mar 14, 2018

@rnorth, yes with pleasure, but I'm in the middle of a move and it's such a mess that I can't find neither time nor my computer in boxes! I will do my best to do this in the next few days. How do you want to proceed?

@bsideup
Copy link
Member

bsideup commented Mar 15, 2018

@rnorth @tchlyah @ldoguin should we close this PR?

@tchlyah tchlyah mentioned this pull request May 13, 2018
@bsideup
Copy link
Member

bsideup commented May 14, 2018

Closing in favour of #688

@bsideup bsideup closed this May 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants