Skip to content

Commit

Permalink
Fixed getServicePort on DockerComposeContainer throws NullPointerExce…
Browse files Browse the repository at this point in the history
…ption if service instance number in not used. (#619)
  • Loading branch information
barrycommins authored and rnorth committed Mar 26, 2018
1 parent 56ffbfd commit 37456ae
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
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);
}
}

0 comments on commit 37456ae

Please sign in to comment.