Search in sources :

Example 1 with SnapshotEvent

use of org.apache.ignite.events.SnapshotEvent in project ignite by apache.

the class IgniteClusterSnapshotRestoreWithIndexingTest method testClusterSnapshotRestoreOnBiggerTopology.

/**
 * @throws Exception If failed.
 */
@Test
public void testClusterSnapshotRestoreOnBiggerTopology() throws Exception {
    valBuilder = new BinaryValueBuilder(TYPE_NAME);
    int nodesCnt = 4;
    startGridsWithCache(nodesCnt - 2, CACHE_KEYS_RANGE, valueBuilder(), dfltCacheCfg);
    grid(0).snapshot().createSnapshot(SNAPSHOT_NAME).get(TIMEOUT);
    startGrid(nodesCnt - 2);
    IgniteEx ignite = startGrid(nodesCnt - 1);
    List<SnapshotEvent> evts = new CopyOnWriteArrayList<>();
    ignite.events().localListen(e -> e instanceof SnapshotEvent && evts.add((SnapshotEvent) e), EVTS_CLUSTER_SNAPSHOT);
    resetBaselineTopology();
    awaitPartitionMapExchange();
    ignite.cache(DEFAULT_CACHE_NAME).destroy();
    awaitPartitionMapExchange();
    // Remove metadata.
    int typeId = ignite.context().cacheObjects().typeId(TYPE_NAME);
    ignite.context().cacheObjects().removeType(typeId);
    forceCheckpoint();
    // Restore from an empty node.
    ignite.snapshot().restoreSnapshot(SNAPSHOT_NAME, Collections.singleton(DEFAULT_CACHE_NAME)).get(TIMEOUT);
    awaitPartitionMapExchange();
    for (Ignite g : G.allGrids()) ofNullable(indexRebuildFuture((IgniteEx) g, CU.cacheId(DEFAULT_CACHE_NAME))).orElse(new GridFinishedFuture<>()).get(TIMEOUT);
    for (Ignite g : G.allGrids()) assertCacheKeys(g.cache(DEFAULT_CACHE_NAME).withKeepBinary(), CACHE_KEYS_RANGE);
    GridTestUtils.waitForCondition(() -> evts.size() == 2, TIMEOUT);
    assertEquals(2, evts.size());
    SnapshotEvent startEvt = evts.get(0);
    assertEquals(SNAPSHOT_NAME, startEvt.snapshotName());
    assertTrue(startEvt.message().contains("caches=[" + DEFAULT_CACHE_NAME + ']'));
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) SnapshotEvent(org.apache.ignite.events.SnapshotEvent) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Test(org.junit.Test)

Aggregations

CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 Ignite (org.apache.ignite.Ignite)1 SnapshotEvent (org.apache.ignite.events.SnapshotEvent)1 IgniteEx (org.apache.ignite.internal.IgniteEx)1 Test (org.junit.Test)1