package com.os.ee.cache.infinispan; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NameClassPair; import javax.naming.NamingEnumeration; import org.infinispan.configuration.cache.CacheMode; import org.infinispan.configuration.cache.Configuration; import org.infinispan.configuration.cache.ConfigurationBuilder; import org.infinispan.manager.EmbeddedCacheManager; import org.infinispan.tree.TreeCache; import org.infinispan.tree.TreeCacheFactory; import org.junit.Test; public class SimpleCacheTest { /** * Make the following entry in standalone-full-ha.xml to define the CacheContainer: * * * * * * * */ @Test public void testCreateTreeCache() throws Exception { ConfigurationBuilder configBuilder = new ConfigurationBuilder(); configBuilder.clustering().cacheMode(CacheMode.REPL_SYNC); configBuilder.invocationBatching().enable(); configBuilder.clustering().stateTransfer().fetchInMemoryState(true); Configuration cfg = configBuilder.build(); Context ctx = new InitialContext(); // HERE is another strange thing: we have to wait for the cache to be registered to jndi. // in earlier versions this was not necessary! boolean containerRegistered = false; while(!containerRegistered) { NamingEnumeration en = ctx.list("java:jboss/exported"); while(en.hasMoreElements()) { NameClassPair ncp = en.next(); if(ncp.getName().equals("jas-cache-container")) { containerRegistered = true; break; } } if(!containerRegistered) { System.out.println("THATS STRANGE: MUST WAIT FOR THE CACHE CONTAINER TO BE REGISTERED...."); Thread.sleep(500); } } EmbeddedCacheManager cacheContainer = (EmbeddedCacheManager)ctx.lookup("java:jboss/exported/jas-cache-container"); cacheContainer.defineConfiguration("jas-application-cache", cfg); cacheContainer.startCaches("jas-application-cache"); org.infinispan.Cache infiniCache = cacheContainer.getCache("jas-application-cache"); TreeCache tc = new TreeCacheFactory().createTreeCache(infiniCache.getAdvancedCache()); InfinispanCache cache = new InfinispanCache(tc); } }