@Test
  public void testAssertBigPayload() {
    List<CachePeer> localPeers = manager1.getCachePeerListener("RMI").getBoundCachePeers();
    List<byte[]> payloadList = PayloadUtil.createCompressedPayloadList(localPeers, 150);
    Assert.assertTrue("Payload is not big enough for cacheManager-1", payloadList.size() > 1);

    localPeers = manager2.getCachePeerListener("RMI").getBoundCachePeers();
    payloadList = PayloadUtil.createCompressedPayloadList(localPeers, 150);
    Assert.assertTrue("Payload is not big enough for cacheManager-2", payloadList.size() > 1);

    localPeers = manager3.getCachePeerListener("RMI").getBoundCachePeers();
    payloadList = PayloadUtil.createCompressedPayloadList(localPeers, 150);
    Assert.assertTrue("Payload is not big enough for cacheManager-3", payloadList.size() > 1);

    CacheManager manager4 =
        new CacheManager(
            AbstractCacheTest.TEST_CONFIG_DIR
                + "distribution/ehcache-distributed-big-payload-4.xml");
    try {
      localPeers = manager4.getCachePeerListener("RMI").getBoundCachePeers();
      payloadList = PayloadUtil.createCompressedPayloadList(localPeers, 150);
      Assert.assertTrue("Payload is not big enough for cacheManager-4", payloadList.size() > 1);
    } finally {
      manager4.shutdown();
    }
  }
Пример #2
0
 /**
  * 376 µs per one gzipping each time. .1 µs if we compare hashCodes on the String and only gzip as
  * necessary.
  *
  * @throws java.io.IOException
  * @throws InterruptedException
  */
 @Test
 public void testGzipSanityAndPerformance() throws IOException, InterruptedException {
   String payload = createReferenceString();
   // warmup vm
   for (int i = 0; i < 10; i++) {
     byte[] compressed = PayloadUtil.gzip(payload.getBytes());
     // make sure we don't forget to close the stream
     assertTrue(compressed.length > 300);
     Thread.sleep(20);
   }
   int hashCode = payload.hashCode();
   StopWatch stopWatch = new StopWatch();
   for (int i = 0; i < 10000; i++) {
     if (hashCode != payload.hashCode()) {
       PayloadUtil.gzip(payload.getBytes());
     }
   }
   long elapsed = stopWatch.getElapsedTime();
   LOG.info("Gzip took " + elapsed / 10F + " µs");
 }
 private void processPayload(byte[] compressedPayload) {
   byte[] payload = PayloadUtil.ungzip(compressedPayload);
   String rmiUrls = new String(payload);
   if (self(rmiUrls)) {
     return;
   }
   rmiUrls = rmiUrls.trim();
   if (LOG.isLoggable(Level.FINE)) {
     LOG.fine("rmiUrls received " + rmiUrls);
   }
   processRmiUrls(rmiUrls);
 }
Пример #4
0
 /**
  * 169 µs per one.
  *
  * @throws IOException
  * @throws InterruptedException
  */
 @Test
 public void testUngzipPerformance() throws IOException, InterruptedException {
   String payload = createReferenceString();
   int length = payload.toCharArray().length;
   byte[] original = payload.getBytes();
   int byteLength = original.length;
   assertEquals(length, byteLength);
   byte[] compressed = PayloadUtil.gzip(original);
   // warmup vm
   for (int i = 0; i < 10; i++) {
     byte[] uncompressed = PayloadUtil.ungzip(compressed);
     uncompressed.hashCode();
     assertEquals(original.length, uncompressed.length);
     Thread.sleep(20);
   }
   StopWatch stopWatch = new StopWatch();
   for (int i = 0; i < 10000; i++) {
     PayloadUtil.ungzip(compressed);
   }
   long elapsed = stopWatch.getElapsedTime();
   LOG.info("Ungzip took " + elapsed / 10000F + " µs");
 }