Java Code Examples for org.apache.commons.lang.time.StopWatch

The following are top voted examples for showing how to use org.apache.commons.lang.time.StopWatch. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: loom   File: BasicQueryOperations.java   View source code 6 votes vote down vote up
static List<QueryResult> queryAllThreads(final LoomClient client, final TapestryDefinition tapestryDefinition) {
    List<QueryResult> queryResults = new ArrayList<QueryResult>(tapestryDefinition.getThreads().size());
    StopWatch watch = new StopWatch();
    watch.start();
    List<ThreadDefinition> threads = tapestryDefinition.getThreads();
    for (ThreadDefinition thread : threads) {
        String threadId = thread.getId();
        QueryResult qr =
                getThreadWithWait(client, tapestryDefinition.getId(), threadId, IntegrationTestBase.greaterThan0);
        assertFalse("Result of a query did not contain elements for " + threadId, qr.getElements().isEmpty());
        queryResults.add(qr);
    }
    watch.stop();
    log.info("Getting all threads time=" + watch);
    assertFalse("Loom stuck in performance black hole", watch.getTime() > (60 * 1000));
    RelationshipsHandling.checkCrossThreadRelationships(queryResults);
    return queryResults;
}
 
Example 2
Project: GitHub   File: TestFastJson.java   View source code 6 votes vote down vote up
@Test
public void testSerializePerformance() throws IOException {
    Object obj = createTest();

    for (int x = 0; x < 20; ++x) {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        for (int i = 0; i < TIMES; ++i) {
            jsonSerialize(obj);
        }
        stopWatch.stop();

        System.out.println("JSON serialize:" + stopWatch.getTime());

        stopWatch.reset();
        stopWatch.start();
        for (int i = 0; i < TIMES; ++i) {
            javaSerialize(obj);
        }
        stopWatch.stop();
        System.out.println("JAVA serialize:" + stopWatch.getTime());
        System.out.println();
    }
}
 
Example 3
Project: soundwave   File: EsServiceMappingStore.java   View source code 6 votes vote down vote up
public List<EsServiceMapping> getServiceMappings() throws Exception {
  StopWatch sw = new StopWatch();
  sw.start();
  List<EsServiceMapping> ret = new ArrayList<>();
  SearchResponse result = getByDocType(10000);
  for (SearchHit hit : result.getHits()) {
    try {
      EsServiceMapping
          serviceMapping =
          mapper.readValue(hit.getSourceAsString(), EsServiceMapping.class);
      serviceMapping.buildMatchPatterns();
      ret.add(serviceMapping);
    } catch (Exception ex) {
      logger.error("Cannot create Service mapping from {}", hit.getSourceAsString());
    }
  }
  sw.stop();
  logger.info("Refresh all service mappings in {} ms", sw.getTime());
  return ret;
}
 
Example 4
Project: jsf-core   File: CallbackLogWorker.java   View source code 6 votes vote down vote up
@Override
public boolean run() {
    if (!CheckDBWorker.isDBOK) {
        return true;
    }
    logger.info("callback-log delete worker is starting ...");
    StopWatch clock = new StopWatch();
    try {
        clock.start();     // 计时开始
        callbackLogServiceImpl.deleteByTime();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        return false;
    } finally {
        clock.stop();      // 计时结束
    }
    logger.info("callback-log delete worker is finished ...... it elapse time: " + clock.getTime() + " ms");
    return true;
}
 
Example 5
Project: jsf-core   File: ServiceTraceLogWorker.java   View source code 6 votes vote down vote up
@Override
public boolean run() {
    if (!CheckDBWorker.isDBOK) {
        return true;
    }
    logger.info("servicetrace-log delete worker is starting ...");
    StopWatch clock = new StopWatch();
    try {
        clock.start();     // 计时开始
        serviceTraceLogServiceImpl.deleteByTime();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        return false;
    } finally {
        clock.stop();      // 计时结束
    }
    logger.info("servicetrace-log delete worker is finished ...... it elapse time: " + clock.getTime() + " ms");
    return true;
}
 
Example 6
Project: loom   File: TestStitcherSession.java   View source code 6 votes vote down vote up
@Override
public void removeStitchedItems(final String typeId, final String providerId) {

    if (!allowStitching) {
        return;
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("Remove all stitched items typeId=" + typeId + " providerId=" + providerId);
    }

    if (ruleManager.rulesExistForItemTypeId(typeId)) {
        StopWatch watch = new StopWatch();
        watch.start();
        // There may be stitches for this item type, which are removed by this call to
        // itemIndexer.
        itemIndexer.removeAllItemsForTypeIdAndProviderId(typeId, providerId);
        itemAttributeIndexer.removeAllItemsForTypeIdAndProviderId(typeId, providerId);
        watch.stop();
        LOG.info("removeStitchedItems " + typeId + " " + providerId + " time=" + watch);
    }
}
 
Example 7
Project: loom   File: RestClient.java   View source code 6 votes vote down vote up
private <T> T get(final String url, final java.lang.Class<T> tClass, final Object... uriVariables) {
    setErrorHandler();
    StopWatch watch = new StopWatch();
    watch.start();
    // T object = restTemplate.getForObject(url, tClass, uriVariables);

    ResponseEntity<T> response = restTemplate.getForEntity(url, tClass, uriVariables);
    HttpHeaders headers = response.getHeaders();

    List<String> cookies = headers.get("Set-Cookie");
    if (cookies != null && cookies.size() > 0) {
        for (String cookie : cookies) {
            if (cookie.substring(0, cookie.indexOf("=")).equals(LoomClient.SESSION_COOKIE)) {
                sessionId = cookie.substring(cookie.indexOf("=") + 1, cookie.indexOf(";"));
                if (sessionId.equals("")) {
                    sessionId = null;
                }
                break;
            }
        }
    }

    watch.stop();
    if (log.isTraceEnabled()) {
        String args = "";
        for (Object arg : uriVariables) {
            args += " " + arg;
        }
        if (watch.getTime() > timewarning) {
            log.trace("GET " + url + " " + args + " WARNING: Operation took " + watch);
        } else {
            log.trace("GET " + url + " " + args + " Operation took " + watch);
        }
    }

    return response.getBody();
    // return object;
}
 
Example 8
Project: loom   File: QueryExecutorImplTest.java   View source code 6 votes vote down vote up
@Test
public void testGetSameQuery()
        throws NoSuchSessionException, NoSuchTapestryDefinitionException, IllegalAccessException,
        UnsupportedOperationException, OperationException, NoSuchAggregationException, InvalidQueryInputException,
        LogicalIdAlreadyExistsException, NoSuchQueryDefinitionException, NoSuchThreadDefinitionException,
        OperationNotSupportedException, InvalidQueryParametersException, PendingQueryResultsException,
        ItemPropertyNotFound, RelationPropertyNotFound, IllegalArgumentException, ThreadDeletedByDynAdapterUnload {

    tap = new TapestryDefinition();
    tap.setThreads(identityThreads);
    tapestryManager.setTapestryDefinition(session, tap);

    StopWatch watch = new StopWatch();
    LOG.info("testing Get Same Query process");
    watch.start();
    QueryResult results = queryExec.processQuery(session, tap.getThreads().get(0));
    QueryResult sameResults = queryExec.processQuery(session, tap.getThreads().get(0));

    assertTrue(results.getLogicalId().equals(sameResults.getLogicalId()));
    assertTrue(results.getElements().size() == sameResults.getElements().size());

    watch.stop();
    LOG.info("tested Get Same Query process --> " + watch);
}
 
Example 9
Project: loom   File: OsItemTest.java   View source code 6 votes vote down vote up
@Test
public void testVolumeJson() throws Exception {
    StopWatch watch = new StopWatch();
    LOG.info("testing VolumeJson");
    watch.start();
    // create a volume Item
    ItemType type = new OsVolumeType(provider);
    type.setId("os-" + type.getLocalId());
    OsVolume volume = new OsVolume("/os/fake/volumes/v1", type);
    OsVolumeAttributes ova =
            new OsVolumeAttributes("v1", "vId1", 40, "AVAILABLE", "zone", new Date().toString(), "None", "1234");
    ova.setItemDescription("A description");
    volume.setCore(ova);
    LOG.info("created JSON is\n" + toJson(volume));
    watch.stop();
    LOG.info("tested VolumeJson --> " + watch);
}
 
Example 10
Project: loom   File: QueryExecutorImplTest.java   View source code 6 votes vote down vote up
@Test(expected = NoSuchSessionException.class)
public void nonExistentSession()
        throws NoSuchSessionException, NoSuchTapestryDefinitionException, LogicalIdAlreadyExistsException,
        NoSuchAggregationException, IllegalAccessException, OperationException, UnsupportedOperationException,
        InvalidQueryInputException, NoSuchQueryDefinitionException, NoSuchThreadDefinitionException,
        OperationNotSupportedException, InvalidQueryParametersException, PendingQueryResultsException,
        ItemPropertyNotFound, RelationPropertyNotFound, IllegalArgumentException, ThreadDeletedByDynAdapterUnload {
    tap = new TapestryDefinition();
    tap.setThreads(groupBraidThreads);
    tapestryManager.setTapestryDefinition(session, tap);

    StopWatch watch = new StopWatch();
    LOG.info("testing bad session process");
    watch.start();
    queryExec.processQuery(new SessionImpl(UUID.randomUUID().toString(), sessionManager.getInterval()),
            tap.getThreads().get(0));

    watch.stop();
    LOG.info("tested bad session process --> " + watch);
}
 
Example 11
Project: loom   File: QueryExecutorImplTest.java   View source code 6 votes vote down vote up
@Test(expected = NoSuchAggregationException.class)
public void nonExistentAggregation()
        throws NoSuchSessionException, NoSuchTapestryDefinitionException, LogicalIdAlreadyExistsException,
        NoSuchAggregationException, IllegalAccessException, OperationException, UnsupportedOperationException,
        InvalidQueryInputException, NoSuchQueryDefinitionException, NoSuchThreadDefinitionException,
        OperationNotSupportedException, InvalidQueryParametersException, PendingQueryResultsException,
        ItemPropertyNotFound, RelationPropertyNotFound, IllegalArgumentException, ThreadDeletedByDynAdapterUnload {
    tap = new TapestryDefinition();
    tap.setThreads(groupBraidThreads);
    tapestryManager.setTapestryDefinition(session, tap);

    StopWatch watch = new StopWatch();
    LOG.info("testing bad aggregation process");
    List<String> badSources = new ArrayList<>(1);
    badSources.add("/bad/sources");

    watch.start();
    groupBraidQuery.setInputs(badSources);
    queryExec.processQuery(session, tap.getThreads().get(0));

    watch.stop();
    LOG.info("tested bad aggregation process --> " + watch);
}
 
Example 12
Project: loom   File: OperationManagerImplTest.java   View source code 6 votes vote down vote up
@Test
public void testWrongUUIDRegister() {
    StopWatch watch = new StopWatch();
    LOG.info("testing OpMgrRegistration");
    watch.start();

    List<String> opList = opMgr.listOperations(UUID.randomUUID());
    assertTrue(opList.size() == 0);

    opMgr.registerOperation("FAKEOP", firstMeta, UUID.randomUUID());
    assertEquals(startValues, opMgr.listOperations(OperationManagerImpl.LOOM_UUID).size());

    opMgr.registerOperation("", firstMeta, OperationManagerImpl.LOOM_UUID);
    assertEquals(startValues, opMgr.listOperations(OperationManagerImpl.LOOM_UUID).size());

    opMgr.registerOperation("FAKEOP", null, OperationManagerImpl.LOOM_UUID);
    assertEquals(startValues, opMgr.listOperations(OperationManagerImpl.LOOM_UUID).size());

    watch.stop();
    LOG.info("tested OpMgrRegistration --> " + watch);

}
 
Example 13
Project: loom   File: OperationManagerImplTest.java   View source code 6 votes vote down vote up
@Test
public void testWrongProviderRegister() {
    StopWatch watch = new StopWatch();
    LOG.info("testing OpMgrRegistration");
    watch.start();

    opMgr.registerOperation4Provider("FAKEOP", firstMeta, null);
    assertEquals(startValues, opMgr.listOperations(OperationManagerImpl.LOOM_UUID).size());

    opMgr.registerOperation4Provider("", firstMeta, new ProviderImpl("test", "test", "none", "test", "com"));
    assertEquals(startValues, opMgr.listOperations(OperationManagerImpl.LOOM_UUID).size());

    opMgr.registerOperation4Provider("FAKEOP", null, new ProviderImpl("test", "test", "none", "test", "com"));
    assertEquals(startValues, opMgr.listOperations(OperationManagerImpl.LOOM_UUID).size());

    watch.stop();
    LOG.info("tested OpMgrRegistration --> " + watch);
}
 
Example 14
Project: loom   File: OsItemTest.java   View source code 6 votes vote down vote up
@Test
public void testRegionCreation() {
    StopWatch watch = new StopWatch();
    LOG.info("testing RegionCreation");
    watch.start();
    // create an instance Item
    String logicalId = "/os/fake/regions/r1";
    String name = "r1";
    String provId = "fake";
    ItemType type = new OsRegionType();
    type.setId("os-" + type.getLocalId());
    OsRegion item = new OsRegion(logicalId, type);
    OsRegionAttributes ora = new OsRegionAttributes();
    ora.setItemId(name);
    ora.setItemName(name);
    ora.setProviderId(provId);
    item.setCore(ora);
    assertEquals("Incorrect logicalId after creation", logicalId, item.getLogicalId());
    assertEquals("Incorrect name after creation", name, item.getCore().getItemName());
    assertEquals("Incorrect id after creation", name, item.getCore().getItemId());
    assertEquals("Incorrect providerId after creation", provId, item.getCore().getProviderId());
    assertEquals("Incorrect type after creation", type, item.getItemType());
    watch.stop();
    LOG.info("tested RegionCreation --> " + watch);
}
 
Example 15
Project: loom   File: OperationManagerImplTest.java   View source code 6 votes vote down vote up
@Test
public void deleteAllOps4ProviderWrongly() {
    StopWatch watch = new StopWatch();
    LOG.info("testing OpMgrDelete");
    watch.start();

    assertEquals(startValues, opMgr.listOperations(OperationManagerImpl.LOOM_UUID).size());

    opMgr.registerOperation4Provider("", firstMeta, new ProviderImpl("test", "test", "none", "test", "com"));
    assertEquals(DefaultOperations.values().length,
            opMgr.listOperations(new ProviderImpl("test", "test", "none", "test", "com")).size());

    opMgr.registerOperation4Provider("FAKEOP2", null, new ProviderImpl("test", "test", "none", "test", "com"));
    assertEquals(DefaultOperations.values().length,
            opMgr.listOperations(new ProviderImpl("test", "test", "none", "test", "com")).size());


}
 
Example 16
Project: loom   File: AdapterManagerTest.java   View source code 6 votes vote down vote up
@Test
public void testNewProviderType()
        throws NoSuchProviderException, DuplicateAdapterException, DuplicateItemTypeException,
        NullItemTypeIdException, DuplicatePatternException, NullPatternIdException, UnsupportedOperationException {
    StopWatch watch = new StopWatch();
    LOG.info("testing NewProviderType");
    watch.start();
    // fakeAdapter.registerWithAdapterManager();
    assertTrue("provider is not registered", adapterManager.getProviders().contains(fakeAdapter.getProvider()));
    Provider dnp = new ProviderImpl("newProviderType", provider.getProviderId(), "newEndpoint", "newName", "com");
    DoNothingAdapter dna = new DoNothingAdapter(dnp);
    adapterManager.registerAdapter(dna);
    assertTrue("provider is not registered", adapterManager.getProviders().contains(dnp));
    adapterManager.deregisterAdapter(dna, new HashSet<>(0));
    watch.stop();
    LOG.info("tested NewProviderType --> " + watch);
}
 
Example 17
Project: loom   File: AdapterManagerTest.java   View source code 6 votes vote down vote up
@Test
public void testAdapterDeregistration()
        throws NoSuchProviderException, DuplicateAdapterException, DuplicateItemTypeException,
        NullItemTypeIdException, DuplicatePatternException, NullPatternIdException, UnsupportedOperationException {
    StopWatch watch = new StopWatch();
    LOG.info("testing AdapterDeregistration");
    watch.start();
    Provider testProvider = new FakeProviderImpl("test", "test", "test", "test", "test", "com");
    DoNothingAdapter dna = new DoNothingAdapter(testProvider);

    dna.setAdapterManager(adapterManager, null);
    adapterManager.registerAdapter(dna);
    dna.onLoad();

    assertTrue("provider is not registered", adapterManager.getProviders().contains(testProvider));
    // now deregister

    dna.onUnload();
    assertFalse("provider is still registered", adapterManager.getProviders().contains(testProvider));
    watch.stop();
    LOG.info("tested AdapterDeregistration --> " + watch);
}
 
Example 18
Project: loom   File: AdapterManagerTest.java   View source code 6 votes vote down vote up
@Test
public void testItemTypeRegistrationWithAdapter() throws NoSuchProviderException, DuplicateAdapterException {
    StopWatch watch = new StopWatch();
    LOG.info("testing ItemRegistration");
    watch.start();
    // itemType can only be registered for a registered Provider/Adapter
    // fakeAdapter.registerWithAdapterManager();
    assertTrue("provider is not registered", adapterManager.getProviders().contains(provider));
    // register Pattern
    // itemType should be automatically registered by registering the adapter
    // check if tapestryManager has received it
    assertTrue("tapestryManager should have received the itemType",
            itemTypeManager.getItemTypes(provider).contains(fakeAdapter.getItemType(OsInstanceType.TYPE_LOCAL_ID)));
    assertTrue("adapterManager should prefix Id with providerType",
            fakeAdapter.getItemType(OsInstanceType.TYPE_LOCAL_ID).getId().startsWith(provider.getProviderType()));
    // now deregister
    // fakeAdapter.deregisterWithAdapterManager();
    watch.stop();
    LOG.info("tested PatternRegistration --> " + watch);
}
 
Example 19
Project: loom   File: OsItemTest.java   View source code 6 votes vote down vote up
@Test
public void testProjectJson() throws Exception {
    StopWatch watch = new StopWatch();
    LOG.info("testing ProjectJson");
    watch.start();
    // create a project Item
    ItemType type = new OsProjectType();
    type.setId("os-" + type.getLocalId());
    OsProject project = new OsProject("/os/fake/projects/p1", type);
    OsProjectAttributes opa = new OsProjectAttributes();
    opa.setItemName("p1");
    opa.setItemId("pId1");
    opa.setItemDescription("description");
    opa.setProviderId("fake");
    project.setCore(opa);
    LOG.info("created JSON is\n" + toJson(project));
    watch.stop();
    LOG.info("tested ProjectJson --> " + watch);
}
 
Example 20
Project: loom   File: AdapterManagerTest.java   View source code 6 votes vote down vote up
@Test
public void testUserDisconnected() throws NoSuchProviderException, DuplicateAdapterException,
        NoSuchSessionException, SessionAlreadyExistsException, UserAlreadyConnectedException, NoSuchUserException,
        DuplicateItemTypeException, NullItemTypeIdException, DuplicatePatternException, NullPatternIdException,
        UnsupportedOperationException {
    StopWatch watch = new StopWatch();
    LOG.info("testing UserDisconnected");
    watch.start();
    Provider prov = createProvider();
    DoNothingAdapter dna = createUnregisteredDoNothingAdapter(prov);
    adapterManager.registerAdapter(dna);
    Session session = new SessionImpl("id1", sessionManager.getInterval());
    aggregationManager.createSession(session);
    stitcher.createSession(session);
    adapterManager.userConnected(session, dna.getProvider(), null);
    assertTrue("both sessions should be the same", session.equals(dna.getSession()));
    adapterManager.userDisconnected(session, dna.getProvider(), null);
    adapterManager.deregisterAdapter(dna, new HashSet<>(0));
    watch.stop();
    LOG.info("tested UserDisconnected --> " + watch);
}
 
Example 21
Project: loom   File: FakeAdapterTest.java   View source code 6 votes vote down vote up
@Test
public void testJustSleep() throws InterruptedException {
    StopWatch watch = new StopWatch();
    LOG.info("testing JustSleep");
    watch.start();
    Provider prov =
            new FakeProviderImpl("os", "private", "http://16.25.166.21:5000/v2.0", "Private", "test", "test");
    assertNotNull("adapter not created", fakeAdapter);
    LOG.info("prov: " + prov);
    LOG.info("faProv: " + fakeAdapter.getProvider());
    assertEquals(true, prov.equals(fakeAdapter.getProvider()));
    LOG.info("test just sleeping...");
    // sleep(1 * 60000);
    watch.stop();
    LOG.info("tested JustSleep --> " + watch);
}
 
Example 22
Project: loom   File: AdapterManagerTest.java   View source code 6 votes vote down vote up
@Test
public void testItemTypeDeRegistrationWithAdapter() throws NoSuchProviderException, DuplicateItemTypeException,
        NullItemTypeIdException, NoSuchItemTypeException, DuplicateAdapterException, DuplicatePatternException,
        NullPatternIdException, UnsupportedOperationException {
    StopWatch watch = new StopWatch();
    LOG.info("testing ItemTypeDeRegistrationWithAdapter");
    watch.start();
    Provider prov = createProvider();
    DoNothingAdapter dna = createUnregisteredDoNothingAdapter(prov);
    adapterManager.registerAdapter(dna);
    ItemType fakeType = new FakeType();
    adapterManager.addItemType(prov, fakeType);
    adapterManager.removeAllItemTypes(prov);
    watch.stop();
    LOG.info("tested ItemTypeDeRegistrationWithAdapter --> " + watch);
}
 
Example 23
Project: loom   File: RestClient.java   View source code 6 votes vote down vote up
private <T> void put(final String url, final Object bodyObj, final java.lang.Class<T> tClass,
        final Object... uriVariables) {
    setErrorHandler();
    StopWatch watch = new StopWatch();
    watch.start();
    restTemplate.put(url, bodyObj, tClass, uriVariables);
    watch.stop();
    if (log.isTraceEnabled()) {
        // if (watch.getTime() > timeWarning) {
        // bodyStr += " WARNING:";
        // }
        String args = "";
        for (Object arg : uriVariables) {
            args += " " + arg;
        }
        log.trace("PUT " + url + " " + args + " " + bodyObj + " Operation took " + watch);
    }
}
 
Example 24
Project: loom   File: AdapterManagerTest.java   View source code 6 votes vote down vote up
@Test(expected = NoSuchProviderException.class)
public void testRegisterPatternsUnknownProvider() throws NoSuchProviderException, DuplicateAdapterException,
        DuplicatePatternException, NullPatternIdException, NoSuchPatternException, UnsupportedOperationException {
    StopWatch watch = new StopWatch();
    LOG.info("testing RegisterPatternsUnknownProvider");
    watch.start();
    Provider prov = createProvider();
    createUnregisteredDoNothingAdapter(prov);
    PatternDefinition pat1 = new PatternDefinition("pat1");
    PatternDefinition pat2 = new PatternDefinition("pat2");
    HashSet<PatternDefinition> patternSet = new HashSet<PatternDefinition>();
    patternSet.add(pat1);
    patternSet.add(pat2);
    adapterManager.addPatternDefinitions(prov, patternSet);
    watch.stop();
    LOG.info("tested RegisterPatternsUnknownProvider --> " + watch);
}
 
Example 25
Project: ditb   File: TestIPCUtil.java   View source code 6 votes vote down vote up
private static void timerTests(final IPCUtil util, final int count, final int size,
    final Codec codec, final CompressionCodec compressor)
throws IOException {
  final int cycles = 1000;
  StopWatch timer = new StopWatch();
  timer.start();
  for (int i = 0; i < cycles; i++) {
    timerTest(util, timer, count, size, codec, compressor, false);
  }
  timer.stop();
  LOG.info("Codec=" + codec + ", compression=" + compressor + ", sized=" + false +
      ", count=" + count + ", size=" + size + ", + took=" + timer.getTime() + "ms");
  timer.reset();
  timer.start();
  for (int i = 0; i < cycles; i++) {
    timerTest(util, timer, count, size, codec, compressor, true);
  }
  timer.stop();
  LOG.info("Codec=" + codec + ", compression=" + compressor + ", sized=" + true +
    ", count=" + count + ", size=" + size + ", + took=" + timer.getTime() + "ms");
}
 
Example 26
Project: loom   File: AdapterManagerTest.java   View source code 6 votes vote down vote up
@Test(expected = NullPatternIdException.class)
public void testRegisterTwoPatternsOneNullId() throws NoSuchProviderException, DuplicateAdapterException,
        DuplicatePatternException, NullPatternIdException, NoSuchPatternException, UnsupportedOperationException,
        DuplicateItemTypeException, NullItemTypeIdException {
    LOG.info("testing RegisterTwoPatternsOneNullId");
    StopWatch watch = new StopWatch();
    watch.start();
    Provider prov = createProvider();
    DoNothingAdapter dna = createUnregisteredDoNothingAdapter(prov);
    adapterManager.registerAdapter(dna);
    PatternDefinition pat1 = new PatternDefinition("pat1");
    PatternDefinition pat2 = new PatternDefinition();
    HashSet<PatternDefinition> patternSet = new HashSet<PatternDefinition>();
    patternSet.add(pat1);
    patternSet.add(pat2);
    adapterManager.addPatternDefinitions(prov, patternSet);
    watch.stop();
    LOG.info("tested RegisterTwoPatternsOneNullId --> " + watch);
}
 
Example 27
Project: loom   File: AdapterManagerTest.java   View source code 6 votes vote down vote up
@Test
public void testGetItemLogicalId()
        throws NoSuchProviderException, DuplicateAdapterException, NoSuchSessionException,
        SessionAlreadyExistsException, LogicalIdAlreadyExistsException, DuplicateItemTypeException,
        NullItemTypeIdException, DuplicatePatternException, NullPatternIdException, UnsupportedOperationException {
    StopWatch watch = new StopWatch();
    LOG.info("testing GetItemLogicalId");
    watch.start();
    Provider prov = createProvider();
    ItemType type = new FakeType();
    type.setId("fake-" + type.getLocalId());
    Session session = createSession();
    aggregationManager.createSession(session);
    Aggregation agg = adapterManager.createGroundedAggregation(session, prov, type, null, true, "vms",
            "List of virtual machines - fake", 44);
    adapterManager.registerAdapter(createUnregisteredDoNothingAdapter(prov));
    String itemId = "a123";
    assertTrue("item LogicalId should combine agg logicalId with itemId ",
            LoomUtils.getItemLogicalId(agg, itemId).equals(agg.getLogicalId() + "/" + itemId));
    watch.stop();
    LOG.info("tested GetItemLogicalId --> " + watch);
}
 
Example 28
Project: loom   File: AdapterManagerTest.java   View source code 6 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testGetItemLogicalIdNullId() throws NoSuchProviderException, NoSuchSessionException,
        SessionAlreadyExistsException, LogicalIdAlreadyExistsException {
    StopWatch watch = new StopWatch();
    LOG.info("testing GetItemLogicalIdNullId");
    watch.start();
    Provider prov = createProvider();
    ItemType type = new FakeType();
    type.setId("fake-" + type.getLocalId());
    Session session = createSession();
    aggregationManager.createSession(session);
    Aggregation agg = adapterManager.createGroundedAggregation(session, prov, type, null, true, "vms",
            "List of virtual machines - fake", 44);
    LoomUtils.getItemLogicalId(agg, null);
    watch.stop();
    LOG.info("tested GetItemLogicalIdNullId --> " + watch);
}
 
Example 29
Project: SkyEye   File: CacheService.java   View source code 6 votes vote down vote up
/**
 * 将数据库中的配置表进行缓存
 */
private void loadCache() {
    StopWatch sw = new StopWatch();
    sw.start();
    LOGGER.info("start load config to cache");

    Iterable<ServiceInfo> serviceInfos = this.serviceInfoRepository.findAll();

    for (Iterator<ServiceInfo> it = serviceInfos.iterator(); it.hasNext();) {
        ServiceInfo serviceInfo = it.next();
        this.setOps.add(SERVICE_INFO_PREFIX, serviceInfo.getSid());
    }

    sw.stop();
    LOGGER.info("load config to cache end, cost {} ms", sw.getTime());
}
 
Example 30
Project: loom   File: AdapterManagerTest.java   View source code 6 votes vote down vote up
@Test
public void testCreateOneAggregation()
        throws NoSuchSessionException, SessionAlreadyExistsException, DuplicateAdapterException,
        LogicalIdAlreadyExistsException, NoSuchProviderException, DuplicateItemTypeException,
        NullItemTypeIdException, DuplicatePatternException, NullPatternIdException, UnsupportedOperationException {
    StopWatch watch = new StopWatch();
    LOG.info("testing CreateOneAggregation");
    watch.start();
    Provider prov = createProvider();
    adapterManager.registerAdapter(createUnregisteredDoNothingAdapter(prov));
    ItemType type = new FakeType();
    type.setId("fake-" + type.getLocalId());
    Session session = createSession();
    aggregationManager.createSession(session);
    adapterManager.createGroundedAggregation(session, prov, type, null, true, "vms",
            "List of virtual machines - fake", 44);
    assertTrue("aggregationManager should know this aggregation",
            aggregationManager.getAggregation(session, "os/testfake/testfakes") != null);
    watch.stop();
    LOG.info("tested CreateOneAggregation --> " + watch);
}
 
Example 31
Project: loom   File: AdapterManagerTest.java   View source code 6 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testCreateOneAggregationNullProvider()
        throws NoSuchSessionException, SessionAlreadyExistsException, DuplicateAdapterException,
        LogicalIdAlreadyExistsException, NoSuchProviderException, DuplicateItemTypeException,
        NullItemTypeIdException, DuplicatePatternException, NullPatternIdException, UnsupportedOperationException {
    StopWatch watch = new StopWatch();
    LOG.info("testing CreateOneAggregationNullProvider");
    watch.start();
    Provider prov = createProvider();
    Adapter adapter = createUnregisteredDoNothingAdapter(prov);
    // adapterManager.deregisterAdapter(adapter, new HashSet<Session>());

    adapterManager.registerAdapter(adapter);
    ItemType type = new FakeType();
    adapterManager.addItemType(prov, type);
    Session session = createSession();
    aggregationManager.createSession(session);
    adapterManager.createGroundedAggregation(session, null, type, null, true, "vms",
            "List of virtual machines - fake", 44);
    watch.stop();
    LOG.info("tested CreateOneAggregationNullProvider --> " + watch);
}
 
Example 32
Project: loom   File: AdapterManagerTest.java   View source code 6 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testCreateOneAggregationNullSession()
        throws NoSuchSessionException, SessionAlreadyExistsException, DuplicateAdapterException,
        LogicalIdAlreadyExistsException, NoSuchProviderException, DuplicateItemTypeException,
        NullItemTypeIdException, DuplicatePatternException, NullPatternIdException, UnsupportedOperationException {
    StopWatch watch = new StopWatch();
    LOG.info("testing CreateOneAggregationNullSession");
    watch.start();
    Provider prov = createProvider();
    adapterManager.registerAdapter(createUnregisteredDoNothingAdapter(prov));
    ItemType type = new FakeType();
    adapterManager.addItemType(prov, type);
    Session session = createSession();
    aggregationManager.createSession(session);
    adapterManager.createGroundedAggregation(null, prov, type, null, true, "vms", "List of virtual machines - fake",
            44);
    watch.stop();
    LOG.info("tested CreateOneAggregationNullSession --> " + watch);
}
 
Example 33
Project: loom   File: AdapterManagerTest.java   View source code 6 votes vote down vote up
@Test
public void testCreateOneAggregationNullLocalIdFalseMapped()
        throws NoSuchSessionException, SessionAlreadyExistsException, DuplicateAdapterException,
        LogicalIdAlreadyExistsException, NoSuchProviderException, DuplicateItemTypeException,
        NullItemTypeIdException, DuplicatePatternException, NullPatternIdException, UnsupportedOperationException {
    StopWatch watch = new StopWatch();
    LOG.info("testing CreateOneAggregationNullLocalIdFalseMapped");
    watch.start();
    Provider prov = createProvider();
    adapterManager.registerAdapter(createUnregisteredDoNothingAdapter(prov));
    ItemType type = new FakeType();
    type.setId("fake-" + type.getLocalId());
    Session session = createSession();
    aggregationManager.createSession(session);
    adapterManager.createGroundedAggregation(session, prov, type, null, false, "vms",
            "List of virtual machines - fake", 44);
    watch.stop();
    LOG.info("tested CreateOneAggregationNullLocalIdFalseMapped --> " + watch);
}
 
Example 34
Project: loom   File: AdapterManagerTest.java   View source code 6 votes vote down vote up
@Test(expected = NoSuchSessionException.class)
public void testCreateOneAggregationUnknownSession()
        throws NoSuchSessionException, SessionAlreadyExistsException, DuplicateAdapterException,
        LogicalIdAlreadyExistsException, NoSuchProviderException, DuplicateItemTypeException,
        NullItemTypeIdException, DuplicatePatternException, NullPatternIdException, UnsupportedOperationException {
    StopWatch watch = new StopWatch();
    LOG.info("testing CreateOneAggregationUnknownSession");
    watch.start();
    Provider prov = createProvider();
    adapterManager.registerAdapter(createUnregisteredDoNothingAdapter(prov));
    ItemType type = new FakeType();
    type.setId("fake-" + type.getLocalId());
    Session session = createSession();
    adapterManager.createGroundedAggregation(session, prov, type, null, true, "vms",
            "List of virtual machines - fake", 44);
    watch.stop();
    LOG.info("tested CreateOneAggregationUnknownSession --> " + watch);
}
 
Example 35
Project: loom   File: AdapterManagerTest.java   View source code 6 votes vote down vote up
@Test
public void testCreateTwoAggregations()
        throws NoSuchSessionException, SessionAlreadyExistsException, DuplicateAdapterException,
        LogicalIdAlreadyExistsException, NoSuchProviderException, DuplicateItemTypeException,
        NullItemTypeIdException, DuplicatePatternException, NullPatternIdException, UnsupportedOperationException {
    StopWatch watch = new StopWatch();
    LOG.info("testing CreateTwoAggregations");
    watch.start();
    Provider prov = createProvider();
    adapterManager.registerAdapter(createUnregisteredDoNothingAdapter(prov));
    Session session = createSession();
    aggregationManager.createSession(session);
    ItemType type = new FakeType();
    type.setId("fake-" + type.getLocalId());
    adapterManager.createGroundedAggregation(session, prov, type, "fake-sfx", true, "vms",
            "List of virtual machines - fake", 44);
    adapterManager.createGroundedAggregation(session, prov, type, "fake-sfx2", true, "vms",
            "List of virtual machines - fake", 44);
    assertTrue("both aggregations should be in", aggregationManager.listAggregations(session).size() == 2);
    watch.stop();
    LOG.info("tested CreateTwoAggregations --> " + watch);
}
 
Example 36
Project: loom   File: AdapterManagerTest.java   View source code 6 votes vote down vote up
@Test(expected = LogicalIdAlreadyExistsException.class)
public void testCreateRepeatAggregations()
        throws NoSuchSessionException, SessionAlreadyExistsException, DuplicateAdapterException,
        LogicalIdAlreadyExistsException, NoSuchProviderException, DuplicateItemTypeException,
        NullItemTypeIdException, DuplicatePatternException, NullPatternIdException, UnsupportedOperationException {
    StopWatch watch = new StopWatch();
    LOG.info("testing CreateRepeatAggregations");
    watch.start();
    Provider prov = createProvider();
    adapterManager.registerAdapter(createUnregisteredDoNothingAdapter(prov));
    Session session = createSession();
    aggregationManager.createSession(session);
    ItemType type = new FakeType();
    type.setId("fake-" + type.getLocalId());
    adapterManager.createGroundedAggregation(session, prov, type, "fake-sfx", true, "vms",
            "List of virtual machines - fake", 44);
    adapterManager.createGroundedAggregation(session, prov, type, "fake-sfx", true, "vms",
            "List of virtual machines - fake", 44);
    assertTrue("both aggregations should be in", aggregationManager.listAggregations(session).size() == 2);
    watch.stop();
    LOG.info("tested CreateRepeatAggregations --> " + watch);
}
 
Example 37
Project: loom   File: AdapterManagerTest.java   View source code 6 votes vote down vote up
@Test
public void testGetAggregationForItem() throws CheckedLoomException {
    StopWatch watch = new StopWatch();
    LOG.info("testGetAggregationForItem start");
    watch.start();
    assertNotNull("Aggregation manager instance not set", aggregationManager);
    Provider prov = createProvider();
    adapterManager.registerAdapter(createUnregisteredDoNothingAdapter(prov));
    Session session = createSession();
    aggregationManager.createSession(session);
    ItemType type = new FakeType();
    type.setId("fake-" + type.getLocalId());
    Aggregation aggregation = adapterManager.createGroundedAggregation(session, prov, type, null, true, "vms",
            "List of virtual machines - fake", 44);
    String logicalId = aggregation.getLogicalId() + "/i-7e9675e2-c5c0-49e3-8b17-2cfaf14307e8";
    Aggregation retrievedAggregation = adapterManager.getAggregationForItem(session, logicalId);
    assertNotNull("Get Aggregation for Item returned null result", retrievedAggregation);
    assertEquals("Returned aggregation had incorrect logicalId", aggregation.getLogicalId(),
            retrievedAggregation.getLogicalId());
    watch.stop();
    LOG.info("testGetAggregationForItem end --> " + watch);
}
 
Example 38
Project: loom   File: TapestryHandling.java   View source code 6 votes vote down vote up
static String clientCreateTapestryDefinition(final LoomClient client, final TapestryDefinition tapestryDefinition) {
    if (predictableOrdering) {
        convertToPredictableOrdering(tapestryDefinition);
    }
    StopWatch watch = new StopWatch();
    watch.start();
    // String id = client.createTapestryDefinition(tapestryDefinition);
    String id = client.createTapestryDefinition(tapestryDefinition).getId();
    watch.stop();
    if (log.isDebugEnabled()) {
        log.debug("Create tapestry time=" + watch + " nthreads=" + tapestryDefinition.getThreads().size() + " id "
                + id);
    }

    return id;
}
 
Example 39
Project: intellij-spring-assistant   File: SuggestionIndexServiceImpl.java   View source code 5 votes vote down vote up
@Override
public void reIndex(Project project) {
  if (indexingInProgress) {
    currentExecution.cancel(false);
  }
  //noinspection CodeBlock2Expr
  currentExecution = getApplication().executeOnPooledThread(() -> {
    getApplication().runReadAction(() -> {
      indexingInProgress = true;
      StopWatch timer = new StopWatch();
      timer.start();
      try {
        debug(() -> log.debug("-> Indexing requested for project " + project.getName()));
        // OrderEnumerator.orderEntries(project) is returning everything from all modules including root level module(which is called project in gradle terms)
        // So, we should not be doing anything with this

        Module[] modules = ModuleManager.getInstance(project).getModules();
        for (Module module : modules) {
          reindexModule(emptyList(), emptyList(), module);
        }
      } finally {
        indexingInProgress = false;
        timer.stop();
        debug(() -> log
            .debug("<- Indexing took " + timer.toString() + " for project " + project.getName()));
      }
    });
  });
}
 
Example 40
Project: intellij-spring-assistant   File: SuggestionIndexServiceImpl.java   View source code 5 votes vote down vote up
@Override
public void reindex(Project project, Module[] modules) {
  if (indexingInProgress) {
    if (currentExecution != null) {
      currentExecution.cancel(false);
    }
  }
  //noinspection CodeBlock2Expr
  currentExecution = getApplication().executeOnPooledThread(() -> {
    getApplication().runReadAction(() -> {
      debug(() -> log.debug(
          "-> Indexing requested for a subset of modules of project " + project.getName()));
      indexingInProgress = true;
      StopWatch timer = new StopWatch();
      timer.start();
      try {
        for (Module module : modules) {
          debug(() -> log.debug("--> Indexing requested for module " + module.getName()));
          StopWatch moduleTimer = new StopWatch();
          moduleTimer.start();
          try {
            reindexModule(emptyList(), emptyList(), module);
          } finally {
            moduleTimer.stop();
            debug(() -> log.debug(
                "<-- Indexing took " + moduleTimer.toString() + " for module " + module
                    .getName()));
          }
        }
      } finally {
        indexingInProgress = false;
        timer.stop();
        debug(() -> log
            .debug("<- Indexing took " + timer.toString() + " for project " + project.getName()));
      }
    });
  });
}