Factored out common target adapter behavior from DefaultTargetAdapter into new AbstractTargetAdapter and implemented ApplicationEventTargetAdapter.

This commit is contained in:
Mark Fisher
2008-01-03 18:41:04 +00:00
parent 5d9602d497
commit 4a3fc43856
13 changed files with 299 additions and 76 deletions

View File

@@ -0,0 +1,61 @@
/*
* Copyright 2002-2007 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.adapter.event;
import static org.junit.Assert.assertEquals;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.integration.bus.MessageBus;
import org.springframework.integration.channel.MessageChannel;
import org.springframework.integration.channel.PointToPointChannel;
import org.springframework.integration.message.StringMessage;
/**
* @author Mark Fisher
*/
public class ApplicationEventTargetAdapterTests {
@Test
public void testSendingEvent() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
ApplicationEventPublisher publisher = new ApplicationEventPublisher() {
public void publishEvent(ApplicationEvent event) {
latch.countDown();
}
};
MessageChannel channel = new PointToPointChannel();
ApplicationEventTargetAdapter adapter = new ApplicationEventTargetAdapter();
adapter.setApplicationEventPublisher(publisher);
adapter.setChannel(channel);
MessageBus bus = new MessageBus();
bus.registerChannel("channel", channel);
bus.registerTargetAdapter("adapter", adapter);
bus.start();
assertEquals(1, latch.getCount());
channel.send(new StringMessage("123", "testing"));
latch.await(100, TimeUnit.MILLISECONDS);
assertEquals(0, latch.getCount());
bus.stop();
}
}

View File

@@ -42,8 +42,8 @@ public class FixedRateConsumerTests {
final AtomicInteger counter = new AtomicInteger(0);
final CountDownLatch latch = new CountDownLatch(messagesToSend);
PointToPointChannel channel = new PointToPointChannel();
MessageEndpoint endpoint = new GenericMessageEndpoint() {
public void messageReceived(Message<?> message) {
MessageEndpoint<String> endpoint = new GenericMessageEndpoint<String>() {
public void messageReceived(Message<String> message) {
counter.incrementAndGet();
latch.countDown();
}
@@ -73,8 +73,8 @@ public class FixedRateConsumerTests {
final AtomicInteger counter = new AtomicInteger(0);
final CountDownLatch latch = new CountDownLatch(messagesToSend);
PointToPointChannel channel = new PointToPointChannel();
MessageEndpoint endpoint = new GenericMessageEndpoint() {
public void messageReceived(Message<?> message) {
MessageEndpoint<String> endpoint = new GenericMessageEndpoint<String>() {
public void messageReceived(Message<String> message) {
counter.incrementAndGet();
latch.countDown();
}

View File

@@ -40,16 +40,16 @@ public class UnicastMessageDispatcherTests {
final AtomicBoolean endpoint1Received = new AtomicBoolean();
final AtomicBoolean endpoint2Received = new AtomicBoolean();
final CountDownLatch latch = new CountDownLatch(1);
MessageEndpoint endpoint1 = new GenericMessageEndpoint() {
MessageEndpoint<String> endpoint1 = new GenericMessageEndpoint<String>() {
@Override
public void messageReceived(Message<?> message) {
public void messageReceived(Message<String> message) {
endpoint1Received.set(true);
latch.countDown();
}
};
MessageEndpoint endpoint2 = new GenericMessageEndpoint() {
MessageEndpoint<String> endpoint2 = new GenericMessageEndpoint<String>() {
@Override
public void messageReceived(Message<?> message) {
public void messageReceived(Message<String> message) {
endpoint2Received.set(true);
latch.countDown();
}