Search in sources :

Example 1 with BindingsLifecycleController

use of org.springframework.cloud.stream.binding.BindingsLifecycleController in project spring-cloud-stream by spring-cloud.

the class ImplicitFunctionBindingTests method testBindingControl.

@SuppressWarnings({ "rawtypes" })
@Test
public void testBindingControl() {
    try (ConfigurableApplicationContext context = new SpringApplicationBuilder(TestChannelBinderConfiguration.getCompleteConfiguration(SendToDestinationConfiguration.class)).web(WebApplicationType.NONE).run("--spring.jmx.enabled=false")) {
        BindingsLifecycleController ctrl = context.getBean(BindingsLifecycleController.class);
        Binding input = ctrl.queryState("echo-in-0");
        Binding output = ctrl.queryState("echo-out-0");
        assertThat(input.isRunning()).isTrue();
        ctrl.changeState("echo-in-0", State.STOPPED);
        assertThat(input.isRunning()).isFalse();
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) Binding(org.springframework.cloud.stream.binder.Binding) BindingsLifecycleController(org.springframework.cloud.stream.binding.BindingsLifecycleController) SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) Test(org.junit.jupiter.api.Test)

Example 2 with BindingsLifecycleController

use of org.springframework.cloud.stream.binding.BindingsLifecycleController in project spring-cloud-stream by spring-cloud.

the class ActuatorBindingsTest method test_2253.

/*
	 * Even though this test performs some simple assertions, the main purpose for it is to validate that
	 * it does not result in recursive exception described in https://github.com/spring-cloud/spring-cloud-stream/issues/2253
	 */
@Test
public void test_2253() {
    try (ConfigurableApplicationContext context = new SpringApplicationBuilder(TestChannelBinderConfiguration.getCompleteConfiguration(Bindings.class)).web(WebApplicationType.NONE).run("--spring.jmx.enabled=false", "--spring.cloud.function.definition=consume", // see https://github.com/spring-cloud/spring-cloud-stream/issues/2253
    "--spring.jackson.visibility.field=ANY")) {
        BindingsLifecycleController controller = context.getBean(BindingsLifecycleController.class);
        List<Map<?, ?>> bindings = controller.queryStates();
        assertThat(bindings.size()).isEqualTo(1);
        assertThat(bindings.get(0).get("bindingName")).isEqualTo("consume-in-0");
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) BindingsLifecycleController(org.springframework.cloud.stream.binding.BindingsLifecycleController) SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 3 with BindingsLifecycleController

use of org.springframework.cloud.stream.binding.BindingsLifecycleController in project spring-cloud-stream by spring-cloud.

the class ImplicitFunctionBindingTests method testDisableAutodetect.

@SuppressWarnings({ "rawtypes" })
@Test
public void testDisableAutodetect() {
    try (ConfigurableApplicationContext context = new SpringApplicationBuilder(TestChannelBinderConfiguration.getCompleteConfiguration(SendToDestinationConfiguration.class)).web(WebApplicationType.NONE).run("--spring.jmx.enabled=false", "--spring.cloud.stream.function.autodetect=false")) {
        BindingsLifecycleController ctrl = context.getBean(BindingsLifecycleController.class);
        Binding input = ctrl.queryState("echo-in-0");
        Binding output = ctrl.queryState("echo-out-0");
        assertThat(input).isNull();
        assertThat(output).isNull();
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) Binding(org.springframework.cloud.stream.binder.Binding) BindingsLifecycleController(org.springframework.cloud.stream.binding.BindingsLifecycleController) SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)3 SpringApplicationBuilder (org.springframework.boot.builder.SpringApplicationBuilder)3 BindingsLifecycleController (org.springframework.cloud.stream.binding.BindingsLifecycleController)3 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)3 Binding (org.springframework.cloud.stream.binder.Binding)2 Map (java.util.Map)1