use of com.hazelcast.partition.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.partition.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.partition.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.partition.PartitioningStrategy in project hazelcast by hazelcast.
the class SerializationIssueTest 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.partition.PartitioningStrategy in project hazelcast by hazelcast.
the class PartitioningStrategyFactoryTest method whenPartitioningStrategyClassDefined_getPartitioningStrategy_returnsNewInstance.
@Test
public void whenPartitioningStrategyClassDefined_getPartitioningStrategy_returnsNewInstance() {
PartitioningStrategyConfig cfg = new PartitioningStrategyConfig();
cfg.setPartitioningStrategyClass("com.hazelcast.partition.strategy.StringPartitioningStrategy");
PartitioningStrategy partitioningStrategy = partitioningStrategyFactory.getPartitioningStrategy(mapName, cfg);
assertEquals(StringPartitioningStrategy.class, partitioningStrategy.getClass());
}
Aggregations