Search in sources :

Example 31 with StopWatch

use of org.springframework.util.StopWatch in project spring-integration by spring-projects.

the class DefaultHttpHeaderMapperFromMessageOutboundTests method perf.

@Test
@Ignore
public void perf() throws ParseException {
    HeaderMapper<HttpHeaders> mapper = DefaultHttpHeaderMapper.outboundMapper();
    HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.set("Transfer-Encoding", "chunked");
    httpHeaders.set("X-Transfer-Encoding1", "chunked");
    httpHeaders.set("X-Transfer-Encoding2", "chunked");
    httpHeaders.set("X-Transfer-Encoding3", "chunked");
    httpHeaders.set("X-Transfer-Encoding4", "chunked");
    httpHeaders.set("X-Transfer-Encoding5", "chunked");
    httpHeaders.set("X-Transfer-Encoding6", "chunked");
    httpHeaders.set("X-Transfer-Encoding7", "chunked");
    StopWatch watch = new StopWatch();
    watch.start();
    for (int i = 0; i < 100000; i++) {
        mapper.toHeaders(httpHeaders);
    }
    watch.stop();
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) StopWatch(org.springframework.util.StopWatch) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 32 with StopWatch

use of org.springframework.util.StopWatch in project spring-integration by spring-projects.

the class ConfigurableMongoDbMessageGroupStoreTests method messageGroupStoreLazyLoadPerformance.

@Test
@Ignore("The performance test. Enough slow. Also needs the release strategy changed to size() == 1000")
@MongoDbAvailable
public void messageGroupStoreLazyLoadPerformance() throws Exception {
    cleanupCollections(new SimpleMongoDbFactory(new MongoClient(), "test"));
    StopWatch watch = new StopWatch("Lazy-Load Performance");
    int sequenceSize = 1000;
    performLazyLoadEagerTest(watch, sequenceSize, true);
    performLazyLoadEagerTest(watch, sequenceSize, false);
// System. out .println(watch.prettyPrint()); // checkstyle
}
Also used : MongoClient(com.mongodb.MongoClient) SimpleMongoDbFactory(org.springframework.data.mongodb.core.SimpleMongoDbFactory) StopWatch(org.springframework.util.StopWatch) Ignore(org.junit.Ignore) Test(org.junit.Test) MongoDbAvailable(org.springframework.integration.mongodb.rules.MongoDbAvailable)

Example 33 with StopWatch

use of org.springframework.util.StopWatch in project spring-integration by spring-projects.

the class ExponentialMovingAverageRateTests method testRate.

@Test
// tolerance needed is too dependent on hardware
@Ignore
public void testRate() {
    ExponentialMovingAverageRate rate = new ExponentialMovingAverageRate(1, 60, 10);
    int count = 1000000;
    StopWatch watch = new StopWatch();
    watch.start();
    for (int i = 0; i < count; i++) {
        rate.increment();
    }
    watch.stop();
    double calculatedRate = count / (double) watch.getTotalTimeMillis() * 1000;
    assertEquals(calculatedRate, rate.getMean(), 4000000);
}
Also used : StopWatch(org.springframework.util.StopWatch) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 34 with StopWatch

use of org.springframework.util.StopWatch in project spring-integration by spring-projects.

the class ConnectionFactoryShutDownTests method testShutdownDoesntDeadlock.

@Test
public void testShutdownDoesntDeadlock() throws Exception {
    final AbstractConnectionFactory factory = new AbstractConnectionFactory(0) {

        @Override
        public TcpConnection getConnection() {
            return null;
        }
    };
    factory.setActive(true);
    Executor executor = factory.getTaskExecutor();
    final CountDownLatch latch1 = new CountDownLatch(1);
    final CountDownLatch latch2 = new CountDownLatch(1);
    executor.execute(() -> {
        latch1.countDown();
        try {
            while (true) {
                factory.getTaskExecutor();
                Thread.sleep(10);
            }
        } catch (MessagingException e1) {
        } catch (InterruptedException e2) {
            Thread.currentThread().interrupt();
        }
        latch2.countDown();
    });
    assertTrue(latch1.await(10, TimeUnit.SECONDS));
    StopWatch watch = new StopWatch();
    watch.start();
    factory.stop();
    watch.stop();
    assertTrue("Expected < 10000, was: " + watch.getLastTaskTimeMillis(), watch.getLastTaskTimeMillis() < 10000);
    assertTrue(latch1.await(10, TimeUnit.SECONDS));
}
Also used : Executor(java.util.concurrent.Executor) MessagingException(org.springframework.messaging.MessagingException) CountDownLatch(java.util.concurrent.CountDownLatch) StopWatch(org.springframework.util.StopWatch) Test(org.junit.Test)

Example 35 with StopWatch

use of org.springframework.util.StopWatch in project spring-integration by spring-projects.

the class JdbcLockRegistryDifferentClientTests method testExclusiveAccess.

@Test
public void testExclusiveAccess() throws Exception {
    DefaultLockRepository client1 = new DefaultLockRepository(dataSource);
    client1.afterPropertiesSet();
    final DefaultLockRepository client2 = new DefaultLockRepository(dataSource);
    client2.afterPropertiesSet();
    Lock lock1 = new JdbcLockRegistry(client1).obtain("foo");
    final BlockingQueue<Integer> data = new LinkedBlockingQueue<>();
    final CountDownLatch latch1 = new CountDownLatch(1);
    lock1.lockInterruptibly();
    new SimpleAsyncTaskExecutor().execute(() -> {
        Lock lock2 = new JdbcLockRegistry(client2).obtain("foo");
        try {
            latch1.countDown();
            StopWatch stopWatch = new StopWatch();
            stopWatch.start();
            lock2.lockInterruptibly();
            stopWatch.stop();
            data.add(4);
            Thread.sleep(10);
            data.add(5);
            Thread.sleep(10);
            data.add(6);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        } finally {
            lock2.unlock();
        }
    });
    assertTrue(latch1.await(10, TimeUnit.SECONDS));
    data.add(1);
    Thread.sleep(100);
    data.add(2);
    Thread.sleep(100);
    data.add(3);
    lock1.unlock();
    for (int i = 0; i < 6; i++) {
        Integer integer = data.poll(10, TimeUnit.SECONDS);
        assertNotNull(integer);
        assertEquals(i + 1, integer.intValue());
    }
}
Also used : SimpleAsyncTaskExecutor(org.springframework.core.task.SimpleAsyncTaskExecutor) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) CountDownLatch(java.util.concurrent.CountDownLatch) Lock(java.util.concurrent.locks.Lock) StopWatch(org.springframework.util.StopWatch) Test(org.junit.Test)

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