Search in sources :

Example 1 with SingleNodeMessage

use of org.apache.ignite.internal.util.distributed.SingleNodeMessage in project ignite by apache.

the class CacheGroupKeyChangeTest method testCacheStartOnClientDuringRotation.

/**
 * @throws Exception If failed.
 */
@Test
public void testCacheStartOnClientDuringRotation() throws Exception {
    T2<IgniteEx, IgniteEx> nodes = startTestGrids(true);
    IgniteEx node0 = nodes.get1();
    IgniteEx node1 = nodes.get2();
    IgniteEx client = startClientGrid(getConfiguration("client"));
    node0.cluster().state(ClusterState.ACTIVE);
    String grpName = "shared";
    createEncryptedCache(client, null, cacheName(), grpName);
    awaitPartitionMapExchange();
    TestRecordingCommunicationSpi commSpi = TestRecordingCommunicationSpi.spi(node1);
    commSpi.blockMessages((node, message) -> message instanceof SingleNodeMessage);
    IgniteFuture<Void> changeKeyFut = node0.encryption().changeCacheGroupKey(Collections.singleton(grpName));
    commSpi.waitForBlocked();
    String cacheName = "userCache";
    IgniteInternalFuture<?> cacheStartFut = runAsync(() -> {
        client.getOrCreateCache(cacheConfiguration(cacheName, grpName));
    });
    commSpi.stopBlock();
    changeKeyFut.get(MAX_AWAIT_MILLIS);
    cacheStartFut.get(MAX_AWAIT_MILLIS);
    IgniteCache<Integer, String> cache = client.cache(cacheName);
    for (int i = 0; i < 200; i++) cache.put(i, String.valueOf(i));
    checkEncryptedCaches(node0, client);
    checkGroupKey(CU.cacheId(grpName), INITIAL_KEY_ID + 1, MAX_AWAIT_MILLIS);
    checkEncryptedCaches(node0, node1);
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteEx(org.apache.ignite.internal.IgniteEx) SingleNodeMessage(org.apache.ignite.internal.util.distributed.SingleNodeMessage) Test(org.junit.Test)

Example 2 with SingleNodeMessage

use of org.apache.ignite.internal.util.distributed.SingleNodeMessage in project ignite by apache.

the class CacheGroupKeyChangeTest method testCacheStartDuringRotation.

/**
 * @throws Exception If failed.
 */
@Test
public void testCacheStartDuringRotation() throws Exception {
    T2<IgniteEx, IgniteEx> grids = startTestGrids(true);
    createEncryptedCache(grids.get1(), grids.get2(), cacheName(), null);
    TestRecordingCommunicationSpi commSpi = TestRecordingCommunicationSpi.spi(grids.get2());
    commSpi.blockMessages((node, msg) -> msg instanceof SingleNodeMessage);
    IgniteFuture<Void> fut = grids.get1().encryption().changeCacheGroupKey(Collections.singleton(cacheName()));
    commSpi.waitForBlocked();
    IgniteCache<Integer, Integer> cache = grids.get1().createCache(cacheConfiguration("cache1", null));
    for (int i = 0; i < 100; i++) cache.put(i, i);
    commSpi.stopBlock();
    fut.get();
    checkGroupKey(CU.cacheId(cacheName()), INITIAL_KEY_ID + 1, MAX_AWAIT_MILLIS);
    checkGroupKey(CU.cacheId("cache1"), INITIAL_KEY_ID, MAX_AWAIT_MILLIS);
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteEx(org.apache.ignite.internal.IgniteEx) SingleNodeMessage(org.apache.ignite.internal.util.distributed.SingleNodeMessage) Test(org.junit.Test)

Example 3 with SingleNodeMessage

use of org.apache.ignite.internal.util.distributed.SingleNodeMessage in project ignite by apache.

the class CacheGroupKeyChangeTest method testClientJoinDuringRotation.

/**
 * @throws Exception If failed.
 */
@Test
public void testClientJoinDuringRotation() throws Exception {
    T2<IgniteEx, IgniteEx> nodes = startTestGrids(true);
    IgniteEx node0 = nodes.get1();
    IgniteEx node1 = nodes.get2();
    node0.cluster().state(ClusterState.ACTIVE);
    createEncryptedCache(node0, node1, cacheName(), null);
    awaitPartitionMapExchange();
    TestRecordingCommunicationSpi commSpi = TestRecordingCommunicationSpi.spi(node1);
    commSpi.blockMessages((node, message) -> message instanceof SingleNodeMessage);
    IgniteFuture<Void> changeKeyFut = node0.encryption().changeCacheGroupKey(Collections.singleton(cacheName()));
    commSpi.waitForBlocked();
    IgniteEx client = startClientGrid(getConfiguration("client"));
    assertTrue(!changeKeyFut.isDone());
    commSpi.stopBlock();
    changeKeyFut.get(MAX_AWAIT_MILLIS);
    checkEncryptedCaches(node0, client);
    checkGroupKey(CU.cacheId(cacheName()), INITIAL_KEY_ID + 1, MAX_AWAIT_MILLIS);
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteEx(org.apache.ignite.internal.IgniteEx) SingleNodeMessage(org.apache.ignite.internal.util.distributed.SingleNodeMessage) Test(org.junit.Test)

Example 4 with SingleNodeMessage

use of org.apache.ignite.internal.util.distributed.SingleNodeMessage in project ignite by apache.

the class CacheGroupKeyChangeTest method testRejectNodeJoinDuringRotation.

/**
 * @throws Exception If failed.
 */
@Test
@SuppressWarnings("ThrowableNotThrown")
public void testRejectNodeJoinDuringRotation() throws Exception {
    T2<IgniteEx, IgniteEx> grids = startTestGrids(true);
    createEncryptedCache(grids.get1(), grids.get2(), cacheName(), null);
    int grpId = CU.cacheId(cacheName());
    assertEquals(0, grids.get1().context().encryption().getActiveKey(grpId).id());
    TestRecordingCommunicationSpi commSpi = TestRecordingCommunicationSpi.spi(grids.get2());
    commSpi.blockMessages((node, msg) -> msg instanceof SingleNodeMessage);
    IgniteFuture<Void> fut = grids.get1().encryption().changeCacheGroupKey(Collections.singleton(cacheName()));
    commSpi.waitForBlocked();
    assertThrowsWithCause(() -> startGrid(3), IgniteCheckedException.class);
    commSpi.stopBlock();
    fut.get();
    checkGroupKey(grpId, INITIAL_KEY_ID + 1, MAX_AWAIT_MILLIS);
    checkEncryptedCaches(grids.get1(), grids.get2());
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteEx(org.apache.ignite.internal.IgniteEx) SingleNodeMessage(org.apache.ignite.internal.util.distributed.SingleNodeMessage) Test(org.junit.Test)

Example 5 with SingleNodeMessage

use of org.apache.ignite.internal.util.distributed.SingleNodeMessage in project ignite by apache.

the class MasterKeyChangeTest method testRejectCacheStartDuringRotation.

/**
 * @throws Exception If failed.
 */
@Test
public void testRejectCacheStartDuringRotation() 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(() -> {
        grids.get1().getOrCreateCache(new CacheConfiguration<>("newCache").setEncryptionEnabled(true));
    }, IgniteCheckedException.class);
    commSpi.stopBlock();
    fut.get();
    assertTrue(checkMasterKeyName(MASTER_KEY_NAME_2));
    createEncryptedCache(grids.get1(), grids.get2(), "cache2", null);
    checkEncryptedCaches(grids.get1(), grids.get2());
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteEx(org.apache.ignite.internal.IgniteEx) SingleNodeMessage(org.apache.ignite.internal.util.distributed.SingleNodeMessage) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Test(org.junit.Test)

Aggregations

IgniteEx (org.apache.ignite.internal.IgniteEx)13 TestRecordingCommunicationSpi (org.apache.ignite.internal.TestRecordingCommunicationSpi)13 SingleNodeMessage (org.apache.ignite.internal.util.distributed.SingleNodeMessage)13 Test (org.junit.Test)11 File (java.io.File)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)2 DistributedProcessType (org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType)2 IOException (java.io.IOException)1 OpenOption (java.nio.file.OpenOption)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 UUID (java.util.UUID)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Consumer (java.util.function.Consumer)1 Function (java.util.function.Function)1