use of org.infinispan.context.impl.NonTxInvocationContext 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.context.impl.NonTxInvocationContext in project infinispan by infinispan.
the class SimpleClusterPublisherManagerTest method testCountWithContextSegments.
@Test(dataProvider = "GuaranteeParallelEntry")
public void testCountWithContextSegments(DeliveryGuarantee deliveryGuarantee, boolean parallel, boolean isEntry) {
Cache<Integer, String> cache = cache(0);
int insertAmount = insert(cache).size();
IntSet targetSegments = IntSets.mutableEmptySet();
for (int i = 2; i <= 8; ++i) {
targetSegments.set(i);
}
KeyPartitioner keyPartitioner = TestingUtil.extractComponent(cache, KeyPartitioner.class);
// We only expect a subset based on the provided segments
int expected = findHowManyInSegments(insertAmount, targetSegments, keyPartitioner);
AtomicInteger contextChange = new AtomicInteger();
InvocationContext ctx = new NonTxInvocationContext(null);
// These elements are removed or null - so aren't counted
ctx.putLookedUpEntry(0, NullCacheEntry.getInstance());
ctx.putLookedUpEntry(insertAmount - 2, Mockito.when(Mockito.mock(CacheEntry.class).isRemoved()).thenReturn(true).getMock());
// This is an extra entry only in this context
ctx.putLookedUpEntry(insertAmount + 1, new ImmortalCacheEntry(insertAmount + 1, insertAmount + 1));
// For every entry that is in the context, we only count values that are in the segments that were provided
ctx.forEachEntry((o, e) -> {
if (targetSegments.contains(keyPartitioner.getSegment(o))) {
contextChange.addAndGet((e.isRemoved() || e.isNull()) ? -1 : 1);
}
});
ClusterPublisherManager<Integer, String> cpm = cpm(cache);
CompletionStage<Long> stageCount;
if (isEntry) {
stageCount = cpm.entryReduction(parallel, targetSegments, null, ctx, EnumUtil.EMPTY_BIT_SET, deliveryGuarantee, PublisherReducers.count(), PublisherReducers.add());
} else {
stageCount = cpm.keyReduction(parallel, targetSegments, null, ctx, EnumUtil.EMPTY_BIT_SET, deliveryGuarantee, PublisherReducers.count(), PublisherReducers.add());
}
Long actualCount = stageCount.toCompletableFuture().join();
// Two keys are removed and another is new
assertEquals(expected + contextChange.get(), actualCount.intValue());
}
use of org.infinispan.context.impl.NonTxInvocationContext in project infinispan by infinispan.
the class SimpleClusterPublisherManagerTest method testContextIteration.
@Test(dataProvider = "GuaranteeEntry")
public void testContextIteration(DeliveryGuarantee deliveryGuarantee, boolean isEntry) {
Cache<Integer, String> cache = cache(0);
Map<Integer, String> values = insert(cache);
InvocationContext ctx = new NonTxInvocationContext(null);
// These elements are removed or null - so aren't counted
ctx.putLookedUpEntry(0, NullCacheEntry.getInstance());
values.remove(0);
ctx.putLookedUpEntry(7, Mockito.when(Mockito.mock(CacheEntry.class).isRemoved()).thenReturn(true).getMock());
values.remove(7);
// This is an extra entry only in this context
ctx.putLookedUpEntry(156, new ImmortalCacheEntry(156, "value-" + 156));
values.put(156, "value-" + 156);
performPublisherOperation(deliveryGuarantee, isEntry, null, null, ctx, values);
}
use of org.infinispan.context.impl.NonTxInvocationContext in project infinispan by infinispan.
the class SimpleClusterPublisherManagerTest method testCountWithContext.
@Test(dataProvider = "GuaranteeParallelEntry")
public void testCountWithContext(DeliveryGuarantee deliveryGuarantee, boolean parallel, boolean isEntry) {
Cache<Integer, String> cache = cache(0);
int insertAmount = insert(cache).size();
InvocationContext ctx = new NonTxInvocationContext(null);
// These elements are removed or null - so aren't counted
ctx.putLookedUpEntry(0, NullCacheEntry.getInstance());
ctx.putLookedUpEntry(insertAmount - 2, Mockito.when(Mockito.mock(CacheEntry.class).isRemoved()).thenReturn(true).getMock());
// This is an extra entry only in this context
ctx.putLookedUpEntry(insertAmount + 1, new ImmortalCacheEntry(insertAmount + 1, insertAmount + 1));
ClusterPublisherManager<Integer, String> cpm = cpm(cache);
CompletionStage<Long> stageCount;
if (isEntry) {
stageCount = cpm.entryReduction(parallel, null, null, ctx, EnumUtil.EMPTY_BIT_SET, deliveryGuarantee, PublisherReducers.count(), PublisherReducers.add());
} else {
stageCount = cpm.keyReduction(parallel, null, null, ctx, EnumUtil.EMPTY_BIT_SET, deliveryGuarantee, PublisherReducers.count(), PublisherReducers.add());
}
Long actualCount = stageCount.toCompletableFuture().join();
// We exclude 2 keys and add 1
int expected = insertAmount - 1;
assertEquals(expected, actualCount.intValue());
}
use of org.infinispan.context.impl.NonTxInvocationContext in project infinispan by infinispan.
the class OnlyPrimaryOwnerTest 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, Encoder.class);
mockRegistry.registerMock(KnownComponentNames.INTERNAL_MARSHALLER, StreamingMarshaller.class);
Configuration config = new ConfigurationBuilder().memory().storageType(StorageType.OBJECT).build();
ClusterEventManager cem = mock(ClusterEventManager.class);
when(cem.sendEvents(any())).thenReturn(CompletableFutures.completedNull());
TestingUtil.inject(n, mockCache, cdl, config, mockRegistry, mock(InternalEntryFactory.class), cem, mock(KeyPartitioner.class), mock(BlockingManager.class));
cl = new PrimaryOwnerCacheListener();
n.start();
n.addListener(cl);
ctx = new NonTxInvocationContext(null);
}
Aggregations