-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Conversation
|
||
@Override | ||
protected void configure() { | ||
addFixedExposedPort(8091, 8091); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 :(
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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 {}
)
modules/couchbase/pom.xml
Outdated
|
||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>selenium</artifactId> |
There was a problem hiding this comment.
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 :)
|
||
protected void initCluster() { | ||
@Override | ||
protected void containerIsStarted(InspectContainerResponse containerInfo) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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!
@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. |
@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 |
Hey @ldoguin, Do you still want to deliver this PR? :) |
I would be happy to but there are some things that are not in my powers. In particular the hardcoded port in Couchbase :( |
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. |
Is there something I can help out with here? |
@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 :) |
@ldoguin Are you referring to 8091 or a different port? |
@benofben different ports. All the one that are hardcoded in the CouchbaseContainer case.
|
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. |
Since the module is now developed in it's own repo, it's okay to close the PR, isn't it? |
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. |
@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? |
Closing in favour of #688 |
This PR adds support for the default Couchbase docker image.