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);
}
}
}
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);
}
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);
}
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;
}
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);
}
Aggregations