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);
}
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);
}
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);
}
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();
}
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()));
}
Aggregations