@Override public void stop() { if (this.adapter != null) { this.adapter.stop(); } }
@Override public void stop(Runnable callback) { if (this.adapter != null) { this.adapter.stop(callback); } else { callback.run(); } }
@After public void tearDown() { this.pollingAdapter.stop(); ThreadPoolTaskScheduler taskScheduler = context.getBean(ThreadPoolTaskScheduler.class); taskScheduler.setAwaitTerminationSeconds(10); taskScheduler.destroy(); if (context != null) { context.close(); } }
@Test public void testWithSPCADefaultErrorChannel() throws Exception { CountDownLatch errorLatch = new CountDownLatch(1); errorChannel.subscribe(message -> errorLatch.countDown()); inboundAdapterDefaultErrorChannel.start(); assertTrue(errorLatch.await(10, TimeUnit.SECONDS)); inboundAdapterDefaultErrorChannel.stop(); }
@Test public void testWithSPCAAssignedErrorChannel() throws Exception { CountDownLatch errorLatch = new CountDownLatch(1); assignedErrorChannel.subscribe(message -> errorLatch.countDown()); inboundAdapterAssignedErrorChannel.start(); assertTrue(errorLatch.await(10, TimeUnit.SECONDS)); inboundAdapterAssignedErrorChannel.stop(); }
@Test public void testWithErrorChannelAndHeader() { ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("PollerWithErrorChannel-context.xml", this.getClass()); SourcePollingChannelAdapter adapter = ac.getBean("withErrorChannelAndHeader", SourcePollingChannelAdapter.class); adapter.start(); PollableChannel errorChannel = ac.getBean("eChannel", PollableChannel.class); assertNotNull(errorChannel.receive(10000)); adapter.stop(); ac.close(); }
@Test public void testWithErrorChannel() throws Exception { ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("PollerWithErrorChannel-context.xml", this.getClass()); SourcePollingChannelAdapter adapter = ac.getBean("withErrorChannel", SourcePollingChannelAdapter.class); adapter.start(); PollableChannel errorChannel = ac.getBean("eChannel", PollableChannel.class); assertNotNull(errorChannel.receive(10000)); adapter.stop(); ac.close(); }
@Test // config the same as above but the error wil come from the send public void testWithErrorChannelAndHeaderWithSendFailure() { ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("PollerWithErrorChannel-context.xml", this.getClass()); SourcePollingChannelAdapter adapter = ac.getBean("withErrorChannelAndHeaderErrorOnSend", SourcePollingChannelAdapter.class); adapter.start(); PollableChannel errorChannel = ac.getBean("errChannel", PollableChannel.class); assertNotNull(errorChannel.receive(10000)); adapter.stop(); ac.close(); }
@Test public void pollDefaultAdapter() throws Exception { adapterDefault.start(); Message<?> result = channel1.receive(testTimeout); assertNotNull(result); assertEquals(HashMap.class, result.getPayload().getClass()); @SuppressWarnings("unchecked") Map<String, Object> beans = (Map<String, Object>) result.getPayload(); // test for a couple of MBeans assertTrue(beans.containsKey("java.lang:type=OperatingSystem")); assertTrue(beans.containsKey("java.lang:type=Runtime")); adapterDefault.stop(); }
@Test public void pollInnerAdapter() throws Exception { adapterInner.start(); Message<?> result = channel2.receive(testTimeout); assertNotNull(result); assertEquals(HashMap.class, result.getPayload().getClass()); @SuppressWarnings("unchecked") Map<String, Object> beans = (Map<String, Object>) result.getPayload(); // test for a couple of MBeans assertTrue(beans.containsKey("java.lang:type=OperatingSystem")); assertTrue(beans.containsKey("java.lang:type=Runtime")); adapterInner.stop(); }
@Test public void pollQueryNameBeanAdapter() throws Exception { adapterQueryNameBean.start(); Message<?> result = channel4.receive(testTimeout); assertNotNull(result); assertEquals(HashMap.class, result.getPayload().getClass()); @SuppressWarnings("unchecked") Map<String, Object> beans = (Map<String, Object>) result.getPayload(); // test for a couple of MBeans assertTrue(beans.containsKey("java.lang:type=OperatingSystem")); assertFalse(beans.containsKey("java.lang:type=Runtime")); adapterQueryNameBean.stop(); }
@Test public void testAutoChannel() throws Exception { setUp("storedProcPollingChannelAdapterParserTest.xml", getClass()); MessageChannel autoChannel = context.getBean("autoChannel", MessageChannel.class); SourcePollingChannelAdapter autoChannelAdapter = context.getBean("autoChannel.adapter", SourcePollingChannelAdapter.class); assertSame(autoChannel, TestUtils.getPropertyValue(autoChannelAdapter, "outputChannel")); assertFalse(TestUtils.getPropertyValue(autoChannelAdapter, "source.executor.returnValueRequired", Boolean.class)); assertFalse(TestUtils.getPropertyValue(autoChannelAdapter, "source.executor.isFunction", Boolean.class)); autoChannelAdapter.stop(); }
@Test @MongoDbAvailable public void testWithStringQueryExpression() throws Exception { this.mongoTemplate.save(this.createPerson("Bob"), "foo"); this.mongoInboundAdapterWithStringQueryExpression.start(); @SuppressWarnings("unchecked") Message<List<Person>> message = (Message<List<Person>>) replyChannel.receive(10000); assertNotNull(message); assertEquals("Bob", message.getPayload().get(0).getName()); this.mongoInboundAdapterWithStringQueryExpression.stop(); }
@Test @MongoDbAvailable public void testWithNamedCollection() throws Exception { this.mongoTemplate.save(this.createPerson("Bob"), "foo"); this.mongoInboundAdapterWithNamedCollection.start(); @SuppressWarnings("unchecked") Message<List<Person>> message = (Message<List<Person>>) replyChannel.receive(10000); assertNotNull(message); assertEquals("Bob", message.getPayload().get(0).getName()); this.mongoInboundAdapterWithNamedCollection.stop(); this.replyChannel.purge(null); }
@Test @MongoDbAvailable public void testWithNamedCollectionExpression() throws Exception { this.mongoTemplate.save(this.createPerson("Bob"), "foo"); this.mongoInboundAdapterWithNamedCollectionExpression.start(); @SuppressWarnings("unchecked") Message<List<Person>> message = (Message<List<Person>>) replyChannel.receive(10000); assertNotNull(message); assertEquals("Bob", message.getPayload().get(0).getName()); this.mongoInboundAdapterWithNamedCollectionExpression.stop(); this.replyChannel.purge(null); }
@Test @MongoDbAvailable public void testWithNamedMongoFactory() throws Exception { this.mongoTemplate.save(this.createPerson("Bob"), "data"); this.mongoInboundAdapterNamedFactory.start(); @SuppressWarnings("unchecked") Message<List<Document>> message = (Message<List<Document>>) replyChannel.receive(10000); assertNotNull(message); assertEquals("Bob", message.getPayload().get(0).get("name")); this.mongoInboundAdapterNamedFactory.stop(); this.replyChannel.purge(null); }
@Test @MongoDbAvailable public void testWithDefaultMongoFactory() throws Exception { this.mongoTemplate.save(createPerson("Bob"), "data"); this.mongoInboundAdapter.start(); @SuppressWarnings("unchecked") Message<List<Person>> message = (Message<List<Person>>) replyChannel.receive(10000); assertNotNull(message); assertEquals("Bob", message.getPayload().get(0).getName()); assertNotNull(this.replyChannel.receive(10000)); this.mongoInboundAdapter.stop(); this.replyChannel.purge(null); }
@Test @MongoDbAvailable public void testWithMongoConverter() throws Exception { this.mongoTemplate.save(this.createPerson("Bob"), "data"); this.mongoInboundAdapterWithConverter.start(); @SuppressWarnings("unchecked") Message<List<Person>> message = (Message<List<Person>>) replyChannel.receive(10000); assertNotNull(message); assertEquals("Bob", message.getPayload().get(0).getName()); assertNotNull(replyChannel.receive(10000)); this.mongoInboundAdapterWithConverter.stop(); this.replyChannel.purge(null); }
@Test @MongoDbAvailable public void testWithMongoTemplate() throws Exception { this.mongoTemplate.save(this.createPerson("Bob"), "data"); this.mongoInboundAdapterWithTemplate.start(); @SuppressWarnings("unchecked") Message<Person> message = (Message<Person>) replyChannel.receive(10000); assertNotNull(message); assertEquals("Bob", message.getPayload().getName()); this.mongoInboundAdapterWithTemplate.stop(); this.replyChannel.purge(null); }
@Test @MongoDbAvailable public void testWithOnSuccessDisposition() throws Exception { this.mongoTemplate.save(createPerson("Bob"), "data"); this.inboundAdapterWithOnSuccessDisposition.start(); assertNotNull(replyChannel.receive(10000)); assertNull(replyChannel.receive(100)); assertNotNull(this.afterCommitChannel.receive(10000)); assertNull(this.mongoTemplate.findOne(new Query(Criteria.where("name").is("Bob")), Person.class, "data")); this.inboundAdapterWithOnSuccessDisposition.stop(); this.replyChannel.purge(null); }