Search in sources :

Example 6 with TestObjectStreamMarshaller

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

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;
    }
}
Also used : InternalEntryFactoryImpl(org.infinispan.container.impl.InternalEntryFactoryImpl) TestObjectStreamMarshaller(org.infinispan.marshall.TestObjectStreamMarshaller) PersistenceException(org.infinispan.persistence.spi.PersistenceException) IOException(java.io.IOException) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 8 with TestObjectStreamMarshaller

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();
    }
}
Also used : TestObjectStreamMarshaller(org.infinispan.marshall.TestObjectStreamMarshaller)

Example 9 with TestObjectStreamMarshaller

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();
    }
}
Also used : TestObjectStreamMarshaller(org.infinispan.marshall.TestObjectStreamMarshaller)

Example 10 with TestObjectStreamMarshaller

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;
    }
}
Also used : InternalEntryFactoryImpl(org.infinispan.container.impl.InternalEntryFactoryImpl) TestObjectStreamMarshaller(org.infinispan.marshall.TestObjectStreamMarshaller) PersistenceException(org.infinispan.persistence.spi.PersistenceException) IOException(java.io.IOException) MarshalledEntryFactoryImpl(org.infinispan.marshall.persistence.impl.MarshalledEntryFactoryImpl) BeforeMethod(org.testng.annotations.BeforeMethod)

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