use of org.infinispan.marshall.TestObjectStreamMarshaller in project infinispan by infinispan.
the class LocalStreamIteratorWithPassivationTest method testConcurrentActivation.
@Test(enabled = false, description = "This requires supporting concurrent activation in cache loader interceptor")
public void testConcurrentActivation() 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<Map.Entry<String, String>> iterator = cache.entrySet().stream().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++;
}
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 BaseStoreTest method setUp.
// alwaysRun = true otherwise, when we run unstable tests, this method is not invoked (because it belongs to the unit group)
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception {
marshaller = new TestObjectStreamMarshaller(getSerializationContextInitializer());
timeService = getTimeService();
factory = new InternalEntryFactoryImpl();
TestingUtil.inject(factory, timeService);
try {
// noinspection unchecked
cl = createStore();
cl.start();
} catch (Exception e) {
log.error("Error creating store", e);
throw e;
}
}
use of org.infinispan.marshall.TestObjectStreamMarshaller in project infinispan by infinispan.
the class BoundedSingleFileStoreTest method testStoreSizeExceeded.
public void testStoreSizeExceeded() {
assertStoreSize(0, 0);
TestObjectStreamMarshaller sm = new TestObjectStreamMarshaller();
try {
store.write(0, MarshalledEntryUtil.create(1, "v1", sm));
store.write(0, MarshalledEntryUtil.create(1, "v2", sm));
assertStoreSize(1, 1);
} finally {
sm.stop();
}
}
use of org.infinispan.marshall.TestObjectStreamMarshaller in project infinispan by infinispan.
the class UnnecessaryLoadingTest method testSkipCacheLoadFlagUsage.
public void testSkipCacheLoadFlagUsage() throws PersistenceException {
CountingStore countingCS = getCountingCacheStore();
TestObjectStreamMarshaller sm = new TestObjectStreamMarshaller();
try {
store.write(MarshalledEntryUtil.create("home", "Vermezzo", sm));
store.write(MarshalledEntryUtil.create("home-second", "Newcastle Upon Tyne", sm));
assert countingCS.numLoads == 0;
// load using SKIP_CACHE_LOAD should not find the object in the store
assert cache.getAdvancedCache().withFlags(Flag.SKIP_CACHE_LOAD).get("home") == null;
assert countingCS.numLoads == 0;
assert cache.getAdvancedCache().withFlags(Flag.SKIP_CACHE_LOAD).put("home", "Newcastle") == null;
assert countingCS.numLoads == 0;
final Object put = cache.getAdvancedCache().put("home-second", "Newcastle Upon Tyne, second");
assertEquals(put, "Newcastle Upon Tyne");
assert countingCS.numLoads == 1;
} finally {
sm.stop();
}
}
use of org.infinispan.marshall.TestObjectStreamMarshaller in project infinispan by infinispan.
the class BaseNonBlockingStoreTest method setUp.
// alwaysRun = true otherwise, when we run unstable tests, this method is not invoked (because it belongs to the unit group)
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception {
marshaller = new TestObjectStreamMarshaller(getSerializationContextInitializer());
timeService = getTimeService();
internalEntryFactory = new InternalEntryFactoryImpl();
TestingUtil.inject(internalEntryFactory, timeService);
marshallableEntryFactory = new MarshalledEntryFactoryImpl();
TestingUtil.inject(marshallableEntryFactory, marshaller);
try {
NonBlockingStore<Object, Object> nonBlockingStore = createStore();
// Make sure all store methods don't block when we invoke them
store = new EnsureNonBlockingStore<>(nonBlockingStore, keyPartitioner);
startStore(store);
} catch (Exception e) {
log.error("Error creating store", e);
throw e;
}
}
Aggregations