use of org.springframework.test.annotation.Repeat in project spring-integration by spring-projects.
the class GroovyScriptExecutingMessageProcessorTests method testSimpleExecution.
@Test
@Repeat(20)
public void testSimpleExecution() throws Exception {
int count = countHolder.getAndIncrement();
String script = "return \"payload is $payload, header is $headers.testHeader\"";
Message<?> message = MessageBuilder.withPayload("foo").setHeader("testHeader", "bar" + count).build();
TestResource resource = new TestResource(script, "simpleTest");
ScriptSource scriptSource = new ResourceScriptSource(resource);
MessageProcessor<Object> processor = new GroovyScriptExecutingMessageProcessor(scriptSource);
Object result = processor.processMessage(message);
assertEquals("payload is foo, header is bar" + count, result.toString());
}
use of org.springframework.test.annotation.Repeat in project spring-integration by spring-projects.
the class RepeatProcessor method apply.
public Statement apply(final Statement base, FrameworkMethod method, Object target) {
Repeat repeat = AnnotationUtils.findAnnotation(method.getMethod(), Repeat.class);
if (repeat == null) {
return base;
}
final int repeats = repeat.value();
if (concurrency <= 0) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
for (int i = 0; i < repeats; i++) {
try {
base.evaluate();
} catch (Throwable t) {
throw new IllegalStateException("Failed on iteration: " + i, t);
}
}
}
};
}
return new Statement() {
@Override
public void evaluate() throws Throwable {
List<Future<Boolean>> results = new ArrayList<Future<Boolean>>();
ExecutorService executor = Executors.newFixedThreadPool(concurrency);
try {
for (int i = 0; i < repeats; i++) {
final int count = i;
results.add(executor.submit(new Callable<Boolean>() {
public Boolean call() {
try {
base.evaluate();
} catch (Throwable t) {
throw new IllegalStateException("Failed on iteration: " + count, t);
}
return true;
}
}));
}
for (Future<Boolean> future : results) {
assertTrue("Null result from completer", future.get(10, TimeUnit.SECONDS));
}
} finally {
executor.shutdownNow();
}
}
};
}
use of org.springframework.test.annotation.Repeat in project spring-integration by spring-projects.
the class MySqlJdbcMessageStoreTests method testSameMessageToMultipleGroups.
@Test
@Transactional
@Rollback(false)
@Repeat(20)
public void testSameMessageToMultipleGroups() throws Exception {
final String group1Id = "group1";
final String group2Id = "group2";
final Message<String> message = MessageBuilder.withPayload("foo").build();
final MessageBuilder<String> builder1 = MessageBuilder.fromMessage(message);
final MessageBuilder<String> builder2 = MessageBuilder.fromMessage(message);
builder1.setSequenceNumber(1);
builder2.setSequenceNumber(2);
final Message<?> message1 = builder1.build();
final Message<?> message2 = builder2.build();
messageStore.addMessageToGroup(group1Id, message1);
messageStore.addMessageToGroup(group2Id, message2);
final Message<?> messageFromGroup1 = messageStore.pollMessageFromGroup(group1Id);
final Message<?> messageFromGroup2 = messageStore.pollMessageFromGroup(group2Id);
assertNotNull(messageFromGroup1);
assertNotNull(messageFromGroup2);
LOG.info("messageFromGroup1: " + messageFromGroup1.getHeaders().getId() + "; Sequence #: " + new IntegrationMessageHeaderAccessor(messageFromGroup1).getSequenceNumber());
LOG.info("messageFromGroup2: " + messageFromGroup2.getHeaders().getId() + "; Sequence #: " + new IntegrationMessageHeaderAccessor(messageFromGroup2).getSequenceNumber());
assertEquals(Integer.valueOf(1), messageFromGroup1.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER));
assertEquals(Integer.valueOf(2), messageFromGroup2.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER));
}
use of org.springframework.test.annotation.Repeat in project spring-integration by spring-projects.
the class MySqlJdbcMessageStoreTests method testSameMessageAndGroupToMultipleRegions.
@Test
@Transactional
@Rollback(false)
@Repeat(20)
public void testSameMessageAndGroupToMultipleRegions() throws Exception {
final String groupId = "myGroup";
final String region1 = "region1";
final String region2 = "region2";
final JdbcMessageStore messageStore1 = new JdbcMessageStore(dataSource);
messageStore1.setRegion(region1);
final JdbcMessageStore messageStore2 = new JdbcMessageStore(dataSource);
messageStore1.setRegion(region2);
final Message<String> message = MessageBuilder.withPayload("foo").build();
final MessageBuilder<String> builder1 = MessageBuilder.fromMessage(message);
final MessageBuilder<String> builder2 = MessageBuilder.fromMessage(message);
builder1.setSequenceNumber(1);
builder2.setSequenceNumber(2);
final Message<?> message1 = builder1.build();
final Message<?> message2 = builder2.build();
messageStore1.addMessageToGroup(groupId, message1);
messageStore2.addMessageToGroup(groupId, message2);
final Message<?> messageFromRegion1 = messageStore1.pollMessageFromGroup(groupId);
final Message<?> messageFromRegion2 = messageStore2.pollMessageFromGroup(groupId);
assertNotNull(messageFromRegion1);
assertNotNull(messageFromRegion2);
LOG.info("messageFromRegion1: " + messageFromRegion1.getHeaders().getId() + "; Sequence #: " + new IntegrationMessageHeaderAccessor(messageFromRegion1).getSequenceNumber());
LOG.info("messageFromRegion2: " + messageFromRegion2.getHeaders().getId() + "; Sequence #: " + new IntegrationMessageHeaderAccessor(messageFromRegion2).getSequenceNumber());
assertEquals(Integer.valueOf(1), messageFromRegion1.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER));
assertEquals(Integer.valueOf(2), messageFromRegion2.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER));
}
use of org.springframework.test.annotation.Repeat in project spring-integration by spring-projects.
the class JdbcMessageStoreChannelIntegrationTests method testTransactionalSendAndReceive.
@Test
@Repeat(2)
public void testTransactionalSendAndReceive() throws Exception {
boolean result = new TransactionTemplate(transactionManager).execute(status -> {
synchronized (storeLock) {
boolean result1 = input.send(new GenericMessage<>("foo"), 100L);
// This will time out because the transaction has not committed yet
try {
Service.await(100);
fail("Expected timeout");
} catch (Exception e) {
// expected
}
return result1;
}
});
assertTrue("Could not send message", result);
waitForMessage();
StopWatch stopWatch = new StopWatch();
try {
stopWatch.start();
// It might be null or not, but we don't want it to block
input.receive(100L);
} finally {
stopWatch.stop();
}
// If the poll blocks in the RDBMS there is no way for the queue to respect the timeout
assertTrue("Timed out waiting for receive", stopWatch.getTotalTimeMillis() < 10000);
}
Aggregations