use of org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType in project ignite by apache.
the class CacheGroupKeyChangeTest method checkNodeFailsDuringRotation.
/**
* @param stopCrd {@code True} to stop coordinator.
* @param prepare {@code True} to stop on the prepare phase. {@code False} to stop on the perform phase.
* @param discoBlock {@code True} to block discovery, {@code False} to block communication SPI.
*/
private void checkNodeFailsDuringRotation(boolean stopCrd, boolean prepare, boolean discoBlock) throws Exception {
cleanPersistenceDir();
DistributedProcessType type = prepare ? DistributedProcessType.CACHE_GROUP_KEY_CHANGE_PREPARE : DistributedProcessType.CACHE_GROUP_KEY_CHANGE_FINISH;
InitMessageDiscoveryHook locHook = new InitMessageDiscoveryHook(type);
if (discoBlock && stopCrd)
discoveryHook = locHook;
IgniteEx grid0 = startGrid(GRID_0);
if (discoBlock && !stopCrd)
discoveryHook = locHook;
IgniteEx grid1 = startGrid(GRID_1);
grid0.cluster().state(ClusterState.ACTIVE);
createEncryptedCache(grid0, grid1, cacheName(), null);
int grpId = CU.cacheId(cacheName());
checkGroupKey(grpId, INITIAL_KEY_ID, MAX_AWAIT_MILLIS);
TestRecordingCommunicationSpi spi = TestRecordingCommunicationSpi.spi(grid1);
if (!discoBlock) {
AtomicBoolean preparePhase = new AtomicBoolean(true);
spi.blockMessages((node, msg) -> {
if (msg instanceof SingleNodeMessage) {
boolean isPrepare = preparePhase.compareAndSet(true, false);
return prepare || !isPrepare;
}
return false;
});
}
String alive = stopCrd ? GRID_1 : GRID_0;
String stopped = stopCrd ? GRID_0 : GRID_1;
IgniteFuture<Void> changeFut = grid(alive).encryption().changeCacheGroupKey(Collections.singleton(cacheName()));
IgniteInternalFuture<?> stopFut = new GridFinishedFuture<>();
if (discoBlock) {
locHook.waitForBlocked(MAX_AWAIT_MILLIS);
stopGrid(stopped, true);
locHook.stopBlock();
} else {
spi.waitForBlocked();
stopFut = runAsync(() -> stopGrid(stopped, true));
}
changeFut.get(MAX_AWAIT_MILLIS);
stopFut.get(MAX_AWAIT_MILLIS);
checkGroupKey(grpId, INITIAL_KEY_ID + 1, MAX_AWAIT_MILLIS);
IgniteEx stoppedNode = startGrid(stopped);
stoppedNode.resetLostPartitions(Collections.singleton(ENCRYPTED_CACHE));
awaitPartitionMapExchange();
checkGroupKey(grpId, INITIAL_KEY_ID + 1, MAX_AWAIT_MILLIS);
stoppedNode.encryption().changeCacheGroupKey(Collections.singleton(cacheName())).get(MAX_AWAIT_MILLIS);
checkGroupKey(grpId, INITIAL_KEY_ID + 2, MAX_AWAIT_MILLIS);
}
Aggregations