Search in sources :

Example 1 with TestObjectStreamMarshaller

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();
    }
}
Also used : HashMap(java.util.HashMap) PersistenceManager(org.infinispan.persistence.manager.PersistenceManager) ImmortalCacheEntry(org.infinispan.container.entries.ImmortalCacheEntry) CacheEntry(org.infinispan.container.entries.CacheEntry) CheckPoint(org.infinispan.test.fwk.CheckPoint) DummyInMemoryStore(org.infinispan.persistence.dummy.DummyInMemoryStore) TestObjectStreamMarshaller(org.infinispan.marshall.TestObjectStreamMarshaller) MagicKey(org.infinispan.distribution.MagicKey) HashMap(java.util.HashMap) Map(java.util.Map) CheckPoint(org.infinispan.test.fwk.CheckPoint) Test(org.testng.annotations.Test)

Example 2 with TestObjectStreamMarshaller

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);
}
Also used : PerKeyLockContainer(org.infinispan.util.concurrent.locks.impl.PerKeyLockContainer) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) NonBlockingThreadFactory(org.infinispan.factories.threads.NonBlockingThreadFactory) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) TestObjectStreamMarshaller(org.infinispan.marshall.TestObjectStreamMarshaller) DefaultTimeService(org.infinispan.commons.time.DefaultTimeService) BeforeClass(org.testng.annotations.BeforeClass)

Example 3 with TestObjectStreamMarshaller

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;
}
Also used : DummyInMemoryStore(org.infinispan.persistence.dummy.DummyInMemoryStore) HashMap(java.util.HashMap) TestObjectStreamMarshaller(org.infinispan.marshall.TestObjectStreamMarshaller) MagicKey(org.infinispan.distribution.MagicKey)

Example 4 with TestObjectStreamMarshaller

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();
    }
}
Also used : HashMap(java.util.HashMap) PersistenceManager(org.infinispan.persistence.manager.PersistenceManager) ImmortalCacheEntry(org.infinispan.container.entries.ImmortalCacheEntry) CacheEntry(org.infinispan.container.entries.CacheEntry) CheckPoint(org.infinispan.test.fwk.CheckPoint) DummyInMemoryStore(org.infinispan.persistence.dummy.DummyInMemoryStore) TestObjectStreamMarshaller(org.infinispan.marshall.TestObjectStreamMarshaller) HashMap(java.util.HashMap) Map(java.util.Map) CheckPoint(org.infinispan.test.fwk.CheckPoint) Test(org.testng.annotations.Test)

Example 5 with TestObjectStreamMarshaller

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();
    }
}
Also used : HashMap(java.util.HashMap) PersistenceManager(org.infinispan.persistence.manager.PersistenceManager) ImmortalCacheEntry(org.infinispan.container.entries.ImmortalCacheEntry) CacheEntry(org.infinispan.container.entries.CacheEntry) CheckPoint(org.infinispan.test.fwk.CheckPoint) DummyInMemoryStore(org.infinispan.persistence.dummy.DummyInMemoryStore) TestObjectStreamMarshaller(org.infinispan.marshall.TestObjectStreamMarshaller) HashMap(java.util.HashMap) Map(java.util.Map) CheckPoint(org.infinispan.test.fwk.CheckPoint) Test(org.testng.annotations.Test)

Aggregations

TestObjectStreamMarshaller (org.infinispan.marshall.TestObjectStreamMarshaller)18 HashMap (java.util.HashMap)7 DummyInMemoryStore (org.infinispan.persistence.dummy.DummyInMemoryStore)7 Map (java.util.Map)6 CacheEntry (org.infinispan.container.entries.CacheEntry)6 ImmortalCacheEntry (org.infinispan.container.entries.ImmortalCacheEntry)6 PersistenceManager (org.infinispan.persistence.manager.PersistenceManager)6 CheckPoint (org.infinispan.test.fwk.CheckPoint)6 Test (org.testng.annotations.Test)6 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)4 MagicKey (org.infinispan.distribution.MagicKey)4 BeforeClass (org.testng.annotations.BeforeClass)4 IOException (java.io.IOException)2 GlobalConfiguration (org.infinispan.configuration.global.GlobalConfiguration)2 InternalEntryFactoryImpl (org.infinispan.container.impl.InternalEntryFactoryImpl)2 MarshalledEntryFactoryImpl (org.infinispan.marshall.persistence.impl.MarshalledEntryFactoryImpl)2 DummyInitializationContext (org.infinispan.persistence.DummyInitializationContext)2 JdbcStringBasedStoreConfigurationBuilder (org.infinispan.persistence.jdbc.configuration.JdbcStringBasedStoreConfigurationBuilder)2 PersistenceException (org.infinispan.persistence.spi.PersistenceException)2 BeforeMethod (org.testng.annotations.BeforeMethod)2