Package org.openxri.resolve

Examples of org.openxri.resolve.ResolverCache


    return new TestSuite(ResolverCacheTest.class);
  }

  public void testCache()
  {
    ResolverCache cache = new ResolverCache();
    cache.setNewCache("test", 1000);
    assertTrue("Initial cache not empty", cache.getSize() == 0);

    XRD xrd = new XRD();
    Service atAuthService = new Service();
    atAuthService.addMediaType(Tags.CONTENT_TYPE_XRDS + ";trust=none");
    atAuthService.addType(Tags.SERVICE_AUTH_RES);
    atAuthService.addURI("http://gcs.epok.net/xri/resolve?ns=at");
    xrd.addService(atAuthService);

    XRD xrd1 = new XRD();
    Service dummyService = new Service();
    dummyService.addMediaType(Tags.CONTENT_TYPE_XRDS + ";trust=none");
    dummyService.addType(Tags.SERVICE_AUTH_RES);
    dummyService.addURI("http://www.example.com/xri/resolve?id=1");
    xrd1.addService(dummyService);

    try {
      GCSAuthority auth = new GCSAuthority("@");
      cache.put(auth.toString(), false, false, xrd.toString().getBytes("UTF-8"), 1000);
      assertTrue("Initial cache incorrect", cache.getSize() == 1);

      cache.put(
          AuthorityPath.buildAuthorityPath("@!a!b!foo").toString(), false, false, xrd1.toString().getBytes("UTF-8"), 1000);
      assertTrue("Cache size incorrect", cache.getSize() == 2);

      cache.put(
          AuthorityPath.buildAuthorityPath("@!a!b!foo").toString(), false, false, xrd1.toString().getBytes("UTF-8"), 1000);
      assertTrue("Cache stores duplicate element?", cache.getSize() == 2);


      byte[] val =
        cache.get(AuthorityPath.buildAuthorityPath("@!a!b!foo").toString(), false, false);
      assertTrue("Cached value not found", val != null);

      val =
        cache.get(AuthorityPath.buildAuthorityPath("@!a!b!woo").toString(), false, false);
      assertTrue("Cached value should not have been found", val == null);
    }
    catch (UnsupportedEncodingException e) {
      assertTrue("Unexpected exception" + e, false);
    }
View Full Code Here




  public void testExpire()
  {
    ResolverCache c = new ResolverCache();
    try {
      c.del("@abc", false, false);
      byte[] s = c.get("@abc", false, false);
      assertTrue("stale cache value", s == null);
     
      c.put("@abc", false, false, "x".getBytes("UTF-8"), 2);
      s = c.get("@abc", false, false);
      assertTrue("unable to retrieve stored value", s != null);

      Thread.sleep(1000);
      s = c.get("@abc", false, false);
      assertTrue("premature expiry", s != null);
 
      Thread.sleep(1500);
      s = c.get("@abc", false, false);
      assertTrue("item should have expired", s == null);
    }
    catch (UnsupportedEncodingException e) {
      e.printStackTrace();
      assertTrue(e.toString(), false);
View Full Code Here

      XRI x = XRI.fromURINormalForm(samlBypassAuthorities[i]);
      this.resolver.addSAMLBypassAuthority(samlBypassAuthorities[i]);
    }

    if (this.config.getUseCache()) {
      this.resolver.setCache(new ResolverCache());
      this.resolver.setDefaultCacheTTL(this.config.getDefaultCacheTTL());
      this.resolver.setMinCacheTTL(this.config.getMinCacheTTL());
      this.resolver.setMaxCacheTTL(this.config.getMaxCacheTTL());
      this.resolver.setNegativeCacheTTL(this.config.getNegativeCacheTTL());
    }
View Full Code Here

  }

 
  public void testConcurrent()
  {
    ResolverCache cache = new ResolverCache();
    cache.setNewCache("testConcurrent", 5);
    cache.del(AuthorityPath.buildAuthorityPath("@").toString(), false, false);
    assertTrue("Initial cache not empty", cache.getSize() == 0);


    XRD xrd = new XRD();
    Service atAuthService = new Service();
    atAuthService.addMediaType(Tags.CONTENT_TYPE_XRDS + ";trust=none");
    atAuthService.addType(Tags.SERVICE_AUTH_RES);
    atAuthService.addURI("http://gcs.epok.net/xri/resolve?ns=at");
    xrd.addService(atAuthService);

    try {
      GCSAuthority auth = new GCSAuthority("@");
      cache.put(auth.toString(), false, false, xrd.toString().getBytes("UTF-8"), 1000);
      assertTrue("Initial cache incorrect", cache.getSize() == 1);
    } catch (UnsupportedEncodingException e) {
      assertTrue("Unexpected exception" + e, false);
    }

    Random rnd = new Random();

    try
    {
      Thread[] threads = new StuffPruneThread[100];
      for (int i = 0; i < threads.length; i++)
      {
        threads[i] = new StuffPruneThread(rnd, cache);
      }

      for (int i = 0; i < threads.length; i++)
      {
        threads[i].start();
      }

      for (int i = 0; i < threads.length; i++)
      {
        threads[i].join();
      }
    }
    catch (Exception e)
    {
      assertTrue("Unexpected exception" + e, false);
    }

    assertTrue(
        "Max cache size not honored",
        cache.getSize() <= cache.getMaxSize());


  }
View Full Code Here

      XRI x = XRI.fromURINormalForm(samlBypassAuthorities[i]);
      this.resolver.addSAMLBypassAuthority(samlBypassAuthorities[i]);
    }

    if (this.config.getUseCache()) {
      this.resolver.setCache(new ResolverCache());
      this.resolver.setDefaultCacheTTL(this.config.getDefaultCacheTTL());
      this.resolver.setMinCacheTTL(this.config.getMinCacheTTL());
      this.resolver.setMaxCacheTTL(this.config.getMaxCacheTTL());
      this.resolver.setNegativeCacheTTL(this.config.getNegativeCacheTTL());
    }
View Full Code Here

    return new TestSuite(ResolverCacheTest.class);
  }

  public void testCache()
  {
    ResolverCache cache = new ResolverCache();
    cache.setNewCache("test", 1000);
    assertTrue("Initial cache not empty", cache.getSize() == 0);

    XRD xrd = new XRD();
    Service atAuthService = new Service();
    atAuthService.addMediaType(Tags.CONTENT_TYPE_XRDS + ";trust=none");
    atAuthService.addType(Tags.SERVICE_AUTH_RES);
    atAuthService.addURI("http://gcs.epok.net/xri/resolve?ns=at");
    xrd.addService(atAuthService);

    XRD xrd1 = new XRD();
    Service dummyService = new Service();
    dummyService.addMediaType(Tags.CONTENT_TYPE_XRDS + ";trust=none");
    dummyService.addType(Tags.SERVICE_AUTH_RES);
    dummyService.addURI("http://www.example.com/xri/resolve?id=1");
    xrd1.addService(dummyService);

    try {
      GCSAuthority auth = new GCSAuthority("@");
      cache.put(auth.toString(), false, false, xrd.toString().getBytes("UTF-8"), 1000);
      assertTrue("Initial cache incorrect", cache.getSize() == 1);

      cache.put(
          AuthorityPath.buildAuthorityPath("@!a!b!foo").toString(), false, false, xrd1.toString().getBytes("UTF-8"), 1000);
      assertTrue("Cache size incorrect", cache.getSize() == 2);

      cache.put(
          AuthorityPath.buildAuthorityPath("@!a!b!foo").toString(), false, false, xrd1.toString().getBytes("UTF-8"), 1000);
      assertTrue("Cache stores duplicate element?", cache.getSize() == 2);


      byte[] val =
        cache.get(AuthorityPath.buildAuthorityPath("@!a!b!foo").toString(), false, false);
      assertTrue("Cached value not found", val != null);

      val =
        cache.get(AuthorityPath.buildAuthorityPath("@!a!b!woo").toString(), false, false);
      assertTrue("Cached value should not have been found", val == null);
    }
    catch (UnsupportedEncodingException e) {
      assertTrue("Unexpected exception" + e, false);
    }
View Full Code Here



  public void testExpire()
  {
    ResolverCache c = new ResolverCache();
    try {
      c.del("@abc", false, false);
      byte[] s = c.get("@abc", false, false);
      assertTrue("stale cache value", s == null);
     
      c.put("@abc", false, false, "x".getBytes("UTF-8"), 2);
      s = c.get("@abc", false, false);
      assertTrue("unable to retrieve stored value", s != null);

      Thread.sleep(1000);
      s = c.get("@abc", false, false);
      assertTrue("premature expiry", s != null);
 
      Thread.sleep(1500);
      s = c.get("@abc", false, false);
      assertTrue("item should have expired", s == null);
    }
    catch (UnsupportedEncodingException e) {
      e.printStackTrace();
      assertTrue(e.toString(), false);
View Full Code Here

  }

 
  public void testConcurrent()
  {
    ResolverCache cache = new ResolverCache();
    cache.setNewCache("testConcurrent", 5);
    cache.del(AuthorityPath.buildAuthorityPath("@").toString(), false, false);
    assertTrue("Initial cache not empty", cache.getSize() == 0);


    XRD xrd = new XRD();
    Service atAuthService = new Service();
    atAuthService.addMediaType(Tags.CONTENT_TYPE_XRDS + ";trust=none");
    atAuthService.addType(Tags.SERVICE_AUTH_RES);
    atAuthService.addURI("http://gcs.epok.net/xri/resolve?ns=at");
    xrd.addService(atAuthService);

    try {
      GCSAuthority auth = new GCSAuthority("@");
      cache.put(auth.toString(), false, false, xrd.toString().getBytes("UTF-8"), 1000);
      assertTrue("Initial cache incorrect", cache.getSize() == 1);
    } catch (UnsupportedEncodingException e) {
      assertTrue("Unexpected exception" + e, false);
    }

    Random rnd = new Random();

    try
    {
      Thread[] threads = new StuffPruneThread[100];
      for (int i = 0; i < threads.length; i++)
      {
        threads[i] = new StuffPruneThread(rnd, cache);
      }

      for (int i = 0; i < threads.length; i++)
      {
        threads[i].start();
      }

      for (int i = 0; i < threads.length; i++)
      {
        threads[i].join();
      }
    }
    catch (Exception e)
    {
      assertTrue("Unexpected exception" + e, false);
    }

    assertTrue(
        "Max cache size not honored",
        cache.getSize() <= cache.getMaxSize());


  }
View Full Code Here

TOP

Related Classes of org.openxri.resolve.ResolverCache

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.