use of com.hazelcast.spi.partition.IPartitionLostEvent in project hazelcast by hazelcast.
the class PartitionLostListenerTest method test_internalPartitionLostEvent_deserialization.
@Test
public void test_internalPartitionLostEvent_deserialization() throws IOException {
IPartitionLostEvent internalEvent = new IPartitionLostEvent();
ObjectDataInput input = mock(ObjectDataInput.class);
when(input.readInt()).thenReturn(1, 2);
internalEvent.readData(input);
assertEquals(1, internalEvent.getPartitionId());
assertEquals(2, internalEvent.getLostReplicaIndex());
}
use of com.hazelcast.spi.partition.IPartitionLostEvent in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method schedule_whenPartitionLost.
@Test()
public void schedule_whenPartitionLost() throws ExecutionException, InterruptedException {
int delay = 1;
HazelcastInstance[] instances = createClusterWithCount(2);
IScheduledExecutorService executorService = getScheduledExecutor(instances, "s");
final IScheduledFuture future = executorService.schedule(new PlainCallableTask(), delay, SECONDS);
ScheduledTaskHandler handler = future.getHandler();
int partitionOwner = handler.getPartitionId();
IPartitionLostEvent internalEvent = new IPartitionLostEvent(partitionOwner, 1, null);
((InternalPartitionServiceImpl) getNodeEngineImpl(instances[0]).getPartitionService()).onPartitionLost(internalEvent);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
try {
future.get();
} catch (IllegalStateException ex) {
assertEquals("Partition holding this Scheduled task was lost along with all backups.", ex.getMessage());
}
}
});
}
use of com.hazelcast.spi.partition.IPartitionLostEvent in project hazelcast by hazelcast.
the class ClientMapPartitionLostListenerTest method test_mapPartitionLostListener_invoked_fromOtherNode.
@Test
public void test_mapPartitionLostListener_invoked_fromOtherNode() {
final String mapName = randomMapName();
final Config config = new Config();
config.getMapConfig(mapName).setBackupCount(0);
final HazelcastInstance instance1 = hazelcastFactory.newHazelcastInstance(config);
final HazelcastInstance instance2 = hazelcastFactory.newHazelcastInstance(config);
final ClientConfig clientConfig = new ClientConfig();
clientConfig.getNetworkConfig().setSmartRouting(false);
final HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
final HazelcastClientInstanceImpl clientInstanceImpl = getHazelcastClientInstanceImpl(client);
final Address clientOwnerAddress = clientInstanceImpl.getClientClusterService().getOwnerConnectionAddress();
final HazelcastInstance other = getAddress(instance1).equals(clientOwnerAddress) ? instance2 : instance1;
final TestEventCollectingMapPartitionLostListener listener = new TestEventCollectingMapPartitionLostListener(0);
client.getMap(mapName).addPartitionLostListener(listener);
assertRegistrationEventually(instance1, mapName, true);
assertRegistrationEventually(instance2, mapName, true);
assertProxyExistsEventually(instance1, mapName);
assertProxyExistsEventually(instance2, mapName);
final MapService mapService = getNode(other).getNodeEngine().getService(SERVICE_NAME);
final int partitionId = 5;
mapService.onPartitionLost(new IPartitionLostEvent(partitionId, 0, null));
assertMapPartitionLostEventEventually(listener, partitionId);
}
use of com.hazelcast.spi.partition.IPartitionLostEvent in project hazelcast by hazelcast.
the class ClientMapPartitionLostListenerTest method test_mapPartitionLostListener_invoked.
@Test
public void test_mapPartitionLostListener_invoked() {
final String mapName = randomMapName();
final Config config = new Config();
config.getMapConfig(mapName).setBackupCount(0);
final HazelcastInstance instance = hazelcastFactory.newHazelcastInstance(config);
final HazelcastInstance client = hazelcastFactory.newHazelcastClient();
warmUpPartitions(instance, client);
final TestEventCollectingMapPartitionLostListener listener = new TestEventCollectingMapPartitionLostListener(0);
client.getMap(mapName).addPartitionLostListener(listener);
final MapService mapService = getNode(instance).getNodeEngine().getService(MapService.SERVICE_NAME);
final int partitionId = 5;
mapService.onPartitionLost(new IPartitionLostEvent(partitionId, 0, null));
assertMapPartitionLostEventEventually(listener, partitionId);
}
use of com.hazelcast.spi.partition.IPartitionLostEvent in project hazelcast by hazelcast.
the class ClientCachePartitionLostListenerTest method test_cachePartitionLostListener_invoked.
@Test
public void test_cachePartitionLostListener_invoked() {
final String cacheName = randomName();
HazelcastInstance instance = hazelcastFactory.newHazelcastInstance();
final HazelcastInstance client = hazelcastFactory.newHazelcastClient();
final HazelcastServerCachingProvider cachingProvider = createCachingProvider(instance);
final CacheManager cacheManager = cachingProvider.getCacheManager();
final CacheConfig<Integer, String> config = new CacheConfig<Integer, String>();
config.setBackupCount(0);
cacheManager.createCache(cacheName, config);
final CachingProvider clientCachingProvider = HazelcastClientCachingProvider.createCachingProvider(client);
final CacheManager clientCacheManager = clientCachingProvider.getCacheManager();
final Cache<Integer, String> cache = clientCacheManager.getCache(cacheName);
final ICache iCache = cache.unwrap(ICache.class);
final EventCollectingCachePartitionLostListener listener = new EventCollectingCachePartitionLostListener();
iCache.addPartitionLostListener(listener);
final CacheService cacheService = getNode(instance).getNodeEngine().getService(CacheService.SERVICE_NAME);
final int partitionId = 5;
cacheService.onPartitionLost(new IPartitionLostEvent(partitionId, 0, null));
assertCachePartitionLostEventEventually(listener, partitionId);
}
Aggregations