protected static CacheManager getCacheManagerMaxEntries() {
    Configuration configuration = new Configuration();
    configuration.setName("testCacheManager");
    configuration.addTerracottaConfig(new TerracottaClientConfiguration().url(CLUSTER_URL));
    CacheConfiguration defaultCacheConfiguration =
        new CacheConfiguration()
            .eternal(true)
            .terracotta(new TerracottaConfiguration())
            .maxEntriesLocalHeap(10000);
    CacheConfiguration cacheConfiguration =
        new CacheConfiguration()
            .name("testCache")
            .terracotta(new TerracottaConfiguration())
            .maxEntriesLocalHeap(10000);
    configuration.setDefaultCacheConfiguration(defaultCacheConfiguration);
    configuration.addCache(cacheConfiguration);
    ManagementRESTServiceConfiguration managementRESTServiceConfiguration =
        new ManagementRESTServiceConfiguration();
    managementRESTServiceConfiguration.setBind("0.0.0.0:" + STANDALONE_REST_AGENT_PORT);
    managementRESTServiceConfiguration.setEnabled(true);
    configuration.addManagementRESTService(managementRESTServiceConfiguration);

    CacheManager mgr = new CacheManager(configuration);
    Cache exampleCache = mgr.getCache("testCache");
    assert (exampleCache != null);
    return mgr;
  }
  protected static CacheManager getCacheManagerMaxbytes() {
    Configuration configuration = new Configuration();
    configuration.setName("testCacheManagerProgrammatic");
    configuration.setMaxBytesLocalDisk("10M");
    configuration.setMaxBytesLocalHeap("5M");
    TerracottaClientConfiguration terracottaConfiguration =
        new TerracottaClientConfiguration().url(CLUSTER_URL);
    configuration.addTerracottaConfig(terracottaConfiguration);
    CacheConfiguration myCache =
        new CacheConfiguration()
            .eternal(false)
            .name("testCache2")
            .terracotta(new TerracottaConfiguration());
    configuration.addCache(myCache);
    ManagementRESTServiceConfiguration managementRESTServiceConfiguration =
        new ManagementRESTServiceConfiguration();
    managementRESTServiceConfiguration.setBind("0.0.0.0:" + STANDALONE_REST_AGENT_PORT);
    managementRESTServiceConfiguration.setEnabled(true);
    configuration.addManagementRESTService(managementRESTServiceConfiguration);

    CacheManager mgr = new CacheManager(configuration);
    Cache exampleCache = mgr.getCache("testCache2");
    assert (exampleCache != null);
    return mgr;
  }
Exemplo n.º 3
0
 @Test(expected = IllegalArgumentException.class)
 public void shouldFailOverToMostApplicableSimpleName() {
   Configuration c = new Configuration();
   final String fullName = "com.mycache.MyCache";
   final String invalidName = "unknown.namespace.MyCache";
   final PerpetualCache cache = new PerpetualCache(fullName);
   c.addCache(cache);
   assertEquals(cache, c.getCache(fullName));
   assertEquals(cache, c.getCache(invalidName));
 }
Exemplo n.º 4
0
 @Test
 public void shouldResolveBothSimpleNameAndFullyQualifiedName() {
   Configuration c = new Configuration();
   final String fullName = "com.mycache.MyCache";
   final String shortName = "MyCache";
   final PerpetualCache cache = new PerpetualCache(fullName);
   c.addCache(cache);
   assertEquals(cache, c.getCache(fullName));
   assertEquals(cache, c.getCache(shortName));
 }
Exemplo n.º 5
0
 @Test
 public void shouldFailToAddDueToNameConflict() {
   Configuration c = new Configuration();
   final String fullName = "com.mycache.MyCache";
   final PerpetualCache cache = new PerpetualCache(fullName);
   try {
     c.addCache(cache);
     c.addCache(cache);
     fail("Exception expected.");
   } catch (Exception e) {
     assertTrue(e.getMessage().contains("already contains value"));
   }
 }
Exemplo n.º 6
0
  @Test
  public void shouldSucceedWhenFullyQualifiedButFailDueToAmbiguity() {
    Configuration c = new Configuration();

    final String name1 = "com.mycache.MyCache";
    final PerpetualCache cache1 = new PerpetualCache(name1);
    c.addCache(cache1);

    final String name2 = "com.other.MyCache";
    final PerpetualCache cache2 = new PerpetualCache(name2);
    c.addCache(cache2);

    final String shortName = "MyCache";

    assertEquals(cache1, c.getCache(name1));
    assertEquals(cache2, c.getCache(name2));

    try {
      c.getCache(shortName);
      fail("Exception expected.");
    } catch (Exception e) {
      assertTrue(e.getMessage().contains("ambiguous"));
    }
  }