Added 'clear()' and 'purge()' methods to channel and added 'isExpired()' method to Message.
This commit is contained in:
@@ -16,9 +16,13 @@
|
||||
|
||||
package org.springframework.integration.channel;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
@@ -27,8 +31,9 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
@@ -189,4 +194,47 @@ public class SimpleChannelTests {
|
||||
assertTrue(sendInterrupted.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClear() {
|
||||
SimpleChannel channel = new SimpleChannel(2);
|
||||
StringMessage message1 = new StringMessage("test1");
|
||||
StringMessage message2 = new StringMessage("test2");
|
||||
StringMessage message3 = new StringMessage("test3");
|
||||
assertTrue(channel.send(message1));
|
||||
assertTrue(channel.send(message2));
|
||||
assertFalse(channel.send(message3, 0));
|
||||
List<Message> clearedMessages = channel.clear();
|
||||
assertNotNull(clearedMessages);
|
||||
assertEquals(2, clearedMessages.size());
|
||||
assertTrue(channel.send(message3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClearEmptyChannel() {
|
||||
SimpleChannel channel = new SimpleChannel();
|
||||
List<Message> clearedMessages = channel.clear();
|
||||
assertNotNull(clearedMessages);
|
||||
assertEquals(0, clearedMessages.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPurge() {
|
||||
SimpleChannel channel = new SimpleChannel(2);
|
||||
long minute = 60 * 1000;
|
||||
long time = System.currentTimeMillis();
|
||||
Date past = new Date(time - minute);
|
||||
Date future = new Date(time + minute);
|
||||
StringMessage expiredMessage = new StringMessage("test1");
|
||||
expiredMessage.getHeader().setExpiration(past);
|
||||
StringMessage unexpiredMessage = new StringMessage("test2");
|
||||
unexpiredMessage.getHeader().setExpiration(future);
|
||||
assertTrue(channel.send(expiredMessage, 0));
|
||||
assertTrue(channel.send(unexpiredMessage, 0));
|
||||
assertFalse(channel.send(new StringMessage("atCapacity"), 0));
|
||||
List<Message> purgedMessages = channel.purge();
|
||||
assertNotNull(purgedMessages);
|
||||
assertEquals(1, purgedMessages.size());
|
||||
assertTrue(channel.send(new StringMessage("roomAvailable"), 0));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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.message;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class GenericMessageTests {
|
||||
|
||||
private static final long ONE_MINUTE = 60 * 1000;
|
||||
|
||||
|
||||
@Test
|
||||
public void testExpiredMessage() {
|
||||
GenericMessage<Integer> expiredMessage = new GenericMessage<Integer>(1);
|
||||
Date past = new Date(System.currentTimeMillis() - ONE_MINUTE);
|
||||
expiredMessage.getHeader().setExpiration(past);
|
||||
assertTrue(expiredMessage.isExpired());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnexpiredMessage() {
|
||||
GenericMessage<Integer> unexpiredMessage = new GenericMessage<Integer>(1);
|
||||
Date future = new Date(System.currentTimeMillis() + ONE_MINUTE);
|
||||
unexpiredMessage.getHeader().setExpiration(future);
|
||||
assertFalse(unexpiredMessage.isExpired());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageWithNullExpirationNeverExpires() {
|
||||
GenericMessage<Integer> message = new GenericMessage<Integer>(1);
|
||||
assertNull(message.getHeader().getExpiration());
|
||||
assertFalse(message.isExpired());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user