Search in sources :

Example 6 with PartitioningStrategy

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);
}
Also used : StringPartitioningStrategy(com.hazelcast.partition.strategy.StringPartitioningStrategy) PartitioningStrategy(com.hazelcast.partition.PartitioningStrategy) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 7 with 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);
}
Also used : PartitioningStrategyConfig(com.hazelcast.config.PartitioningStrategyConfig) StringPartitioningStrategy(com.hazelcast.partition.strategy.StringPartitioningStrategy) PartitioningStrategy(com.hazelcast.partition.PartitioningStrategy) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 8 with PartitioningStrategy

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));
}
Also used : PartitioningStrategyConfig(com.hazelcast.config.PartitioningStrategyConfig) StringPartitioningStrategy(com.hazelcast.partition.strategy.StringPartitioningStrategy) PartitioningStrategy(com.hazelcast.partition.PartitioningStrategy) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 9 with PartitioningStrategy

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());
}
Also used : PartitioningStrategy(com.hazelcast.partition.PartitioningStrategy) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 10 with PartitioningStrategy

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());
}
Also used : PartitioningStrategyConfig(com.hazelcast.config.PartitioningStrategyConfig) StringPartitioningStrategy(com.hazelcast.partition.strategy.StringPartitioningStrategy) PartitioningStrategy(com.hazelcast.partition.PartitioningStrategy) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

PartitioningStrategy (com.hazelcast.partition.PartitioningStrategy)11 QuickTest (com.hazelcast.test.annotation.QuickTest)6 Test (org.junit.Test)6 StringPartitioningStrategy (com.hazelcast.partition.strategy.StringPartitioningStrategy)5 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)5 PartitioningStrategyConfig (com.hazelcast.config.PartitioningStrategyConfig)4 Data (com.hazelcast.internal.serialization.Data)3 SerializationConfig (com.hazelcast.config.SerializationConfig)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 SerializationService (com.hazelcast.internal.serialization.SerializationService)2 SerializationServiceBuilder (com.hazelcast.internal.serialization.SerializationServiceBuilder)2 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)2 DefaultPartitioningStrategy (com.hazelcast.partition.strategy.DefaultPartitioningStrategy)2 HazelcastClientNotActiveException (com.hazelcast.client.HazelcastClientNotActiveException)1 ClientConfig (com.hazelcast.client.config.ClientConfig)1 ClientMapProxy (com.hazelcast.client.impl.proxy.ClientMapProxy)1 AuditlogConfig (com.hazelcast.config.AuditlogConfig)1 Config (com.hazelcast.config.Config)1 ConfigAccessor.getActiveMemberNetworkConfig (com.hazelcast.config.ConfigAccessor.getActiveMemberNetworkConfig)1 InstanceTrackingConfig (com.hazelcast.config.InstanceTrackingConfig)1