From 4a10825cfa9fc770b48f4168c0ecc7a73ce900d4 Mon Sep 17 00:00:00 2001 From: Soby Chacko Date: Fri, 20 Jan 2023 10:54:57 -0500 Subject: [PATCH] Pulsar binder basic integ test (#279) * Pulsar binder basic integ test * PR review --- .../build.gradle | 4 + .../binder/PulsarBinderIntegrationTests.java | 77 +++++++++++++++++++ .../stream/binder/PulsarBinderTests.java | 28 ------- 3 files changed, 81 insertions(+), 28 deletions(-) create mode 100644 spring-pulsar-spring-cloud-stream-binder/src/test/java/org/springframework/pulsar/spring/cloud/stream/binder/PulsarBinderIntegrationTests.java delete mode 100644 spring-pulsar-spring-cloud-stream-binder/src/test/java/org/springframework/pulsar/spring/cloud/stream/binder/PulsarBinderTests.java diff --git a/spring-pulsar-spring-cloud-stream-binder/build.gradle b/spring-pulsar-spring-cloud-stream-binder/build.gradle index 9891c643..46f16da7 100644 --- a/spring-pulsar-spring-cloud-stream-binder/build.gradle +++ b/spring-pulsar-spring-cloud-stream-binder/build.gradle @@ -10,6 +10,10 @@ dependencies { exclude group: 'javax.activation', module: 'javax.activation-api' exclude group: 'javax.annotation', module: 'javax.annotation-api' } + testImplementation project(':spring-pulsar-test') testImplementation 'org.springframework.boot:spring-boot-starter-test' + testImplementation 'org.awaitility:awaitility' + testImplementation 'org.testcontainers:junit-jupiter' + testImplementation 'org.testcontainers:pulsar' } diff --git a/spring-pulsar-spring-cloud-stream-binder/src/test/java/org/springframework/pulsar/spring/cloud/stream/binder/PulsarBinderIntegrationTests.java b/spring-pulsar-spring-cloud-stream-binder/src/test/java/org/springframework/pulsar/spring/cloud/stream/binder/PulsarBinderIntegrationTests.java new file mode 100644 index 00000000..edec4593 --- /dev/null +++ b/spring-pulsar-spring-cloud-stream-binder/src/test/java/org/springframework/pulsar/spring/cloud/stream/binder/PulsarBinderIntegrationTests.java @@ -0,0 +1,77 @@ +/* + * Copyright 2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.pulsar.spring.cloud.stream.binder; + +import java.time.Duration; +import java.util.function.Consumer; +import java.util.function.Supplier; + +import org.awaitility.Awaitility; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.SpringBootConfiguration; +import org.springframework.boot.WebApplicationType; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.system.CapturedOutput; +import org.springframework.boot.test.system.OutputCaptureExtension; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.pulsar.test.support.PulsarTestContainerSupport; + +/** + * @author Soby Chacko + */ +@ExtendWith(OutputCaptureExtension.class) +class PulsarBinderIntegrationTests implements PulsarTestContainerSupport { + + @Test + void basicProducerConsumerBindingEndToEnd(CapturedOutput output) { + SpringApplication app = new SpringApplication(BasicScenarioConfig.class); + app.setWebApplicationType(WebApplicationType.NONE); + try (ConfigurableApplicationContext context = app.run( + "--spring.pulsar.client.service-url=" + PulsarTestContainerSupport.getPulsarBrokerUrl(), + "--spring.cloud.function.definition=textSupplier;textLogger", + "--spring.cloud.stream.bindings.textLogger-in-0.destination=textSupplier-out-0", + "--spring.cloud.stream.pulsar.bindings.textLogger-in-0.consumer.subscription-name=basic-scenario-sub-1")) { + Awaitility.await().atMost(Duration.ofSeconds(10)) + .until(() -> output.toString().contains("Hello binder: test-basic-scenario")); + } + } + + @EnableAutoConfiguration + @SpringBootConfiguration + static class BasicScenarioConfig { + + private final Logger logger = LoggerFactory.getLogger(BasicScenarioConfig.class); + + @Bean + public Supplier textSupplier() { + return () -> "test-basic-scenario"; + } + + @Bean + public Consumer textLogger() { + return s -> this.logger.info("Hello binder: " + s); + } + + } + +} diff --git a/spring-pulsar-spring-cloud-stream-binder/src/test/java/org/springframework/pulsar/spring/cloud/stream/binder/PulsarBinderTests.java b/spring-pulsar-spring-cloud-stream-binder/src/test/java/org/springframework/pulsar/spring/cloud/stream/binder/PulsarBinderTests.java deleted file mode 100644 index f555e4e5..00000000 --- a/spring-pulsar-spring-cloud-stream-binder/src/test/java/org/springframework/pulsar/spring/cloud/stream/binder/PulsarBinderTests.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2023 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.pulsar.spring.cloud.stream.binder; - -import org.junit.jupiter.api.Test; - -public class PulsarBinderTests { - - @Test - void testBasicBinding() { - - } - -}