@Test public void testGatewayParser() throws Exception { setUp("JobLaunchingGatewayParserTests-context.xml", getClass()); final AbstractMessageChannel inputChannel = TestUtils.getPropertyValue(this.consumer, "inputChannel", AbstractMessageChannel.class); assertEquals("requestChannel", inputChannel.getComponentName()); final JobLaunchingMessageHandler jobLaunchingMessageHandler = TestUtils.getPropertyValue(this.consumer, "handler.jobLaunchingMessageHandler", JobLaunchingMessageHandler.class); assertNotNull(jobLaunchingMessageHandler); final MessagingTemplate messagingTemplate = TestUtils.getPropertyValue(this.consumer, "handler.messagingTemplate", MessagingTemplate.class); final Long sendTimeout = TestUtils.getPropertyValue(messagingTemplate, "sendTimeout", Long.class); assertEquals("Wrong sendTimeout", Long.valueOf(123L), sendTimeout); assertFalse(this.consumer.isRunning()); }
/** * Returns the fully qualified channel name including the application context * id, if available. * * @return The name. */ public String getFullChannelName() { if (this.fullChannelName == null) { String contextId = getApplicationContextId(); String componentName = getComponentName(); componentName = (StringUtils.hasText(contextId) ? contextId + "." : "") + (StringUtils.hasText(componentName) ? componentName : "unknown.channel.name"); this.fullChannelName = componentName; } return this.fullChannelName; }
private TimerFacade buildSendTimer(boolean success, String exception) { TimerFacade timer = this.metricsCaptor.timerBuilder(SEND_TIMER_NAME) .tag("type", "channel") .tag("name", getComponentName() == null ? "unknown" : getComponentName()) .tag("result", success ? "success" : "failure") .tag("exception", exception) .description("Send processing time") .build(); this.meters.add(timer); return timer; }
private Message<?> convertPayloadIfNecessary(Message<?> message) { // first pass checks if the payload type already matches any of the datatypes for (Class<?> datatype : this.datatypes) { if (datatype.isAssignableFrom(message.getPayload().getClass())) { return message; } } if (this.messageConverter != null) { // second pass applies conversion if possible, attempting datatypes in order for (Class<?> datatype : this.datatypes) { Object converted = this.messageConverter.fromMessage(message, datatype); if (converted != null) { if (converted instanceof Message) { return (Message<?>) converted; } else { return getMessageBuilderFactory() .withPayload(converted) .copyHeaders(message.getHeaders()) .build(); } } } } throw new MessageDeliveryException(message, "Channel '" + this.getComponentName() + "' expected one of the following datataypes [" + StringUtils.arrayToCommaDelimitedString(this.datatypes) + "], but received [" + message.getPayload().getClass() + "]"); }
@Test public void channelName() { AbstractMessageChannel channel = context.getBean("adapterWithPattern", AbstractMessageChannel.class); assertEquals("adapterWithPattern", channel.getComponentName()); }
@Test public void channelName() throws Exception { AbstractMessageChannel channel = context.getBean("inputDirPoller", AbstractMessageChannel.class); assertEquals("Channel should be available under specified id", "inputDirPoller", channel.getComponentName()); }
() -> "failed to send Message to channel '" + this.getComponentName() + "'", e);
@Test public void advisedAndTransactional() throws Exception { setUp("JpaMessageHandlerParserTests.xml", getClass()); EventDrivenConsumer consumer = this.context.getBean("advisedAndTransactional", EventDrivenConsumer.class); final AbstractMessageChannel inputChannel = TestUtils.getPropertyValue(consumer, "inputChannel", AbstractMessageChannel.class); assertEquals("target", inputChannel.getComponentName()); final MessageHandler handler = TestUtils.getPropertyValue(consumer, "handler", MessageHandler.class); adviceCalled = 0; handler.handleMessage(new GenericMessage<String>("foo")); assertEquals(1, adviceCalled); }
@Test public void advised() throws Exception { setUp("JpaMessageHandlerParserTests.xml", getClass()); EventDrivenConsumer consumer = this.context.getBean("advised", EventDrivenConsumer.class); final AbstractMessageChannel inputChannel = TestUtils.getPropertyValue(consumer, "inputChannel", AbstractMessageChannel.class); assertEquals("target", inputChannel.getComponentName()); final MessageHandler handler = TestUtils.getPropertyValue(consumer, "handler", MessageHandler.class); adviceCalled = 0; handler.handleMessage(new GenericMessage<String>("foo")); assertEquals(1, adviceCalled); }
/** * Method used by the Esper subscriber contract where the payload of the * event is passed to the subscriber. In this case the payload is a * calculated throughput. * * @param throughput * the calculated throughput for the channel */ public void update(long throughput) { if (LOG.isDebugEnabled()) { LOG.debug("Received throughput of " + throughput + " on channel - " + this.channel.getComponentName()); } this.throughput = throughput; }
@Test public void testJpaInboundChannelAdapterParser() throws Exception { AbstractMessageChannel outputChannel = TestUtils.getPropertyValue(this.jpaInboundChannelAdapter1, "outputChannel", AbstractMessageChannel.class); assertEquals("out", outputChannel.getComponentName()); JpaExecutor jpaExecutor = TestUtils.getPropertyValue(this.jpaInboundChannelAdapter1, "source.jpaExecutor", JpaExecutor.class); assertNotNull(jpaExecutor); Class<?> entityClass = TestUtils.getPropertyValue(jpaExecutor, "entityClass", Class.class); assertEquals("org.springframework.integration.jpa.test.entity.StudentDomain", entityClass.getName()); JpaOperations jpaOperations = TestUtils.getPropertyValue(jpaExecutor, "jpaOperations", JpaOperations.class); assertNotNull(jpaOperations); assertTrue(TestUtils.getPropertyValue(jpaExecutor, "expectSingleResult", Boolean.class)); ParameterSource parameterSource = this.context.getBean(ParameterSource.class); assertSame(parameterSource, TestUtils.getPropertyValue(jpaExecutor, "parameterSource")); }
/** * * @param ps_count * @param pr_count * @param pr_avg */ public void update(Long ps_count, Long pr_count, Double pr_avg) { ps_count = ps_count == null ? 0 : ps_count; pr_count = pr_count == null ? 0 : pr_count; if (LOG.isDebugEnabled()) { LOG.debug("Sent throughput of " + ps_count + ", received throughput of " + pr_count + " average " + pr_avg + " on pollable channel - " + this.channel.getComponentName()); } this.throughput = pr_count; }
@SuppressWarnings({ "rawtypes", "unchecked" }) private void addMatchingWireTaps(AbstractMessageChannel channel) { Assert.notNull(channel.getComponentName(), "channel name must not be null"); Set<Entry> patternWireTapEntries = this.channelPatternMappings.entrySet(); for (Entry patternWireTapEntry : patternWireTapEntries) { if (((Pattern) patternWireTapEntry.getKey()).matcher(channel.getComponentName()).matches()) { channel.addInterceptor((EsperWireTap) patternWireTapEntry.getValue()); } } } }
assertEquals("target", inputChannel.getComponentName());
@Test public void testJpaInboundChannelAdapterParserWithMaxResultsExpression() throws Exception { AbstractMessageChannel outputChannel = TestUtils.getPropertyValue(this.jpaInboundChannelAdapter3, "outputChannel", AbstractMessageChannel.class); assertEquals("out", outputChannel.getComponentName()); JpaExecutor jpaExecutor = TestUtils.getPropertyValue(this.jpaInboundChannelAdapter3, "source.jpaExecutor", JpaExecutor.class); assertNotNull(jpaExecutor); Class<?> entityClass = TestUtils.getPropertyValue(jpaExecutor, "entityClass", Class.class); assertEquals("org.springframework.integration.jpa.test.entity.StudentDomain", entityClass.getName()); final JpaOperations jpaOperations = TestUtils.getPropertyValue(jpaExecutor, "jpaOperations", JpaOperations.class); assertNotNull(jpaOperations); SpelExpression expression = TestUtils.getPropertyValue(jpaExecutor, "maxResultsExpression", SpelExpression.class); assertNotNull(expression); assertEquals("@maxNumberOfResults", TestUtils.getPropertyValue(expression, "expression")); }
@Test public void testJpaMessageHandlerParser() throws Exception { setUp("JpaMessageHandlerParserTests.xml", getClass()); final AbstractMessageChannel inputChannel = TestUtils.getPropertyValue(this.consumer, "inputChannel", AbstractMessageChannel.class); assertEquals("target", inputChannel.getComponentName()); final JpaExecutor jpaExecutor = TestUtils.getPropertyValue(this.consumer, "handler.jpaExecutor", JpaExecutor.class); assertNotNull(jpaExecutor); final String query = TestUtils.getPropertyValue(jpaExecutor, "jpaQuery", String.class); assertEquals("from Student", query); final JpaOperations jpaOperations = TestUtils.getPropertyValue(jpaExecutor, "jpaOperations", JpaOperations.class); assertNotNull(jpaOperations); final PersistMode persistMode = TestUtils.getPropertyValue(jpaExecutor, "persistMode", PersistMode.class); assertEquals(PersistMode.PERSIST, persistMode); @SuppressWarnings("unchecked") List<JpaParameter> jpaParameters = TestUtils.getPropertyValue(jpaExecutor, "jpaParameters", List.class); assertNotNull(jpaParameters); assertTrue(jpaParameters.size() == 3); assertEquals(Integer.valueOf(10), TestUtils.getPropertyValue(jpaExecutor, "flushSize", Integer.class)); assertTrue(TestUtils.getPropertyValue(jpaExecutor, "clearOnFlush", Boolean.class)); }
@Test public void testJpaInboundChannelAdapterParserWithMaxResults() throws Exception { AbstractMessageChannel outputChannel = TestUtils.getPropertyValue(this.jpaInboundChannelAdapter2, "outputChannel", AbstractMessageChannel.class); assertEquals("out", outputChannel.getComponentName()); JpaExecutor jpaExecutor = TestUtils.getPropertyValue(this.jpaInboundChannelAdapter2, "source.jpaExecutor", JpaExecutor.class); assertNotNull(jpaExecutor); Class<?> entityClass = TestUtils.getPropertyValue(jpaExecutor, "entityClass", Class.class); assertEquals("org.springframework.integration.jpa.test.entity.StudentDomain", entityClass.getName()); JpaOperations jpaOperations = TestUtils.getPropertyValue(jpaExecutor, "jpaOperations", JpaOperations.class); assertNotNull(jpaOperations); LiteralExpression expression = TestUtils.getPropertyValue(jpaExecutor, "maxResultsExpression", LiteralExpression.class); assertNotNull(expression); assertEquals("13", TestUtils.getPropertyValue(expression, "literalValue")); assertTrue(TestUtils.getPropertyValue(jpaExecutor, "deleteAfterPoll", Boolean.class)); assertTrue(TestUtils.getPropertyValue(jpaExecutor, "flush", Boolean.class)); }
TestUtils.getPropertyValue(this.consumer, "inputChannel", AbstractMessageChannel.class); assertEquals("in", inputChannel.getComponentName());
private TimerFacade buildSendTimer(boolean success, String exception) { TimerFacade timer = this.metricsCaptor.timerBuilder(SEND_TIMER_NAME) .tag("type", "channel") .tag("name", getComponentName() == null ? "unknown" : getComponentName()) .tag("result", success ? "success" : "failure") .tag("exception", exception) .description("Send processing time") .build(); this.meters.add(timer); return timer; }
@Test public void testRetrievingJpaOutboundGatewayParser() { setUp("JpaOutboundGatewayParserTests.xml", getClass(), "retrievingJpaOutboundGateway"); final AbstractMessageChannel inputChannel = TestUtils.getPropertyValue(this.consumer, "inputChannel", AbstractMessageChannel.class); assertEquals("in", inputChannel.getComponentName()); final JpaOutboundGateway jpaOutboundGateway = TestUtils.getPropertyValue(this.consumer, "handler", JpaOutboundGateway.class); final OutboundGatewayType gatewayType = TestUtils.getPropertyValue(jpaOutboundGateway, "gatewayType", OutboundGatewayType.class); assertEquals(OutboundGatewayType.RETRIEVING, gatewayType); long sendTimeout = TestUtils.getPropertyValue(jpaOutboundGateway, "messagingTemplate.sendTimeout", Long.class); assertEquals(100, sendTimeout); assertFalse(TestUtils.getPropertyValue(jpaOutboundGateway, "requiresReply", Boolean.class)); final JpaExecutor jpaExecutor = TestUtils.getPropertyValue(this.consumer, "handler.jpaExecutor", JpaExecutor.class); assertNotNull(jpaExecutor); final Class<?> entityClass = TestUtils.getPropertyValue(jpaExecutor, "entityClass", Class.class); assertEquals("org.springframework.integration.jpa.test.entity.StudentDomain", entityClass.getName()); final JpaOperations jpaOperations = TestUtils.getPropertyValue(jpaExecutor, "jpaOperations", JpaOperations.class); assertNotNull(jpaOperations); assertTrue(TestUtils.getPropertyValue(jpaExecutor, "expectSingleResult", Boolean.class)); final LiteralExpression maxResultsExpression = TestUtils.getPropertyValue(jpaExecutor, "maxResultsExpression", LiteralExpression.class); assertNotNull(maxResultsExpression); assertEquals("55", TestUtils.getPropertyValue(maxResultsExpression, "literalValue")); assertTrue(TestUtils.getPropertyValue(jpaExecutor, "deleteAfterPoll", Boolean.class)); assertTrue(TestUtils.getPropertyValue(jpaExecutor, "flush", Boolean.class)); }