Honor the FluxSink State in the PollChPublisherAd

The `PollableChannelPublisherAdapter` is based on the poll model of the
`FluxSink` and iterate and poll downstream `PollableChannel` until
there is an item or `n > 0`.
Having `take(6)` we end up with the cancel from the downstream
`Subscriber` after the batch is filled, but at the same time we continue
to poll the upstream source because `n` is like `Long.MAX_VALUE`.

* The proper way to interact is check for the `!sink.isCancelled()`
as well.
This way cancelled `sink` won't "steal" data from other subscribers

Fix compatibility with the latest dependencies

* Upgrade to Gradle 4.1
* Upgrade as much dependencies as possible
* Fix MongoDB module to resolve deprecation in the latest driver
* Increase receive timeout in the `ResequencerTests`
* Restore generic argument for the method reference in the `ReactiveStreamsTests`
* Fix `WebFluxInboundEndpoint` for the compatibility with the latest Reactor API
This commit is contained in:
Artem Bilan
2017-09-01 16:26:50 -04:00
committed by Gary Russell
parent cfab1fb1a4
commit 46de69dbf2
10 changed files with 74 additions and 49 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 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.
@@ -32,7 +32,6 @@ import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.BasicQuery;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.integration.aop.AbstractMessageSourceAdvice;
@@ -46,12 +45,11 @@ import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.mongodb.util.JSON;
/**
* @author Oleg Zhurakousky
* @author Artem Bilan
* @author Yaron Yamin
*
* @since 2.2
*/
@ContextConfiguration
@@ -168,6 +166,7 @@ public class MongoDbInboundChannelAdapterIntegrationTests extends MongoDbAvailab
this.mongoInboundAdapterWithNamedCollection.stop();
this.replyChannel.purge(null);
}
@Test
@MongoDbAvailable
public void testWithQueryExpression() throws Exception {
@@ -181,6 +180,7 @@ public class MongoDbInboundChannelAdapterIntegrationTests extends MongoDbAvailab
assertEquals("Bob", message.getPayload().get(0).getName());
this.mongoInboundAdapterWithQueryExpression.stop();
}
@Test
@MongoDbAvailable
public void testWithStringQueryExpression() throws Exception {
@@ -273,7 +273,7 @@ public class MongoDbInboundChannelAdapterIntegrationTests extends MongoDbAvailab
if (target instanceof List<?>) {
List<?> documents = (List<?>) target;
for (Object document : documents) {
mongoOperations.remove(new BasicQuery(JSON.serialize(document)), collectionName);
mongoOperations.remove(document, collectionName);
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 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.
@@ -32,16 +32,18 @@ import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.GenericMessage;
import com.mongodb.BasicDBObject;
import com.mongodb.util.JSON;
/**
* @author Oleg Zhurakousky
* @author Artem Bilan
*/
public class MongoDbOutboundChannelAdapterIntegrationTests extends MongoDbAvailableTests {
@Test
@MongoDbAvailable
public void testWithDefaultMongoFactory() throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("outbound-adapter-config.xml", this.getClass());
ClassPathXmlApplicationContext context =
new ClassPathXmlApplicationContext("outbound-adapter-config.xml", this.getClass());
MessageChannel channel = context.getBean("simpleAdapter", MessageChannel.class);
Message<Person> message = new GenericMessage<MongoDbAvailableTests.Person>(this.createPerson("Bob"));
@@ -57,10 +59,14 @@ public class MongoDbOutboundChannelAdapterIntegrationTests extends MongoDbAvaila
@MongoDbAvailable
public void testWithNamedCollection() throws Exception {
MongoDbFactory mongoDbFactory = this.prepareMongoFactory("foo");
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("outbound-adapter-config.xml", this.getClass());
ClassPathXmlApplicationContext context =
new ClassPathXmlApplicationContext("outbound-adapter-config.xml", this.getClass());
MessageChannel channel = context.getBean("simpleAdapterWithNamedCollection", MessageChannel.class);
Message<Person> message = MessageBuilder.withPayload(this.createPerson("Bob")).setHeader("collectionName", "foo").build();
Message<Person> message =
MessageBuilder.withPayload(this.createPerson("Bob"))
.setHeader("collectionName", "foo")
.build();
channel.send(message);
MongoTemplate template = new MongoTemplate(mongoDbFactory);
@@ -72,10 +78,15 @@ public class MongoDbOutboundChannelAdapterIntegrationTests extends MongoDbAvaila
@MongoDbAvailable
public void testWithTemplate() throws Exception {
MongoDbFactory mongoDbFactory = this.prepareMongoFactory("foo");
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("outbound-adapter-config.xml", this.getClass());
ClassPathXmlApplicationContext context =
new ClassPathXmlApplicationContext("outbound-adapter-config.xml", this.getClass());
MessageChannel channel = context.getBean("simpleAdapterWithTemplate", MessageChannel.class);
Message<Person> message = MessageBuilder.withPayload(this.createPerson("Bob")).setHeader("collectionName", "foo").build();
Message<Person> message =
MessageBuilder.withPayload(this.createPerson("Bob"))
.setHeader("collectionName", "foo")
.build();
channel.send(message);
MongoTemplate template = new MongoTemplate(mongoDbFactory);
@@ -87,13 +98,19 @@ public class MongoDbOutboundChannelAdapterIntegrationTests extends MongoDbAvaila
@MongoDbAvailable
public void testSavingDbObject() throws Exception {
BasicDBObject dbObject = (BasicDBObject) JSON.parse("{'foo' : 'bar'}");
BasicDBObject dbObject = BasicDBObject.parse("{'foo' : 'bar'}");
MongoDbFactory mongoDbFactory = this.prepareMongoFactory("foo");
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("outbound-adapter-config.xml", this.getClass());
ClassPathXmlApplicationContext context =
new ClassPathXmlApplicationContext("outbound-adapter-config.xml", this.getClass());
MessageChannel channel = context.getBean("simpleAdapterWithTemplate", MessageChannel.class);
Message<BasicDBObject> message = MessageBuilder.withPayload(dbObject).setHeader("collectionName", "foo").build();
Message<BasicDBObject> message =
MessageBuilder.withPayload(dbObject)
.setHeader("collectionName", "foo")
.build();
channel.send(message);
MongoTemplate template = new MongoTemplate(mongoDbFactory);
@@ -108,10 +125,16 @@ public class MongoDbOutboundChannelAdapterIntegrationTests extends MongoDbAvaila
String object = "{'foo' : 'bar'}";
MongoDbFactory mongoDbFactory = this.prepareMongoFactory("foo");
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("outbound-adapter-config.xml", this.getClass());
ClassPathXmlApplicationContext context =
new ClassPathXmlApplicationContext("outbound-adapter-config.xml", this.getClass());
MessageChannel channel = context.getBean("simpleAdapterWithTemplate", MessageChannel.class);
Message<String> message = MessageBuilder.withPayload(object).setHeader("collectionName", "foo").build();
Message<String> message =
MessageBuilder.withPayload(object)
.setHeader("collectionName", "foo")
.build();
channel.send(message);
MongoTemplate template = new MongoTemplate(mongoDbFactory);
@@ -122,7 +145,8 @@ public class MongoDbOutboundChannelAdapterIntegrationTests extends MongoDbAvaila
@Test
@MongoDbAvailable
public void testWithMongoConverter() throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("outbound-adapter-config.xml", this.getClass());
ClassPathXmlApplicationContext context =
new ClassPathXmlApplicationContext("outbound-adapter-config.xml", this.getClass());
MessageChannel channel = context.getBean("simpleAdapterWithConverter", MessageChannel.class);
Message<Person> message = new GenericMessage<MongoDbAvailableTests.Person>(this.createPerson("Bob"));
@@ -133,4 +157,5 @@ public class MongoDbOutboundChannelAdapterIntegrationTests extends MongoDbAvaila
assertNotNull(template.find(new BasicQuery("{'name' : 'Bob'}"), Person.class, "data"));
context.close();
}
}

View File

@@ -42,13 +42,14 @@ import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.integration.mongodb.rules.MongoDbAvailable;
import org.springframework.integration.mongodb.rules.MongoDbAvailableTests;
import com.mongodb.util.JSON;
import com.mongodb.BasicDBObject;
/**
* @author Amol Nayak
* @author Oleg Zhurakousky
* @author Gary Russell
* @author Yaron Yamin
* @author Artem Bilan
*
* @since 2.2
*
@@ -280,7 +281,7 @@ public class MongoDbMessageSourceTests extends MongoDbAvailableTests {
MongoTemplate template = new MongoTemplate(mongoDbFactory);
template.save(JSON.parse("{'name' : 'Manny', 'id' : 1}"), "data");
template.save(BasicDBObject.parse("{'name' : 'Manny', 'id' : 1}"), "data");
Expression queryExpression = new LiteralExpression("{'name' : 'Manny'}");
MongoDbMessageSource messageSource = new MongoDbMessageSource(mongoDbFactory, queryExpression);