Search in sources :

Example 91 with StopWatch

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

the class MethodInvokingMessageProcessorTests method testPerformanceSpelVersusInvocable.

@Test
public void testPerformanceSpelVersusInvocable() throws Exception {
    AnnotatedTestService service = new AnnotatedTestService();
    Method method = service.getClass().getMethod("integerMethod", Integer.class);
    MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(service, method);
    processor.setUseSpelInvoker(true);
    Message<Integer> message = MessageBuilder.withPayload(42).build();
    StopWatch stopWatch = new StopWatch("SpEL vs Invocable Performance");
    int count = 20_000;
    stopWatch.start("SpEL");
    for (int i = 0; i < count; i++) {
        processor.processMessage(message);
    }
    stopWatch.stop();
    processor = new MethodInvokingMessageProcessor(service, method);
    stopWatch.start("Invocable");
    for (int i = 0; i < count; i++) {
        processor.processMessage(message);
    }
    stopWatch.stop();
    DirectFieldAccessor compilerConfigAccessor = compileImmediate(processor);
    processor = new MethodInvokingMessageProcessor(service, method);
    processor.setUseSpelInvoker(true);
    stopWatch.start("Compiled SpEL");
    for (int i = 0; i < count; i++) {
        processor.processMessage(message);
    }
    stopWatch.stop();
    logger.warn(stopWatch.prettyPrint());
    compilerConfigAccessor.setPropertyValue("compilerMode", SpelCompilerMode.OFF);
}
Also used : DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Method(java.lang.reflect.Method) StopWatch(org.springframework.util.StopWatch) Test(org.junit.Test)

Example 92 with StopWatch

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

the class AcceptOnceFileListFilterTests method testPerformance_INT3572.

@Test
public // This test used to take 34 seconds to run; now 25 milliseconds.
void testPerformance_INT3572() {
    StopWatch watch = new StopWatch();
    watch.start();
    AcceptOnceFileListFilter<String> filter = new AcceptOnceFileListFilter<String>();
    for (int i = 0; i < 100000; i++) {
        filter.accept("" + i);
    }
    watch.stop();
    assertTrue(watch.getTotalTimeMillis() < 5000);
}
Also used : StopWatch(org.springframework.util.StopWatch) Test(org.junit.Test)

Example 93 with StopWatch

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

the class JdbcMessageStoreChannelOnePollerIntegrationTests method testSameTransactionDifferentChannelSendAndReceive.

@Test
public void testSameTransactionDifferentChannelSendAndReceive() throws Exception {
    Service.reset(1);
    assertNull(this.durable.receive(100L));
    assertNull(this.relay.receive(100L));
    final StopWatch stopWatch = new StopWatch();
    boolean result = new TransactionTemplate(this.transactionManager).execute(status -> {
        synchronized (this.storeLock) {
            boolean result1 = this.relay.send(new GenericMessage<>("foo"), 500L);
            // This will time out because the transaction has not committed yet
            try {
                Service.await(100);
                fail("Expected timeout");
            } catch (Exception e) {
            // expected
            }
            try {
                stopWatch.start();
                // It hasn't arrive yet because we are still in the sending transaction
                assertNull(this.durable.receive(100L));
            } finally {
                stopWatch.stop();
            }
            return result1;
        }
    });
    assertTrue("Could not send message", result);
    // 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);
    Service.await(10000);
    // Eventual activation
    assertEquals(1, Service.messages.size());
    /*
		 * Without the storeLock:
		 *
		 * If we do this in a transaction it deadlocks occasionally. Without a transaction and it's pretty much every
		 * time.
		 *
		 * With the storeLock: It doesn't deadlock as long as the lock is injected into the poller as well.
		 */
    new TransactionTemplate(this.transactionManager).execute(status -> {
        synchronized (this.storeLock) {
            try {
                stopWatch.start();
                this.durable.receive(100L);
                return null;
            } 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) StopWatch(org.springframework.util.StopWatch) Test(org.junit.Test)

Example 94 with StopWatch

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

the class JdbcMessageStoreChannelIntegrationTests method testSameTransactionSendAndReceive.

@Test
public void testSameTransactionSendAndReceive() {
    final StopWatch stopWatch = new StopWatch();
    DefaultTransactionDefinition transactionDefinition = new DefaultTransactionDefinition();
    // With a timeout on the transaction the test fails (after a long time) on the assertion in the transactional
    // receive.
    transactionDefinition.setTimeout(200);
    boolean result = new TransactionTemplate(transactionManager, transactionDefinition).execute(status -> {
        synchronized (storeLock) {
            boolean result1 = input.send(new GenericMessage<String>("foo"), 500L);
            // This will time out because the transaction has not committed yet
            try {
                Service.await(1000);
                fail("Expected timeout");
            } catch (Exception e) {
            // expected
            }
            try {
                stopWatch.start();
                assertNotNull(input.receive(100L));
            } finally {
                stopWatch.stop();
            }
            return result1;
        }
    });
    assertTrue("Could not send message", result);
    // So no activation
    assertEquals(0, Service.messages.size());
    // 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() < 1000);
}
Also used : DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) Matchers.containsString(org.hamcrest.Matchers.containsString) 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)

Example 95 with StopWatch

use of org.springframework.util.StopWatch in project cuba by cuba-platform.

the class ClusteredHttpInvokerRequestExecutor method doExecuteRequest.

@Override
protected RemoteInvocationResult doExecuteRequest(HttpInvokerClientConfiguration config, ByteArrayOutputStream baos) throws IOException, ClassNotFoundException {
    RemoteInvocationResult result;
    Object context = serverSelector.initContext();
    String url = currentServiceUrl(serverSelector.getUrl(context), config);
    if (url == null)
        throw new IllegalStateException("Server URL list is empty");
    while (true) {
        HttpURLConnection con = openConnection(url);
        try {
            StopWatch sw = new StopWatch();
            prepareConnection(con, baos.size());
            writeRequestBody(config, con, baos);
            sw.start("waiting time");
            validateResponse(config, con);
            CountingInputStream responseInputStream = new CountingInputStream(readResponseBody(config, con));
            sw.stop();
            serverSelector.success(context);
            sw.start("reading time");
            try (ObjectInputStream ois = createObjectInputStream(decorateInputStream(responseInputStream), config.getCodebaseUrl())) {
                result = doReadRemoteInvocationResult(ois);
            }
            sw.stop();
            if (log.isDebugEnabled()) {
                log.debug(String.format("Receiving HTTP invoker response for service at [%s], with size %s, %s", config.getServiceUrl(), responseInputStream.getCount(), printStopWatch(sw)));
            }
            break;
        } catch (IOException e) {
            log.info(String.format("Invocation of %s failed: %s", url, e));
            serverSelector.fail(context);
            url = currentServiceUrl(serverSelector.getUrl(context), config);
            if (url != null) {
                log.info("Trying to invoke the next available URL: " + url);
                continue;
            }
            log.info("No more URL available");
            throw e;
        }
    }
    return result;
}
Also used : HttpURLConnection(java.net.HttpURLConnection) RemoteInvocationResult(org.springframework.remoting.support.RemoteInvocationResult) CountingInputStream(com.google.common.io.CountingInputStream) IOException(java.io.IOException) StopWatch(org.springframework.util.StopWatch) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

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