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

Rewrite Couchbase module. closes #2447 #2491

Merged
merged 9 commits into from Apr 12, 2020
Merged

Conversation

bsideup
Copy link
Member

@bsideup bsideup commented Mar 29, 2020

Closes #2486.

daschl and others added 3 commits March 27, 2020 16:06
This changeset completely reworks the couchbase module and hopefully
greatly improve the out-of-the-box experience. Note that this is a
breaking change over the previous code because by intention it does
NOT depend on SDK 2 so you can test SDK 2 and 3 with it at the same
time.

Highlights:

 - Removed the need for a SDK, so both 2 and 3 can be used with it.
 - Updated to 6.5.0 baseline and using alternate addresses for
   "proper" port exposure without having to rely on the socat
   proxy container like the previous version had to.
 - Allows to define which services should be exposed and handles
   states automatically (i.e. will not try to create the primary
   index if the query service is not enabled).

Note that a bunch of tests have been removed since they are not
adequate anymore. A side effect of the alternate address change
is that older servers cannot be used. 6.5.0 is available in both
CE and EE, and Couchbase in general allows EE versions to be used
in development and testing so we should use it if we can.
@bsideup bsideup added type/breaking-api-change Public APIs are being changed modules/couchbase labels Mar 29, 2020
@bsideup bsideup added this to the next milestone Mar 29, 2020
@bsideup bsideup requested a review from a team March 29, 2020 17:00
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
Copy link
Member

Choose a reason for hiding this comment

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

Ideally, we add the original source of this file, for future reference.

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 comment is invalid ;)

Comment on lines -64 to -65
public static final String VERSION = "5.5.1";
public static final String DOCKER_IMAGE_NAME = "couchbase/server:";
Copy link
Member

Choose a reason for hiding this comment

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

I know this is a big breaking change after all, but in other modules, we sometimes also have image name and tag public.

Copy link
Member Author

Choose a reason for hiding this comment

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

see #2054 for the discussion

private final CouchbaseEnvironment couchbaseEnvironment = createCouchbaseEnvironment();
private static final OkHttpClient HTTP_CLIENT = new OkHttpClient()
.newBuilder()
.readTimeout(Duration.ofMinutes(1))
Copy link
Member

Choose a reason for hiding this comment

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

Big timeout necessary for startup?

Copy link
Member Author

Choose a reason for hiding this comment

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

there are per-strategy timeouts too, I see no harm here

Copy link
Member

Choose a reason for hiding this comment

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

We can reduce it too if needed, but I figured maybe on slower machines it might help not break

/**
* Checks if already running and if so raises an exception to prevent too-late setters.
*/
private void checkNotRunning() {
Copy link
Member

Choose a reason for hiding this comment

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

Nice idea from a user perspective, but this behaves very different (better?) than other TC modules.

Copy link
Member Author

Choose a reason for hiding this comment

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

we also check isRunning() from getMappedPort, for example

Copy link
Member

Choose a reason for hiding this comment

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

@bsideup funny: that's how I ended it up adding it like this, because I accidentally had to get a mapped port before it was running...

.forPath("/pools/default")
.forPort(MGMT_PORT)
.withBasicCredentials(username, password)
.forStatusCode(200)
Copy link
Member

Choose a reason for hiding this comment

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

could be omitted, we use 200 as default

.forPath("/admin/ping")
.forPort(QUERY_PORT)
.withBasicCredentials(username, password)
.forStatusCode(200)
Copy link
Member

Choose a reason for hiding this comment

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

see above

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's not :D
Really does not help, especially when someone who knows Couchbase wants to see which endpoint is used to check the liveness here

Copy link
Member

Choose a reason for hiding this comment

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

Why does knowing about status code 200 help?

.forPath("/pools/default/buckets/" + bucket.getName())
.forPort(MGMT_PORT)
.withBasicCredentials(username, password)
.forStatusCode(200)
Copy link
Member

Choose a reason for hiding this comment

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

see above

Comment on lines 371 to 375
final Map<String, ContainerNetwork> networks = getContainerInfo().getNetworkSettings().getNetworks();
for (ContainerNetwork network : networks.values()) {
return network.getIpAddress();
}
throw new IllegalStateException("No network available to extract the internal IP from!");
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
final Map<String, ContainerNetwork> networks = getContainerInfo().getNetworkSettings().getNetworks();
for (ContainerNetwork network : networks.values()) {
return network.getIpAddress();
}
throw new IllegalStateException("No network available to extract the internal IP from!");
return getContainerInfo().getNetworkSettings().getNetworks().values().stream()
.map(ContainerNetwork::getIpAddress)
.findFirst()
.orElseThrow(() -> new IllegalStateException("No network available to extract the internal IP from!"));

Not sure if better, but on first reading, I stumbled upon the for-loop for getting the first element.

Comment on lines 42 to 43
.bootstrapCarrierDirectPort(container.getMappedPort(11210))
.bootstrapHttpDirectPort(container.getMappedPort(8091))
Copy link
Member

Choose a reason for hiding this comment

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

Here I was wondering if it wouldn't be nicer to make those default ports public constants in the container class?

Copy link
Member

Choose a reason for hiding this comment

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

@kiview one other option would be to provide explicit getters for only those two that you might need for bootstrapping? So people don't have to concern themselves with the implementation details at all. This is needed for SDK 2 only, for SDK 3 all you need to do is getConnectionString() .. so something like getCarrierDirectPort() and getHttpDirectPort() and the same for the ssl ports if someone wants to use that.

.forPath("/admin/ping")
.forPort(QUERY_PORT)
.withBasicCredentials(username, password)
.forStatusCode(200)
Copy link
Member

Choose a reason for hiding this comment

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

Why does knowing about status code 200 help?

Co-Authored-By: Kevin Wittek <kiview@users.noreply.github.com>
@rnorth
Copy link
Member

rnorth commented Apr 12, 2020

Docs are now incorrect 😅

Copy link
Member

@rnorth rnorth left a comment

Choose a reason for hiding this comment

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

Looks great! Thanks for all your hard work on this @bsideup and @daschl!

@bsideup bsideup merged commit c6e0cd9 into master Apr 12, 2020
@delete-merged-branch delete-merged-branch bot deleted the daschl/couchbase-rewrite branch April 12, 2020 18:23
@rnorth
Copy link
Member

rnorth commented Apr 13, 2020

This was released in https://github.com/testcontainers/testcontainers-java/releases/tag/1.14.0 🎉

Thanks for the contribution!

quincy pushed a commit to quincy/testcontainers-java that referenced this pull request May 28, 2020
…2491)

* Rewrite couchbase module. closes testcontainers#2447

This changeset completely reworks the couchbase module and hopefully
greatly improve the out-of-the-box experience. Note that this is a
breaking change over the previous code because by intention it does
NOT depend on SDK 2 so you can test SDK 2 and 3 with it at the same
time.

Highlights:

 - Removed the need for a SDK, so both 2 and 3 can be used with it.
 - Updated to 6.5.0 baseline and using alternate addresses for
   "proper" port exposure without having to rely on the socat
   proxy container like the previous version had to.
 - Allows to define which services should be exposed and handles
   states automatically (i.e. will not try to create the primary
   index if the query service is not enabled).

Note that a bunch of tests have been removed since they are not
adequate anymore. A side effect of the alternate address change
is that older servers cannot be used. 6.5.0 is available in both
CE and EE, and Couchbase in general allows EE versions to be used
in development and testing so we should use it if we can.

* Wait until query respsonds with 200

* fixes

* add `getBootstrap*DirectPort()` methods, review fixes

* Restore `getConnectionString()`

* Apply suggestions from code review

Co-Authored-By: Kevin Wittek <kiview@users.noreply.github.com>

* Update docs

* Update docs (2)

Co-authored-by: Michael Nitschinger <michael@nitschinger.at>
Co-authored-by: Kevin Wittek <kiview@users.noreply.github.com>
sd-yip added a commit to sd-yip/testcontainers-java that referenced this pull request May 11, 2021
sd-yip added a commit to sd-yip/testcontainers-java that referenced this pull request May 12, 2021
sd-yip added a commit to sd-yip/testcontainers-java that referenced this pull request May 12, 2021
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

4 participants