Removed EndpointTrigger, EndpointPoller, and EndpointVisitor. MessageBus now schedules PollingDispatchers for endpoints.

This commit is contained in:
Mark Fisher
2008-08-05 01:59:35 +00:00
parent 46b37df03d
commit 9f3e7d3d24
13 changed files with 146 additions and 375 deletions

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2002-2008 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.dispatcher;
import static org.easymock.EasyMock.createMock;
@@ -8,39 +24,39 @@ import static org.easymock.EasyMock.verify;
import org.junit.Before;
import org.junit.Test;
import org.springframework.integration.message.BlockingSource;
import org.springframework.integration.message.Message;
import org.springframework.integration.scheduling.Schedule;
/**
*
* @author Iwein Fuld
*
*/
@SuppressWarnings("unchecked")
public class PollingDispatcherTest {
public class PollingDispatcherTests {
private PollingDispatcher pollingDispatcher;
private Schedule scheduleMock = createMock(Schedule.class);
private MessageDispatcher dispatcherMock = createMock(MessageDispatcher.class);
private BlockingSource sourceMock = createMock(BlockingSource.class);
private Message messageMock = createMock(Message.class);
private Object[] globalMocks = new Object[] { scheduleMock, dispatcherMock,
sourceMock, messageMock };
private Object[] globalMocks = new Object[] { scheduleMock, dispatcherMock, sourceMock, messageMock };
@Before
public void init() {
pollingDispatcher = new PollingDispatcher(sourceMock, dispatcherMock,
scheduleMock);
pollingDispatcher = new PollingDispatcher(sourceMock, scheduleMock, dispatcherMock);
pollingDispatcher.setReceiveTimeout(-1);
reset(globalMocks);
}
@Test
public void singleMessage() {
expect(sourceMock.receive()).andReturn(messageMock);
expect(dispatcherMock.send(messageMock)).andReturn(true);
replay(globalMocks);
pollingDispatcher.setMaxMessagesPerPoll(1);
pollingDispatcher.run();
verify(globalMocks);
}
@@ -50,7 +66,7 @@ public class PollingDispatcherTest {
expect(sourceMock.receive()).andReturn(messageMock).times(5);
expect(dispatcherMock.send(messageMock)).andReturn(true).times(5);
replay(globalMocks);
pollingDispatcher.setMaxMessagesPerTask(5);
pollingDispatcher.setMaxMessagesPerPoll(5);
pollingDispatcher.run();
verify(globalMocks);
}
@@ -61,7 +77,7 @@ public class PollingDispatcherTest {
expect(sourceMock.receive()).andReturn(null);
expect(dispatcherMock.send(messageMock)).andReturn(true).times(5);
replay(globalMocks);
pollingDispatcher.setMaxMessagesPerTask(6);
pollingDispatcher.setMaxMessagesPerPoll(6);
pollingDispatcher.run();
verify(globalMocks);
}
@@ -80,15 +96,14 @@ public class PollingDispatcherTest {
expect(sourceMock.receive()).andReturn(messageMock).times(1);
expect(dispatcherMock.send(messageMock)).andReturn(false).anyTimes();
replay(globalMocks);
pollingDispatcher.setMaxMessagesPerTask(10);
pollingDispatcher.setMaxMessagesPerPoll(10);
pollingDispatcher.run();
verify(globalMocks);
}
@Test
public void blockingSourceTimedOut() {
pollingDispatcher = new PollingDispatcher(sourceMock, dispatcherMock,
scheduleMock);
pollingDispatcher = new PollingDispatcher(sourceMock, scheduleMock, dispatcherMock);
// we don't need to await the timeout, returning null suffices
expect(sourceMock.receive(1)).andReturn(null);
replay(globalMocks);
@@ -99,8 +114,7 @@ public class PollingDispatcherTest {
@Test
public void blockingSourceNotTimedOut() {
pollingDispatcher = new PollingDispatcher(sourceMock, dispatcherMock,
scheduleMock);
pollingDispatcher = new PollingDispatcher(sourceMock, scheduleMock, dispatcherMock);
expect(sourceMock.receive(1)).andReturn(messageMock);
expect(dispatcherMock.send(messageMock)).andReturn(false);
replay(globalMocks);
@@ -108,4 +122,5 @@ public class PollingDispatcherTest {
pollingDispatcher.run();
verify(globalMocks);
}
}

View File

@@ -1,75 +0,0 @@
/*
* Copyright 2002-2008 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.endpoint;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.Test;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.message.GenericMessage;
import org.springframework.integration.message.Message;
import org.springframework.integration.message.PollableSource;
/**
* @author Mark Fisher
*/
public class SourceEndpointTests {
@Test
public void testPolledSourceSendsToChannel() {
TestSource source = new TestSource("testing", 1);
QueueChannel channel = new QueueChannel();
SourceEndpoint endpoint = new SourceEndpoint(source);
endpoint.setTarget(channel);
endpoint.afterPropertiesSet();
endpoint.send(new TriggerMessage());
Message<?> message = channel.receive(1000);
assertNotNull("message should not be null", message);
assertEquals("testing.1", message.getPayload());
}
private static class TestSource implements PollableSource<String> {
private String message;
private int limit;
private AtomicInteger count = new AtomicInteger();
public TestSource(String message, int limit) {
this.message = message;
this.limit = limit;
}
public void resetCounter() {
this.count.set(0);
}
public Message<String> receive() {
if (count.get() >= limit) {
return null;
}
return new GenericMessage<String>(message + "." + count.incrementAndGet());
}
}
}