Search in sources :

Example 6 with PartitioningStrategy

use of com.hazelcast.core.PartitioningStrategy in project hazelcast by hazelcast.

the class PartitioningStrategyFactoryTest method whenStrategyForMapAlreadyDefined_getPartitioningStrategy_returnsSameInstance.

// when a partitioning strategy has already been cached, then another invocation to obtain the partitioning
// strategy for the same map name retrieves the same instance
@Test
public void whenStrategyForMapAlreadyDefined_getPartitioningStrategy_returnsSameInstance() {
    PartitioningStrategyConfig cfg = new PartitioningStrategyConfig();
    cfg.setPartitioningStrategyClass("com.hazelcast.partition.strategy.StringPartitioningStrategy");
    // when we have already obtained the partitioning strategy for a given map name
    PartitioningStrategy partitioningStrategy = partitioningStrategyFactory.getPartitioningStrategy(mapName, cfg);
    // then once we get it again with the same arguments, we retrieve the same instance
    PartitioningStrategy cachedPartitioningStrategy = partitioningStrategyFactory.getPartitioningStrategy(mapName, cfg);
    assertSame(partitioningStrategy, cachedPartitioningStrategy);
}
Also used : PartitioningStrategyConfig(com.hazelcast.config.PartitioningStrategyConfig) PartitioningStrategy(com.hazelcast.core.PartitioningStrategy) StringPartitioningStrategy(com.hazelcast.partition.strategy.StringPartitioningStrategy) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 7 with PartitioningStrategy

use of com.hazelcast.core.PartitioningStrategy in project hazelcast by hazelcast.

the class PartitioningStrategyFactoryTest method whenRemoveInvoked_entryIsRemovedFromCache.

@Test
public void whenRemoveInvoked_entryIsRemovedFromCache() {
    PartitioningStrategyConfig cfg = new PartitioningStrategyConfig();
    cfg.setPartitioningStrategyClass("com.hazelcast.partition.strategy.StringPartitioningStrategy");
    PartitioningStrategy partitioningStrategy = partitioningStrategyFactory.getPartitioningStrategy(mapName, cfg);
    partitioningStrategyFactory.removePartitioningStrategyFromCache(mapName);
    assertFalse(partitioningStrategyFactory.cache.containsKey(mapName));
}
Also used : PartitioningStrategyConfig(com.hazelcast.config.PartitioningStrategyConfig) PartitioningStrategy(com.hazelcast.core.PartitioningStrategy) StringPartitioningStrategy(com.hazelcast.partition.strategy.StringPartitioningStrategy) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 8 with PartitioningStrategy

use of com.hazelcast.core.PartitioningStrategy in project hazelcast by hazelcast.

the class PartitioningStrategyFactoryTest method whenConfigNull_getPartitioningStrategy_returnsNull.

@Test
public void whenConfigNull_getPartitioningStrategy_returnsNull() {
    PartitioningStrategy partitioningStrategy = partitioningStrategyFactory.getPartitioningStrategy(mapName, null);
    assertNull(partitioningStrategy);
}
Also used : PartitioningStrategy(com.hazelcast.core.PartitioningStrategy) StringPartitioningStrategy(com.hazelcast.partition.strategy.StringPartitioningStrategy) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 9 with PartitioningStrategy

use of com.hazelcast.core.PartitioningStrategy in project hazelcast by hazelcast.

the class SerializationTest method testPartitionHash.

@Test
public void testPartitionHash() {
    PartitioningStrategy partitionStrategy = new PartitioningStrategy() {

        @Override
        public Object getPartitionKey(Object key) {
            return key.hashCode();
        }
    };
    SerializationService ss = new DefaultSerializationServiceBuilder().build();
    String obj = String.valueOf(System.nanoTime());
    Data dataWithPartitionHash = ss.toData(obj, partitionStrategy);
    Data dataWithOutPartitionHash = ss.toData(obj);
    assertTrue(dataWithPartitionHash.hasPartitionHash());
    assertNotEquals(dataWithPartitionHash.hashCode(), dataWithPartitionHash.getPartitionHash());
    assertFalse(dataWithOutPartitionHash.hasPartitionHash());
    assertEquals(dataWithOutPartitionHash.hashCode(), dataWithOutPartitionHash.getPartitionHash());
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) PartitioningStrategy(com.hazelcast.core.PartitioningStrategy) SerializationService(com.hazelcast.spi.serialization.SerializationService) HeapData(com.hazelcast.internal.serialization.impl.HeapData) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 10 with PartitioningStrategy

use of com.hazelcast.core.PartitioningStrategy in project hazelcast by hazelcast.

the class PartitionControlledIdTest method startHazelcastInstances.

@BeforeClass
public static void startHazelcastInstances() throws Exception {
    Config config = new Config();
    PartitioningStrategy partitioningStrategy = StringAndPartitionAwarePartitioningStrategy.INSTANCE;
    config.getMapConfig("default").setPartitioningStrategyConfig(new PartitioningStrategyConfig(partitioningStrategy));
    TestHazelcastInstanceFactory instanceFactory = new TestHazelcastInstanceFactory(4);
    instances = instanceFactory.newInstances(config);
    warmUpPartitions(instances);
}
Also used : PartitioningStrategyConfig(com.hazelcast.config.PartitioningStrategyConfig) PartitioningStrategyConfig(com.hazelcast.config.PartitioningStrategyConfig) Config(com.hazelcast.config.Config) StringAndPartitionAwarePartitioningStrategy(com.hazelcast.partition.strategy.StringAndPartitionAwarePartitioningStrategy) StringPartitioningStrategy(com.hazelcast.partition.strategy.StringPartitioningStrategy) PartitioningStrategy(com.hazelcast.core.PartitioningStrategy) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) BeforeClass(org.junit.BeforeClass)

Aggregations

PartitioningStrategy (com.hazelcast.core.PartitioningStrategy)12 StringPartitioningStrategy (com.hazelcast.partition.strategy.StringPartitioningStrategy)6 QuickTest (com.hazelcast.test.annotation.QuickTest)6 Test (org.junit.Test)6 PartitioningStrategyConfig (com.hazelcast.config.PartitioningStrategyConfig)5 ParallelTest (com.hazelcast.test.annotation.ParallelTest)5 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)4 Config (com.hazelcast.config.Config)2 MapConfig (com.hazelcast.config.MapConfig)2 SerializationConfig (com.hazelcast.config.SerializationConfig)2 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)2 SerializationServiceBuilder (com.hazelcast.internal.serialization.SerializationServiceBuilder)2 DefaultPartitioningStrategy (com.hazelcast.partition.strategy.DefaultPartitioningStrategy)2 ClientConfig (com.hazelcast.client.config.ClientConfig)1 MapStoreConfig (com.hazelcast.config.MapStoreConfig)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 VersionMismatchException (com.hazelcast.internal.cluster.impl.VersionMismatchException)1 HeapData (com.hazelcast.internal.serialization.impl.HeapData)1 SerializationUtil.isNullData (com.hazelcast.internal.serialization.impl.SerializationUtil.isNullData)1 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)1