コード例 #1
0
ファイル: TestHtmlReport.java プロジェクト: sreev/javamelody
  /**
   * Test.
   *
   * @throws IOException e
   */
  @Test
  public void testCache() throws IOException {
    final String cacheName = "test 1";
    final CacheManager cacheManager = CacheManager.getInstance();
    cacheManager.addCache(cacheName);
    final String cacheName2 = "test 2";
    try {
      final Cache cache = cacheManager.getCache(cacheName);
      cache.put(new Element(1, Math.random()));
      cache.get(1);
      cache.get(0);
      cacheManager.addCache(cacheName2);
      final Cache cache2 = cacheManager.getCache(cacheName2);
      cache2.getCacheConfiguration().setOverflowToDisk(false);
      cache2.getCacheConfiguration().setEternal(true);
      cache2.getCacheConfiguration().setMaxElementsInMemory(0);

      // JavaInformations doit être réinstancié pour récupérer les caches
      final List<JavaInformations> javaInformationsList2 =
          Collections.singletonList(new JavaInformations(null, true));
      final HtmlReport htmlReport =
          new HtmlReport(collector, null, javaInformationsList2, Period.TOUT, writer);
      htmlReport.toHtml(null, null);
      assertNotEmptyAndClear(writer);
      setProperty(Parameter.SYSTEM_ACTIONS_ENABLED, "false");
      htmlReport.toHtml(null, null);
      assertNotEmptyAndClear(writer);
    } finally {
      setProperty(Parameter.SYSTEM_ACTIONS_ENABLED, null);
      cacheManager.removeCache(cacheName);
      cacheManager.removeCache(cacheName2);
    }
  }
コード例 #2
0
  private void internalRemove(String uuid, String reason) {

    if (!sessions.containsKey(uuid)) {
      log.warn("Session not in cache: " + uuid);
      return; // EARLY EXIT!
    }

    log.info("Destroying session " + uuid + " due to : " + reason);

    // Announce to all callbacks.
    Set<SessionCallback> cbs = sessionCallbackMap.get(uuid);
    if (cbs != null) {
      for (SessionCallback cb : cbs) {
        try {
          cb.close();
        } catch (Exception e) {
          final String msg = "SessionCallback %s throw exception for session %s";
          log.warn(String.format(msg, cb, uuid), e);
        }
      }
    }

    // Announce to all listeners
    try {
      context.publishEvent(new DestroySessionMessage(this, uuid));
    } catch (RuntimeException re) {
      final String msg = "Session listener threw an exception for session %s";
      log.warn(String.format(msg, uuid), re);
    }

    ehmanager.removeCache("memory:" + uuid);
    ehmanager.removeCache("ondisk:" + uuid);
    sessions.remove(uuid);
  }
コード例 #3
0
 public void dispose() {
   if (cacheManager.getStatus().equals(Status.STATUS_ALIVE)) {
     log.info("Disposing cache: " + ehcache);
     if (this.ehcache != null) {
       cacheManager.removeCache(this.ehcache.getName());
       ehcache = null;
     }
   } else {
     log.debug("Not disposing cache, because cacheManager is not alive: " + ehcache);
   }
 }
コード例 #4
0
  /** Are all of the CachePeers for replicated caches bound to the listener and working? */
  @Test
  public void testBoundListenerPeersAfterCacheRemove() throws RemoteException {
    String[] boundCachePeers =
        ((RMICacheManagerPeerListener) manager1.getCachePeerListener("RMI"))
            .listBoundRMICachePeers();
    assertEquals(1, boundCachePeers.length);
    validateBoundCachePeer(boundCachePeers);

    // Remove a replicated cache
    manager1.removeCache("asynchronousCache");
    boundCachePeers =
        ((RMICacheManagerPeerListener) manager1.getCachePeerListener("RMI"))
            .listBoundRMICachePeers();
    assertEquals(0, boundCachePeers.length);
    validateBoundCachePeer(boundCachePeers);
  }