@AfterMethod public void tearDown() { TestingUtil.killCacheManagers(cm); cm = null; c = null; }
public void testClose() { withCacheManager(new CacheManagerCallable(TestCacheManagerFactory.createCacheManager()) { @Override public void call() throws Exception { AdvancedCache<Integer, String> advCache = cm.<Integer, String>getCache().getAdvancedCache(); Cache<Integer, String> local = FunctionalJCache.create(advCache); assertFalse(local.isClosed()); local.close(); assertTrue(local.isClosed()); } }); }
@BeforeClass protected void setUpTempDir() { tmpDirectory = TestingUtil.tmpDirectory(this.getClass()); }
public static CommandsFactory extractCommandsFactory(Cache<?, ?> cache) { if (cache instanceof AbstractDelegatingCache) { // Need to unwrap to the base cache return extractCommandsFactory(extractField(cache, "cache")); } return (CommandsFactory) extractField(cache, "commandsFactory"); }
/** * Waits for the given memebrs to be removed from the cluster. The difference between this and {@link * #blockUntilViewsReceived(long, org.infinispan.manager.CacheContainer...)} methods(s) is that it does not barf if * more than expected memebers is in the cluster - this is because we expect to start with a grater number fo * memebers than we eventually expect. It will barf though, if the number of members is not the one expected but only * after the timeout expieres. */ public static void blockForMemberToFail(long timeout, CacheContainer... cacheContainers) { blockUntilViewsReceived(timeout, false, cacheContainers); areCacheViewsComplete(true, cacheContainers); }
private ClusterStreamManager replaceWithSpy(Cache<?,?> cache) { ClusterStreamManager component = TestingUtil.extractComponent(cache, ClusterStreamManager.class); ClusterStreamManager clusterStreamManager = spy(component); TestingUtil.replaceComponent(cache, ClusterStreamManager.class, clusterStreamManager, false); return clusterStreamManager; }
protected void killMember(int cacheIndex, String cacheName, boolean awaitRehash) { List<Cache<Object, Object>> caches = caches(cacheName); caches.remove(cacheIndex); manager(cacheIndex).stop(); cacheManagers.remove(cacheIndex); if (awaitRehash && caches.size() > 0) { TestingUtil.blockUntilViewsReceived(60000, false, caches); TestingUtil.waitForNoRebalance(caches); } }
@AfterMethod(alwaysRun = true) protected void clearContent() throws Throwable { if (cleanupAfterTest()) { log.debug("*** Test method complete; clearing contents on all caches."); TestingUtil.clearContent(cacheManagers); } else { TestingUtil.clearContent(cacheManagers); TestingUtil.killCacheManagers(cacheManagers); TestResourceTracker.cleanUpResources(getTestName()); cacheManagers.clear(); } }
private static CacheLoaderInterceptor cacheLoaderInterceptor(Cache<?, ?> cache) { AsyncInterceptorChain chain = TestingUtil.extractComponent(cache, AsyncInterceptorChain.class); return chain.findInterceptorExtending( CacheLoaderInterceptor.class); }
@Override protected void setup() throws Exception { super.setup(); loader = (AdvancedLoadWriteStore) TestingUtil.getFirstLoader(cache); }
static CounterBackupReceiverRepository replaceOn(CacheContainer cacheContainer) { BackupReceiverRepository delegate = extractGlobalComponent(cacheContainer, BackupReceiverRepository.class); CounterBackupReceiverRepository wrapper = new CounterBackupReceiverRepository(delegate); replaceComponent(cacheContainer, BackupReceiverRepository.class, wrapper, true); return wrapper; } }
public static GlobalMarshaller extractGlobalMarshaller(EmbeddedCacheManager cm) { GlobalComponentRegistry gcr = extractField(cm, "globalComponentRegistry"); return (GlobalMarshaller) gcr.getComponent(StreamingMarshaller.class); }
@BeforeMethod public void setUp() { cm = TestCacheManagerFactory.createCacheManager(false); timeService = new ControlledTimeService(); TestingUtil.replaceComponent(cm, TimeService.class, timeService, true); }
@AfterMethod public void tearDown() throws Exception { TestingUtil.replaceComponent(cache, CacheNotifier.class, origNotifier, true); TestingUtil.killCaches(cache); cm.stop(); }
@BeforeMethod public void setUp() throws Exception { ConfigurationBuilder builder = TestCacheManagerFactory.getDefaultCacheConfiguration(true); builder.transaction().autoCommit(false) .clustering().cacheMode(CacheMode.LOCAL) .locking().isolationLevel(IsolationLevel.REPEATABLE_READ); cm = TestCacheManagerFactory.createCacheManager(builder); cache = cm.getCache(); tm = TestingUtil.getTransactionManager(cache); mockNotifier = mock(CacheNotifier.class); origNotifier = TestingUtil.replaceComponent(cache, CacheNotifier.class, mockNotifier, true); }
@BeforeMethod(alwaysRun = true) public void setUp() { cfg = getConfiguration(); configure(cfg); cm = TestCacheManagerFactory.createCacheManager(cfg); cache = getCache(cm); store = TestingUtil.getFirstLoader(cache); writer = TestingUtil.getFirstLoader(cache); tm = TestingUtil.getTransactionManager(cache); sm = cache.getAdvancedCache().getComponentRegistry().getCacheMarshaller(); }
public static void blockUntilViewsReceived(int timeout, boolean barfIfTooManyMembers, Collection caches) { Object first = caches.iterator().next(); if (first instanceof Cache) { blockUntilViewsReceived(timeout, barfIfTooManyMembers, (Cache[]) caches.toArray(new Cache[]{})); } else { blockUntilViewsReceived(timeout, barfIfTooManyMembers, (CacheContainer[]) caches.toArray(new CacheContainer[]{})); } }
private void assertNoLocks() { LockManager lm = TestingUtil.extractLockManager(cache); LockAssert.assertNoLocks(lm); LockContainer lc = TestingUtil.extractField(lm, "lockContainer"); assert lc.size() == 0; } }
public static CountingRequestRepository replaceDispatcher(EmbeddedCacheManager cacheManager) { GlobalComponentRegistry gcr = cacheManager.getGlobalComponentRegistry(); JGroupsTransport transport = (JGroupsTransport) gcr.getComponent(Transport.class); RequestRepository requestRepository = (RequestRepository) TestingUtil.extractField(JGroupsTransport.class, transport, "requests"); CountingRequestRepository instance = new CountingRequestRepository(requestRepository); TestingUtil.replaceField(instance, "requests", transport, JGroupsTransport.class); return instance; }
public static void installNewView(Stream<Address> members, EmbeddedCacheManager... where) { installNewView(members, ecm -> { Transport transport = ecm.getTransport(); while (Proxy.isProxyClass(transport.getClass())) { // Unwrap proxies created by the StateSequencer transport = extractField(extractField(transport, "h"), "wrappedInstance"); } return ((JGroupsTransport) transport).getChannel(); }, where); }