Search in sources :

Example 1 with NonTxInvocationContext

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);
}
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 2 with NonTxInvocationContext

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());
}
Also used : IntSet(org.infinispan.commons.util.IntSet) NonTxInvocationContext(org.infinispan.context.impl.NonTxInvocationContext) ImmortalCacheEntry(org.infinispan.container.entries.ImmortalCacheEntry) CacheEntry(org.infinispan.container.entries.CacheEntry) NullCacheEntry(org.infinispan.container.entries.NullCacheEntry) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) KeyPartitioner(org.infinispan.distribution.ch.KeyPartitioner) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ImmortalCacheEntry(org.infinispan.container.entries.ImmortalCacheEntry) InvocationContext(org.infinispan.context.InvocationContext) NonTxInvocationContext(org.infinispan.context.impl.NonTxInvocationContext) Test(org.testng.annotations.Test) MultipleCacheManagersTest(org.infinispan.test.MultipleCacheManagersTest)

Example 3 with NonTxInvocationContext

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);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ImmortalCacheEntry(org.infinispan.container.entries.ImmortalCacheEntry) NonTxInvocationContext(org.infinispan.context.impl.NonTxInvocationContext) InvocationContext(org.infinispan.context.InvocationContext) NonTxInvocationContext(org.infinispan.context.impl.NonTxInvocationContext) ImmortalCacheEntry(org.infinispan.container.entries.ImmortalCacheEntry) CacheEntry(org.infinispan.container.entries.CacheEntry) NullCacheEntry(org.infinispan.container.entries.NullCacheEntry) Test(org.testng.annotations.Test) MultipleCacheManagersTest(org.infinispan.test.MultipleCacheManagersTest)

Example 4 with NonTxInvocationContext

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());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ImmortalCacheEntry(org.infinispan.container.entries.ImmortalCacheEntry) NonTxInvocationContext(org.infinispan.context.impl.NonTxInvocationContext) InvocationContext(org.infinispan.context.InvocationContext) NonTxInvocationContext(org.infinispan.context.impl.NonTxInvocationContext) ImmortalCacheEntry(org.infinispan.container.entries.ImmortalCacheEntry) CacheEntry(org.infinispan.container.entries.CacheEntry) NullCacheEntry(org.infinispan.container.entries.NullCacheEntry) Test(org.testng.annotations.Test) MultipleCacheManagersTest(org.infinispan.test.MultipleCacheManagersTest)

Example 5 with NonTxInvocationContext

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);
}
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) NonTxInvocationContext(org.infinispan.context.impl.NonTxInvocationContext) 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) InternalEntryFactory(org.infinispan.container.impl.InternalEntryFactory) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

NonTxInvocationContext (org.infinispan.context.impl.NonTxInvocationContext)6 KeyPartitioner (org.infinispan.distribution.ch.KeyPartitioner)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 EncoderCache (org.infinispan.cache.impl.EncoderCache)3 Configuration (org.infinispan.configuration.cache.Configuration)3 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)3 CacheEntry (org.infinispan.container.entries.CacheEntry)3 ImmortalCacheEntry (org.infinispan.container.entries.ImmortalCacheEntry)3 NullCacheEntry (org.infinispan.container.entries.NullCacheEntry)3 InvocationContext (org.infinispan.context.InvocationContext)3 ComponentRegistry (org.infinispan.factories.ComponentRegistry)3 BasicComponentRegistry (org.infinispan.factories.impl.BasicComponentRegistry)3 MockBasicComponentRegistry (org.infinispan.factories.impl.MockBasicComponentRegistry)3 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)3 ClusterEventManager (org.infinispan.notifications.cachelistener.cluster.ClusterEventManager)3 MultipleCacheManagersTest (org.infinispan.test.MultipleCacheManagersTest)3 BlockingManager (org.infinispan.util.concurrent.BlockingManager)3 BeforeMethod (org.testng.annotations.BeforeMethod)3 Test (org.testng.annotations.Test)3 InternalEntryFactory (org.infinispan.container.impl.InternalEntryFactory)2