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

Socat sidecar proxy for Couchbase container to support random ports #815

Merged
merged 8 commits into from
Aug 7, 2018

Conversation

klara-l
Copy link
Contributor

@klara-l klara-l commented Aug 2, 2018

inspired by #785.

  • containerIsCreated hook
  • added support for couchbase 5.5
  • added ALL couchbase client ports
  • restructured integration tests for couchbase 4.6, 5.1 and 5.5

bsideup and others added 6 commits July 15, 2018 14:58
- updated couchbase sdk to support 5.5.0
- added all client ports to port mappings
- configuring couchbase through static_config file
- added @ClassRule for the couchbase container tests instead of
  static variables to prevent race conditions
- configured socat to expose the bootstrap ports as target.
  These bootstrap ports are not added to the couchbase config file.
…ports

# Conflicts:
#	modules/couchbase/src/main/java/org/testcontainers/couchbase/CouchbaseContainer.java
@@ -356,6 +358,10 @@ protected void configure() {

}

@SuppressWarnings({"EmptyMethod", "UnusedParameters"})
protected void containerIsCreated(String containerId) {
Copy link
Member

Choose a reason for hiding this comment

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

It's actually containerWasCreated, or is it still in process?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The creation is finished. I just named it in the style of the other callbacks containerIsStarted and containerIsStarting.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, was assuming something like this and makes sense to keep the style consistent. Just maybe less clear language.

@@ -556,7 +562,10 @@ public void setWaitStrategy(org.testcontainers.containers.wait.strategy.WaitStra
* @see #waitingFor(org.testcontainers.containers.wait.strategy.WaitStrategy)
*/
protected void waitUntilContainerStarted() {
getWaitStrategy().waitUntilReady(this);
org.testcontainers.containers.wait.strategy.WaitStrategy waitStrategy = getWaitStrategy();
Copy link
Member

Choose a reason for hiding this comment

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

Is the import missing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no, this is the new org.testcontainers.containers.wait.strategy.WaitStrategy which is has a name clash with the deprecated org.testcontainers.containers.wait.WaitStrategy

@@ -1028,8 +1037,8 @@ public void copyFileToContainer(MountableFile mountableLocalFile, String contain
@Override
public void copyFileFromContainer(String containerPath, String destinationPath) throws IOException {

if (!isRunning()) {
throw new IllegalStateException("copyFileToContainer can only be used while the Container is running");
if (!isCreated()) {
Copy link
Member

Choose a reason for hiding this comment

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

Kind of like above, wasCreated() seems more clear.
Would change the exception message accordingly to "after the container was created".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is a public (default) method from ContainerState.java which is only used twice in the project. Still I do not feel comfortable to rename it.

Copy link
Member

Choose a reason for hiding this comment

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

Okay, let's not rename it if we break the public API.

Stream.<Runnable>of(super::stop, proxy::stop, this::stopCluster).parallel().forEach(Runnable::run);
}

private void stopCluster() {
Copy link
Member

Choose a reason for hiding this comment

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

what's the point of it? We're forcibly shutting down the container, isn't it enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This shuts down the state of the sdk. If you have multiple tests with different containers, the CouchbaseContainer will create a new environment and the couchbase sdk even warns that you should always reuse the sdk

11:19:46.345 WARN  com.couchbase.client.core.env.CoreEnvironment - More than 1 Couchbase Environments found (2), this can have severe impact on performance and stability. Reuse environments!

private File copyConfigFromContainer(String containerId) throws IOException {
File tempDirectory = Files.createTempDirectory("testcontainer_" + containerId + "_").toFile();
tempDirectory.deleteOnExit();
File tempFile = new File(tempDirectory, STATIC_CONFIG_NAME);
Copy link
Member

Choose a reason for hiding this comment

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

there is Files.createTempFile()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes but currently the copy to container functionality does not support renaming the file. Therefore we would copy with the wrong file name. A normal rename of the file is not an option as then it is not really tmp. I would have to change the copy code to support renaming.


private void appendPortsToConfig(File tempFile) throws IOException {
for(CouchbasePort port: CouchbasePort.values()) {
if (! port.isBootstrap()) {
Copy link
Member

Choose a reason for hiding this comment

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

code style: no space after !

}

private void appendPortsToConfig(File tempFile) throws IOException {
for(CouchbasePort port: CouchbasePort.values()) {
Copy link
Member

Choose a reason for hiding this comment

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

codestyle: space before :


final int originalPort;

final boolean isBootstrap;
Copy link
Member

Choose a reason for hiding this comment

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

I would rename to dynamic, and also mark MEMCACHED as dynamic (as it was in the previous implementation)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

renaming is fine.

Problem with MEMCACHED is, that when marking them as dynamic, the sdk does not work:

11:26:49.578 WARN  com.couchbase.client.core.endpoint.Endpoint - [localhost:11210][KeyValueEndpoint]: Could not connect to endpoint on reconnect attempt 5, retrying with delay 32 MILLISECONDS: com.couchbase.client.deps.io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: localhost/127.0.0.1:11210
11:26:49.612 WARN  com.couchbase.client.core.endpoint.Endpoint - [localhost:11210][KeyValueEndpoint]: Could not connect to remote socket: Connection refused: localhost/127.0.0.1:11210

It uses the right mapped port for bootstrapping but then discovers the unmapped port from the cluster and then tries to connect to that port and fails with connection refused.

- minor code style and naming improvements
@bsideup bsideup modified the milestones: 1.8.3, next Aug 6, 2018
@bsideup bsideup merged commit 7e99051 into testcontainers:master Aug 7, 2018
@rnorth
Copy link
Member

rnorth commented Sep 10, 2018

We have this out in a Release Candidate build (1.9.0-rc1) for anyone who is keen to try it!

Release notes

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