private GlobalTxTable globalTxTable(int index) { return extractGlobalComponent(cacheManagers.get(index), GlobalTxTable.class); }
public static <T, W extends T> W wrapGlobalComponent(CacheContainer cacheContainer, Class<T> tClass, Function<T, W> ctor, boolean rewire) { T current = extractGlobalComponent(cacheContainer, tClass); W wrap = ctor.apply(current); replaceComponent(cacheContainer, tClass, wrap, rewire); return wrap; }
public static <T, W extends T> W wrapGlobalComponent(CacheContainer cacheContainer, Class<T> tClass, WrapFactory<T, W, CacheContainer> factory, boolean rewire) { T current = extractGlobalComponent(cacheContainer, tClass); W wrap = factory.wrap(cacheContainer, current); replaceComponent(cacheContainer, tClass, wrap, rewire); return wrap; }
static CounterBackupReceiverRepository replaceOn(CacheContainer cacheContainer) { BackupReceiverRepository delegate = extractGlobalComponent(cacheContainer, BackupReceiverRepository.class); CounterBackupReceiverRepository wrapper = new CounterBackupReceiverRepository(delegate); replaceComponent(cacheContainer, BackupReceiverRepository.class, wrapper, true); return wrapper; } }
private void replaceInboundInvocationHandler(EmbeddedCacheManager cm, CheckPoint checkPoint, int index) { InboundInvocationHandler handler = extractGlobalComponent(cm, InboundInvocationHandler.class); BlockingInboundInvocationHandler ourHandler = new BlockingInboundInvocationHandler(handler, checkPoint, index); replaceComponent(cm, InboundInvocationHandler.class, ourHandler, true); }
static void replaceInCache(CacheContainer cacheContainer, BackupListener listener) { BackupReceiverRepository delegate = extractGlobalComponent(cacheContainer, BackupReceiverRepository.class); BackupReceiverRepositoryWrapper wrapper = new BackupReceiverRepositoryWrapper(delegate, listener); replaceComponent(cacheContainer, BackupReceiverRepository.class, wrapper, true); } }
private void blockRebalanceConfirmation(final EmbeddedCacheManager manager, final CheckPoint checkPoint, int rebalanceTopologyId) throws Exception { ClusterTopologyManager ctm = TestingUtil.extractGlobalComponent(manager, ClusterTopologyManager.class); ClusterTopologyManager spyManager = spy(ctm); doAnswer(invocation -> { Object[] arguments = invocation.getArguments(); Address source = (Address) arguments[1]; int topologyId = (Integer) arguments[2]; if (topologyId == rebalanceTopologyId) { checkPoint.trigger("pre_rebalance_confirmation_" + topologyId + "_from_" + source); checkPoint.awaitStrict("resume_rebalance_confirmation_" + topologyId + "_from_" + source, 10, SECONDS); } return invocation.callRealMethod(); }).when(spyManager).handleRebalancePhaseConfirm(anyString(), any(Address.class), anyInt(), isNull(), anyInt()); TestingUtil.replaceComponent(manager, ClusterTopologyManager.class, spyManager, true); } }
private void blockRebalanceConfirmation(final EmbeddedCacheManager manager, final CheckPoint checkPoint, int rebalanceTopologyId) throws Exception { ClusterTopologyManager ctm = TestingUtil.extractGlobalComponent(manager, ClusterTopologyManager.class); ClusterTopologyManager spyManager = spy(ctm); doAnswer(invocation -> { Object[] arguments = invocation.getArguments(); Address source = (Address) arguments[1]; int topologyId = (Integer) arguments[2]; if (rebalanceTopologyId == topologyId) { checkPoint.trigger("pre_rebalance_confirmation_" + topologyId + "_from_" + source); checkPoint.awaitStrict("resume_rebalance_confirmation_" + topologyId + "_from_" + source, 10, SECONDS); } return invocation.callRealMethod(); }).when(spyManager).handleRebalancePhaseConfirm(anyString(), any(Address.class), anyInt(), isNull(), anyInt()); TestingUtil.replaceComponent(manager, ClusterTopologyManager.class, spyManager, true); } }
private static Set<Cache> getRunningCaches(EmbeddedCacheManager cacheContainer) { if (cacheContainer == null || !cacheContainer.getStatus().allowInvocations()) return Collections.emptySet(); Set<String> running = new LinkedHashSet<>(getOrderedCacheNames(cacheContainer)); extractGlobalComponent(cacheContainer, InternalCacheRegistry.class).filterPrivateCaches(running); running.addAll(cacheContainer.getCacheNames()); running.add(cacheContainer.getCacheManagerConfiguration().defaultCacheName().orElse(DEFAULT_CACHE_NAME)); return running.stream() .map(s -> cacheContainer.getCache(s, false)) .filter(Objects::nonNull) .filter(c -> c.getStatus().allowInvocations()) .collect(Collectors.toCollection(LinkedHashSet::new)); }
private void checkClusterRestartedCorrectly(Map<JGroupsAddress, PersistentUUID> addressMappings) throws Exception { Iterator<Map.Entry<JGroupsAddress, PersistentUUID>> addressIterator = addressMappings.entrySet().iterator(); for (int i = 0; i < cacheManagers.size(); i++) { LocalTopologyManager ltm = TestingUtil.extractGlobalComponent(manager(i), LocalTopologyManager.class); // Ensure that nodes have the old UUID assertEquals(addressIterator.next().getValue(), ltm.getPersistentUUID()); // Ensure that rebalancing is enabled for the cache assertTrue(ltm.isCacheRebalancingEnabled(cache(0).getName())); } }
public static BlockingLocalTopologyManager replaceTopologyManager(EmbeddedCacheManager cacheContainer, String cacheName) { LocalTopologyManager manager = TestingUtil.extractGlobalComponent(cacheContainer, LocalTopologyManager.class); BlockingLocalTopologyManager controlledLocalTopologyManager = new BlockingLocalTopologyManager(manager, cacheContainer.getAddress(), cacheName); TestingUtil.replaceComponent(cacheContainer, LocalTopologyManager.class, controlledLocalTopologyManager, true); return controlledLocalTopologyManager; }
private void addBlockingLocalTopologyManager(final EmbeddedCacheManager manager, final CheckPoint checkPoint, final int currentTopologyId) throws InterruptedException { LocalTopologyManager component = TestingUtil.extractGlobalComponent(manager, LocalTopologyManager.class); LocalTopologyManager spyLtm = spy(component); doAnswer(invocation -> { CacheTopology topology = (CacheTopology) invocation.getArguments()[1]; // Ignore the first topology update on the joiner, which is with the topology before the join if (topology.getTopologyId() != currentTopologyId) { checkPoint.trigger("pre_topology_" + topology.getTopologyId() + "_on_" + manager.getAddress()); assertTrue(checkPoint.await("allow_topology_" + topology.getTopologyId() + "_on_" + manager.getAddress(), 10, TimeUnit.SECONDS)); } return invocation.callRealMethod(); }).when(spyLtm).handleTopologyUpdate(eq(CacheContainer.DEFAULT_CACHE_NAME), any(CacheTopology.class), any(AvailabilityMode.class), anyInt(), any(Address.class)); TestingUtil.replaceComponent(manager, LocalTopologyManager.class, spyLtm, true); }
public void testExecutorMBeans() throws Exception { LazyInitializingScheduledExecutorService timeoutExecutor = extractGlobalComponent(cacheManager, LazyInitializingScheduledExecutorService.class, TIMEOUT_SCHEDULE_EXECUTOR); timeoutExecutor.submit(() -> {}); ObjectName objectName = getCacheManagerObjectName(JMX_DOMAIN, "DefaultCacheManager", TIMEOUT_SCHEDULE_EXECUTOR); assertTrue(existsObject(objectName)); assertEquals(1, server.getAttribute(objectName, "PoolSize")); assertEquals(Integer.MAX_VALUE, server.getAttribute(objectName, "MaximumPoolSize")); }
@BeforeClass(alwaysRun = true) @Override public void createBeforeClass() throws Throwable { super.createBeforeClass(); ConfigurationBuilder builder = getDefaultClusteredCacheConfig(CacheMode.DIST_SYNC, true); builder.transaction().lockingMode(LockingMode.PESSIMISTIC); for (EmbeddedCacheManager cm : cacheManagers) { //use the same time service in all managers replaceComponent(cm, TimeService.class, timeService, true); //stop reaper. we are going to trigger it manually extractGlobalComponent(cm, GlobalTxTable.class).stop(); } }
public static DISCARD getDiscardForCache(EmbeddedCacheManager cacheManager) throws Exception { JGroupsTransport jgt = (JGroupsTransport) TestingUtil.extractGlobalComponent(cacheManager, Transport.class); JChannel ch = jgt.getChannel(); ProtocolStack ps = ch.getProtocolStack(); DISCARD discard = new DISCARD(); discard.setExcludeItself(false); ps.insertProtocol(discard, ProtocolStack.Position.ABOVE, TP.class); return discard; }
private Map<JGroupsAddress, PersistentUUID> createInitialCluster() { waitForClusterToForm(); Map<JGroupsAddress, PersistentUUID> addressMappings = new LinkedHashMap<>(); for (int i = 0; i < getClusterSize(); i++) { LocalTopologyManager ltm = TestingUtil.extractGlobalComponent(manager(i), LocalTopologyManager.class); PersistentUUID uuid = ltm.getPersistentUUID(); assertNotNull(uuid); addressMappings.put((JGroupsAddress) manager(i).getAddress(), uuid); } fillData(); checkData(); return addressMappings; }
public void testExecutorMBeans() throws Exception { ObjectName objectName = getCacheManagerObjectName(JMX_DOMAIN, "DefaultCacheManager", TIMEOUT_SCHEDULE_EXECUTOR); assertTrue(existsObject(objectName)); assertEquals(Integer.MAX_VALUE, server.getAttribute(objectName, "MaximumPoolSize")); assertEquals(0L, server.getAttribute(objectName, "KeepAliveTime")); LazyInitializingBlockingTaskAwareExecutorService remoteExecutor = extractGlobalComponent(manager(0), LazyInitializingBlockingTaskAwareExecutorService.class, REMOTE_COMMAND_EXECUTOR); remoteExecutor.submit(() -> {}); objectName = getCacheManagerObjectName(JMX_DOMAIN, "DefaultCacheManager", REMOTE_COMMAND_EXECUTOR); assertTrue(existsObject(objectName)); assertEquals(30000L, server.getAttribute(objectName, "KeepAliveTime")); assertEquals(TestCacheManagerFactory.NAMED_EXECUTORS_THREADS_NO_QUEUE, server.getAttribute(objectName, "MaximumPoolSize")); } }
private void assertServerTransactionTableEmpty() { for (Cache cache : caches(cacheName())) { PerCacheTxTable perCacheTxTable = extractComponent(cache, PerCacheTxTable.class); assertTrue(perCacheTxTable.isEmpty()); } for (EmbeddedCacheManager cm : managers()) { GlobalTxTable globalTxTable = extractGlobalComponent(cm, GlobalTxTable.class); assertTrue(globalTxTable.isEmpty()); } } }
private void assertServerTransactionTableEmpty() { for (Cache cache : caches(cacheName())) { PerCacheTxTable perCacheTxTable = extractComponent(cache, PerCacheTxTable.class); assertTrue(perCacheTxTable.isEmpty()); } for (EmbeddedCacheManager cm : managers()) { GlobalTxTable globalTxTable = extractGlobalComponent(cm, GlobalTxTable.class); assertTrue(globalTxTable.isEmpty()); } }
public void testTakeSiteOffline(Method m) { final String key = k(m); final String value = v(m); assertAllCachesEmpty(); assertSiteStatusInAllCaches(XSiteAdminOperations.ONLINE); extractGlobalComponent(site(0).cacheManagers().get(0), GlobalXSiteAdminOperations.class).takeSiteOffline(siteName(1)); assertSiteStatus(0, 0, null, 1, XSiteAdminOperations.OFFLINE); assertSiteStatus(0, 0, CacheType.BACKUP_TO_SITE_1_AND_2.name(), 1, XSiteAdminOperations.OFFLINE); assertSiteStatus(0, 0, CacheType.BACKUP_TO_SITE_1_AND_2.name(), 2, XSiteAdminOperations.ONLINE); assertSiteStatus(0, 0, CacheType.BACKUP_TO_SITE_2.name(), 2, XSiteAdminOperations.ONLINE); //double check with data putInAllCache(key, value); assertValueInAllCachesInPrimarySite(key, value); //all caches should have the value in primary site assertCacheEmpty(1, 0, null); assertCacheEmpty(1, 0, CacheType.BACKUP_TO_SITE_1_AND_2.name()); assertValueInCache(2, CacheType.BACKUP_TO_SITE_1_AND_2.name(), key, value); assertValueInCache(2, CacheType.BACKUP_TO_SITE_2.name(), key, value); }