use of com.hazelcast.internal.partition.PartitionLostEventImpl in project hazelcast by hazelcast.
the class ScheduledExecutorServiceBasicTest method schedule_testPartitionLostEvent.
public void schedule_testPartitionLostEvent(int replicaLostCount) {
int delay = 1;
HazelcastInstance[] instances = createClusterWithCount(1);
IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
final IScheduledFuture future = executorService.schedule(new PlainCallableTask(), delay, SECONDS);
// Used to make sure both futures (on the same handler) get the event.
// Catching possible equal/hashcode issues in the Map
final IScheduledFuture futureCopyInstance = (IScheduledFuture) ((List) executorService.getAllScheduledFutures().values().toArray()[0]).get(0);
ScheduledTaskHandler handler = future.getHandler();
int partitionOwner = handler.getPartitionId();
IPartitionLostEvent internalEvent = new PartitionLostEventImpl(partitionOwner, replicaLostCount, null);
((InternalPartitionServiceImpl) getNodeEngineImpl(instances[0]).getPartitionService()).onPartitionLost(internalEvent);
assertTrueEventually(() -> {
try {
future.get();
fail();
} catch (IllegalStateException ex) {
try {
futureCopyInstance.get();
fail();
} catch (IllegalStateException ex2) {
assertEquals(format("Partition %d, holding this scheduled task was lost along with all backups.", future.getHandler().getPartitionId()), ex.getMessage());
assertEquals(format("Partition %d, holding this scheduled task was lost along with all backups.", future.getHandler().getPartitionId()), ex2.getMessage());
}
}
});
}
use of com.hazelcast.internal.partition.PartitionLostEventImpl in project hazelcast by hazelcast.
the class PartitionLostListenerTest method test_allPartitionLostListenersInvoked.
@Test
public void test_allPartitionLostListenersInvoked() {
HazelcastInstance instance1 = instances[0];
HazelcastInstance instance2 = instances[1];
EventCollectingPartitionLostListener listener1 = new EventCollectingPartitionLostListener();
EventCollectingPartitionLostListener listener2 = new EventCollectingPartitionLostListener();
instance1.getPartitionService().addPartitionLostListener(listener1);
instance2.getPartitionService().addPartitionLostListener(listener2);
IPartitionLostEvent internalEvent = new PartitionLostEventImpl(1, 0, null);
NodeEngineImpl nodeEngine = getNode(instance1).getNodeEngine();
InternalPartitionServiceImpl partitionService = (InternalPartitionServiceImpl) nodeEngine.getPartitionService();
partitionService.onPartitionLost(internalEvent);
assertEventEventually(listener1, internalEvent);
assertEventEventually(listener2, internalEvent);
}
use of com.hazelcast.internal.partition.PartitionLostEventImpl in project hazelcast by hazelcast.
the class PartitionLostListenerTest method test_internalPartitionLostEvent_deserialization.
@Test
public void test_internalPartitionLostEvent_deserialization() throws IOException {
PartitionLostEventImpl internalEvent = new PartitionLostEventImpl();
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.internal.partition.PartitionLostEventImpl 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 = createServerCachingProvider(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 = createClientCachingProvider(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 PartitionLostEventImpl(partitionId, 0, null));
assertCachePartitionLostEventEventually(listener, partitionId);
}
use of com.hazelcast.internal.partition.PartitionLostEventImpl in project hazelcast by hazelcast.
the class ClientMapPartitionLostListenerTest method test_mapPartitionLostListener_invoked_fromOtherNode.
@Test
public void test_mapPartitionLostListener_invoked_fromOtherNode() {
String mapName = randomMapName();
Config config = getConfig();
config.getMapConfig(mapName).setBackupCount(0);
HazelcastInstance instance1 = hazelcastFactory.newHazelcastInstance(config);
ClientConfig clientConfig = getClientConfig();
clientConfig.getNetworkConfig().setSmartRouting(false);
HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
HazelcastInstance instance2 = hazelcastFactory.newHazelcastInstance(config);
TestEventCollectingMapPartitionLostListener listener = new TestEventCollectingMapPartitionLostListener(0);
client.getMap(mapName).addPartitionLostListener(listener);
assertRegistrationEventually(instance1, mapName, true);
assertRegistrationEventually(instance2, mapName, true);
assertProxyExistsEventually(instance1, mapName);
assertProxyExistsEventually(instance2, mapName);
MapService mapService = getNode(instance2).getNodeEngine().getService(SERVICE_NAME);
int partitionId = 5;
mapService.onPartitionLost(new PartitionLostEventImpl(partitionId, 0, null));
assertMapPartitionLostEventEventually(listener, partitionId);
}
Aggregations