PollableSource no longer accepts a "limit" argument in its poll() method (INT-181).
This commit is contained in:
@@ -19,8 +19,6 @@ package org.springframework.integration.adapter;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.integration.message.MessagingException;
|
||||
@@ -35,9 +33,9 @@ public class MethodInvokingSourceTests {
|
||||
MethodInvokingSource<TestBean> source = new MethodInvokingSource<TestBean>();
|
||||
source.setObject(new TestBean());
|
||||
source.setMethod("validMethod");
|
||||
Collection<Object> result = source.poll(5);
|
||||
Object result = source.poll();
|
||||
assertNotNull(result);
|
||||
assertEquals("valid", result.iterator().next());
|
||||
assertEquals("valid", result);
|
||||
}
|
||||
|
||||
@Test(expected=MessagingException.class)
|
||||
@@ -45,7 +43,7 @@ public class MethodInvokingSourceTests {
|
||||
MethodInvokingSource<TestBean> source = new MethodInvokingSource<TestBean>();
|
||||
source.setObject(new TestBean());
|
||||
source.setMethod("noMatchingMethod");
|
||||
source.poll(5);
|
||||
source.poll();
|
||||
}
|
||||
|
||||
@Test(expected=MessagingException.class)
|
||||
@@ -53,7 +51,7 @@ public class MethodInvokingSourceTests {
|
||||
MethodInvokingSource<TestBean> source = new MethodInvokingSource<TestBean>();
|
||||
source.setObject(new TestBean());
|
||||
source.setMethod("invalidMethodWithArg");
|
||||
source.poll(5);
|
||||
source.poll();
|
||||
}
|
||||
|
||||
@Test(expected=MessagingException.class)
|
||||
@@ -61,7 +59,7 @@ public class MethodInvokingSourceTests {
|
||||
MethodInvokingSource<TestBean> source = new MethodInvokingSource<TestBean>();
|
||||
source.setObject(new TestBean());
|
||||
source.setMethod("invalidMethodWithNoReturnValue");
|
||||
source.poll(5);
|
||||
source.poll();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -20,16 +20,12 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.integration.channel.SimpleChannel;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessagingException;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
@@ -66,11 +62,12 @@ public class PollingSourceAdapterTests {
|
||||
assertEquals("testing.1", message1.getPayload());
|
||||
Message<?> message2 = channel.receive(0);
|
||||
assertNull("second message should be null", message2);
|
||||
source.resetCounter();
|
||||
adapter.start();
|
||||
adapter.processMessages();
|
||||
Message<?> message3 = channel.receive(100);
|
||||
assertNotNull("third message should not be null", message3);
|
||||
assertEquals("testing.3", message3.getPayload());
|
||||
assertEquals("testing.1", message3.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -96,38 +93,29 @@ public class PollingSourceAdapterTests {
|
||||
assertNull("message should be null", message4);
|
||||
}
|
||||
|
||||
@Test(expected=MessagingException.class)
|
||||
public void testResultSizeExceedsLimit() {
|
||||
TestSource source = new TestSource("testing", 3);
|
||||
SimpleChannel channel = new SimpleChannel();
|
||||
PollingSourceAdapter<String> adapter = new PollingSourceAdapter<String>(source);
|
||||
adapter.setChannel(channel);
|
||||
adapter.setPeriod(1000);
|
||||
adapter.setMaxMessagesPerTask(2);
|
||||
adapter.start();
|
||||
adapter.processMessages();
|
||||
}
|
||||
|
||||
|
||||
private static class TestSource implements PollableSource<String> {
|
||||
|
||||
private String message;
|
||||
|
||||
private int messagesPerPoll;
|
||||
private int limit;
|
||||
|
||||
private AtomicInteger count = new AtomicInteger();
|
||||
|
||||
public TestSource(String message, int messagesPerPoll) {
|
||||
public TestSource(String message, int limit) {
|
||||
this.message = message;
|
||||
this.messagesPerPoll = messagesPerPoll;
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
public Collection<String> poll(int limit) {
|
||||
List<String> results = new ArrayList<String>(this.messagesPerPoll);
|
||||
for (int i = 0; i < this.messagesPerPoll; i++) {
|
||||
results.add(message + "." + count.incrementAndGet());
|
||||
public void resetCounter() {
|
||||
this.count.set(0);
|
||||
}
|
||||
|
||||
public String poll() {
|
||||
if (count.get() >= limit) {
|
||||
return null;
|
||||
}
|
||||
return results;
|
||||
return message + "." + count.incrementAndGet();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -269,7 +269,7 @@ public class MessageBusTests {
|
||||
this.latch = latch;
|
||||
}
|
||||
|
||||
public Collection<Object> poll(int limit) {
|
||||
public Collection<Object> poll() {
|
||||
latch.countDown();
|
||||
throw new RuntimeException("intentional test failure");
|
||||
}
|
||||
|
||||
@@ -21,8 +21,6 @@ import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.SynchronousQueue;
|
||||
@@ -99,8 +97,8 @@ public class SynchronousChannelTests {
|
||||
@Test
|
||||
public void testReceive() {
|
||||
SynchronousChannel channel = new SynchronousChannel(new PollableSource<String>() {
|
||||
public Collection<String> poll(int limit) {
|
||||
return Collections.singleton("foo");
|
||||
public String poll() {
|
||||
return "foo";
|
||||
}
|
||||
});
|
||||
Message<?> message = channel.receive();
|
||||
@@ -186,10 +184,10 @@ public class SynchronousChannelTests {
|
||||
this.messageText = messageText;
|
||||
}
|
||||
|
||||
public Collection<StringMessage> poll(int limit) {
|
||||
public StringMessage poll() {
|
||||
StringMessage message = new StringMessage(messageText);
|
||||
message.getHeader().setProperty(HANDLER_THREAD, Thread.currentThread().getName());
|
||||
return Collections.singleton(message);
|
||||
return message;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user