Search in sources :

Example 96 with StopWatch

use of org.springframework.util.StopWatch in project tutorials by eugenp.

the class TransactionalService method getQuickHowManyVisits.

public Integer getQuickHowManyVisits() {
    try {
        TransactionManager tm = transactionalCache.getAdvancedCache().getTransactionManager();
        tm.begin();
        Integer howManyVisits = transactionalCache.get(KEY);
        howManyVisits++;
        System.out.println("Ill try to set HowManyVisits to " + howManyVisits);
        StopWatch watch = new StopWatch();
        watch.start();
        transactionalCache.put(KEY, howManyVisits);
        watch.stop();
        System.out.println("I was able to set HowManyVisits to " + howManyVisits + " after waiting " + watch.getTotalTimeSeconds() + " seconds");
        tm.commit();
        return howManyVisits;
    } catch (Exception e) {
        e.printStackTrace();
        return 0;
    }
}
Also used : TransactionManager(javax.transaction.TransactionManager) StopWatch(org.springframework.util.StopWatch)

Example 97 with StopWatch

use of org.springframework.util.StopWatch in project TeachingInSimulation by ScOrPiOzzy.

the class FileDownload method testConcurrent.

@Test
public void testConcurrent() throws Exception {
    FTPUtils util = getUtil("anonymous", "");
    StopWatch w = new StopWatch();
    w.start("开始下载");
    InputStream stream = util.downloadFile("/assets/Model/", "11.j3o");
    FileOutputStream out;
    try {
        File file;
        out = new FileOutputStream(file = new File("model-file-" + 0));
        Util.copyStream(stream, out);
        out.close();
        // 服务器中11.j3o文件大小是3,506,624
        Assert.assertEquals(3506624, file.length());
        w.stop();
        System.out.println(w.getTotalTimeMillis());
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) FTPUtils(com.cas.sim.tis.util.FTPUtils) IOException(java.io.IOException) File(java.io.File) StopWatch(org.springframework.util.StopWatch) Test(org.junit.Test)

Example 98 with StopWatch

use of org.springframework.util.StopWatch in project WTFDYUM by jchampemont.

the class CronServiceImpl method checkCredentials.

@Override
@Scheduled(fixedDelayString = "${wtfdyum.credentials-check-delay}", initialDelay = 120000L)
public void checkCredentials() {
    log.debug("Checking credentials...");
    final StopWatch watch = new StopWatch();
    watch.start();
    final Set<Long> members = principalService.getMembers();
    for (final Long userId : members) {
        final Principal principal = principalService.get(userId);
        if (!twitterService.verifyCredentials(principal)) {
            userService.applyLimit(userId, UserLimitType.CREDENTIALS_INVALID);
            userService.addEvent(userId, new Event(EventType.INVALID_TWITTER_CREDENTIALS, ""));
        } else {
            userService.resetLimit(userId, UserLimitType.CREDENTIALS_INVALID);
        }
    }
    watch.stop();
    log.debug("Finished checking credentials in {} ms", watch.getTotalTimeMillis());
}
Also used : Event(com.jeanchampemont.wtfdyum.dto.Event) Principal(com.jeanchampemont.wtfdyum.dto.Principal) StopWatch(org.springframework.util.StopWatch) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 99 with StopWatch

use of org.springframework.util.StopWatch in project WTFDYUM by jchampemont.

the class CronServiceImpl method cron.

@Override
@Scheduled(fixedDelayString = "${wtfdyum.unfollow-check-delay}", initialDelay = 120000L)
public void cron() {
    log.debug("Starting cron method...");
    final StopWatch watch = new StopWatch();
    watch.start();
    final Set<Long> members = principalService.getMembers();
    for (final Long userId : members) {
        try {
            final Set<Feature> enabledFeatures = userService.getEnabledFeatures(userId);
            final Set<Event> events = new HashSet<>();
            for (final Feature enabledFeature : enabledFeatures) {
                final Set<Event> es = featureService.cron(userId, enabledFeature);
                events.addAll(es);
            }
            for (final Event e : events) {
                userService.addEvent(userId, e);
            }
            for (final Feature enabledFeature : enabledFeatures) {
                featureService.completeCron(userId, enabledFeature);
            }
        } catch (final WTFDYUMException e) {
            if (WTFDYUMExceptionType.GET_FOLLOWERS_RATE_LIMIT_EXCEEDED.equals(e.getType())) {
                userService.addEvent(userId, new Event(EventType.RATE_LIMIT_EXCEEDED, null));
                log.warn("GET_FOLLOWERS_RATE_LIMIT_EXCEEDED for user id {}", userId);
            } else {
                userService.addEvent(userId, new Event(EventType.TWITTER_ERROR, null));
                log.error("Twitter error for userId " + userId, e.getCause());
            }
        } catch (final Throwable t) {
            userService.addEvent(userId, new Event(EventType.UNKNOWN_ERROR, null));
            log.error("Unknown error for user id " + userId, t);
        }
    }
    watch.stop();
    log.debug("Finished cron in {} ms", watch.getTotalTimeMillis());
}
Also used : WTFDYUMException(com.jeanchampemont.wtfdyum.utils.WTFDYUMException) Event(com.jeanchampemont.wtfdyum.dto.Event) Feature(com.jeanchampemont.wtfdyum.dto.Feature) StopWatch(org.springframework.util.StopWatch) HashSet(java.util.HashSet) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 100 with StopWatch

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

the class ProtectPointcutPerformanceTests method usingPrototypeDoesNotParsePointcutOnEachCall.

// Method for use with profiler
@Test
public void usingPrototypeDoesNotParsePointcutOnEachCall() {
    StopWatch sw = new StopWatch();
    sw.start();
    for (int i = 0; i < 1000; i++) {
        try {
            SessionRegistry reg = (SessionRegistry) this.ctx.getBean("sessionRegistryPrototype");
            reg.getAllPrincipals();
            fail("Expected AuthenticationCredentialsNotFoundException");
        } catch (AuthenticationCredentialsNotFoundException expected) {
        }
    }
    sw.stop();
// assertThat(sw.getTotalTimeMillis() < 1000).isTrue();
}
Also used : SessionRegistry(org.springframework.security.core.session.SessionRegistry) AuthenticationCredentialsNotFoundException(org.springframework.security.authentication.AuthenticationCredentialsNotFoundException) StopWatch(org.springframework.util.StopWatch) Test(org.junit.jupiter.api.Test)

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