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);
}
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));
}
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);
}
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());
}
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);
}
Aggregations