@Test public void testConcurrentRegistration() throws InterruptedException { ExecutorService executorService = Executors.newCachedThreadPool(); List<IntegrationFlowRegistration> flowRegistrations = new CopyOnWriteArrayList<>(); AtomicBoolean exceptionHappened = new AtomicBoolean(); for (int i = 0; i < 100; i++) { int index = i; executorService.execute(() -> { IntegrationFlow flow = f -> f .transform(m -> m); try { IntegrationFlowContext.IntegrationFlowRegistrationBuilder registration = this.integrationFlowContext.registration(flow); if (index % 2 == 0) { registration.id("concurrentFlow#" + index); } flowRegistrations.add(registration.register()); } catch (Exception e) { exceptionHappened.set(true); } }); } executorService.shutdownNow(); assertTrue(executorService.awaitTermination(10, TimeUnit.SECONDS)); assertFalse(exceptionHappened.get()); flowRegistrations.forEach(IntegrationFlowRegistration::destroy); }
@Test void testRuntimeBeanRegistration(@Autowired IntegrationFlowContext context) throws Exception { Set<ObjectName> query = this.server.queryNames(new ObjectName("dsl:type=MessageChannel,*"), null); assertThat(query).hasSize(3); query = this.server.queryNames(new ObjectName("dsl:type=MessageHandler,*"), null); assertThat(query).hasSize(2); query = this.server.queryNames(new ObjectName("dsl:type=MessageSource,*"), null); assertThat(query).hasSize(0); IntegrationFlow dynamicFlow = IntegrationFlows.from(() -> "foo", e -> e.poller(p -> p.fixedDelay(1000))) .channel("channelTwo") .nullChannel(); IntegrationFlowContext.IntegrationFlowRegistration registration = context.registration(dynamicFlow) .id("dynamic") .register(); query = this.server.queryNames(new ObjectName("dsl:type=MessageChannel,*"), null); assertThat(query).hasSize(4); query = this.server.queryNames(new ObjectName("dsl:type=MessageHandler,*"), null); assertThat(query).hasSize(3); query = this.server.queryNames(new ObjectName("dsl:type=MessageSource,*"), null); assertThat(query).hasSize(1); registration.destroy(); query = this.server.queryNames(new ObjectName("dsl:type=MessageChannel,*"), null); assertThat(query).hasSize(3); query = this.server.queryNames(new ObjectName("dsl:type=MessageHandler,*"), null); assertThat(query).hasSize(2); query = this.server.queryNames(new ObjectName("dsl:type=MessageSource,*"), null); assertThat(query).hasSize(0); }
@Test public void testRegistrationDuplicationRejected() { String testId = "testId"; StandardIntegrationFlow testFlow = IntegrationFlows.from(Supplier.class) .get(); IntegrationFlowRegistration flowRegistration = this.integrationFlowContext .registration(testFlow) .id(testId) .register(); try { this.integrationFlowContext .registration(testFlow) .id(testId) .register(); } catch (Exception e) { assertThat(e, instanceOf(IllegalArgumentException.class)); assertThat(e.getMessage(), containsString("with flowId '" + testId + "' is already registered.")); } flowRegistration.destroy(); }
private void register(IntegrationFlowRegistrationBuilder builder) { IntegrationFlow integrationFlow = builder.integrationFlowRegistration.getIntegrationFlow(); String flowId = builder.integrationFlowRegistration.getId(); if (flowId == null) { flowId = generateBeanName(integrationFlow, null); builder.id(flowId); } IntegrationFlow theFlow = (IntegrationFlow) registerBean(integrationFlow, flowId, null); builder.integrationFlowRegistration.setIntegrationFlow(theFlow); for (Map.Entry<Object, String> entry : builder.additionalBeans.entrySet()) { registerBean(entry.getKey(), entry.getValue(), flowId); } if (builder.autoStartup) { builder.integrationFlowRegistration.start(); } this.registry.put(flowId, builder.integrationFlowRegistration); }
private void register(IntegrationFlowRegistrationBuilder builder) { IntegrationFlow integrationFlow = builder.integrationFlowRegistration.getIntegrationFlow(); String flowId = builder.integrationFlowRegistration.getId(); if (flowId == null) { flowId = generateBeanName(integrationFlow, null); builder.id(flowId); } IntegrationFlow theFlow = (IntegrationFlow) registerBean(integrationFlow, flowId, null); builder.integrationFlowRegistration.setIntegrationFlow(theFlow); for (Map.Entry<Object, String> entry : builder.additionalBeans.entrySet()) { registerBean(entry.getKey(), entry.getValue(), flowId); } if (builder.autoStartup) { builder.integrationFlowRegistration.start(); } this.registry.put(flowId, builder.integrationFlowRegistration); }
@Test public void testDynamicSubFlow() { PollableChannel resultChannel = new QueueChannel(); this.integrationFlowContext.registration(flow -> flow.publishSubscribeChannel(p -> p .minSubscribers(1) .subscribe(f -> f.channel(resultChannel)) )) .id("dynamicFlow") .register(); this.integrationFlowContext.messagingTemplateFor("dynamicFlow").send(new GenericMessage<>("test")); Message<?> receive = resultChannel.receive(1000); assertNotNull(receive); assertEquals("test", receive.getPayload()); }
IntegrationFlowRegistration flowRegistration = this.integrationFlowContext.registration(myFlow) .id(flowId) .useFlowIdAsPrefix() .addBean(additionalBean)
@Test public void testDynamicSubFlow() { PollableChannel resultChannel = new QueueChannel(); this.integrationFlowContext.registration(flow -> flow.publishSubscribeChannel(p -> p .minSubscribers(1) .subscribe(f -> f.channel(resultChannel)) )) .id("dynamicFlow") .register(); this.integrationFlowContext.messagingTemplateFor("dynamicFlow").send(new GenericMessage<>("test")); Message<?> receive = resultChannel.receive(1000); assertNotNull(receive); assertEquals("test", receive.getPayload()); MessageHistory messageHistory = MessageHistory.read(receive); assertNotNull(messageHistory); String messageHistoryString = messageHistory.toString(); assertThat(messageHistoryString, Matchers.containsString("dynamicFlow.input")); assertThat(messageHistoryString, Matchers.containsString("dynamicFlow.subFlow#0.channel#1")); this.integrationFlowContext.remove("dynamicFlow"); }