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; }
public static <T, W extends T> W wrapComponent(Cache<?, ?> cache, Class<T> tClass, Function<T, W> ctor) { T current = extractComponent(cache, tClass); W wrap = ctor.apply(current); replaceComponent(cache, tClass, wrap, true); return wrap; }
public static <T extends PerCacheInboundInvocationHandler> T wrapInboundInvocationHandler(Cache cache, Function<PerCacheInboundInvocationHandler, T> ctor) { PerCacheInboundInvocationHandler current = extractComponent(cache, PerCacheInboundInvocationHandler.class); T wrap = ctor.apply(current); replaceComponent(cache, PerCacheInboundInvocationHandler.class, wrap, true); return wrap; }
private EntryFactory spyEntryFactory(Cache<Object, Object> cache) { EntryFactory spy = spy(extractComponent(cache, EntryFactory.class)); TestingUtil.replaceComponent(cache, EntryFactory.class, spy, true); return spy; }
private static <T extends RpcManager> T replace(Cache<Object, Object> cache, Function<RpcManager, T> ctor) { T crm = ctor.apply(TestingUtil.extractComponent(cache, RpcManager.class)); TestingUtil.replaceComponent(cache, RpcManager.class, crm, true); return crm; }
@Override public boolean isSatisfied() throws Exception { return TestingUtil.extractComponent(cache(0), PartitionHandlingManager.class).getAvailabilityMode() == AvailabilityMode.AVAILABLE; } });
public static <T extends CacheLoader<K, V>, K, V> T getFirstLoader(Cache<K, V> cache) { PersistenceManagerImpl persistenceManager = (PersistenceManagerImpl) extractComponent(cache, PersistenceManager.class); //noinspection unchecked return (T) persistenceManager.getAllLoaders().get(0); }
public static String printCache(Cache cache) { DataContainer dataContainer = TestingUtil.extractComponent(cache, InternalDataContainer.class); Iterator it = dataContainer.iterator(); StringBuilder builder = new StringBuilder(cache.getName() + "["); while (it.hasNext()) { CacheEntry ce = (CacheEntry) it.next(); builder.append(ce.getKey() ).append("=").append( ce.getValue() ).append( ",l=" ).append( ce.getLifespan() ) .append( "; "); } builder.append("]"); return builder.toString(); }
@Override protected void createCacheManagers() throws Throwable { super.createCacheManagers(); ownerCacheStore = TestingUtil.extractComponent(cache(0, cacheName), PersistenceManager.class).getStores(DummyInMemoryStore.class).iterator().next(); nonOwnerCacheStore = TestingUtil.extractComponent(cache(1, cacheName), PersistenceManager.class).getStores(DummyInMemoryStore.class).iterator().next(); }
public AfterPassivationOrCacheWriter injectThis(Cache<Object, Object> injectInCache) { AsyncInterceptorChain chain = extractComponent(injectInCache, AsyncInterceptorChain.class); AsyncInterceptor interceptor = chain.findInterceptorExtending(CacheWriterInterceptor.class); if (interceptor == null) { interceptor = chain.findInterceptorExtending(CacheLoaderInterceptor.class); } if (interceptor == null) { throw new IllegalStateException("Should not happen!"); } chain.addInterceptorAfter(this, interceptor.getClass()); return this; }
private void replaceRpcManagerInCache(Cache cache) { RpcManager rpcManager = TestingUtil.extractComponent(cache, RpcManager.class); TestControllerRpcManager testControllerRpcManager = new TestControllerRpcManager(rpcManager); TestingUtil.replaceComponent(cache, RpcManager.class, testControllerRpcManager, true); }
private void assertNotLocked(Cache c, Object... keys) { LockManager lm = extractComponent(c, LockManager.class); for (Object key : keys) { //the keys are unlocked asynchronously eventually(() -> format("Expected unlocked key '%s' (lock-owner='%s')", key, lm.getOwner(key)), () -> !lm.isLocked(key)); } }
private boolean isNotReceivingStateForCache(Cache<?, ?> cache) { CommitManager commitManager = extractComponent(cache, CommitManager.class); return !commitManager.isTracking(Flag.PUT_FOR_STATE_TRANSFER) && !commitManager.isTracking(Flag.PUT_FOR_X_SITE_STATE_TRANSFER) && commitManager.isEmpty(); }
private void assertNoLocks() { eventually(() -> { for (Cache cache : caches()) { if (TestingUtil.extractComponent(cache, TotalOrderManager.class).hasAnyLockAcquired()) { return false; } } return true; }); }
private void assertNoLocksOrTxs(Object key, Cache<Object, String> cache) { assertEventuallyNotLocked(originatorCache, key); final TransactionTable transactionTable = TestingUtil.extractComponent(cache, TransactionTable.class); eventuallyEquals(0, transactionTable::getLocalTxCount); eventuallyEquals(0, transactionTable::getRemoteTxCount); }
private void assertNoStateTransferInReceivingSite() { for (Cache<?, ?> cache : caches(NYC)) { eventually(() -> extractComponent(cache, XSiteStateConsumer.class).getSendingSiteName() == null); eventually(() -> { CommitManager commitManager = extractComponent(cache, CommitManager.class); return !commitManager.isTracking(Flag.PUT_FOR_STATE_TRANSFER) && !commitManager.isTracking(Flag.PUT_FOR_X_SITE_STATE_TRANSFER) && commitManager.isEmpty(); }); } }
@Override public TestCache create(String groupName, List<Cache<GroupKey, String>> cacheList) { for (Cache<GroupKey, String> cache : cacheList) { DistributionManager distributionManager = TestingUtil.extractComponent(cache, DistributionManager.class); DistributionInfo distributionInfo = distributionManager.getCacheTopology().getDistribution(groupName); if (distributionInfo.isPrimary()) { return new TestCache(cache, cache.getAdvancedCache()); } } throw new IllegalStateException("didn't find a cache... should never happen!"); } },
public void revertRpcManager() { stopBlocking(); log.tracef("Restoring regular RpcManager on %s", getAddress()); RpcManager rpcManager = TestingUtil.extractComponent(cache, RpcManager.class); assertSame(this, rpcManager); TestingUtil.replaceComponent(cache, RpcManager.class, realOne, true); }
@Override protected void checkProperlyCleanup(final int managerIndex) { eventually(() -> TestingUtil.extractLockManager(cache(managerIndex, "test")).getNumberOfLocksHeld() == 0); final TransactionTable tt = TestingUtil.extractComponent(cache(managerIndex, "test"), TransactionTable.class); eventually(() -> (tt.getRemoteTxCount() == 0) && (tt.getLocalTxCount() == 0)); final RecoveryManager rm = TestingUtil.extractComponent(cache(managerIndex, "test"), RecoveryManager.class); eventually(() -> rm.getInDoubtTransactions().size() == 0); eventually(() -> rm.getPreparedTransactionsFromCluster().all().length == 0); }
private void assertKeyVersionInDataContainer(Object key, Cache... owners) { for (Cache cache : owners) { DataContainer dataContainer = TestingUtil.extractComponent(cache, InternalDataContainer.class); InternalCacheEntry entry = dataContainer.get(key); assertNotNull("Entry cannot be null in " + address(cache) + ".", entry); assertNotNull("Version cannot be null.", entry.getMetadata().version()); } }