use of org.infinispan.factories.GlobalComponentRegistry in project infinispan by infinispan.
the class TestingUtil method addCacheStartingHook.
/**
* Add a hook to cache startup sequence that will allow to replace existing component with a mock.
*/
public static void addCacheStartingHook(EmbeddedCacheManager cacheContainer, BiConsumer<String, ComponentRegistry> consumer) {
GlobalComponentRegistry gcr = extractGlobalComponentRegistry(cacheContainer);
extractField(gcr, "moduleLifecycles");
TestingUtil.<Collection<ModuleLifecycle>>replaceField(gcr, "moduleLifecycles", moduleLifecycles -> {
Collection<ModuleLifecycle> copy = new ArrayList<>(moduleLifecycles);
copy.add(new ModuleLifecycle() {
@Override
public void cacheStarting(ComponentRegistry cr, Configuration configuration, String cacheName) {
consumer.accept(cacheName, cr);
}
});
return copy;
});
}
use of org.infinispan.factories.GlobalComponentRegistry in project infinispan by infinispan.
the class VolatileLocalConfigurationStorage method removeCacheSync.
protected void removeCacheSync(String name, EnumSet<CacheContainerAdmin.AdminFlag> flags) {
log.debugf("Remove cache %s", name);
GlobalComponentRegistry globalComponentRegistry = SecurityActions.getGlobalComponentRegistry(cacheManager);
ComponentRegistry cacheComponentRegistry = globalComponentRegistry.getNamedComponentRegistry(name);
if (cacheComponentRegistry != null) {
cacheComponentRegistry.getComponent(PersistenceManager.class).setClearOnStop(true);
cacheComponentRegistry.getComponent(PassivationManager.class).skipPassivationOnStop(true);
Cache<?, ?> cache = cacheManager.getCache(name, false);
if (cache != null) {
SecurityActions.stopCache(cache);
}
}
globalComponentRegistry.removeCache(name);
// Remove cache configuration and remove it from the computed cache name list
globalComponentRegistry.getComponent(ConfigurationManager.class).removeConfiguration(name);
// Remove cache from dependency graph
// noinspection unchecked
globalComponentRegistry.getComponent(DependencyGraph.class, CACHE_DEPENDENCY_GRAPH).remove(name);
}
use of org.infinispan.factories.GlobalComponentRegistry in project infinispan by infinispan.
the class VolatileLocalConfigurationStorage method removeTemplateSync.
protected void removeTemplateSync(String name, EnumSet<CacheContainerAdmin.AdminFlag> flags) {
log.debugf("Remove template %s", name);
GlobalComponentRegistry globalComponentRegistry = SecurityActions.getGlobalComponentRegistry(cacheManager);
// Remove cache configuration and remove it from the computed cache name list
globalComponentRegistry.getComponent(ConfigurationManager.class).removeConfiguration(name);
}
use of org.infinispan.factories.GlobalComponentRegistry in project infinispan by infinispan.
the class ChannelLookupTest method channelLookupTest.
public void channelLookupTest() {
when(mockChannel.getAddress()).thenReturn(a);
when(mockChannel.down(isA(Event.class))).thenReturn(a);
when(mockChannel.getView()).thenReturn(v);
when(mockChannel.getProtocolStack()).thenReturn(ps);
when(ps.getTransport()).thenReturn(new UDP());
EmbeddedCacheManager cm = null;
try {
GlobalConfigurationBuilder gc = GlobalConfigurationBuilder.defaultClusteredBuilder();
gc.transport().defaultTransport().addProperty("channelLookup", DummyLookup.class.getName());
cm = TestCacheManagerFactory.createClusteredCacheManager(gc, new ConfigurationBuilder());
cm.start();
cm.getCache();
GlobalComponentRegistry gcr = TestingUtil.extractGlobalComponentRegistry(cm);
Transport t = gcr.getComponent(Transport.class);
assertNotNull(t);
assertTrue(t instanceof JGroupsTransport);
assertNotSame(JChannel.class, ((JGroupsTransport) t).getChannel().getClass());
} finally {
TestingUtil.killCacheManagers(cm);
}
}
use of org.infinispan.factories.GlobalComponentRegistry in project infinispan by infinispan.
the class ClusterTopologyManagerImplTest method testClusterStartupWith2Nodes.
/**
* Start two nodes and make both join the cache.
*/
public void testClusterStartupWith2Nodes() throws Exception {
// Create global component registry with dependencies
GlobalConfiguration gc = GlobalConfigurationBuilder.defaultClusteredBuilder().build();
EmbeddedCacheManager cacheManager = mock(EmbeddedCacheManager.class);
GlobalComponentRegistry gcr = new GlobalComponentRegistry(gc, cacheManager, Collections.emptySet(), TestModuleRepository.defaultModuleRepository(), mock(ConfigurationManager.class));
BasicComponentRegistry gbcr = gcr.getComponent(BasicComponentRegistry.class);
CacheManagerNotifierImpl managerNotifier = new CacheManagerNotifierImpl();
gbcr.replaceComponent(CacheManagerNotifier.class.getName(), managerNotifier, false);
managerNotifier.start();
MockTransport transport = new MockTransport(A);
gbcr.replaceComponent(Transport.class.getName(), transport, false);
PersistentUUIDManager persistentUUIDManager = new PersistentUUIDManagerImpl();
gbcr.replaceComponent(PersistentUUIDManager.class.getName(), persistentUUIDManager, false);
gbcr.replaceComponent(KnownComponentNames.NON_BLOCKING_EXECUTOR, executor, false);
gbcr.replaceComponent(KnownComponentNames.TIMEOUT_SCHEDULE_EXECUTOR, scheduledExecutor, false);
MockLocalTopologyManager ltm = new MockLocalTopologyManager(CACHE_NAME);
gbcr.replaceComponent(LocalTopologyManager.class.getName(), ltm, false);
// Initial conditions
transport.init(1, singletonList(A));
ltm.init(null, null, null, null);
// Component under test: ClusterTopologyManagerImpl on the coordinator (A)
ClusterTopologyManagerImpl ctm = new ClusterTopologyManagerImpl();
gbcr.replaceComponent(ClusterTopologyManager.class.getName(), ctm, false);
gcr.rewire();
ctm.start();
// CTMI becomes coordinator and fetches the cluster status
transport.expectCommand(CacheStatusRequestCommand.class).finish();
// No caches, so no topology update is expected here
Thread.sleep(1);
transport.verifyNoErrors();
// First node joins the cache
CacheStatusResponse joinResponseA = CompletionStages.join(ctm.handleJoin(CACHE_NAME, A, joinInfoA, 1));
assertEquals(1, joinResponseA.getCacheTopology().getTopologyId());
assertCHMembers(joinResponseA.getCacheTopology().getCurrentCH(), A);
assertNull(joinResponseA.getCacheTopology().getPendingCH());
// LTMI normally updates the topology when receiving the join response
ltm.handleTopologyUpdate(CACHE_NAME, joinResponseA.getCacheTopology(), joinResponseA.getAvailabilityMode(), 1, A);
ltm.expectTopology(1, singletonList(A), null, CacheTopology.Phase.NO_REBALANCE);
// CTMI replies to the initial stable topology broadcast
transport.expectCommand(TopologyUpdateStableCommand.class, c -> {
assertCHMembers(c.getCurrentCH(), A);
assertNull(c.getPendingCH());
}).finish();
// Add a second node
transport.updateView(2, asList(A, B));
managerNotifier.notifyViewChange(asList(A, B), singletonList(A), A, 2);
// CTMI confirms availability
transport.expectHeartBeatCommand().finish();
// Second node tries to join with old view and is rejected
CacheStatusResponse joinResponseB1 = CompletionStages.join(ctm.handleJoin(CACHE_NAME, B, joinInfoB, 1));
assertNull(joinResponseB1);
// Second node joins the cache with correct view id, receives the initial topology
CacheStatusResponse joinResponseB = CompletionStages.join(ctm.handleJoin(CACHE_NAME, B, joinInfoB, 2));
assertEquals(1, joinResponseB.getCacheTopology().getTopologyId());
assertCHMembers(joinResponseB.getCacheTopology().getCurrentCH(), A);
assertNull(joinResponseB.getCacheTopology().getPendingCH());
verifyRebalance(transport, ltm, ctm, 2, 1, singletonList(A), asList(A, B));
transport.verifyNoErrors();
gcr.stop();
}
Aggregations