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

getServicePort on DockerComposeContainer throws NullPointerException if service instance number in not used. #619

Merged
merged 1 commit into from Mar 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.

### Fixed
- Fixed extraneous insertion of `useSSL=false` in all JDBC URL strings, even for DBs that do not understand it. Usage is now restricted to MySQL by default and can be overridden by authors of `JdbcDatabaseContainer` subclasses ([\#568](https://github.com/testcontainers/testcontainers-java/issues/568))
- Fixed `getServicePort` on `DockerComposeContainer` throws NullPointerException if service instance number in not used. ([\#619](https://github.com/testcontainers/testcontainers-java/issues/619))

### Changed
- Abstracted and changed database init script functionality to support use of SQL-like scripts with non-JDBC connections. ([\#551](https://github.com/testcontainers/testcontainers-java/pull/551))
Expand Down
Expand Up @@ -352,7 +352,7 @@ public String getServiceHost(String serviceName, Integer servicePort) {
* @return a port that can be used for accessing the service container.
*/
public Integer getServicePort(String serviceName, Integer servicePort) {
return ambassadorContainer.getMappedPort(ambassadorPortMappings.get(serviceName).get(servicePort));
return ambassadorContainer.getMappedPort(ambassadorPortMappings.get(getServiceInstanceName(serviceName)).get(servicePort));
}

public SELF withScaledService(String serviceBaseName, int numInstances) {
Expand Down
@@ -1,10 +1,14 @@
package org.testcontainers.junit;

import org.junit.Rule;
import org.junit.Test;
import org.testcontainers.containers.DockerComposeContainer;

import java.io.File;

import static org.rnorth.visibleassertions.VisibleAssertions.assertEquals;
import static org.rnorth.visibleassertions.VisibleAssertions.assertNotNull;

/**
* Created by rnorth on 08/08/2015.
*/
Expand All @@ -20,4 +24,13 @@ public class DockerComposeContainerTest extends BaseDockerComposeTest {
protected DockerComposeContainer getEnvironment() {
return environment;
}

@Test
public void testGetServicePort() {
int serviceWithInstancePort = environment.getServicePort("redis_1", REDIS_PORT);
assertNotNull("Port is set for service with instance number", serviceWithInstancePort);
int serviceWithoutInstancePort = environment.getServicePort("redis", REDIS_PORT);
assertNotNull("Port is set for service with instance number", serviceWithoutInstancePort);
assertEquals("Service ports are the same", serviceWithInstancePort, serviceWithoutInstancePort);
}
}