Search in sources :

Example 11 with MapProxyImpl

use of com.hazelcast.map.impl.proxy.MapProxyImpl in project hazelcast by hazelcast.

the class MapPartitionIteratorTest method test_Remove.

@Test
public void test_Remove() throws Exception {
    HazelcastInstance instance = createHazelcastInstance();
    MapProxyImpl<Object, Object> proxy = (MapProxyImpl<Object, Object>) instance.getMap(randomMapName());
    String key = generateKeyForPartition(instance, 1);
    String value = randomString();
    proxy.put(key, value);
    Iterator<Map.Entry<Object, Object>> iterator = proxy.iterator(10, 1, prefetchValues);
    iterator.next();
    iterator.remove();
    assertEquals(0, proxy.size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapProxyImpl(com.hazelcast.map.impl.proxy.MapProxyImpl) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 12 with MapProxyImpl

use of com.hazelcast.map.impl.proxy.MapProxyImpl in project hazelcast by hazelcast.

the class DynamicMapConfigTest method isRecordStoreExpirable.

private boolean isRecordStoreExpirable(IMap map) {
    MapProxyImpl mapProxy = (MapProxyImpl) map;
    MapService mapService = (MapService) mapProxy.getService();
    MapServiceContext mapServiceContext = (MapServiceContext) mapService.getMapServiceContext();
    PartitionContainer container = mapServiceContext.getPartitionContainer(0);
    RecordStore recordStore = container.getExistingRecordStore(map.getName());
    return recordStore.isExpirable();
}
Also used : PartitionContainer(com.hazelcast.map.impl.PartitionContainer) MapProxyImpl(com.hazelcast.map.impl.proxy.MapProxyImpl) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) MapService(com.hazelcast.map.impl.MapService) MapServiceContext(com.hazelcast.map.impl.MapServiceContext)

Example 13 with MapProxyImpl

use of com.hazelcast.map.impl.proxy.MapProxyImpl in project hazelcast by hazelcast.

the class MapRemoveFailingBackupTest method testMapRemoveFailingBackupShouldNotLeadToStaleDataWhenReadBackupIsEnabled.

@Test
public void testMapRemoveFailingBackupShouldNotLeadToStaleDataWhenReadBackupIsEnabled() throws Exception {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    final String mapName = randomMapName();
    final String key = "2";
    final String value = "value2";
    Config config = getConfig();
    config.getSerializationConfig().addDataSerializableFactory(100, new Factory());
    config.setProperty(GroupProperty.PARTITION_BACKUP_SYNC_INTERVAL.getName(), "5");
    config.getMapConfig(mapName).setReadBackupData(true);
    HazelcastInstance hz1 = factory.newHazelcastInstance(config);
    HazelcastInstance hz2 = factory.newHazelcastInstance(config);
    final HazelcastInstanceImpl hz1Impl = TestUtil.getHazelcastInstanceImpl(hz1);
    final IMap<Object, Object> map1 = hz1.getMap(mapName);
    final IMap<Object, Object> map2 = hz2.getMap(mapName);
    MapProxyImpl<Object, Object> mock1 = (MapProxyImpl<Object, Object>) spy(map1);
    when(mock1.remove(anyString())).then(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            NodeEngineImpl nodeEngine = hz1Impl.node.nodeEngine;
            Object object = invocation.getArguments()[0];
            final Data key = nodeEngine.toData(object);
            RemoveOperation operation = new RemoveOperation(mapName, key);
            int partitionId = nodeEngine.getPartitionService().getPartitionId(key);
            operation.setThreadId(ThreadUtil.getThreadId());
            OperationService operationService = nodeEngine.getOperationService();
            InternalCompletableFuture<Data> f = operationService.createInvocationBuilder(SERVICE_NAME, operation, partitionId).setResultDeserialized(false).invoke();
            Data result = f.get();
            return nodeEngine.toObject(result);
        }
    });
    mock1.put(key, value);
    mock1.remove(key);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertNull(map1.get(key));
            assertNull(map2.get(key));
        }
    }, 30);
}
Also used : HazelcastInstanceImpl(com.hazelcast.instance.HazelcastInstanceImpl) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Config(com.hazelcast.config.Config) InternalCompletableFuture(com.hazelcast.spi.InternalCompletableFuture) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) DataSerializableFactory(com.hazelcast.nio.serialization.DataSerializableFactory) BaseRemoveOperation(com.hazelcast.map.impl.operation.BaseRemoveOperation) Data(com.hazelcast.nio.serialization.Data) Matchers.anyString(org.mockito.Matchers.anyString) HazelcastInstance(com.hazelcast.core.HazelcastInstance) InvocationOnMock(org.mockito.invocation.InvocationOnMock) MapProxyImpl(com.hazelcast.map.impl.proxy.MapProxyImpl) AssertTask(com.hazelcast.test.AssertTask) OperationService(com.hazelcast.spi.OperationService) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 14 with MapProxyImpl

use of com.hazelcast.map.impl.proxy.MapProxyImpl in project hazelcast by hazelcast.

the class MapPartitionIteratorTest method test_HasNext_Returns_False_On_EmptyPartition.

@Test
public void test_HasNext_Returns_False_On_EmptyPartition() throws Exception {
    HazelcastInstance instance = createHazelcastInstance();
    MapProxyImpl<Object, Object> proxy = (MapProxyImpl<Object, Object>) instance.getMap(randomMapName());
    Iterator<Map.Entry<Object, Object>> iterator = proxy.iterator(10, 1, prefetchValues);
    assertFalse(iterator.hasNext());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapProxyImpl(com.hazelcast.map.impl.proxy.MapProxyImpl) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 15 with MapProxyImpl

use of com.hazelcast.map.impl.proxy.MapProxyImpl in project hazelcast by hazelcast.

the class MapPartitionIteratorTest method test_DoesNotReturn_DuplicateEntry_When_Rehashing_Happens.

@Test
@Ignore
public void test_DoesNotReturn_DuplicateEntry_When_Rehashing_Happens() throws Exception {
    HazelcastInstance instance = createHazelcastInstance();
    MapProxyImpl<String, String> proxy = (MapProxyImpl<String, String>) instance.<String, String>getMap(randomMapName());
    HashSet<String> readKeys = new HashSet<String>();
    String value = "initialValue";
    putValuesToPartition(instance, proxy, value, 1, 100);
    Iterator<Map.Entry<String, String>> iterator = proxy.iterator(10, 1, prefetchValues);
    assertUniques(readKeys, iterator, 50);
    // force rehashing
    putValuesToPartition(instance, proxy, randomString(), 1, 150);
    assertUniques(readKeys, iterator);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapProxyImpl(com.hazelcast.map.impl.proxy.MapProxyImpl) HashSet(java.util.HashSet) Ignore(org.junit.Ignore) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

MapProxyImpl (com.hazelcast.map.impl.proxy.MapProxyImpl)24 HazelcastInstance (com.hazelcast.core.HazelcastInstance)13 ParallelTest (com.hazelcast.test.annotation.ParallelTest)12 QuickTest (com.hazelcast.test.annotation.QuickTest)12 Test (org.junit.Test)12 MapService (com.hazelcast.map.impl.MapService)10 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)7 Config (com.hazelcast.config.Config)3 DistributedObject (com.hazelcast.core.DistributedObject)3 MapContainer (com.hazelcast.map.impl.MapContainer)3 Map (java.util.Map)3 MapConfig (com.hazelcast.config.MapConfig)2 PartitionContainer (com.hazelcast.map.impl.PartitionContainer)2 RecordStore (com.hazelcast.map.impl.recordstore.RecordStore)2 Address (com.hazelcast.nio.Address)2 NodeEngine (com.hazelcast.spi.NodeEngine)2 IPartitionService (com.hazelcast.spi.partition.IPartitionService)2 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)2 HashSet (java.util.HashSet)2 Ignore (org.junit.Ignore)2