Skip to content

Commit 84b1c3a

Browse files
authored
Add getHttpPort and getGrpcPort methods in WeaviateContainer (#11712)
1 parent a412b8e commit 84b1c3a

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

modules/weaviate/src/main/java/org/testcontainers/weaviate/WeaviateContainer.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
*/
1818
public class WeaviateContainer extends GenericContainer<WeaviateContainer> {
1919

20+
private static final int HTTP_PORT = 8080;
21+
22+
private static final int GRPC_PORT = 50051;
23+
2024
private static final DockerImageName DEFAULT_WEAVIATE_IMAGE = DockerImageName.parse(
2125
"cr.weaviate.io/semitechnologies/weaviate"
2226
);
@@ -30,17 +34,25 @@ public WeaviateContainer(String dockerImageName) {
3034
public WeaviateContainer(DockerImageName dockerImageName) {
3135
super(dockerImageName);
3236
dockerImageName.assertCompatibleWith(DEFAULT_WEAVIATE_IMAGE, DOCKER_HUB_WEAVIATE_IMAGE);
33-
withExposedPorts(8080, 50051);
37+
withExposedPorts(HTTP_PORT, GRPC_PORT);
3438
withEnv("AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED", "true");
3539
withEnv("PERSISTENCE_DATA_PATH", "/var/lib/weaviate");
36-
waitingFor(Wait.forHttp("/v1/.well-known/ready").forPort(8080).forStatusCode(200));
40+
waitingFor(Wait.forHttp("/v1/.well-known/ready").forPort(HTTP_PORT).forStatusCode(200));
3741
}
3842

3943
public String getHttpHostAddress() {
40-
return getHost() + ":" + getMappedPort(8080);
44+
return getHost() + ":" + getHttpPort();
45+
}
46+
47+
public Integer getHttpPort() {
48+
return getMappedPort(HTTP_PORT);
4149
}
4250

4351
public String getGrpcHostAddress() {
44-
return getHost() + ":" + getMappedPort(50051);
52+
return getHost() + ":" + getGrpcPort();
53+
}
54+
55+
public Integer getGrpcPort() {
56+
return getMappedPort(GRPC_PORT);
4557
}
4658
}

modules/weaviate/src/test/java/org/testcontainers/weaviate/WeaviateContainerTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ void testWeaviate() throws Exception {
2626
return conn
2727
.scheme("http")
2828
.httpHost(weaviate.getHost())
29-
.httpPort(weaviate.getMappedPort(8080))
29+
.httpPort(weaviate.getHttpPort())
3030
.grpcHost(weaviate.getHost())
31-
.grpcPort(weaviate.getMappedPort(50051));
31+
.grpcPort(weaviate.getGrpcPort());
3232
})
3333
) {
3434
InstanceMetadata meta = client.meta();
@@ -56,9 +56,9 @@ void testWeaviateWithModules() throws Exception {
5656
return conn
5757
.scheme("http")
5858
.httpHost(weaviate.getHost())
59-
.httpPort(weaviate.getMappedPort(8080))
59+
.httpPort(weaviate.getHttpPort())
6060
.grpcHost(weaviate.getHost())
61-
.grpcPort(weaviate.getMappedPort(50051));
61+
.grpcPort(weaviate.getGrpcPort());
6262
})
6363
) {
6464
InstanceMetadata meta = client.meta();

0 commit comments

Comments
 (0)