How to use testPulsarFunctionality method of org.testcontainers.containers.PulsarContainerTest class

Best Testcontainers-java code snippet using org.testcontainers.containers.PulsarContainerTest.testPulsarFunctionality

Source:PulsarContainerTest.java Github

copy

Full Screen

...27 @Test28 public void testUsage() throws Exception {29 try (PulsarContainer pulsar = new PulsarContainer(PULSAR_IMAGE)) {30 pulsar.start();31 testPulsarFunctionality(pulsar.getPulsarBrokerUrl());32 }33 }34 @Test35 public void shouldNotEnableFunctionsWorkerByDefault() throws Exception {36 try (PulsarContainer pulsar = new PulsarContainer(PULSAR_IMAGE)) {37 pulsar.start();38 PulsarAdmin pulsarAdmin = PulsarAdmin.builder()39 .serviceHttpUrl(pulsar.getHttpServiceUrl())40 .build();41 assertThrows(PulsarAdminException.class, () -> pulsarAdmin.functions().getFunctions("public", "default"));42 }43 }44 @Test45 public void shouldWaitForFunctionsWorkerStarted() throws Exception {46 try (PulsarContainer pulsar = new PulsarContainer(PULSAR_IMAGE).withFunctionsWorker()) {47 pulsar.start();48 PulsarAdmin pulsarAdmin = PulsarAdmin.builder()49 .serviceHttpUrl(pulsar.getHttpServiceUrl())50 .build();51 int s = pulsarAdmin.functions().getFunctions("public", "default").size();52 assertEquals(s, 0);53 }54 }55 protected void testPulsarFunctionality(String pulsarBrokerUrl) throws Exception {56 try (57 PulsarClient client = PulsarClient.builder()58 .serviceUrl(pulsarBrokerUrl)59 .build();60 Consumer consumer = client.newConsumer()61 .topic(TEST_TOPIC)62 .subscriptionName("test-subs")63 .subscribe();64 Producer<byte[]> producer = client.newProducer()65 .topic(TEST_TOPIC)66 .create()67 ) {68 producer.send("test containers".getBytes());69 CompletableFuture<Message> future = consumer.receiveAsync();...

Full Screen

Full Screen

testPulsarFunctionality

Using AI Code Generation

copy

Full Screen

1package org.testcontainers.containers;2import org.apache.pulsar.client.admin.PulsarAdmin;3import org.apache.pulsar.client.admin.PulsarAdminException;4import org.apache.pulsar.client.api.Consumer;5import org.apache.pulsar.client.api.Message;6import org.apache.pulsar.client.api.Producer;7import org.apache.pulsar.client.api.PulsarClient;8import org.apache.pulsar.client.api.PulsarClientException;9import org.apache.pulsar.client.api.SubscriptionType;10import org.apache.pulsar.common.policies.data.TenantInfo;11import org.apache.pulsar.common.policies.data.TopicStats;12import org.junit.Test;13import org.testcontainers.containers.output.Slf4jLogConsumer;14import java.util.concurrent.TimeUnit;15import static org.assertj.core.api.Assertions.assertThat;16public class PulsarContainerTest {17 public void testPulsarFunctionality() throws PulsarClientException, PulsarAdminException, InterruptedException {18 try (PulsarContainer pulsarContainer = new PulsarContainer()) {19 pulsarContainer.start();20 pulsarContainer.followOutput(new Slf4jLogConsumer(PulsarContainerTest.class));21 String tenant = "tenant";22 TenantInfo tenantInfo = new TenantInfo();23 tenantInfo.setAllowedClusters("standalone");24 try (PulsarAdmin admin = pulsarContainer.getAdminClient()) {25 admin.tenants().createTenant(tenant, tenantInfo);26 }27 String namespace = "namespace";28 try (PulsarAdmin admin = pulsarContainer.getAdminClient()) {29 admin.namespaces().createNamespace(tenant + "/" + namespace);30 }31 String topic = "topic";32 try (PulsarAdmin admin = pulsarContainer.getAdminClient()) {33 admin.topics().createNonPartitionedTopic(tenant + "/" + namespace + "/" + topic);34 }35 String message = "Hello world!";36 try (PulsarClient client = pulsarContainer.getPulsarClient()) {37 Producer<byte[]> producer = client.newProducer()38 .topic(tenant + "/" + namespace + "/" + topic)39 .create();40 producer.send(message.getBytes());41 }42 try (PulsarClient client = puls

Full Screen

Full Screen

testPulsarFunctionality

Using AI Code Generation

copy

Full Screen

1package org.testcontainers.containers;2import org.junit.Test;3import org.testcontainers.utility.DockerImageName;4import static org.junit.Assert.assertEquals;5public class PulsarContainerTest {6 public void testPulsarFunctionality() {7 try (PulsarContainer pulsarContainer = new PulsarContainer(DockerImageName.parse("apachepulsar/pulsar:2.7.2"))) {8 pulsarContainer.start();9 pulsarContainer.createTenant("my-tenant", "my-namespace");10 pulsarContainer.createTopic("my-tenant/my-namespace/my-topic");11 }12 }13}

Full Screen

Full Screen

testPulsarFunctionality

Using AI Code Generation

copy

Full Screen

1 [INFO] [INFO] --- maven-compiler-plugin:3.8.0:testCompile (default-testCompile) @ pulsar --- 2 [INFO] [INFO] --- maven-surefire-plugin:2.22.1:test (default-test) @ pulsar --- 3 [INFO] [INFO] --- maven-jar-plugin:3.1.0:jar (default-jar) @ pulsar --- 4 [INFO] [INFO] --- maven-install-plugin:2.4:install (default-install) @ pulsar --- 5 [INFO] [INFO] --- maven-failsafe-plugin:2.22.1:integration-test (default) @ pulsar --- 6 [INFO] [INFO] --- maven-failsafe-plugin:2.22.1:verify (default) @ pulsar ---

Full Screen

Full Screen

testPulsarFunctionality

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.containers.PulsarContainer;2import org.testcontainers.containers.output.Slf4jLogConsumer;3import org.testcontainers.utility.DockerImageName;4import java.io.IOException;5import java.util.concurrent.TimeUnit;6import static org.testcontainers.containers.PulsarContainer.*;7@Slf4jLogConsumer logConsumer = new Slf4jLogConsumer(log);8PulsarContainer pulsarContainer = new PulsarContainer(DockerImageName.parse("apachepulsar/pulsar:2.8.0"))9 .withLogConsumer(logConsumer)10 .withStartupAttempts(3)11 .withStartupTimeout(Duration.ofMinutes(5))12 .withEnv("PULSAR_MEM", "-Xms1g -Xmx1g -XX:MaxDirectMemorySize=1g")13 .withEnv("PULSAR_EXTRA_OPTS", "-Dpulsar.function.logTopicEnabled=true")14 .withEnv("PULSAR_LOGS_DIR", "/pulsar/logs")15 .withEnv("PULSAR_LOGS_FILE_MAX_SIZE", "1GB")16 .withEnv("PULSAR_LOGS_MAX_INDEX", "10")17 .withEnv("PULSAR_LOGS_MAX_TOTAL_SIZE", "10GB")18 .withCommand("bin/pulsar", "standalone")19 .withFileSystemBind("src/test/resources", "/pulsar/conf", BindMode.READ_ONLY)20 .withFileSystemBind("src/test/resources/functions", "/pulsar/functions", BindMode.READ_ONLY)21 .withFileSystemBind("src/test/resources/connectors", "/pulsar/connectors", BindMode.READ_ONLY)22 .withFileSystemBind("src/test/resources/standalone.conf", "/pulsar/conf/standalone.conf", BindMode.READ_ONLY)23 .withFileSystemBind("src/test/resources/functions_worker.yml", "/pulsar/conf/functions_worker.yml", BindMode.READ_ONLY)24 .withFileSystemBind("src/test/resources/functions_worker.yml", "/pulsar/conf/functions_worker.yml", BindMode.READ_ONLY)25 .withFileSystemBind("src/test/resources/log4j2.yaml", "/pulsar/conf/log4j2.yaml", BindMode.READ_ONLY)26 .withFileSystemBind("src/test/resources/log4j2.yaml", "/pulsar/conf/log4j2

Full Screen

Full Screen

testPulsarFunctionality

Using AI Code Generation

copy

Full Screen

1package org.testcontainers.containers;2import org.apache.pulsar.client.api.Consumer;3import org.apache.pulsar.client.api.Message;4import org.apache.pulsar.client.api.MessageId;5import org.apache.pulsar.client.api.MessageRouter;6import org.apache.pulsar.client.api.Producer;7import org.apache.pulsar.client.api.PulsarClient;8import org.apache.pulsar.client.api.Schema;9import org.apache.pulsar.client.api.SubscriptionType;10import org.apache.pulsar.client.impl.schema.JSONSchema;11import org.junit.Test;12import java.util.concurrent.TimeUnit;13import static java.nio.charset.StandardCharsets.UTF_8;14import static org.junit.Assert.assertEquals;15import static org.junit.Assert.assertNotNull;16import static org.junit.Assert.assertNull;17public class PulsarContainerTest {18 public void testPulsarFunctionality() throws Exception {19 try (PulsarContainer pulsarContainer = new PulsarContainer()) {20 pulsarContainer.start();21 String serviceUrl = pulsarContainer.getPlainTextPulsarBrokerUrl();22 String adminUrl = pulsarContainer.getHttpServiceUrl();23 try (PulsarClient client = PulsarClient.builder()24 .serviceUrl(serviceUrl)25 .build()) {26 try (Producer<byte[]> producer = client.newProducer(Schema.BYTES)27 .topic(topic)28 .create()) {29 MessageId messageId = producer.send("test-message".getBytes(UTF_8));30 assertNotNull(messageId);31 }32 try (Consumer<byte[]> consumer = client.newConsumer(Schema.BYTES)33 .topic(topic)34 .subscriptionType(SubscriptionType.Exclusive)35 .subscriptionName("test-subscription")36 .subscribe()) {37 Message<byte[]> message = consumer.receive(1, TimeUnit.SECONDS);38 assertNotNull(message);39 assertEquals("test-message", new String(message.getValue(), UTF_8));40 consumer.acknowledge(message);41 }42 }

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful