-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for apachepulsar/pulsar-all image (#9448)
`apachepulsar/pulsar-all` brings connectors in the image.
- Loading branch information
1 parent
7c024ed
commit 4f9594d
Showing
4 changed files
with
113 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
modules/pulsar/src/test/java/org/testcontainers/containers/AbstractPulsar.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package org.testcontainers.containers; | ||
|
||
import org.apache.pulsar.client.admin.ListTopicsOptions; | ||
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; | ||
import org.apache.pulsar.client.api.PulsarClient; | ||
import org.apache.pulsar.client.api.Schema; | ||
import org.apache.pulsar.client.api.SubscriptionInitialPosition; | ||
import org.apache.pulsar.client.api.transaction.Transaction; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class AbstractPulsar { | ||
|
||
public static final String TEST_TOPIC = "test_topic"; | ||
|
||
protected void testPulsarFunctionality(String pulsarBrokerUrl) throws Exception { | ||
try ( | ||
PulsarClient client = PulsarClient.builder().serviceUrl(pulsarBrokerUrl).build(); | ||
Consumer consumer = client.newConsumer().topic(TEST_TOPIC).subscriptionName("test-subs").subscribe(); | ||
Producer<byte[]> producer = client.newProducer().topic(TEST_TOPIC).create() | ||
) { | ||
producer.send("test containers".getBytes()); | ||
CompletableFuture<Message> future = consumer.receiveAsync(); | ||
Message message = future.get(5, TimeUnit.SECONDS); | ||
|
||
assertThat(new String(message.getData())).isEqualTo("test containers"); | ||
} | ||
} | ||
|
||
protected void testTransactionFunctionality(String pulsarBrokerUrl) throws Exception { | ||
try ( | ||
PulsarClient client = PulsarClient.builder().serviceUrl(pulsarBrokerUrl).enableTransaction(true).build(); | ||
Consumer<String> consumer = client | ||
.newConsumer(Schema.STRING) | ||
.topic("transaction-topic") | ||
.subscriptionInitialPosition(SubscriptionInitialPosition.Earliest) | ||
.subscriptionName("test-transaction-sub") | ||
.subscribe(); | ||
Producer<String> producer = client | ||
.newProducer(Schema.STRING) | ||
.sendTimeout(0, TimeUnit.SECONDS) | ||
.topic("transaction-topic") | ||
.create() | ||
) { | ||
final Transaction transaction = client.newTransaction().build().get(); | ||
producer.newMessage(transaction).value("first").send(); | ||
transaction.commit(); | ||
Message<String> message = consumer.receive(); | ||
assertThat(message.getValue()).isEqualTo("first"); | ||
} | ||
} | ||
|
||
protected void assertTransactionsTopicCreated(PulsarAdmin pulsarAdmin) throws PulsarAdminException { | ||
final List<String> topics = pulsarAdmin | ||
.topics() | ||
.getPartitionedTopicList("pulsar/system", ListTopicsOptions.builder().includeSystemTopic(true).build()); | ||
assertThat(topics).contains("persistent://pulsar/system/transaction_coordinator_assign"); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...s/pulsar/src/test/java/org/testcontainers/containers/CompatibleApachePulsarImageTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.testcontainers.containers; | ||
|
||
import org.apache.pulsar.client.admin.PulsarAdmin; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
@RunWith(Parameterized.class) | ||
public class CompatibleApachePulsarImageTest extends AbstractPulsar { | ||
|
||
@Parameterized.Parameters(name = "{0}") | ||
public static String[] params() { | ||
return new String[] { "apachepulsar/pulsar:3.0.0", "apachepulsar/pulsar-all:3.0.0" }; | ||
} | ||
|
||
@Parameterized.Parameter | ||
public String imageName; | ||
|
||
@Test | ||
public void testUsage() throws Exception { | ||
try (PulsarContainer pulsar = new PulsarContainer(DockerImageName.parse(this.imageName));) { | ||
pulsar.start(); | ||
final String pulsarBrokerUrl = pulsar.getPulsarBrokerUrl(); | ||
|
||
testPulsarFunctionality(pulsarBrokerUrl); | ||
} | ||
} | ||
|
||
@Test | ||
public void testTransactions() throws Exception { | ||
try (PulsarContainer pulsar = new PulsarContainer(DockerImageName.parse(this.imageName)).withTransactions();) { | ||
pulsar.start(); | ||
|
||
try (PulsarAdmin pulsarAdmin = PulsarAdmin.builder().serviceHttpUrl(pulsar.getHttpServiceUrl()).build()) { | ||
assertTransactionsTopicCreated(pulsarAdmin); | ||
} | ||
testTransactionFunctionality(pulsar.getPulsarBrokerUrl()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters