Pulsar binder basic integ test (#279)

* Pulsar binder basic integ test

* PR review
This commit is contained in:
Soby Chacko
2023-01-20 10:54:57 -05:00
committed by GitHub
parent 31dd9ed0d4
commit 4a10825cfa
3 changed files with 81 additions and 28 deletions

View File

@@ -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'
}

View File

@@ -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<String> textSupplier() {
return () -> "test-basic-scenario";
}
@Bean
public Consumer<String> textLogger() {
return s -> this.logger.info("Hello binder: " + s);
}
}
}

View File

@@ -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() {
}
}