use of org.apache.ignite.internal.util.distributed.SingleNodeMessage 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);
}
use of org.apache.ignite.internal.util.distributed.SingleNodeMessage in project ignite by apache.
the class MasterKeyChangeTest method testRejectNodeJoinDuringRotation.
/**
* @throws Exception If failed.
*/
@Test
public void testRejectNodeJoinDuringRotation() throws Exception {
T2<IgniteEx, IgniteEx> grids = startTestGrids(true);
createEncryptedCache(grids.get1(), grids.get2(), cacheName(), null);
assertTrue(checkMasterKeyName(DEFAULT_MASTER_KEY_NAME));
TestRecordingCommunicationSpi commSpi = TestRecordingCommunicationSpi.spi(grids.get2());
commSpi.blockMessages((node, msg) -> msg instanceof SingleNodeMessage);
IgniteFuture<Void> fut = grids.get1().encryption().changeMasterKey(MASTER_KEY_NAME_2);
commSpi.waitForBlocked();
assertThrowsWithCause(() -> startGrid(3), IgniteCheckedException.class);
commSpi.stopBlock();
fut.get();
assertTrue(checkMasterKeyName(MASTER_KEY_NAME_2));
checkEncryptedCaches(grids.get1(), grids.get2());
}
use of org.apache.ignite.internal.util.distributed.SingleNodeMessage in project ignite by apache.
the class MasterKeyChangeTest method checkNodeFailsDuringRotation.
/**
* @param stopCrd {@code True} if stop coordinator.
* @param prepare {@code True} if stop on the prepare phase. {@code False} if stop on the perform phase.
*/
private void checkNodeFailsDuringRotation(boolean stopCrd, boolean prepare) throws Exception {
T2<IgniteEx, IgniteEx> grids = startTestGrids(true);
createEncryptedCache(grids.get1(), grids.get2(), cacheName(), null);
assertTrue(checkMasterKeyName(DEFAULT_MASTER_KEY_NAME));
TestRecordingCommunicationSpi spi = TestRecordingCommunicationSpi.spi(grids.get2());
AtomicBoolean preparePhase = new AtomicBoolean(true);
spi.blockMessages((node, msg) -> {
if (msg instanceof SingleNodeMessage) {
boolean isPrepare = preparePhase.compareAndSet(true, false);
return prepare || !isPrepare;
}
return false;
});
IgniteEx aliveNode = stopCrd ? grids.get2() : grids.get1();
IgniteFuture<Void> fut = aliveNode.encryption().changeMasterKey(MASTER_KEY_NAME_2);
spi.waitForBlocked();
runAsync(() -> {
if (stopCrd)
stopGrid(GRID_0, true);
else
stopGrid(GRID_1, true);
});
fut.get();
assertEquals(MASTER_KEY_NAME_2, aliveNode.encryption().getMasterKeyName());
}
Aggregations