Search in sources :

Example 1 with WithinThreadExecutor

use of org.infinispan.util.concurrent.WithinThreadExecutor in project infinispan by infinispan.

the class PessimisticLockingTxClusterExtendedStatisticLogicTest method createCacheManagers.

@Override
protected void createCacheManagers() {
    for (int i = 0; i < NUM_NODES; ++i) {
        ConfigurationBuilder builder = getDefaultClusteredCacheConfig(CacheMode.REPL_SYNC, true);
        builder.clustering().hash().numSegments(1).consistentHashFactory(new ReplicatedControlledConsistentHashFactory(0));
        // 
        builder.locking().isolationLevel(IsolationLevel.REPEATABLE_READ).lockAcquisitionTimeout(// the timeout are triggered by the TimeService!
        60000);
        builder.transaction().recovery().disable();
        builder.transaction().lockingMode(LockingMode.PESSIMISTIC);
        // builder.versioning().enable().scheme(VersioningScheme.SIMPLE);
        extendedStatisticInterceptors[i] = new ExtendedStatisticInterceptor();
        builder.customInterceptors().addInterceptor().interceptor(extendedStatisticInterceptors[i]).after(TxInterceptor.class);
        addClusterEnabledCacheManager(builder);
    }
    waitForClusterToForm();
    for (int i = 0; i < NUM_NODES; ++i) {
        ExtendedStatisticInterceptor interceptor = extendedStatisticInterceptors[i];
        CacheStatisticManager manager = extractField(interceptor, "cacheStatisticManager");
        CacheStatisticCollector collector = extractField(manager, "cacheStatisticCollector");
        ConcurrentGlobalContainer globalContainer = extractField(collector, "globalContainer");
        ExtendedStatisticRpcManager rpcManager = (ExtendedStatisticRpcManager) extractComponent(cache(i), RpcManager.class);
        ExtendedStatisticLockManager lockManager = (ExtendedStatisticLockManager) extractLockManager(cache(i));
        lockManagers[i] = lockManager;
        replaceField(TEST_TIME_SERVICE, "timeService", manager, CacheStatisticManager.class);
        replaceField(TEST_TIME_SERVICE, "timeService", collector, CacheStatisticCollector.class);
        replaceField(TEST_TIME_SERVICE, "timeService", globalContainer, ConcurrentGlobalContainer.class);
        replaceField(TEST_TIME_SERVICE, "timeService", interceptor, ExtendedStatisticInterceptor.class);
        replaceField(TEST_TIME_SERVICE, "timeService", lockManager, ExtendedStatisticLockManager.class);
        replaceField(TEST_TIME_SERVICE, "timeService", rpcManager, ExtendedStatisticRpcManager.class);
        controlledRpcManager[i] = ControlledRpcManager.replaceRpcManager(cache(i));
        transactionTrackInterceptors[i] = TransactionTrackInterceptor.injectInCache(cache(i));
        if (i == 0) {
            LockManager actualLockManager = lockManager.getActual();
            LockContainer container = extractField(actualLockManager, "lockContainer");
            TestingUtil.inject(container, new WithinThreadExecutor(), lockManagerTimeService);
        }
    }
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) ExtendedStatisticRpcManager(org.infinispan.extendedstats.wrappers.ExtendedStatisticRpcManager) ExtendedStatisticRpcManager(org.infinispan.extendedstats.wrappers.ExtendedStatisticRpcManager) ControlledRpcManager(org.infinispan.util.ControlledRpcManager) RpcManager(org.infinispan.remoting.rpc.RpcManager) CacheStatisticCollector(org.infinispan.extendedstats.CacheStatisticCollector) ExtendedStatisticInterceptor(org.infinispan.extendedstats.wrappers.ExtendedStatisticInterceptor) WithinThreadExecutor(org.infinispan.util.concurrent.WithinThreadExecutor) ReplicatedControlledConsistentHashFactory(org.infinispan.util.ReplicatedControlledConsistentHashFactory) ExtendedStatisticLockManager(org.infinispan.extendedstats.wrappers.ExtendedStatisticLockManager) ConcurrentGlobalContainer(org.infinispan.extendedstats.container.ConcurrentGlobalContainer) CacheStatisticManager(org.infinispan.extendedstats.CacheStatisticManager) LockManager(org.infinispan.util.concurrent.locks.LockManager) ExtendedStatisticLockManager(org.infinispan.extendedstats.wrappers.ExtendedStatisticLockManager) TestingUtil.extractLockManager(org.infinispan.test.TestingUtil.extractLockManager) LockContainer(org.infinispan.util.concurrent.locks.impl.LockContainer)

Example 2 with WithinThreadExecutor

use of org.infinispan.util.concurrent.WithinThreadExecutor in project infinispan by infinispan.

the class CacheNotifierImplTest method setUp.

@BeforeMethod
public void setUp() {
    n = new CacheNotifierImpl();
    mockCache = mock(EncoderCache.class);
    EmbeddedCacheManager cacheManager = mock(EmbeddedCacheManager.class);
    when(mockCache.getCacheManager()).thenReturn(cacheManager);
    when(mockCache.getAdvancedCache()).thenReturn(mockCache);
    when(mockCache.getKeyDataConversion()).thenReturn(DataConversion.IDENTITY_KEY);
    when(mockCache.getValueDataConversion()).thenReturn(DataConversion.IDENTITY_VALUE);
    when(mockCache.getStatus()).thenReturn(ComponentStatus.INITIALIZING);
    ComponentRegistry componentRegistry = mock(ComponentRegistry.class);
    when(mockCache.getComponentRegistry()).thenReturn(componentRegistry);
    MockBasicComponentRegistry mockRegistry = new MockBasicComponentRegistry();
    when(componentRegistry.getComponent(BasicComponentRegistry.class)).thenReturn(mockRegistry);
    mockRegistry.registerMocks(RpcManager.class, CommandsFactory.class);
    mockRegistry.registerMock(KnownComponentNames.INTERNAL_MARSHALLER, StreamingMarshaller.class);
    ClusteringDependentLogic.LocalLogic cdl = new ClusteringDependentLogic.LocalLogic();
    Configuration config = new ConfigurationBuilder().build();
    cdl.init(null, config, mock(KeyPartitioner.class));
    ClusterEventManager cem = mock(ClusterEventManager.class);
    when(cem.sendEvents(any())).thenReturn(CompletableFutures.completedNull());
    BlockingManager handler = mock(BlockingManager.class);
    when(handler.continueOnNonBlockingThread(any(), any())).thenReturn(CompletableFutures.completedNull());
    TestingUtil.inject(n, mockCache, cdl, config, mockRegistry, mock(InternalEntryFactory.class), cem, mock(KeyPartitioner.class), new FakeEncoderRegistry(), TestingUtil.named(KnownComponentNames.ASYNC_NOTIFICATION_EXECUTOR, new WithinThreadExecutor()), handler);
    cl = new CacheListener();
    n.start();
    addListener();
    ctx = new NonTxInvocationContext(null);
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) Configuration(org.infinispan.configuration.cache.Configuration) ClusterEventManager(org.infinispan.notifications.cachelistener.cluster.ClusterEventManager) BlockingManager(org.infinispan.util.concurrent.BlockingManager) ClusteringDependentLogic(org.infinispan.interceptors.locking.ClusteringDependentLogic) NonTxInvocationContext(org.infinispan.context.impl.NonTxInvocationContext) WithinThreadExecutor(org.infinispan.util.concurrent.WithinThreadExecutor) EncoderCache(org.infinispan.cache.impl.EncoderCache) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) KeyPartitioner(org.infinispan.distribution.ch.KeyPartitioner) ComponentRegistry(org.infinispan.factories.ComponentRegistry) BasicComponentRegistry(org.infinispan.factories.impl.BasicComponentRegistry) MockBasicComponentRegistry(org.infinispan.factories.impl.MockBasicComponentRegistry) MockBasicComponentRegistry(org.infinispan.factories.impl.MockBasicComponentRegistry) InternalEntryFactory(org.infinispan.container.impl.InternalEntryFactory) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 3 with WithinThreadExecutor

use of org.infinispan.util.concurrent.WithinThreadExecutor in project infinispan by infinispan.

the class LimitedExecutorTest method testConcurrencyLimitWithinThread.

/**
 * Test that no more than 1 task runs at a time when using a {@link WithinThreadExecutor}.
 */
public void testConcurrencyLimitWithinThread() throws Exception {
    LimitedExecutor limitedExecutor = new LimitedExecutor(NAME, new WithinThreadExecutor(), 1);
    CompletableFuture<String> blocker1 = new CompletableFuture<>();
    CompletableFuture<String> blocker2 = new CompletableFuture<>();
    CompletableFuture<String> cf1 = new CompletableFuture<>();
    // execute() will block
    Future<?> fork1 = fork(() -> {
        limitedExecutor.execute(() -> {
            blocker2.complete("blocking");
            try {
                cf1.complete(blocker1.get(10, SECONDS));
            } catch (Exception e) {
                cf1.completeExceptionally(e);
            }
        });
    });
    assertEquals("blocking", blocker2.get(10, SECONDS));
    verifyTaskIsBlocked(limitedExecutor, blocker1, cf1);
    fork1.get(10, SECONDS);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) WithinThreadExecutor(org.infinispan.util.concurrent.WithinThreadExecutor)

Example 4 with WithinThreadExecutor

use of org.infinispan.util.concurrent.WithinThreadExecutor in project infinispan by infinispan.

the class IracTombstoneUnitTest method createIracTombstoneManager.

private static DefaultIracTombstoneManager createIracTombstoneManager(Queue<? super RunnableData> queue, int targetSize, long maxDelay, AtomicBoolean keep) {
    DefaultIracTombstoneManager manager = new DefaultIracTombstoneManager(createConfiguration(targetSize, maxDelay));
    TestingUtil.inject(manager, createDistributionManager(), createTakeOfflineManager(), createIracManager(keep), new WithinThreadExecutor(), createScheduledExecutorService(queue), createCommandFactory(), createRpcManager());
    return manager;
}
Also used : WithinThreadExecutor(org.infinispan.util.concurrent.WithinThreadExecutor) DefaultIracTombstoneManager(org.infinispan.container.versioning.irac.DefaultIracTombstoneManager)

Example 5 with WithinThreadExecutor

use of org.infinispan.util.concurrent.WithinThreadExecutor in project infinispan by infinispan.

the class BaseCacheNotifierImplInitialTransferTest method setUp.

@BeforeMethod
public void setUp() {
    n = new CacheNotifierImpl();
    mockCache = mock(EncoderCache.class);
    EmbeddedCacheManager cacheManager = mock(EmbeddedCacheManager.class);
    when(mockCache.getCacheManager()).thenReturn(cacheManager);
    when(mockCache.getAdvancedCache()).thenReturn(mockCache);
    when(mockCache.getKeyDataConversion()).thenReturn(DataConversion.IDENTITY_KEY);
    when(mockCache.getValueDataConversion()).thenReturn(DataConversion.IDENTITY_VALUE);
    Configuration config = new ConfigurationBuilder().clustering().cacheMode(cacheMode).build();
    GlobalConfiguration globalConfig = GlobalConfigurationBuilder.defaultClusteredBuilder().build();
    when(mockCache.getStatus()).thenReturn(ComponentStatus.INITIALIZING);
    mockPublisherManager = mock(ClusterPublisherManager.class);
    ComponentRegistry componentRegistry = mock(ComponentRegistry.class);
    when(mockCache.getComponentRegistry()).thenReturn(componentRegistry);
    MockBasicComponentRegistry mockRegistry = new MockBasicComponentRegistry();
    when(componentRegistry.getComponent(BasicComponentRegistry.class)).thenReturn(mockRegistry);
    mockRegistry.registerMocks(RpcManager.class, CommandsFactory.class);
    mockRegistry.registerMock(KnownComponentNames.INTERNAL_MARSHALLER, StreamingMarshaller.class);
    ClusteringDependentLogic.LocalLogic cdl = new ClusteringDependentLogic.LocalLogic();
    cdl.init(null, config, mock(KeyPartitioner.class));
    ClusterEventManager cem = mock(ClusterEventManager.class);
    when(cem.sendEvents(any())).thenReturn(CompletableFutures.completedNull());
    BlockingManager handler = mock(BlockingManager.class);
    when(handler.continueOnNonBlockingThread(any(), any())).thenReturn(CompletableFutures.completedNull());
    TestingUtil.inject(n, mockCache, cdl, config, globalConfig, mockRegistry, mockPublisherManager, new InternalEntryFactoryImpl(), cem, mock(KeyPartitioner.class), handler, TestingUtil.named(KnownComponentNames.ASYNC_NOTIFICATION_EXECUTOR, new WithinThreadExecutor()));
    n.start();
    ctx = new NonTxInvocationContext(null);
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) ClusterPublisherManager(org.infinispan.reactive.publisher.impl.ClusterPublisherManager) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) InternalEntryFactoryImpl(org.infinispan.container.impl.InternalEntryFactoryImpl) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) Configuration(org.infinispan.configuration.cache.Configuration) ClusterEventManager(org.infinispan.notifications.cachelistener.cluster.ClusterEventManager) BlockingManager(org.infinispan.util.concurrent.BlockingManager) ClusteringDependentLogic(org.infinispan.interceptors.locking.ClusteringDependentLogic) NonTxInvocationContext(org.infinispan.context.impl.NonTxInvocationContext) WithinThreadExecutor(org.infinispan.util.concurrent.WithinThreadExecutor) EncoderCache(org.infinispan.cache.impl.EncoderCache) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) KeyPartitioner(org.infinispan.distribution.ch.KeyPartitioner) BasicComponentRegistry(org.infinispan.factories.impl.BasicComponentRegistry) ComponentRegistry(org.infinispan.factories.ComponentRegistry) MockBasicComponentRegistry(org.infinispan.factories.impl.MockBasicComponentRegistry) MockBasicComponentRegistry(org.infinispan.factories.impl.MockBasicComponentRegistry) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

WithinThreadExecutor (org.infinispan.util.concurrent.WithinThreadExecutor)11 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)5 CompletableFuture (java.util.concurrent.CompletableFuture)3 EncoderCache (org.infinispan.cache.impl.EncoderCache)2 Configuration (org.infinispan.configuration.cache.Configuration)2 NonTxInvocationContext (org.infinispan.context.impl.NonTxInvocationContext)2 KeyPartitioner (org.infinispan.distribution.ch.KeyPartitioner)2 CacheStatisticCollector (org.infinispan.extendedstats.CacheStatisticCollector)2 CacheStatisticManager (org.infinispan.extendedstats.CacheStatisticManager)2 ConcurrentGlobalContainer (org.infinispan.extendedstats.container.ConcurrentGlobalContainer)2 ExtendedStatisticInterceptor (org.infinispan.extendedstats.wrappers.ExtendedStatisticInterceptor)2 ExtendedStatisticLockManager (org.infinispan.extendedstats.wrappers.ExtendedStatisticLockManager)2 ExtendedStatisticRpcManager (org.infinispan.extendedstats.wrappers.ExtendedStatisticRpcManager)2 ComponentRegistry (org.infinispan.factories.ComponentRegistry)2 BasicComponentRegistry (org.infinispan.factories.impl.BasicComponentRegistry)2 MockBasicComponentRegistry (org.infinispan.factories.impl.MockBasicComponentRegistry)2 ClusteringDependentLogic (org.infinispan.interceptors.locking.ClusteringDependentLogic)2 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)2 ClusterEventManager (org.infinispan.notifications.cachelistener.cluster.ClusterEventManager)2 RpcManager (org.infinispan.remoting.rpc.RpcManager)2