Search in sources :

Example 1 with InternalDataContainer

use of org.infinispan.container.impl.InternalDataContainer in project infinispan by infinispan.

the class DistributedStreamRehashTest method testNodeFailureDuringProcessingForCollect.

public void testNodeFailureDuringProcessingForCollect() throws InterruptedException, TimeoutException, ExecutionException {
    // Insert a key into each cache - so we always have values to find on each node
    for (Cache<MagicKey, Object> cache : this.<MagicKey, Object>caches(CACHE_NAME)) {
        MagicKey key = new MagicKey(cache);
        cache.put(key, key.toString());
    }
    Cache<MagicKey, Object> originator = cache(0, CACHE_NAME);
    // We stop the #1 node which equates to entries store in segment 2
    Cache<MagicKey, Object> nodeToBlockBeforeProcessing = cache(1, CACHE_NAME);
    Cache<MagicKey, Object> nodeToStop = cache(3, CACHE_NAME);
    CheckPoint checkPoint = new CheckPoint();
    // Always let it process the publisher
    checkPoint.triggerForever(Mocks.BEFORE_RELEASE);
    // Block on the publisher
    InternalDataContainer internalDataContainer = TestingUtil.extractComponent(nodeToBlockBeforeProcessing, InternalDataContainer.class);
    InternalDataContainer spy = spy(internalDataContainer);
    doAnswer(invocation -> {
        Publisher result = (Publisher) invocation.callRealMethod();
        return Mocks.blockingPublisher(result, checkPoint);
    // Cache2 owns segment 1 primary and 2 as backup
    }).when(spy).publisher(eq(1));
    TestingUtil.replaceComponent(nodeToBlockBeforeProcessing, InternalDataContainer.class, spy, true);
    Future<List<Map.Entry<MagicKey, Object>>> future = fork(() -> originator.entrySet().stream().collect(() -> Collectors.toList()));
    // Make sure we are up to sync
    checkPoint.awaitStrict(Mocks.AFTER_INVOCATION, 10, TimeUnit.SECONDS);
    // Note that segment 2 doesn't map to the node1 anymore
    consistentHashFactory.setOwnerIndexes(new int[][] { { 0, 1 }, { 0, 2 }, { 2, 1 }, { 1, 0 } });
    // Have to remove the cache manager so the cluster formation can work properly
    cacheManagers.remove(cacheManagers.size() - 1);
    nodeToStop.getCacheManager().stop();
    TestingUtil.blockUntilViewsReceived((int) TimeUnit.SECONDS.toMillis(10), false, caches(CACHE_NAME));
    TestingUtil.waitForNoRebalance(caches(CACHE_NAME));
    // Now let the stream be processed
    checkPoint.triggerForever(Mocks.AFTER_RELEASE);
    List<Map.Entry<MagicKey, Object>> list = future.get(10, TimeUnit.SECONDS);
    assertEquals(cacheManagers.size() + 1, list.size());
}
Also used : List(java.util.List) Publisher(org.reactivestreams.Publisher) InternalDataContainer(org.infinispan.container.impl.InternalDataContainer) MagicKey(org.infinispan.distribution.MagicKey) Map(java.util.Map) CheckPoint(org.infinispan.test.fwk.CheckPoint)

Example 2 with InternalDataContainer

use of org.infinispan.container.impl.InternalDataContainer in project infinispan by infinispan.

the class DistributedStreamIteratorExceptionTest method ensureDataContainerRemoteExceptionPropagated.

public void ensureDataContainerRemoteExceptionPropagated() {
    Cache cache0 = cache(0, CACHE_NAME);
    Cache cache1 = cache(1, CACHE_NAME);
    // Extract real one to replace after
    InternalDataContainer dataContainer = TestingUtil.extractComponent(cache1, InternalDataContainer.class);
    try {
        Throwable t = new AssertionError();
        InternalDataContainer mockContainer = mockContainer(t);
        TestingUtil.replaceComponent(cache1, InternalDataContainer.class, mockContainer, true);
        try {
            cache0.entrySet().stream().iterator().hasNext();
            fail("We should have gotten a CacheException");
        } catch (CacheException e) {
            Throwable cause = e;
            while ((cause = cause.getCause()) != null) {
                if (t.getClass().isInstance(cause)) {
                    break;
                }
            }
            assertNotNull("We should have found the throwable as a cause", cause);
        }
    } finally {
        TestingUtil.replaceComponent(cache1, InternalDataContainer.class, dataContainer, true);
    }
}
Also used : CacheException(org.infinispan.commons.CacheException) InternalDataContainer(org.infinispan.container.impl.InternalDataContainer) Cache(org.infinispan.Cache)

Example 3 with InternalDataContainer

use of org.infinispan.container.impl.InternalDataContainer in project infinispan by infinispan.

the class LocalStreamIteratorExceptionTest method ensureDataContainerExceptionPropagated.

public void ensureDataContainerExceptionPropagated() {
    Cache cache = cache(0, CACHE_NAME);
    // Extract real one to replace after
    InternalDataContainer dataContainer = TestingUtil.extractComponent(cache, InternalDataContainer.class);
    try {
        Throwable t = new CacheException();
        InternalDataContainer mockContainer = when(mock(InternalDataContainer.class).publisher(anyInt())).thenThrow(t).getMock();
        TestingUtil.replaceComponent(cache, InternalDataContainer.class, mockContainer, true);
        try {
            cache.entrySet().stream().iterator().hasNext();
            fail("We should have gotten a CacheException");
        } catch (CacheException e) {
            assertSame("We should have found the throwable as a cause", t, e);
        }
    } finally {
        TestingUtil.replaceComponent(cache, InternalDataContainer.class, dataContainer, true);
    }
}
Also used : CacheException(org.infinispan.commons.CacheException) InternalDataContainer(org.infinispan.container.impl.InternalDataContainer) Cache(org.infinispan.Cache)

Example 4 with InternalDataContainer

use of org.infinispan.container.impl.InternalDataContainer in project infinispan by infinispan.

the class RehashClusterPublisherManagerTest method testSegmentMovesToOriginatorJustBeforePublisherCompletes.

@Test(dataProvider = "GuaranteeParallelEntry")
public void testSegmentMovesToOriginatorJustBeforePublisherCompletes(DeliveryGuarantee deliveryGuarantee, boolean parallel, boolean isEntry) throws Exception {
    Cache cache2 = cache(2);
    CheckPoint checkPoint = new CheckPoint();
    // Always let it process the publisher
    checkPoint.triggerForever(Mocks.BEFORE_RELEASE);
    // Block on the publisher
    InternalDataContainer internalDataContainer = TestingUtil.extractComponent(cache2, InternalDataContainer.class);
    InternalDataContainer spy = spy(internalDataContainer);
    Answer blockingAnswer = invocation -> {
        Publisher result = (Publisher) invocation.callRealMethod();
        return Mocks.blockingPublisher(result, checkPoint);
    };
    // Depending upon if it is parallel or not, it can invoke either method
    doAnswer(blockingAnswer).when(spy).publisher(eq(2));
    doAnswer(blockingAnswer).when(spy).publisher(eq(IntSets.immutableSet(2)));
    TestingUtil.replaceComponent(cache2, InternalDataContainer.class, spy, true);
    int expectedAmount = caches().size();
    // At least once is retried after retrieving the value, so it will count the value for segment 2 twice
    if (deliveryGuarantee == DeliveryGuarantee.AT_LEAST_ONCE) {
        expectedAmount++;
    }
    runCommand(deliveryGuarantee, parallel, isEntry, expectedAmount, () -> {
        // Wait until after the publisher completes - but don't let it just yet
        checkPoint.awaitStrict(Mocks.AFTER_INVOCATION, 10, TimeUnit.SECONDS);
        triggerRebalanceSegment2MovesToNode0();
        checkPoint.triggerForever(Mocks.AFTER_RELEASE);
    });
}
Also used : ControlledConsistentHashFactory(org.infinispan.util.ControlledConsistentHashFactory) Arrays(java.util.Arrays) IntSets(org.infinispan.commons.util.IntSets) CheckPoint(org.infinispan.test.fwk.CheckPoint) DataProvider(org.testng.annotations.DataProvider) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) PublisherReducers(org.infinispan.reactive.publisher.PublisherReducers) Mocks(org.infinispan.test.Mocks) HashMap(java.util.HashMap) Test(org.testng.annotations.Test) Mockito.spy(org.mockito.Mockito.spy) Cache(org.infinispan.Cache) Function(java.util.function.Function) EnumUtil(org.infinispan.commons.util.EnumUtil) HashSet(java.util.HashSet) Answer(org.mockito.stubbing.Answer) Future(java.util.concurrent.Future) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Map(java.util.Map) TestingUtil(org.infinispan.test.TestingUtil) Address(org.infinispan.remoting.transport.Address) ArgumentMatchers.isA(org.mockito.ArgumentMatchers.isA) ExceptionRunnable(org.infinispan.commons.test.ExceptionRunnable) MagicKey(org.infinispan.distribution.MagicKey) TestDataSCI(org.infinispan.test.TestDataSCI) InternalDataContainer(org.infinispan.container.impl.InternalDataContainer) MultipleCacheManagersTest(org.infinispan.test.MultipleCacheManagersTest) Publisher(org.reactivestreams.Publisher) BeforeMethod(org.testng.annotations.BeforeMethod) Set(java.util.Set) RpcManager(org.infinispan.remoting.rpc.RpcManager) TimeUnit(java.util.concurrent.TimeUnit) Mockito(org.mockito.Mockito) CacheMode(org.infinispan.configuration.cache.CacheMode) CompletionStage(java.util.concurrent.CompletionStage) Stream(java.util.stream.Stream) ReductionPublisherRequestCommand(org.infinispan.reactive.publisher.impl.commands.reduction.ReductionPublisherRequestCommand) Mockito.any(org.mockito.Mockito.any) AssertJUnit.assertEquals(org.testng.AssertJUnit.assertEquals) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Publisher(org.reactivestreams.Publisher) InternalDataContainer(org.infinispan.container.impl.InternalDataContainer) CheckPoint(org.infinispan.test.fwk.CheckPoint) Cache(org.infinispan.Cache) CheckPoint(org.infinispan.test.fwk.CheckPoint) Test(org.testng.annotations.Test) MultipleCacheManagersTest(org.infinispan.test.MultipleCacheManagersTest)

Example 5 with InternalDataContainer

use of org.infinispan.container.impl.InternalDataContainer in project infinispan by infinispan.

the class ManualEvictionWithSizeBasedAndConcurrentOperationsInPrimaryOwnerTest method replaceControlledDataContainer.

private void replaceControlledDataContainer(final Latch latch) {
    InternalDataContainer current = TestingUtil.extractComponent(cache, InternalDataContainer.class);
    // noinspection unchecked
    InternalDataContainer controlledDataContainer = new AbstractDelegatingInternalDataContainer() {

        @Override
        protected InternalDataContainer delegate() {
            return current;
        }

        @Override
        public void evict(Object key) {
            latch.blockIfNeeded();
            super.evict(key);
        }

        @Override
        public CompletionStage<Void> evict(int segment, Object key) {
            latch.blockIfNeeded();
            return super.evict(segment, key);
        }
    };
    TestingUtil.replaceComponent(cache, InternalDataContainer.class, controlledDataContainer, true);
}
Also used : AbstractDelegatingInternalDataContainer(org.infinispan.container.impl.AbstractDelegatingInternalDataContainer) AbstractDelegatingInternalDataContainer(org.infinispan.container.impl.AbstractDelegatingInternalDataContainer) InternalDataContainer(org.infinispan.container.impl.InternalDataContainer)

Aggregations

InternalDataContainer (org.infinispan.container.impl.InternalDataContainer)10 Cache (org.infinispan.Cache)6 Map (java.util.Map)5 TimeUnit (java.util.concurrent.TimeUnit)4 CacheMode (org.infinispan.configuration.cache.CacheMode)4 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)4 RpcManager (org.infinispan.remoting.rpc.RpcManager)4 Address (org.infinispan.remoting.transport.Address)4 TestingUtil (org.infinispan.test.TestingUtil)4 Answer (org.mockito.stubbing.Answer)4 Test (org.testng.annotations.Test)4 HashMap (java.util.HashMap)3 List (java.util.List)3 Set (java.util.Set)3 Future (java.util.concurrent.Future)3 CacheException (org.infinispan.commons.CacheException)3 MagicKey (org.infinispan.distribution.MagicKey)3 KeyPartitioner (org.infinispan.distribution.ch.KeyPartitioner)3 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)3 Mockito.mock (org.mockito.Mockito.mock)3