Package org.infinispan.jcache.util

Source Code of org.infinispan.jcache.util.JCacheTestingUtil$TestClassLoader

package org.infinispan.jcache.util;

import org.infinispan.jcache.JCacheManager;
import org.infinispan.manager.EmbeddedCacheManager;

import javax.cache.Caching;
import javax.cache.spi.CachingProvider;
import java.net.URI;

/**
* Testing utilities for JCache tests.
*
* @author Galder Zamarreño
* @since 5.3
*/
public class JCacheTestingUtil {

   private JCacheTestingUtil() {
      // Do not instantiate
   }

   /**
    * Run a task defined by the {@link Runnable} instance with a
    * {@link CachingProvider} making sure that the caching provider is
    * closed after use.
    *
    * @param r task to execute with caching provider
    */
   public static void withCachingProvider(JCacheRunnable r) {
      ClassLoader tccl = Thread.currentThread().getContextClassLoader();
      CachingProvider p = Caching.getCachingProvider(new TestClassLoader(tccl));
      try {
         r.run(p);
      } finally {
         p.close();
      }
   }

   public static JCacheManager createJCacheManager(EmbeddedCacheManager cm, Object creator) {
      return new JCacheManager(URI.create(creator.getClass().getName()), cm, null);
   }

   private static class TestClassLoader extends ClassLoader {
      public TestClassLoader(ClassLoader parent) {
         super(parent);
      }
   }

}
TOP

Related Classes of org.infinispan.jcache.util.JCacheTestingUtil$TestClassLoader

TOP
Copyright © 2018 www.massapi.com. 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.