Search in sources :

Example 16 with GlobalComponentRegistry

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;
    });
}
Also used : ModuleLifecycle(org.infinispan.lifecycle.ModuleLifecycle) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) Configuration(org.infinispan.configuration.cache.Configuration) BasicComponentRegistry(org.infinispan.factories.impl.BasicComponentRegistry) GlobalComponentRegistry(org.infinispan.factories.GlobalComponentRegistry) ComponentRegistry(org.infinispan.factories.ComponentRegistry) ArrayList(java.util.ArrayList) Collection(java.util.Collection) GlobalComponentRegistry(org.infinispan.factories.GlobalComponentRegistry)

Example 17 with GlobalComponentRegistry

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);
}
Also used : PassivationManager(org.infinispan.eviction.impl.PassivationManager) GlobalComponentRegistry(org.infinispan.factories.GlobalComponentRegistry) ComponentRegistry(org.infinispan.factories.ComponentRegistry) PersistenceManager(org.infinispan.persistence.manager.PersistenceManager) DependencyGraph(org.infinispan.util.DependencyGraph) GlobalComponentRegistry(org.infinispan.factories.GlobalComponentRegistry) ConfigurationManager(org.infinispan.configuration.ConfigurationManager)

Example 18 with GlobalComponentRegistry

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);
}
Also used : GlobalComponentRegistry(org.infinispan.factories.GlobalComponentRegistry) ConfigurationManager(org.infinispan.configuration.ConfigurationManager)

Example 19 with GlobalComponentRegistry

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);
    }
}
Also used : UDP(org.jgroups.protocols.UDP) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) JGroupsTransport(org.infinispan.remoting.transport.jgroups.JGroupsTransport) Event(org.jgroups.Event) GlobalComponentRegistry(org.infinispan.factories.GlobalComponentRegistry) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) Transport(org.infinispan.remoting.transport.Transport) JGroupsTransport(org.infinispan.remoting.transport.jgroups.JGroupsTransport)

Example 20 with GlobalComponentRegistry

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();
}
Also used : MockTransport(org.infinispan.remoting.transport.MockTransport) TestModuleRepository(org.infinispan.manager.TestModuleRepository) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) KnownComponentNames(org.infinispan.factories.KnownComponentNames) CompletionStages(org.infinispan.util.concurrent.CompletionStages) Test(org.testng.annotations.Test) AssertJUnit.assertTrue(org.testng.AssertJUnit.assertTrue) Collections.singletonList(java.util.Collections.singletonList) CacheManagerNotifierImpl(org.infinispan.notifications.cachemanagerlistener.CacheManagerNotifierImpl) BasicComponentRegistry(org.infinispan.factories.impl.BasicComponentRegistry) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) AbstractInfinispanTest(org.infinispan.test.AbstractInfinispanTest) Arrays.asList(java.util.Arrays.asList) ReplicatedConsistentHashFactory(org.infinispan.distribution.ch.impl.ReplicatedConsistentHashFactory) AssertJUnit.assertNull(org.testng.AssertJUnit.assertNull) CacheStatusRequestCommand(org.infinispan.commands.topology.CacheStatusRequestCommand) ExecutorService(java.util.concurrent.ExecutorService) Address(org.infinispan.remoting.transport.Address) ConfigurationManager(org.infinispan.configuration.ConfigurationManager) AfterClass(org.testng.annotations.AfterClass) Transport(org.infinispan.remoting.transport.Transport) ConsistentHash(org.infinispan.distribution.ch.ConsistentHash) GlobalComponentRegistry(org.infinispan.factories.GlobalComponentRegistry) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) TopologyUpdateCommand(org.infinispan.commands.topology.TopologyUpdateCommand) TopologyUpdateStableCommand(org.infinispan.commands.topology.TopologyUpdateStableCommand) Executors(java.util.concurrent.Executors) CacheManagerNotifier(org.infinispan.notifications.cachemanagerlistener.CacheManagerNotifier) TimeUnit(java.util.concurrent.TimeUnit) ConsistentHashFactory(org.infinispan.distribution.ch.ConsistentHashFactory) List(java.util.List) CacheMode(org.infinispan.configuration.cache.CacheMode) RebalanceStartCommand(org.infinispan.commands.topology.RebalanceStartCommand) SuccessfulResponse(org.infinispan.remoting.responses.SuccessfulResponse) Optional(java.util.Optional) AssertJUnit.assertEquals(org.testng.AssertJUnit.assertEquals) Collections(java.util.Collections) RebalanceStatusRequestCommand(org.infinispan.commands.topology.RebalanceStatusRequestCommand) TestAddress(org.infinispan.distribution.TestAddress) AvailabilityMode(org.infinispan.partitionhandling.AvailabilityMode) Mockito.mock(org.mockito.Mockito.mock) TopologyUpdateStableCommand(org.infinispan.commands.topology.TopologyUpdateStableCommand) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) CacheManagerNotifier(org.infinispan.notifications.cachemanagerlistener.CacheManagerNotifier) GlobalComponentRegistry(org.infinispan.factories.GlobalComponentRegistry) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) CacheManagerNotifierImpl(org.infinispan.notifications.cachemanagerlistener.CacheManagerNotifierImpl) BasicComponentRegistry(org.infinispan.factories.impl.BasicComponentRegistry) MockTransport(org.infinispan.remoting.transport.MockTransport) CacheStatusRequestCommand(org.infinispan.commands.topology.CacheStatusRequestCommand) MockTransport(org.infinispan.remoting.transport.MockTransport) Transport(org.infinispan.remoting.transport.Transport) ConfigurationManager(org.infinispan.configuration.ConfigurationManager)

Aggregations

GlobalComponentRegistry (org.infinispan.factories.GlobalComponentRegistry)26 GlobalConfiguration (org.infinispan.configuration.global.GlobalConfiguration)7 ComponentRegistry (org.infinispan.factories.ComponentRegistry)7 BasicComponentRegistry (org.infinispan.factories.impl.BasicComponentRegistry)7 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)7 ConfigurationManager (org.infinispan.configuration.ConfigurationManager)5 Cache (org.infinispan.Cache)4 CacheException (org.infinispan.commons.CacheException)4 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)4 Transport (org.infinispan.remoting.transport.Transport)4 CacheMode (org.infinispan.configuration.cache.CacheMode)3 Configuration (org.infinispan.configuration.cache.Configuration)3 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)3 ModuleLifecycle (org.infinispan.lifecycle.ModuleLifecycle)3 JGroupsTransport (org.infinispan.remoting.transport.jgroups.JGroupsTransport)3 Path (java.nio.file.Path)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 Properties (java.util.Properties)2 AdvancedCache (org.infinispan.AdvancedCache)2