use of org.springframework.util.StopWatch 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);
}
use of org.springframework.util.StopWatch in project spring-integration by spring-projects.
the class MiscellaneousTests method testTimeoutHonoringWhenRequestsQueuedUp.
/**
* Asserts that receive-timeout is honored even if
* requests (once in process), takes less then receive-timeout value
* when requests are queued up (e.g., single consumer receiver)
*/
@Test
public void testTimeoutHonoringWhenRequestsQueuedUp() throws Exception {
ActiveMqTestUtils.prepare();
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("honor-timeout.xml", this.getClass());
final RequestReplyExchanger gateway = context.getBean(RequestReplyExchanger.class);
final CountDownLatch latch = new CountDownLatch(3);
final AtomicInteger replies = new AtomicInteger();
StopWatch stopWatch = new StopWatch();
stopWatch.start();
for (int i = 0; i < 3; i++) {
this.exchange(latch, gateway, replies);
}
latch.await();
stopWatch.stop();
assertTrue(stopWatch.getTotalTimeMillis() <= 18000);
assertEquals(1, replies.get());
context.close();
}
use of org.springframework.util.StopWatch in project spring-integration-samples by spring-projects.
the class PayloadAwareTimingInterceptor method preSend.
@Override
public Message<?> preSend(Message<?> message, MessageChannel channel) {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
this.stopWatchHolder.set(new StopWatchHolder(stopWatch, message.getPayload().getClass()));
return super.preSend(message, channel);
}
use of org.springframework.util.StopWatch in project RxJavaInAction by fengzhizi715.
the class TasksController method concurrent.
@GetMapping("/concurrent")
public ApiResponseDTO concurrent(@RequestParam("task") int[] taskDelaysInSeconds, @RequestParam("threads") int numberOfConcurrentThreads) {
StopWatch watch = new StopWatch();
watch.start();
List<ITask> delayedTasks = IntStream.of(taskDelaysInSeconds).mapToObj(MockTask::new).collect(Collectors.toList());
new ConcurrentTasksExecutor(numberOfConcurrentThreads, delayedTasks).execute();
watch.stop();
return new ApiResponseDTO(watch.getTotalTimeSeconds());
}
use of org.springframework.util.StopWatch in project Gemma by PavlidisLab.
the class MonitorAdvice method profile.
@Around("@annotation(ubic.gemma.persistence.util.monitor.Monitored)")
public Object profile(ProceedingJoinPoint pjp) throws Throwable {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
Object retVal = pjp.proceed();
stopWatch.stop();
log.info(pjp.getSignature().toString() + " took " + stopWatch.getLastTaskTimeMillis() + "ms.");
return retVal;
}
Aggregations