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

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

Source:PulsarContainerTest.java Github

copy

Full Screen

...95 .contains("persistent://pulsar/system/transaction_coordinator_assign-partition-0")96 )97 .isTrue();98 }99 testTransactionFunctionality(pulsar.getPulsarBrokerUrl());100 }101 }102 @Test103 public void testTransactionsAndFunctionsWorker() throws Exception {104 try (PulsarContainer pulsar = new PulsarContainer(PULSAR_IMAGE).withTransactions().withFunctionsWorker()) {105 pulsar.start();106 try (PulsarAdmin pulsarAdmin = PulsarAdmin.builder().serviceHttpUrl(pulsar.getHttpServiceUrl()).build();) {107 assertThat(108 pulsarAdmin109 .topics()110 .getList("pulsar/system")111 .contains("persistent://pulsar/system/transaction_coordinator_assign-partition-0")112 )113 .isTrue();114 assertThat(pulsarAdmin.functions().getFunctions("public", "default")).hasSize(0);115 }116 testTransactionFunctionality(pulsar.getPulsarBrokerUrl());117 }118 }119 @Test120 public void testClusterFullyInitialized() throws Exception {121 try (PulsarContainer pulsar = new PulsarContainer(PULSAR_IMAGE)) {122 pulsar.start();123 try (PulsarAdmin pulsarAdmin = PulsarAdmin.builder().serviceHttpUrl(pulsar.getHttpServiceUrl()).build()) {124 assertThat(pulsarAdmin.clusters().getClusters()).hasSize(1).contains("standalone");125 }126 }127 }128 @Test129 public void testStartupTimeoutIsHonored() {130 try (PulsarContainer pulsar = new PulsarContainer(PULSAR_IMAGE).withStartupTimeout(Duration.ZERO)) {131 assertThatThrownBy(pulsar::start)132 .hasRootCauseMessage("Precondition failed: timeout must be greater than zero");133 }134 }135 protected void testPulsarFunctionality(String pulsarBrokerUrl) throws Exception {136 try (137 PulsarClient client = PulsarClient.builder().serviceUrl(pulsarBrokerUrl).build();138 Consumer consumer = client.newConsumer().topic(TEST_TOPIC).subscriptionName("test-subs").subscribe();139 Producer<byte[]> producer = client.newProducer().topic(TEST_TOPIC).create()140 ) {141 producer.send("test containers".getBytes());142 CompletableFuture<Message> future = consumer.receiveAsync();143 Message message = future.get(5, TimeUnit.SECONDS);144 assertThat(new String(message.getData())).isEqualTo("test containers");145 }146 }147 protected void testTransactionFunctionality(String pulsarBrokerUrl) throws Exception {148 try (149 PulsarClient client = PulsarClient.builder().serviceUrl(pulsarBrokerUrl).enableTransaction(true).build();150 Consumer<String> consumer = client151 .newConsumer(Schema.STRING)152 .topic("transaction-topic")153 .subscriptionInitialPosition(SubscriptionInitialPosition.Earliest)154 .subscriptionName("test-transaction-sub")155 .subscribe();156 Producer<String> producer = client157 .newProducer(Schema.STRING)158 .sendTimeout(0, TimeUnit.SECONDS)159 .topic("transaction-topic")160 .create()161 ) {...

Full Screen

Full Screen

testTransactionFunctionality

Using AI Code Generation

copy

Full Screen

1public void testTransactionFunctionality() throws Exception {2 PulsarContainer pulsarContainer = new PulsarContainer();3 pulsarContainer.start();4 String serviceUrl = pulsarContainer.getContainerIpAddress() + ":" + pulsarContainer.getMappedPort(6650);5 String adminUrl = pulsarContainer.getContainerIpAddress() + ":" + pulsarContainer.getMappedPort(8080);6 PulsarClient client = PulsarClient.builder()7 .serviceUrl(serviceUrl)8 .build();9 PulsarAdmin admin = PulsarAdmin.builder()10 .serviceHttpUrl(adminUrl)11 .build();12 admin.topics().createNonPartitionedTopic(topicName);13 Producer<byte[]> producer = client.newProducer()14 .topic(topicName)15 .enableBatching(false)16 .create();17 Transaction txn = client.newTransaction()18 .withTransactionTimeout(30, TimeUnit.SECONDS)19 .build()20 .get();21 producer.newMessage(txn).value("test".getBytes()).send();22 txn.commit().get();23 try (Consumer<byte[]> consumer = client.newConsumer()24 .topic(topicName)25 .subscriptionName("sub")26 .subscriptionType(SubscriptionType.Exclusive)27 .subscribe()) {28 Message<byte[]> message = consumer.receive();29 assertEquals("test", new String(message.getValue()));30 }31 client.close();32 admin.close();33 pulsarContainer.close();34}

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