Search in sources :

Example 16 with StopWatch

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

the class AnnotationProcessorPerformanceTests method testPrototypeCreationWithOverriddenResourcePropertiesIsFastEnough.

@Test
public void testPrototypeCreationWithOverriddenResourcePropertiesIsFastEnough() {
    GenericApplicationContext ctx = new GenericApplicationContext();
    AnnotationConfigUtils.registerAnnotationConfigProcessors(ctx);
    ctx.refresh();
    RootBeanDefinition rbd = new RootBeanDefinition(ResourceAnnotatedTestBean.class);
    rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
    rbd.getPropertyValues().add("spouse", new RuntimeBeanReference("spouse"));
    ctx.registerBeanDefinition("test", rbd);
    ctx.registerBeanDefinition("spouse", new RootBeanDefinition(TestBean.class));
    TestBean spouse = (TestBean) ctx.getBean("spouse");
    StopWatch sw = new StopWatch();
    sw.start("prototype");
    for (int i = 0; i < 100000; i++) {
        TestBean tb = (TestBean) ctx.getBean("test");
        assertSame(spouse, tb.getSpouse());
    }
    sw.stop();
    assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 4000);
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) StopWatch(org.springframework.util.StopWatch) Test(org.junit.Test)

Example 17 with StopWatch

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

the class AnnotationProcessorPerformanceTests method testPrototypeCreationWithOverriddenAutowiredPropertiesIsFastEnough.

@Test
public void testPrototypeCreationWithOverriddenAutowiredPropertiesIsFastEnough() {
    GenericApplicationContext ctx = new GenericApplicationContext();
    AnnotationConfigUtils.registerAnnotationConfigProcessors(ctx);
    ctx.refresh();
    RootBeanDefinition rbd = new RootBeanDefinition(AutowiredAnnotatedTestBean.class);
    rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
    rbd.getPropertyValues().add("spouse", new RuntimeBeanReference("spouse"));
    ctx.registerBeanDefinition("test", rbd);
    ctx.registerBeanDefinition("spouse", new RootBeanDefinition(TestBean.class));
    TestBean spouse = (TestBean) ctx.getBean("spouse");
    StopWatch sw = new StopWatch();
    sw.start("prototype");
    for (int i = 0; i < 100000; i++) {
        TestBean tb = (TestBean) ctx.getBean("test");
        assertSame(spouse, tb.getSpouse());
    }
    sw.stop();
    assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 6000);
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) StopWatch(org.springframework.util.StopWatch) Test(org.junit.Test)

Example 18 with StopWatch

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

the class AnnotationProcessorPerformanceTests method testPrototypeCreationWithResourcePropertiesIsFastEnough.

@Test
public void testPrototypeCreationWithResourcePropertiesIsFastEnough() {
    GenericApplicationContext ctx = new GenericApplicationContext();
    AnnotationConfigUtils.registerAnnotationConfigProcessors(ctx);
    ctx.refresh();
    RootBeanDefinition rbd = new RootBeanDefinition(ResourceAnnotatedTestBean.class);
    rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
    ctx.registerBeanDefinition("test", rbd);
    ctx.registerBeanDefinition("spouse", new RootBeanDefinition(TestBean.class));
    TestBean spouse = (TestBean) ctx.getBean("spouse");
    StopWatch sw = new StopWatch();
    sw.start("prototype");
    for (int i = 0; i < 100000; i++) {
        TestBean tb = (TestBean) ctx.getBean("test");
        assertSame(spouse, tb.getSpouse());
    }
    sw.stop();
    assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 4000);
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) StopWatch(org.springframework.util.StopWatch) Test(org.junit.Test)

Example 19 with StopWatch

use of org.springframework.util.StopWatch in project webofneeds by researchstudio-sat.

the class DebugBotIncomingMessageToEventMappingAction method referToEarlierMessages.

private void referToEarlierMessages(EventListenerContext ctx, EventBus bus, Connection con, String crawlAnnouncement, MessageFinder messageFinder, MessageReferrer messageReferrer, TextMessageMaker textMessageMaker) {
    Model messageModel = WonRdfUtils.MessageUtils.textMessage(crawlAnnouncement);
    bus.publish(new ConnectionMessageCommandEvent(con, messageModel));
    // initiate crawl behaviour
    CrawlConnectionCommandEvent command = new CrawlConnectionCommandEvent(con.getNeedURI(), con.getConnectionURI());
    CrawlConnectionDataBehaviour crawlConnectionDataBehaviour = new CrawlConnectionDataBehaviour(ctx, command, Duration.ofSeconds(60));
    final StopWatch crawlStopWatch = new StopWatch();
    crawlStopWatch.start("crawl");
    AgreementProtocolState state = WonConversationUtils.getAgreementProtocolState(con.getConnectionURI(), ctx.getLinkedDataSource());
    crawlStopWatch.stop();
    Duration crawlDuration = Duration.ofMillis(crawlStopWatch.getLastTaskTimeMillis());
    messageModel = WonRdfUtils.MessageUtils.textMessage("Finished crawl in " + getDurationString(crawlDuration) + " seconds. The dataset has " + state.getConversationDataset().asDatasetGraph().size() + " rdf graphs.");
    getEventListenerContext().getEventBus().publish(new ConnectionMessageCommandEvent(con, messageModel));
    messageModel = makeReferringMessage(state, messageFinder, messageReferrer, textMessageMaker);
    getEventListenerContext().getEventBus().publish(new ConnectionMessageCommandEvent(con, messageModel));
    crawlConnectionDataBehaviour.activate();
}
Also used : CrawlConnectionDataBehaviour(won.bot.framework.eventbot.behaviour.CrawlConnectionDataBehaviour) Model(org.apache.jena.rdf.model.Model) Duration(java.time.Duration) AgreementProtocolState(won.protocol.agreement.AgreementProtocolState) ConnectionMessageCommandEvent(won.bot.framework.eventbot.event.impl.command.connectionmessage.ConnectionMessageCommandEvent) CrawlConnectionCommandEvent(won.bot.framework.eventbot.event.impl.crawlconnection.CrawlConnectionCommandEvent) StopWatch(org.springframework.util.StopWatch)

Example 20 with StopWatch

use of org.springframework.util.StopWatch in project webofneeds by researchstudio-sat.

the class CrawlAction method doRun.

@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
    if (!(event instanceof CrawlCommandEvent))
        return;
    CrawlCommandEvent crawlCommandEvent = (CrawlCommandEvent) event;
    EventListenerContext ctx = getEventListenerContext();
    logger.debug("starting crawl for {}", crawlCommandEvent.getStartURI());
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    Dataset crawledData = null;
    try {
        crawledData = ctx.getLinkedDataSource().getDataForResourceWithPropertyPath(crawlCommandEvent.getStartURI(), crawlCommandEvent.getNeedURI(), crawlCommandEvent.getPropertyPaths(), crawlCommandEvent.getGetMaxRequest(), crawlCommandEvent.getMaxDepth());
    } catch (Exception e) {
        logger.debug("caught exeption during crawl for {}", crawlCommandEvent.getStartURI(), e);
        ctx.getEventBus().publish(new CrawlCommandFailureEvent(crawlCommandEvent, "Could not crawl " + crawlCommandEvent.getStartURI() + " with WebID " + crawlCommandEvent.getNeedURI() + ": caught " + e));
        return;
    }
    stopWatch.stop();
    logger.debug("finished crawl for {} in {} millis", crawlCommandEvent.getStartURI(), stopWatch.getTotalTimeMillis());
    ctx.getEventBus().publish(new CrawlCommandSuccessEvent(crawlCommandEvent, crawledData, "Finished crawling " + crawlCommandEvent.getStartURI() + " in " + stopWatch.getTotalTimeMillis()));
}
Also used : EventListenerContext(won.bot.framework.eventbot.EventListenerContext) CrawlCommandEvent(won.bot.framework.eventbot.event.impl.crawl.CrawlCommandEvent) CrawlCommandFailureEvent(won.bot.framework.eventbot.event.impl.crawl.CrawlCommandFailureEvent) Dataset(org.apache.jena.query.Dataset) CrawlCommandSuccessEvent(won.bot.framework.eventbot.event.impl.crawl.CrawlCommandSuccessEvent) StopWatch(org.springframework.util.StopWatch)

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