Search in sources :

Example 6 with MapStoreAdapter

use of com.hazelcast.map.MapStoreAdapter in project hazelcast by hazelcast.

the class ClientMapNearCacheTest method testMapDestroy_succeeds_when_writeBehind_and_nearCache_enabled.

@Test
public void testMapDestroy_succeeds_when_writeBehind_and_nearCache_enabled() {
    Config config = newConfig();
    config.getMapConfig("default").getMapStoreConfig().setEnabled(true).setWriteDelaySeconds(1).setImplementation(new MapStoreAdapter());
    IMap<Integer, Integer> map = getNearCachedMapFromClient(config, newInvalidationEnabledNearCacheConfig());
    populateMap(map, 10);
    populateNearCache(map, 10);
    map.destroy();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NearCacheConfig(com.hazelcast.config.NearCacheConfig) NearCacheTestUtils.getBaseConfig(com.hazelcast.internal.nearcache.impl.NearCacheTestUtils.getBaseConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) Config(com.hazelcast.config.Config) MapStoreAdapter(com.hazelcast.map.MapStoreAdapter) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 7 with MapStoreAdapter

use of com.hazelcast.map.MapStoreAdapter in project hazelcast by hazelcast.

the class TransactionsWithWriteBehind_whenNoCoalescingQueueIsFullTest method getConfig.

private Config getConfig(String mapName, long maxWbqCapacity) {
    Config config = smallInstanceConfig();
    config.setProperty(ClusterProperty.MAP_WRITE_BEHIND_QUEUE_CAPACITY.toString(), String.valueOf(maxWbqCapacity));
    config.getMapConfig(mapName).setBackupCount(1).setAsyncBackupCount(0).getMapStoreConfig().setEnabled(true).setImplementation(new MapStoreAdapter()).setWriteCoalescing(false).setWriteDelaySeconds(6);
    return config;
}
Also used : Config(com.hazelcast.config.Config) MapStoreAdapter(com.hazelcast.map.MapStoreAdapter)

Example 8 with MapStoreAdapter

use of com.hazelcast.map.MapStoreAdapter in project hazelcast by hazelcast.

the class MapTransactionTest method testGet_LoadsKeyFromMapLoader_whenKeyDoesNotExistsInDb.

@Test
public void testGet_LoadsKeyFromMapLoader_whenKeyDoesNotExistsInDb() {
    final String mapName = randomMapName();
    final MapStoreAdapter mock = mock(MapStoreAdapter.class);
    when(mock.load(anyObject())).thenReturn(null);
    Config config = getConfig();
    MapStoreConfig storeConfig = new MapStoreConfig();
    storeConfig.setEnabled(true).setImplementation(mock);
    config.getMapConfig(mapName).setMapStoreConfig(storeConfig);
    HazelcastInstance instance = createHazelcastInstance(config);
    instance.executeTransaction(new TransactionalTask<Object>() {

        @Override
        public Object execute(TransactionalTaskContext context) throws TransactionException {
            TransactionalMap<Object, Object> map = context.getMap(mapName);
            Object value = map.get(1);
            assertNull("value should be null", value);
            verify(mock, times(1)).load(anyObject());
            return null;
        }
    });
}
Also used : TransactionalMap(com.hazelcast.transaction.TransactionalMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionException(com.hazelcast.transaction.TransactionException) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) MapStoreAdapter(com.hazelcast.map.MapStoreAdapter) TransactionalTaskContext(com.hazelcast.transaction.TransactionalTaskContext) Mockito.anyObject(org.mockito.Mockito.anyObject) MapStoreConfig(com.hazelcast.config.MapStoreConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 9 with MapStoreAdapter

use of com.hazelcast.map.MapStoreAdapter in project hazelcast by hazelcast.

the class MapTransactionTest method testGetForUpdate_LoadsKeyFromMapLoader_whenKeyDoesNotExistsInDb.

@Test
public void testGetForUpdate_LoadsKeyFromMapLoader_whenKeyDoesNotExistsInDb() {
    final String mapName = randomMapName();
    final MapStoreAdapter mock = mock(MapStoreAdapter.class);
    when(mock.load(anyObject())).thenReturn(null);
    Config config = new Config();
    MapStoreConfig storeConfig = new MapStoreConfig();
    storeConfig.setEnabled(true).setImplementation(mock);
    config.getMapConfig(mapName).setMapStoreConfig(storeConfig);
    HazelcastInstance instance = createHazelcastInstance(config);
    instance.executeTransaction(new TransactionalTask<Object>() {

        @Override
        public Object execute(TransactionalTaskContext context) throws TransactionException {
            TransactionalMap<Object, Object> map = context.getMap(mapName);
            Object value = map.getForUpdate(1);
            assertNull("value should be null", value);
            verify(mock, times(1)).load(anyObject());
            return null;
        }
    });
}
Also used : TransactionalMap(com.hazelcast.transaction.TransactionalMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionException(com.hazelcast.transaction.TransactionException) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) MapStoreAdapter(com.hazelcast.map.MapStoreAdapter) TransactionalTaskContext(com.hazelcast.transaction.TransactionalTaskContext) Mockito.anyObject(org.mockito.Mockito.anyObject) MapStoreConfig(com.hazelcast.config.MapStoreConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Aggregations

MapStoreAdapter (com.hazelcast.map.MapStoreAdapter)9 Config (com.hazelcast.config.Config)8 MapStoreConfig (com.hazelcast.config.MapStoreConfig)7 NightlyTest (com.hazelcast.test.annotation.NightlyTest)6 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)6 QuickTest (com.hazelcast.test.annotation.QuickTest)6 Test (org.junit.Test)6 HazelcastInstance (com.hazelcast.core.HazelcastInstance)5 TransactionException (com.hazelcast.transaction.TransactionException)5 TransactionalTaskContext (com.hazelcast.transaction.TransactionalTaskContext)5 Mockito.anyObject (org.mockito.Mockito.anyObject)5 TransactionalMap (com.hazelcast.transaction.TransactionalMap)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ClientConfig (com.hazelcast.client.config.ClientConfig)1 MapConfig (com.hazelcast.config.MapConfig)1 NearCacheConfig (com.hazelcast.config.NearCacheConfig)1 NearCacheTestUtils.getBaseConfig (com.hazelcast.internal.nearcache.impl.NearCacheTestUtils.getBaseConfig)1 ExpectedRuntimeException (com.hazelcast.test.ExpectedRuntimeException)1 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)1 Collection (java.util.Collection)1