use of org.infinispan.encoding.DataConversion in project infinispan by infinispan.
the class ExceptionEvictionTest method testDistributedOverflow.
void testDistributedOverflow(boolean onPrimary) {
if (!cacheMode.isDistributed() || nodeCount < 3) {
// Ignore the test if it isn't distributed and doesn't have at least 3 nodes
return;
}
// Now we add 2 more nodes which means we have 5 nodes and 3 owners
addClusterEnabledCacheManager(configurationBuilder);
addClusterEnabledCacheManager(configurationBuilder);
try {
waitForClusterToForm();
LocalizedCacheTopology lct = cache(0).getAdvancedCache().getDistributionManager().getCacheTopology();
DataConversion dc = cache(0).getAdvancedCache().getKeyDataConversion();
// use positive numbers as protobuf encodes negative numbers as 10-bytes long
int minKey = 1;
int nextKey = minKey;
Address targetNode;
Iterator<Address> owners = lct.getWriteOwners(dc.toStorage(nextKey)).iterator();
if (onPrimary) {
targetNode = owners.next();
} else {
// Skip first one
owners.next();
targetNode = owners.next();
}
cache(0).put(nextKey, nextKey);
// This will fill up the cache with entries that all map to owners
for (int i = 0; i < SIZE - 1; ++i) {
nextKey = getNextIntWithOwners(nextKey, lct, dc, targetNode, null);
cache(0).put(nextKey, nextKey);
}
// We should have interceptor count equal to number of owners times how much storage takes up
assertInterceptorCount();
for (Cache cache : caches()) {
if (targetNode.equals(cache.getCacheManager().getAddress())) {
assertEquals(10, cache.getAdvancedCache().getDataContainer().size());
break;
}
}
nextKey = getNextIntWithOwners(nextKey, lct, dc, targetNode, onPrimary);
try {
cache(0).put(nextKey, nextKey);
fail("Should have thrown an exception!");
} catch (Throwable t) {
Exceptions.assertException(ContainerFullException.class, getMostNestedSuppressedThrowable(t));
}
// Now that it partially failed it should have rolled back all the results
assertInterceptorCount();
} finally {
killMember(3);
killMember(3);
}
}
use of org.infinispan.encoding.DataConversion in project infinispan by infinispan.
the class LocalModePassivationTest method testEntrySetWithEvictedEntriesAndFlags.
public void testEntrySetWithEvictedEntriesAndFlags() {
final int numKeys = 300;
for (int i = 0; i < numKeys; i++) {
cache.put(i, i);
}
AdvancedCache<Object, Object> flagCache = cache.getAdvancedCache().withFlags(Flag.SKIP_CACHE_LOAD);
DataContainer<Object, Object> dc = flagCache.getDataContainer();
assertFalse("Data Container should not have all keys", numKeys == dc.size());
Set<Map.Entry<Object, Object>> entrySet = flagCache.entrySet();
assertEquals(dc.size(), entrySet.size());
DataConversion keyDataConversion = flagCache.getAdvancedCache().getKeyDataConversion();
DataConversion valueDataConversion = flagCache.getAdvancedCache().getValueDataConversion();
Map<WrappedByteArray, WrappedByteArray> map = new HashMap<>(entrySet.size());
for (Map.Entry<Object, Object> entry : entrySet) {
WrappedByteArray storedKey = (WrappedByteArray) keyDataConversion.toStorage(entry.getKey());
WrappedByteArray storedValue = (WrappedByteArray) valueDataConversion.toStorage(entry.getValue());
map.put(storedKey, storedValue);
}
for (InternalCacheEntry entry : dc) {
assertEquals("Key/Value mismatch!", entry.getValue(), map.get(entry.getKey()));
}
}
use of org.infinispan.encoding.DataConversion in project infinispan by infinispan.
the class CacheNotifierImpl method convertValue.
private V convertValue(CacheEntryListenerInvocation listenerInvocation, V value) {
if (value == null)
return null;
DataConversion valueDataConversion = listenerInvocation.getValueDataConversion();
Wrapper wrp = valueDataConversion.getWrapper();
Object unwrappedValue = valueDataConversion.getEncoder().fromStorage(wrp.unwrap(value));
CacheEventFilter filter = listenerInvocation.getFilter();
CacheEventConverter converter = listenerInvocation.getConverter();
if (filter == null && converter == null) {
if (listenerInvocation.useStorageFormat()) {
return (V) unwrappedValue;
}
// If no filter is present, convert to the requested format directly
return (V) valueDataConversion.fromStorage(value);
}
MediaType convertFormat = filter == null ? converter.format() : filter.format();
if (listenerInvocation.useStorageFormat() || convertFormat == null) {
// Filter will be run on the storage format, return the unwrapped key
return (V) unwrappedValue;
}
// Filter has a specific format to run, convert to that format
return (V) encoderRegistry.convert(unwrappedValue, valueDataConversion.getStorageMediaType(), convertFormat);
}
use of org.infinispan.encoding.DataConversion in project infinispan by infinispan.
the class PreloadManager method doPreload.
private CompletionStage<Void> doPreload() {
Publisher<MarshallableEntry<Object, Object>> publisher = persistenceManager.preloadPublisher();
long start = timeService.time();
final long maxEntries = getMaxEntries();
final long flags = getFlagsForStateInsertion();
AdvancedCache<?, ?> tmpCache = this.cache.wired().withStorageMediaType();
DataConversion keyDataConversion = tmpCache.getKeyDataConversion();
DataConversion valueDataConversion = tmpCache.getValueDataConversion();
Transaction outerTransaction = suspendIfNeeded();
try {
return Flowable.fromPublisher(publisher).take(maxEntries).concatMapSingle(me -> preloadEntry(flags, me, keyDataConversion, valueDataConversion)).count().toCompletionStage().thenAccept(insertAmount -> {
this.fullyPreloaded = insertAmount < maxEntries;
log.debugf("Preloaded %d keys in %s", insertAmount, Util.prettyPrintTime(timeService.timeDuration(start, MILLISECONDS)));
});
} finally {
resumeIfNeeded(outerTransaction);
}
}
use of org.infinispan.encoding.DataConversion in project infinispan by infinispan.
the class OffHeapMultiNodeTest method testRemoveSegments.
public void testRemoveSegments() {
Cache<String, String> cache = cache(0);
if (cache.getCacheConfiguration().clustering().cacheMode() == CacheMode.LOCAL) {
// Local caches don't support removing segments
return;
}
String key = "some-key";
String value = "some-value";
DataConversion keyDataConversion = cache.getAdvancedCache().getKeyDataConversion();
DataConversion valueDataConversion = cache.getAdvancedCache().getValueDataConversion();
Object storedKey = keyDataConversion.toStorage(key);
Object storedValue = valueDataConversion.toStorage(value);
Cache<String, String> primaryOwnerCache;
int segmentWrittenTo;
List<Cache<String, String>> caches = caches();
if (caches.size() == 1) {
primaryOwnerCache = cache;
segmentWrittenTo = 0;
} else {
primaryOwnerCache = DistributionTestHelper.getFirstOwner(storedKey, caches());
KeyPartitioner keyPartitioner = TestingUtil.extractComponent(primaryOwnerCache, KeyPartitioner.class);
segmentWrittenTo = keyPartitioner.getSegment(storedKey);
}
InternalDataContainer container = TestingUtil.extractComponent(primaryOwnerCache, InternalDataContainer.class);
assertEquals(0, container.size());
container.put(storedKey, storedValue, new EmbeddedMetadata.Builder().build());
assertEquals(1, container.size());
container.removeSegments(IntSets.immutableSet(segmentWrittenTo));
assertEquals(0, container.size());
}
Aggregations