Search in sources :

Example 36 with StopWatch

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);
}
Also used : TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) SerializationFailedException(org.springframework.core.serializer.support.SerializationFailedException) NotSerializableException(java.io.NotSerializableException) MessageDeliveryException(org.springframework.messaging.MessageDeliveryException) StopWatch(org.springframework.util.StopWatch) Test(org.junit.Test) Repeat(org.springframework.test.annotation.Repeat)

Example 37 with StopWatch

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();
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) RequestReplyExchanger(org.springframework.integration.gateway.RequestReplyExchanger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CountDownLatch(java.util.concurrent.CountDownLatch) StopWatch(org.springframework.util.StopWatch) LongRunningIntegrationTest(org.springframework.integration.test.support.LongRunningIntegrationTest) Test(org.junit.Test)

Example 38 with StopWatch

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);
}
Also used : StopWatch(org.springframework.util.StopWatch)

Example 39 with StopWatch

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());
}
Also used : ITask(com.safframework.study.task.core.common.ITask) ConcurrentTasksExecutor(com.safframework.study.task.core.impl.ConcurrentTasksExecutor) ApiResponseDTO(com.safframework.study.task.web.dto.ApiResponseDTO) StopWatch(org.springframework.util.StopWatch)

Example 40 with StopWatch

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;
}
Also used : StopWatch(org.springframework.util.StopWatch) Around(org.aspectj.lang.annotation.Around)

Aggregations

StopWatch (org.springframework.util.StopWatch)106 Test (org.junit.Test)45 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)12 ArrayList (java.util.ArrayList)10 ITestBean (org.springframework.tests.sample.beans.ITestBean)9 TestBean (org.springframework.tests.sample.beans.TestBean)9 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)8 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)7 List (java.util.List)6 Test (org.junit.jupiter.api.Test)6 ITestBean (org.springframework.beans.testfixture.beans.ITestBean)6 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 ApplicationMap (com.navercorp.pinpoint.web.applicationmap.ApplicationMap)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 Ignore (org.junit.Ignore)5 NestedTestBean (org.springframework.tests.sample.beans.NestedTestBean)5 Range (com.navercorp.pinpoint.web.vo.Range)4 Dataset (org.apache.jena.query.Dataset)4