Skip to content

Method to enable functions worker in pulsar container #2711

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

Merged
merged 6 commits into from
Jun 30, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modules/pulsar/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ dependencies {

testCompile group: 'org.apache.pulsar', name: 'pulsar-client', version: '2.5.1'
testCompile group: 'org.assertj', name: 'assertj-core', version: '3.16.1'
testCompile group: 'org.apache.pulsar', name: 'pulsar-client-admin', version: '2.5.1'
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.testcontainers.containers;

import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.containers.wait.strategy.WaitAllStrategy;
import org.testcontainers.utility.TestcontainersConfiguration;

/**
Expand All @@ -14,6 +15,8 @@ public class PulsarContainer extends GenericContainer<PulsarContainer> {

private static final String PULSAR_VERSION = "2.2.0";

private boolean functionsWorkerEnabled = false;

public PulsarContainer() {
this(PULSAR_VERSION);
}
Expand All @@ -25,6 +28,25 @@ public PulsarContainer(String pulsarVersion) {
waitingFor(Wait.forHttp(METRICS_ENDPOINT).forStatusCode(200).forPort(BROKER_HTTP_PORT));
}

@Override
protected void configure() {
super.configure();

if (functionsWorkerEnabled) {
withCommand("/pulsar/bin/pulsar", "standalone");
waitingFor(
new WaitAllStrategy()
.withStrategy(waitStrategy)
.withStrategy(Wait.forLogMessage(".*Function worker service started.*", 1))
);
}
}

public PulsarContainer withFunctionsWorker() {
functionsWorkerEnabled = true;
return this;
}

public String getPulsarBrokerUrl() {
return String.format("pulsar://%s:%s", getContainerIpAddress(), getMappedPort(BROKER_PORT));
}
Expand All @@ -33,4 +55,3 @@ public String getHttpServiceUrl() {
return String.format("http://%s:%s", getContainerIpAddress(), getMappedPort(BROKER_HTTP_PORT));
}
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.testcontainers.containers;

import org.apache.pulsar.client.admin.PulsarAdmin;
import org.apache.pulsar.client.admin.PulsarAdminException;
import org.apache.pulsar.client.api.Consumer;
import org.apache.pulsar.client.api.Message;
import org.apache.pulsar.client.api.Producer;
Expand All @@ -10,6 +12,7 @@
import java.util.concurrent.TimeUnit;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

public class PulsarContainerTest {

Expand All @@ -23,6 +26,33 @@ public void testUsage() throws Exception {
}
}

@Test
public void shouldNotEnableFunctionsWorkerByDefault() throws Exception {
try (PulsarContainer pulsar = new PulsarContainer("2.5.1")) {
pulsar.start();

PulsarAdmin pulsarAdmin = PulsarAdmin.builder()
.serviceHttpUrl(pulsar.getHttpServiceUrl())
.build();

assertThatThrownBy(() -> pulsarAdmin.functions().getFunctions("public", "default"))
.isInstanceOf(PulsarAdminException.class);
}
}

@Test
public void shouldWaitForFunctionsWorkerStarted() throws Exception {
try (PulsarContainer pulsar = new PulsarContainer("2.5.1").withFunctionsWorker()) {
pulsar.start();

PulsarAdmin pulsarAdmin = PulsarAdmin.builder()
.serviceHttpUrl(pulsar.getHttpServiceUrl())
.build();

assertThat(pulsarAdmin.functions().getFunctions("public", "default")).hasSize(0);
}
}

protected void testPulsarFunctionality(String pulsarBrokerUrl) throws Exception {

try (
Expand Down