コード例 #1
0
  @Override
  protected void runTest(Cache cache, Toolkit clusteringToolkit) throws Throwable {
    int size = cache.getSize();
    assertEquals(0, size);
    System.out.println("Client populating cache.");
    for (int i = 0; i < 7000; i++) {
      cache.put(new Element("key-" + i, "value-" + i));
    }
    System.out.println("Cache populate. Size: " + cache.getSize());
    // assert range as some may already have got evicted while populating
    // eviction is aggressive with new impl based on "evictUnexpiredEntries" with true by default
    assertRange(5000, 7000, cache);

    System.out.println("Sleeping for 3 mins (now=" + new Date() + ") ... ");
    // Sleep for TTI to kick in:
    Thread.sleep(3 * 60 * 1000);

    System.out.println("After sleeping 3 mins. Size: " + cache);
    // Now size should be equal to capacity
    assertRange(3000, 6000, cache);

    System.out.println("Trying to get on all elements, inline eviction should happen");
    // all others should be evicted inline
    for (int i = 0; i < 7000; i++) {
      Element element = cache.get("key-" + i);
      Assert.assertNull("Element should be null of key-" + i, element);
    }

    Thread.sleep(5 * 1000);

    System.out.println("After inline eviction. Size: " + cache.getSize());
    // Now size should be equal to 0
    assertEquals(0, cache.getSize());
  }
コード例 #2
0
ファイル: Load.java プロジェクト: vinaynair/tc-labs
  public static void main(String[] args) throws Exception {
    Config config = new Config();
    Cache cache = config.getCache();

    // cache data generator sequence
    FixedSizeElementSequence elementSequence =
        new FixedSizeElementSequence(Config.NUMBER_OF_ENTRIES, Config.SIZE_OF_ENTRY);

    cache.removeAll();
    LOG.info("cache size should be zero. size=" + cache.getSize() + "\n starting load");
    Util.sleepFor(3);
    cache.setNodeBulkLoadEnabled(true);

    long start = System.currentTimeMillis();
    // single threaded for now
    // start putting data into the cache
    PutWorker putWorker = new PutWorker(cache, elementSequence);
    // TODO:use executor to make this multi-threaded
    putWorker.start();
    // for now, waiting for put to complete
    putWorker.join();
    // now remove bulkmode
    long endOfWorkerThread = System.currentTimeMillis();

    cache.setNodeBulkLoadEnabled(false);

    Config.CALL_TIMER.stop(); // stop the timer
    long endOfBulkLoadReset = System.currentTimeMillis();

    int endSize = cache.getSize();
    LOG.info(
        "complete. total time for "
            + Config.NUMBER_OF_ENTRIES
            + " puts to complete is "
            + (endOfWorkerThread - start)
            + "ms, and time it took to reset bulk mode is "
            + (endOfBulkLoadReset - endOfWorkerThread)
            + "ms \n End size="
            + endSize);

    // just wait for return
    // for now, waiting for user input to close the
    // program. This gives us time to look at the metrics on JMX console or
    // TMC :)

    Util.waitForInput();
    ConsoleReporter.enable(1, TimeUnit.SECONDS);
    Util.sleepFor(2);
  }
コード例 #3
0
  public static void main(String args[]) {

    Map<Object, Element> map = new HashMap<Object, Element>();
    List<String> list = new ArrayList<String>();

    // Create a cache manager
    CacheManager cacheManager = CacheManager.getInstance();

    // Creates a cache called newCache
    cacheManager.addCache("newCache");

    // Get cache called newCache
    Cache cache = cacheManager.getCache("newCache");
    StatisticsGateway stats = cache.getStatistics();

    // put into cache
    cache.put(new Element("1", "Monday"));
    list.add("1");
    cache.put(new Element("2", "Tuesday"));
    list.add("2");
    cache.put(new Element("3", "Wednesday"));
    list.add("3");
    cache.put(new Element("4", "Thursday"));
    list.add("4");

    // Displaying all elements
    System.out.println("All elements");
    map = cache.getAll(list);
    Iterator it = map.entrySet().iterator();
    while (it.hasNext()) {
      Map.Entry pair = (Map.Entry) it.next();
      System.out.println(pair.getKey() + " = " + pair.getValue());
    }

    // Displaying elements and size of cache
    Element element = cache.get("1");
    System.out.println("Value of key 1 :" + element.getObjectValue().toString());
    System.out.println("Cache Size " + cache.getSize());
    element = cache.get("2");
    System.out.println("Value of key 2 :" + element.getObjectValue().toString());
    System.out.println("Cache Size " + cache.getSize());
    cache.removeElement(element);
    System.out.println("Cache Size after removing an element : " + cache.getSize());
    cache.flush();
    System.out.println("Removed Cache with key 3 :" + cache.remove("3"));
    System.out.println("Size after remove : " + cache.getSize());
  }
コード例 #4
0
    private void runBasicPinningTest(Cache cache) {
      for (int i = 0; i < ELEMENT_COUNT; i++) {
        cache.put(new Element(i, i));
      }

      Assert.assertEquals(ELEMENT_COUNT, cache.getSize());

      for (int i = 0; i < ELEMENT_COUNT; i++) {
        Assert.assertNotNull(cache.get(i));
      }

      Assert.assertEquals(ELEMENT_COUNT, cache.getStatistics().getInMemoryHits());
      Assert.assertEquals(0, cache.getStatistics().getInMemoryMisses());
      Assert.assertEquals(0, cache.getStatistics().getOnDiskHits());
      Assert.assertEquals(0, cache.getStatistics().getOnDiskMisses());
      Assert.assertEquals(0, cache.getStatistics().getEvictionCount());
    }
コード例 #5
0
    @Override
    protected void runTest(Cache cache, ClusteringToolkit clusteringToolkit) throws Throwable {
      final int index = waitForAllClients();

      Assert.assertEquals(0, cache.getSize());

      waitForAllClients();

      cache.put(new Element("key" + index, "value" + index));
      cache.put(new Element("key" + index, "valueUpdated" + index));
      cache.remove("key" + index);

      waitForAllClients();

      cache.removeAll();

      waitForAllClients();

      Thread.sleep(10000);

      EhcacheTerracottaEventListener listener = null;
      Set<CacheEventListener> listeners =
          cache.getCacheEventNotificationService().getCacheEventListeners();
      for (CacheEventListener l : listeners) {
        if (l instanceof EhcacheTerracottaEventListener) {
          listener = (EhcacheTerracottaEventListener) l;
          break;
        }
      }

      Assert.assertNotNull(listener);

      Assert.assertEquals(1, listener.getPut().size());
      Assert.assertEquals(1, listener.getUpdate().size());
      Assert.assertEquals(1, listener.getRemove().size());
      Assert.assertEquals(1, listener.getRemoveAll());
    }
コード例 #6
0
 /*
  * (non-Javadoc)
  *
  * @see com.impetus.kundera.cache.Cache#size()
  */
 @Override
 public int size() {
   return ehcache.getSize();
 }
コード例 #7
0
ファイル: UserCache.java プロジェクト: kubbye/framework
 @Override
 public int size() {
   return userCache.getSize();
 }
コード例 #8
0
 public int getSize() {
   return cache.getSize();
 }
コード例 #9
-1
  /**
   * Performance and capacity tests.
   *
   * <p>
   */
  @Test
  public void testBootstrap() throws CacheException, InterruptedException, RemoteException {

    // load up some data
    StopWatch stopWatch = new StopWatch();
    Integer index = null;
    for (int i = 0; i < 2; i++) {
      for (int j = 0; j < 1000; j++) {
        index = Integer.valueOf(((1000 * i) + j));
        cache1.put(
            new Element(
                index,
                "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                    + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                    + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                    + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
                    + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"));
      }
    }
    long elapsed = stopWatch.getElapsedTime();
    long putTime = ((elapsed / 1000));
    LOG.info("Put Elapsed time: " + putTime);

    assertEquals(2000, cache1.getSize());

    Thread.sleep(7000);
    assertEquals(2000, manager2.getCache("sampleCache1").getSize());
    assertEquals(2000, manager3.getCache("sampleCache1").getSize());
    assertEquals(2000, manager4.getCache("sampleCache1").getSize());
    assertEquals(2000, manager5.getCache("sampleCache1").getSize());

    // now test bootstrap
    manager1.addCache("bootStrapResults");
    Cache cache = manager1.getCache("bootStrapResults");
    List cachePeers = manager1.getCacheManagerPeerProvider("RMI").listRemoteCachePeers(cache1);
    CachePeer cachePeer = (CachePeer) cachePeers.get(0);

    List keys = cachePeer.getKeys();
    assertEquals(2000, keys.size());

    Element firstElement = cachePeer.getQuiet((Serializable) keys.get(0));
    long size = firstElement.getSerializedSize();
    assertEquals(504, size);

    int chunkSize = (int) (5000000 / size);

    List requestChunk = new ArrayList();
    for (int i = 0; i < keys.size(); i++) {
      Serializable serializable = (Serializable) keys.get(i);
      requestChunk.add(serializable);
      if (requestChunk.size() == chunkSize) {
        fetchAndPutElements(cache, requestChunk, cachePeer);
        requestChunk.clear();
      }
    }
    // get leftovers
    fetchAndPutElements(cache, requestChunk, cachePeer);

    assertEquals(keys.size(), cache.getSize());
  }