use of org.springframework.integration.store.MessageGroupQueue in project spring-integration by spring-projects.
the class MessageGroupQueueTests method testConcurrentReadersWithTimeout.
@Test
public void testConcurrentReadersWithTimeout() throws Exception {
final MessageGroupQueue queue = new MessageGroupQueue(new SimpleMessageStore(), 1, 1);
final AtomicReference<Message<?>> messageHolder1 = new AtomicReference<Message<?>>();
final AtomicReference<Message<?>> messageHolder2 = new AtomicReference<Message<?>>();
final AtomicReference<Message<?>> messageHolder3 = new AtomicReference<Message<?>>();
Thread t1 = new Thread(() -> {
try {
messageHolder1.set(queue.poll(10, TimeUnit.SECONDS));
} catch (Exception e) {
LogFactory.getLog(getClass()).error("queue poll failed", e);
}
});
Thread t2 = new Thread(() -> {
try {
messageHolder2.set(queue.poll(10, TimeUnit.SECONDS));
} catch (Exception e) {
LogFactory.getLog(getClass()).error("queue poll failed", e);
}
});
Thread t3 = new Thread(() -> {
try {
messageHolder3.set(queue.poll(10, TimeUnit.SECONDS));
} catch (Exception e) {
LogFactory.getLog(getClass()).error("queue poll failed", e);
}
});
Thread t4 = new Thread(() -> {
try {
queue.offer(new GenericMessage<String>("Hi"), 10, TimeUnit.SECONDS);
} catch (Exception e) {
LogFactory.getLog(getClass()).error("queue offer failed", e);
}
});
t1.start();
Thread.sleep(1000);
t2.start();
Thread.sleep(1000);
t3.start();
Thread.sleep(1000);
t4.start();
Thread.sleep(1000);
assertNotNull(messageHolder1.get());
assertEquals("Hi", messageHolder1.get().getPayload());
Thread.sleep(4000);
assertTrue(messageHolder2.get() == null);
}
use of org.springframework.integration.store.MessageGroupQueue in project spring-integration by spring-projects.
the class MessageGroupQueueTests method testConcurrentWritersWithTimeout.
@Test
public void testConcurrentWritersWithTimeout() throws Exception {
final MessageGroupQueue queue = new MessageGroupQueue(new SimpleMessageStore(), 1, 1);
final AtomicReference<Boolean> booleanHolder1 = new AtomicReference<Boolean>(true);
final AtomicReference<Boolean> booleanHolder2 = new AtomicReference<Boolean>(true);
final AtomicReference<Boolean> booleanHolder3 = new AtomicReference<Boolean>(true);
Thread t1 = new Thread(() -> {
try {
booleanHolder1.set(queue.offer(new GenericMessage<String>("Hi-1"), 2, TimeUnit.SECONDS));
} catch (Exception e) {
LogFactory.getLog(getClass()).error("queue offer failed", e);
}
});
Thread t2 = new Thread(() -> {
try {
boolean offered = queue.offer(new GenericMessage<String>("Hi-2"), 2, TimeUnit.SECONDS);
booleanHolder2.set(offered);
} catch (Exception e) {
LogFactory.getLog(getClass()).error("queue offer failed", e);
}
});
Thread t3 = new Thread(() -> {
try {
boolean offered = queue.offer(new GenericMessage<String>("Hi-3"), 2, TimeUnit.SECONDS);
booleanHolder3.set(offered);
} catch (Exception e) {
LogFactory.getLog(getClass()).error("queue offer failed", e);
}
});
t1.start();
Thread.sleep(1000);
t2.start();
Thread.sleep(100);
t3.start();
Thread.sleep(4000);
assertTrue(booleanHolder1.get());
assertFalse(booleanHolder2.get());
assertFalse(booleanHolder3.get());
}
use of org.springframework.integration.store.MessageGroupQueue in project spring-integration by spring-projects.
the class MessageGroupQueueTests method testConcurrentWriteReadMulti.
@Test
public void testConcurrentWriteReadMulti() throws Exception {
final MessageGroupQueue queue = new MessageGroupQueue(new SimpleMessageStore(), 1, 4);
final AtomicReference<Message<?>> messageHolder = new AtomicReference<Message<?>>();
queue.offer(new GenericMessage<String>("hello"), 1000, TimeUnit.SECONDS);
Thread t1 = new Thread(() -> {
try {
queue.offer(new GenericMessage<String>("Hi"), 1000, TimeUnit.SECONDS);
queue.offer(new GenericMessage<String>("Hi"), 1000, TimeUnit.SECONDS);
queue.offer(new GenericMessage<String>("Hi"), 1000, TimeUnit.SECONDS);
} catch (Exception e) {
LogFactory.getLog(getClass()).error("queue offer failed", e);
}
});
Thread t2 = new Thread(() -> {
try {
queue.poll(1000, TimeUnit.SECONDS);
messageHolder.set(queue.poll(1000, TimeUnit.SECONDS));
queue.poll(1000, TimeUnit.SECONDS);
queue.poll(1000, TimeUnit.SECONDS);
} catch (Exception e) {
LogFactory.getLog(getClass()).error("queue poll failed", e);
}
});
t1.start();
Thread.sleep(1000);
t2.start();
Thread.sleep(1000);
assertTrue(messageHolder.get().getPayload().equals("Hi"));
assertNull(queue.poll(5, TimeUnit.SECONDS));
}
Aggregations