forked from spring-cloud/spring-cloud-function
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix compiled scripts demo from README
Compiled functions always show up with no metadata, and you can only guess what the types are from the bean definition. Probably we should add more information to the bean definition if we have it when we compile the function. There is still a problem if user defines functions that are not of Flux<String> (but that has always been the case).
- Loading branch information
Showing
6 changed files
with
108 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
...oud-function-web/src/test/java/org/springframework/cloud/function/web/SingletonTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Copyright 2012-2015 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.web; | ||
|
||
import java.net.URI; | ||
import java.util.function.Supplier; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import org.springframework.beans.BeansException; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; | ||
import org.springframework.beans.factory.support.BeanDefinitionRegistry; | ||
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor; | ||
import org.springframework.beans.factory.support.RootBeanDefinition; | ||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
import org.springframework.boot.context.embedded.LocalServerPort; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; | ||
import org.springframework.boot.test.web.client.TestRestTemplate; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.RequestEntity; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import reactor.core.publisher.Flux; | ||
|
||
/** | ||
* @author Dave Syer | ||
* | ||
*/ | ||
@RunWith(SpringRunner.class) | ||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) | ||
public class SingletonTests { | ||
|
||
@LocalServerPort | ||
private int port; | ||
@Autowired | ||
private TestRestTemplate rest; | ||
|
||
@Test | ||
public void words() throws Exception { | ||
ResponseEntity<String> result = rest.exchange( | ||
RequestEntity.get(new URI("/words")).build(), String.class); | ||
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK); | ||
assertThat(result.getBody()).isEqualTo("[\"foo\",\"bar\"]"); | ||
} | ||
|
||
@EnableAutoConfiguration | ||
@org.springframework.boot.test.context.TestConfiguration | ||
protected static class TestConfiguration { | ||
@Bean | ||
public static BeanDefinitionRegistryPostProcessor processor() { | ||
return new BeanDefinitionRegistryPostProcessor() { | ||
|
||
@Override | ||
public void postProcessBeanFactory( | ||
ConfigurableListableBeanFactory beanFactory) | ||
throws BeansException { | ||
} | ||
|
||
@Override | ||
public void postProcessBeanDefinitionRegistry( | ||
BeanDefinitionRegistry registry) throws BeansException { | ||
// Simulates what happens whem you add a compiled function | ||
RootBeanDefinition beanDefinition = new RootBeanDefinition(MySupplier.class); | ||
registry.registerBeanDefinition("words", beanDefinition); | ||
} | ||
}; | ||
} | ||
} | ||
|
||
static class MySupplier implements Supplier<Flux<String>> { | ||
@Override | ||
public Flux<String> get() { | ||
return Flux.just("foo", "bar"); | ||
} | ||
} | ||
} |