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