diff --git a/spring-cloud-function-deployer/src/it/flux/pom.xml b/spring-cloud-function-deployer/src/it/flux/pom.xml new file mode 100644 index 000000000..20d9d76a5 --- /dev/null +++ b/spring-cloud-function-deployer/src/it/flux/pom.xml @@ -0,0 +1,129 @@ + + + 4.0.0 + + com.example + flux-sample + 1.0.0.M1 + jar + + + org.springframework.boot + spring-boot-starter-parent + 2.0.5.RELEASE + + + + + 1.8 + 2.0.0.BUILD-SNAPSHOT + 1.0.15.RELEASE + + + + + org.springframework.cloud + spring-cloud-function-context + ${spring-cloud-function.version} + + + org.springframework.boot + spring-boot-starter + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + exec + + + + org.apache.maven.plugins + maven-dependency-plugin + + + unpack + package + + unpack + + + + + ${project.groupId} + ${project.artifactId} + ${project.version} + exec + + + + + + + + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/libs-snapshot-local + + true + + + false + + + + spring-milestones + Spring Milestones + https://repo.spring.io/libs-milestone-local + + false + + + + spring-releases + Spring Releases + https://repo.spring.io/release + + false + + + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/libs-snapshot-local + + true + + + false + + + + spring-milestones + Spring Milestones + https://repo.spring.io/libs-milestone-local + + false + + + + spring-releases + Spring Releases + https://repo.spring.io/libs-release-local + + false + + + + + diff --git a/spring-cloud-function-deployer/src/it/flux/src/main/java/com/example/functions/FunctionApp.java b/spring-cloud-function-deployer/src/it/flux/src/main/java/com/example/functions/FunctionApp.java new file mode 100644 index 000000000..2c873c706 --- /dev/null +++ b/spring-cloud-function-deployer/src/it/flux/src/main/java/com/example/functions/FunctionApp.java @@ -0,0 +1,67 @@ +/* + * Copyright 2017 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 + * + * http://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 com.example.functions; + +import java.util.function.Function; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; + +import reactor.core.publisher.Flux; + +/** + * @author Dave Syer + */ +@SpringBootApplication +public class FunctionApp { + + @Bean + public Function, Flux> foos() { + return flux -> flux.map(value -> new Foo(value.getValue().toUpperCase())); + } + + public static void main(String[] args) throws Exception { + SpringApplication.run(FunctionApp.class, args); + } +} + +class Foo { + + private String value; + + public Foo() { + } + + public Foo(String value) { + this.value = value; + } + + public String getValue() { + return this.value; + } + + public void setValue(String value) { + this.value = value; + } + + @Override + public String toString() { + return "Foo [value=" + this.value + "]"; + } + +} \ No newline at end of file diff --git a/spring-cloud-function-deployer/src/main/java/org/springframework/cloud/function/deployer/ApplicationBootstrap.java b/spring-cloud-function-deployer/src/main/java/org/springframework/cloud/function/deployer/ApplicationBootstrap.java index 2904b89d8..f9222aabd 100644 --- a/spring-cloud-function-deployer/src/main/java/org/springframework/cloud/function/deployer/ApplicationBootstrap.java +++ b/spring-cloud-function-deployer/src/main/java/org/springframework/cloud/function/deployer/ApplicationBootstrap.java @@ -83,6 +83,10 @@ public class ApplicationBootstrap { } } + public ApplicationRunner getRunner() { + return this.runner; + } + private ApplicationRunner runner(Class mainClass) { if (this.runner == null) { synchronized (this) { diff --git a/spring-cloud-function-deployer/src/test/java/org/springframework/cloud/function/deployer/SpringFunctionFluxConfigurationTests.java b/spring-cloud-function-deployer/src/test/java/org/springframework/cloud/function/deployer/SpringFunctionFluxConfigurationTests.java new file mode 100644 index 000000000..8da1d6e25 --- /dev/null +++ b/spring-cloud-function-deployer/src/test/java/org/springframework/cloud/function/deployer/SpringFunctionFluxConfigurationTests.java @@ -0,0 +1,101 @@ +/* + * Copyright 2017 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 + * + * http://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.cloud.function.deployer; + +import java.util.function.Function; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import org.springframework.boot.SpringBootConfiguration; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.cloud.function.context.FunctionCatalog; + +import static org.assertj.core.api.Assertions.assertThat; + +import reactor.core.publisher.Flux; + +@SpringBootConfiguration +@EnableAutoConfiguration +@EnableFunctionDeployer +public class SpringFunctionFluxConfigurationTests { + + private Object catalog; + + private ApplicationBootstrap bootstrap; + + @Before + public void run() { + if (bootstrap == null) { + bootstrap = new ApplicationBootstrap(); + bootstrap.run(SpringFunctionFluxConfigurationTests.class, + "--function.location=file:target/it/flux/target/dependency", + "--function.bean=foos", + "--function.main=com.example.functions.FunctionApp"); + catalog = bootstrap.getRunner().getBean(FunctionCatalog.class.getName()); + } + } + + @After + public void close() { + if (bootstrap != null) { + bootstrap.close(); + } + } + + // @TestPropertySource(properties = { "", + // "function.main=com.example.functions.FunctionApp" }) + // public static class SourceTests extends SpringFunctionFluxConfigurationTests { + + @Test + public void test() throws Exception { + @SuppressWarnings("unchecked") + Function, Flux> function = (Function, Flux>) bootstrap + .getRunner() + .evaluate("lookup(T(java.util.function.Function), 'function0')", catalog); + assertThat(function.apply(Flux.just(new Foo("foo"))).blockFirst().getValue()) + .isEqualTo("FOO"); + } + +} + +class Foo { + + private String value; + + public Foo() { + } + + public Foo(String value) { + this.value = value; + } + + public String getValue() { + return this.value; + } + + public void setValue(String value) { + this.value = value; + } + + @Override + public String toString() { + return "Foo [value=" + this.value + "]"; + } + +} \ No newline at end of file