use of org.infinispan.marshall.TestObjectStreamMarshaller in project infinispan by infinispan.
the class DistributedStreamIteratorWithPassivationTest method testConcurrentActivationWithFilter.
@Test(enabled = false, description = "This requires supporting concurrent activation in cache loader interceptor")
public // TODO: this test needs to be redone to take into account filtering as well, after we support activated entries
void testConcurrentActivationWithFilter() throws InterruptedException, ExecutionException, TimeoutException {
final Cache<MagicKey, String> cache0 = cache(0, CACHE_NAME);
Cache<MagicKey, String> cache1 = cache(1, CACHE_NAME);
Cache<MagicKey, String> cache2 = cache(2, CACHE_NAME);
Map<MagicKey, String> originalValues = new HashMap<>();
originalValues.put(new MagicKey(cache0), "cache0");
originalValues.put(new MagicKey(cache1), "cache1");
originalValues.put(new MagicKey(cache2), "cache2");
final MagicKey loaderKey = new MagicKey(cache0);
final String loaderValue = "loader0";
cache0.putAll(originalValues);
PersistenceManager persistenceManager = TestingUtil.extractComponent(cache0, PersistenceManager.class);
DummyInMemoryStore store = persistenceManager.getStores(DummyInMemoryStore.class).iterator().next();
TestObjectStreamMarshaller sm = new TestObjectStreamMarshaller();
PersistenceManager pm = null;
try {
store.write(MarshalledEntryUtil.create(loaderKey, loaderValue, sm));
final CheckPoint checkPoint = new CheckPoint();
pm = waitUntilAboutToProcessStoreTask(cache0, checkPoint);
Future<Void> future = fork(() -> {
// Wait until loader is invoked
checkPoint.awaitStrict("pre_process_on_all_stores_invoked", 10, TimeUnit.SECONDS);
// Now force the entry to be moved to the in memory
assertEquals(loaderValue, cache0.get(loaderKey));
checkPoint.triggerForever("pre_process_on_all_stores_released");
return null;
});
KeyValueFilter<MagicKey, String> filter = (Serializable & KeyValueFilter<MagicKey, String>) (k, v, m) -> originalValues.containsKey(k);
Iterator<CacheEntry<MagicKey, String>> iterator = cache0.getAdvancedCache().cacheEntrySet().stream().filter(CacheFilters.predicate(filter)).iterator();
// we need this count since the map will replace same key'd value
int count = 0;
Map<MagicKey, String> results = new HashMap<>();
while (iterator.hasNext()) {
Map.Entry<MagicKey, String> entry = iterator.next();
results.put(entry.getKey(), entry.getValue());
count++;
}
// We shouldn't have found the value in the loader
assertEquals(count, 3);
assertEquals(originalValues, results);
future.get(10, TimeUnit.SECONDS);
} finally {
if (pm != null) {
TestingUtil.replaceComponent(cache0, PersistenceManager.class, pm, true, true);
}
sm.stop();
}
}
use of org.infinispan.marshall.TestObjectStreamMarshaller in project infinispan by infinispan.
the class AsyncStoreStressTest method startMarshaller.
@BeforeClass(alwaysRun = true)
void startMarshaller() {
marshaller = new TestObjectStreamMarshaller();
location = CommonsTestingUtil.tmpDirectory(this.getClass());
nonBlockingExecutor = new ThreadPoolExecutor(0, ProcessorInfo.availableProcessors() * 2, 60L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(KnownComponentNames.getDefaultQueueSize(KnownComponentNames.NON_BLOCKING_EXECUTOR)), new NonBlockingThreadFactory("ISPN-non-blocking-thread-group", Thread.NORM_PRIORITY, DefaultThreadFactory.DEFAULT_PATTERN, "Test", "non-blocking"), NonBlockingRejectedExecutionHandler.getInstance());
blockingExecutor = new ThreadPoolExecutor(0, 150, 60L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(KnownComponentNames.getDefaultQueueSize(KnownComponentNames.BLOCKING_EXECUTOR)), getTestThreadFactory("Blocking"), BlockingRejectedExecutionHandler.getInstance());
PerKeyLockContainer lockContainer = new PerKeyLockContainer();
TestingUtil.inject(lockContainer, new DefaultTimeService());
locks = lockContainer;
timeService = new DefaultTimeService();
TestingUtil.inject(locks, timeService, nonBlockingExecutor);
}
use of org.infinispan.marshall.TestObjectStreamMarshaller in project infinispan by infinispan.
the class BaseStreamIteratorWithLoaderTest method insertDefaultValues.
private Map<Object, String> insertDefaultValues(boolean includeLoaderEntry) {
Cache<Object, String> cache0 = cache(0);
Map<Object, String> originalValues = new HashMap<>();
Object loaderKey;
if (cacheMode.needsStateTransfer()) {
Cache<Object, String> cache1 = cache(1);
Cache<Object, String> cache2 = cache(2);
originalValues.put(new MagicKey(cache0), "cache0");
originalValues.put(new MagicKey(cache1), "cache1");
originalValues.put(new MagicKey(cache2), "cache2");
loaderKey = new MagicKey(cache2);
} else {
originalValues.put(1, "value0");
originalValues.put(2, "value1");
originalValues.put(3, "value2");
loaderKey = 4;
}
cache0.putAll(originalValues);
DummyInMemoryStore store = TestingUtil.getFirstStore(cache0);
TestObjectStreamMarshaller sm = new TestObjectStreamMarshaller(sci);
try {
String loaderValue = "loader-value";
store.write(MarshalledEntryUtil.create(loaderKey, loaderValue, sm));
if (includeLoaderEntry) {
originalValues.put(loaderKey, loaderValue);
}
} finally {
sm.stop();
}
return originalValues;
}
use of org.infinispan.marshall.TestObjectStreamMarshaller in project infinispan by infinispan.
the class LocalStreamIteratorWithPassivationTest method testConcurrentActivationWithFilter.
@Test(enabled = false, description = "This requires supporting concurrent activation in cache loader interceptor")
public void testConcurrentActivationWithFilter() throws InterruptedException, ExecutionException, TimeoutException {
final Cache<String, String> cache = cache(0, CACHE_NAME);
Map<String, String> originalValues = new HashMap<>();
originalValues.put(cache.toString() + 1, "cache0");
originalValues.put(cache.toString() + 2, "cache1");
originalValues.put(cache.toString() + 3, "cache2");
final String loaderKey = cache.toString() + " in loader";
final String loaderValue = "loader0";
final String filteredLoaderKey = cache.toString() + " in loader1";
final String filteredLoaderValue = "loader1";
cache.putAll(originalValues);
// Put this in after the cache has been updated
originalValues.put(loaderKey, loaderValue);
PersistenceManager persistenceManager = TestingUtil.extractComponent(cache, PersistenceManager.class);
DummyInMemoryStore store = persistenceManager.getStores(DummyInMemoryStore.class).iterator().next();
TestObjectStreamMarshaller sm = new TestObjectStreamMarshaller();
PersistenceManager pm = null;
try {
store.write(MarshalledEntryUtil.create(loaderKey, loaderValue, sm));
store.write(MarshalledEntryUtil.create(filteredLoaderKey, filteredLoaderValue, sm));
final CheckPoint checkPoint = new CheckPoint();
pm = waitUntilAboutToProcessStoreTask(cache, checkPoint);
Future<Void> future = fork(() -> {
// Wait until loader is invoked
checkPoint.awaitStrict("pre_process_on_all_stores_invoked", 10, TimeUnit.SECONDS);
// Now force the entry to be moved to the in memory
assertEquals(loaderValue, cache.get(loaderKey));
checkPoint.triggerForever("pre_process_on_all_stores_released");
return null;
});
Iterator<CacheEntry<String, String>> iterator = cache.getAdvancedCache().cacheEntrySet().stream().filter(CacheFilters.predicate((k, v, m) -> originalValues.containsKey(k))).iterator();
// we need this count since the map will replace same key'd value
int count = 0;
Map<String, String> results = new HashMap<>();
while (iterator.hasNext()) {
Map.Entry<String, String> entry = iterator.next();
results.put(entry.getKey(), entry.getValue());
count++;
}
// We shouldn't have found the value in the loader
assertEquals(4, count);
assertEquals(originalValues, results);
future.get(10, TimeUnit.SECONDS);
} finally {
if (pm != null) {
TestingUtil.replaceComponent(cache, PersistenceManager.class, pm, true, true);
}
sm.stop();
}
}
use of org.infinispan.marshall.TestObjectStreamMarshaller in project infinispan by infinispan.
the class LocalStreamIteratorWithPassivationTest method testConcurrentActivationWithConverter.
@Test(enabled = false, description = "This requires supporting concurrent activation in cache loader interceptor")
public void testConcurrentActivationWithConverter() throws InterruptedException, ExecutionException, TimeoutException {
final Cache<String, String> cache = cache(0, CACHE_NAME);
Map<String, String> originalValues = new HashMap<>();
originalValues.put(cache.toString() + 1, "cache0");
originalValues.put(cache.toString() + 2, "cache1");
originalValues.put(cache.toString() + 3, "cache2");
final String loaderKey = cache.toString() + " in loader";
final String loaderValue = "loader0";
cache.putAll(originalValues);
// Put this in after the cache has been updated
originalValues.put(loaderKey, loaderValue);
PersistenceManager persistenceManager = TestingUtil.extractComponent(cache, PersistenceManager.class);
DummyInMemoryStore store = persistenceManager.getStores(DummyInMemoryStore.class).iterator().next();
TestObjectStreamMarshaller sm = new TestObjectStreamMarshaller();
PersistenceManager pm = null;
try {
store.write(MarshalledEntryUtil.create(loaderKey, loaderValue, sm));
final CheckPoint checkPoint = new CheckPoint();
pm = waitUntilAboutToProcessStoreTask(cache, checkPoint);
Future<Void> future = fork(() -> {
// Wait until loader is invoked
checkPoint.awaitStrict("pre_process_on_all_stores_invoked", 10, TimeUnit.SECONDS);
// Now force the entry to be moved to the in memory
assertEquals(loaderValue, cache.get(loaderKey));
checkPoint.triggerForever("pre_process_on_all_stores_released");
return null;
});
Iterator<CacheEntry<String, String>> iterator = cache.getAdvancedCache().cacheEntrySet().stream().map(CacheFilters.function(new StringTruncator(1, 3))).iterator();
// we need this count since the map will replace same key'd value
int count = 0;
Map<String, String> results = new HashMap<>();
while (iterator.hasNext()) {
Map.Entry<String, String> entry = iterator.next();
results.put(entry.getKey(), entry.getValue());
count++;
}
// We shouldn't have found the value in the loader
assertEquals(4, count);
for (Map.Entry<String, String> entry : originalValues.entrySet()) {
assertEquals(entry.getValue().substring(1, 4), results.get(entry.getKey()));
}
future.get(10, TimeUnit.SECONDS);
} finally {
if (pm != null) {
TestingUtil.replaceComponent(cache, PersistenceManager.class, pm, true, true);
}
sm.stop();
}
}
Aggregations