Search in sources :

Example 1 with GridTestUtils.assertThrowsAnyCause

use of org.apache.ignite.testframework.GridTestUtils.assertThrowsAnyCause in project ignite by apache.

the class IgniteClusterSnapshotRestoreSelfTest method testIncompatibleMetasUpdate.

/**
 * @throws Exception If failed.
 */
@Test
public void testIncompatibleMetasUpdate() throws Exception {
    valBuilder = new BinaryValueBuilder(TYPE_NAME);
    IgniteEx ignite = startGridsWithSnapshot(2, CACHE_KEYS_RANGE);
    int typeId = ignite.context().cacheObjects().typeId(TYPE_NAME);
    ignite.context().cacheObjects().removeType(typeId);
    BinaryObject[] objs = new BinaryObject[CACHE_KEYS_RANGE];
    IgniteCache<Integer, Object> cache1 = createCacheWithBinaryType(ignite, "cache1", n -> {
        BinaryObjectBuilder builder = ignite.binary().builder(TYPE_NAME);
        builder.setField("id", n);
        objs[n] = builder.build();
        return objs[n];
    });
    ignite.snapshot().restoreSnapshot(SNAPSHOT_NAME, Collections.singleton(DEFAULT_CACHE_NAME)).get(TIMEOUT);
    // Ensure that existing type has been updated.
    BinaryType type = ignite.context().cacheObjects().metadata(typeId);
    assertTrue(type.fieldNames().contains("name"));
    for (int i = 0; i < CACHE_KEYS_RANGE; i++) assertEquals(objs[i], cache1.get(i));
    cache1.destroy();
    grid(0).cache(DEFAULT_CACHE_NAME).destroy();
    ignite.context().cacheObjects().removeType(typeId);
    // Create cache with incompatible binary type.
    cache1 = createCacheWithBinaryType(ignite, "cache1", n -> {
        BinaryObjectBuilder builder = ignite.binary().builder(TYPE_NAME);
        builder.setField("id", UUID.randomUUID());
        objs[n] = builder.build();
        return objs[n];
    });
    IgniteFuture<Void> fut0 = ignite.snapshot().restoreSnapshot(SNAPSHOT_NAME, Collections.singleton(DEFAULT_CACHE_NAME));
    GridTestUtils.assertThrowsAnyCause(log, () -> fut0.get(TIMEOUT), BinaryObjectException.class, null);
    ensureCacheAbsent(dfltCacheCfg);
    for (int i = 0; i < CACHE_KEYS_RANGE; i++) assertEquals(objs[i], cache1.get(i));
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) BinaryObject(org.apache.ignite.binary.BinaryObject) Arrays(java.util.Arrays) IgniteEx(org.apache.ignite.internal.IgniteEx) PART_FILE_PREFIX(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.PART_FILE_PREFIX) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) GridTestUtils.runAsync(org.apache.ignite.testframework.GridTestUtils.runAsync) FileIO(org.apache.ignite.internal.processors.cache.persistence.file.FileIO) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DistributedProcessType(org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType) Path(java.nio.file.Path) TMP_CACHE_DIR_PREFIX(org.apache.ignite.internal.processors.cache.persistence.snapshot.SnapshotRestoreProcess.TMP_CACHE_DIR_PREFIX) GridTestUtils.assertThrowsAnyCause(org.apache.ignite.testframework.GridTestUtils.assertThrowsAnyCause) EVT_CLUSTER_SNAPSHOT_RESTORE_FINISHED(org.apache.ignite.events.EventType.EVT_CLUSTER_SNAPSHOT_RESTORE_FINISHED) IgniteFuture(org.apache.ignite.lang.IgniteFuture) RandomAccessFileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory) EVT_CLUSTER_SNAPSHOT_RESTORE_FAILED(org.apache.ignite.events.EventType.EVT_CLUSTER_SNAPSHOT_RESTORE_FAILED) SingleNodeMessage(org.apache.ignite.internal.util.distributed.SingleNodeMessage) EVT_CLUSTER_SNAPSHOT_RESTORE_STARTED(org.apache.ignite.events.EventType.EVT_CLUSTER_SNAPSHOT_RESTORE_STARTED) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) FilePageStoreManager(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager) UUID(java.util.UUID) IgniteCache(org.apache.ignite.IgniteCache) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) CountDownLatch(java.util.concurrent.CountDownLatch) Nullable(org.jetbrains.annotations.Nullable) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) FilePageStoreManager.getPartitionFileName(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.getPartitionFileName) CACHE_DIR_PREFIX(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.CACHE_DIR_PREFIX) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) ClusterState(org.apache.ignite.cluster.ClusterState) U(org.apache.ignite.internal.util.typedef.internal.U) CacheExistsException(org.apache.ignite.cache.CacheExistsException) Function(java.util.function.Function) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder) FileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory) IntSupplier(java.util.function.IntSupplier) RESTORE_CACHE_GROUP_SNAPSHOT_PREPARE(org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.RESTORE_CACHE_GROUP_SNAPSHOT_PREPARE) RESTORE_CACHE_GROUP_SNAPSHOT_PRELOAD(org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.RESTORE_CACHE_GROUP_SNAPSHOT_PRELOAD) G(org.apache.ignite.internal.util.typedef.G) OpenOption(java.nio.file.OpenOption) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) IOException(java.io.IOException) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) FILE_SUFFIX(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.FILE_SUFFIX) BinaryType(org.apache.ignite.binary.BinaryType) RESTORE_CACHE_GROUP_SNAPSHOT_START(org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.RESTORE_CACHE_GROUP_SNAPSHOT_START) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException) Paths(java.nio.file.Paths) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Collections(java.util.Collections) IgniteSnapshot(org.apache.ignite.IgniteSnapshot) CacheMode(org.apache.ignite.cache.CacheMode) DynamicCacheChangeBatch(org.apache.ignite.internal.processors.cache.DynamicCacheChangeBatch) BinaryType(org.apache.ignite.binary.BinaryType) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BinaryObject(org.apache.ignite.binary.BinaryObject) IgniteEx(org.apache.ignite.internal.IgniteEx) BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder) Test(org.junit.Test)

Example 2 with GridTestUtils.assertThrowsAnyCause

use of org.apache.ignite.testframework.GridTestUtils.assertThrowsAnyCause in project ignite by apache.

the class IgniteClusterSnapshotRestoreSelfTest method testNodeFailDuringFilesCopy.

/**
 * @throws Exception If failed.
 */
@Test
public void testNodeFailDuringFilesCopy() throws Exception {
    dfltCacheCfg.setCacheMode(CacheMode.REPLICATED).setAffinity(new RendezvousAffinityFunction());
    startGridsWithSnapshot(3, CACHE_KEYS_RANGE);
    TestRecordingCommunicationSpi spi = TestRecordingCommunicationSpi.spi(grid(2));
    CountDownLatch stopLatch = new CountDownLatch(1);
    spi.blockMessages((node, msg) -> msg instanceof SingleNodeMessage && ((SingleNodeMessage<?>) msg).type() == RESTORE_CACHE_GROUP_SNAPSHOT_PRELOAD.ordinal());
    String failingFilePath = Paths.get(CACHE_DIR_PREFIX + DEFAULT_CACHE_NAME, PART_FILE_PREFIX + (dfltCacheCfg.getAffinity().partitions() / 2) + FILE_SUFFIX).toString();
    grid(2).context().cache().context().snapshotMgr().ioFactory(new CustomFileIOFactory(new RandomAccessFileIOFactory(), file -> {
        if (file.getPath().endsWith(failingFilePath)) {
            stopLatch.countDown();
            throw new RuntimeException("Test exception");
        }
    }));
    File node2dbDir = ((FilePageStoreManager) grid(2).context().cache().context().pageStore()).cacheWorkDir(dfltCacheCfg).getParentFile();
    IgniteInternalFuture<Object> stopFut = runAsync(() -> {
        U.await(stopLatch, TIMEOUT, TimeUnit.MILLISECONDS);
        stopGrid(2, true);
        return null;
    });
    IgniteFuture<Void> fut = grid(0).snapshot().restoreSnapshot(SNAPSHOT_NAME, Collections.singleton(DEFAULT_CACHE_NAME));
    stopFut.get(TIMEOUT);
    GridTestUtils.assertThrowsAnyCause(log, () -> fut.get(TIMEOUT), ClusterTopologyCheckedException.class, null);
    File[] files = node2dbDir.listFiles(file -> file.getName().startsWith(TMP_CACHE_DIR_PREFIX));
    assertEquals("A temp directory with potentially corrupted files must exist.", 1, files.length);
    ensureCacheAbsent(dfltCacheCfg);
    dfltCacheCfg = null;
    startGrid(2);
    files = node2dbDir.listFiles(file -> file.getName().startsWith(TMP_CACHE_DIR_PREFIX));
    assertEquals("A temp directory should be removed at node startup", 0, files.length);
    waitForEvents(EVT_CLUSTER_SNAPSHOT_RESTORE_STARTED, EVT_CLUSTER_SNAPSHOT_RESTORE_FAILED);
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) BinaryObject(org.apache.ignite.binary.BinaryObject) Arrays(java.util.Arrays) IgniteEx(org.apache.ignite.internal.IgniteEx) PART_FILE_PREFIX(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.PART_FILE_PREFIX) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) GridTestUtils.runAsync(org.apache.ignite.testframework.GridTestUtils.runAsync) FileIO(org.apache.ignite.internal.processors.cache.persistence.file.FileIO) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DistributedProcessType(org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType) Path(java.nio.file.Path) TMP_CACHE_DIR_PREFIX(org.apache.ignite.internal.processors.cache.persistence.snapshot.SnapshotRestoreProcess.TMP_CACHE_DIR_PREFIX) GridTestUtils.assertThrowsAnyCause(org.apache.ignite.testframework.GridTestUtils.assertThrowsAnyCause) EVT_CLUSTER_SNAPSHOT_RESTORE_FINISHED(org.apache.ignite.events.EventType.EVT_CLUSTER_SNAPSHOT_RESTORE_FINISHED) IgniteFuture(org.apache.ignite.lang.IgniteFuture) RandomAccessFileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory) EVT_CLUSTER_SNAPSHOT_RESTORE_FAILED(org.apache.ignite.events.EventType.EVT_CLUSTER_SNAPSHOT_RESTORE_FAILED) SingleNodeMessage(org.apache.ignite.internal.util.distributed.SingleNodeMessage) EVT_CLUSTER_SNAPSHOT_RESTORE_STARTED(org.apache.ignite.events.EventType.EVT_CLUSTER_SNAPSHOT_RESTORE_STARTED) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) FilePageStoreManager(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager) UUID(java.util.UUID) IgniteCache(org.apache.ignite.IgniteCache) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) CountDownLatch(java.util.concurrent.CountDownLatch) Nullable(org.jetbrains.annotations.Nullable) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) FilePageStoreManager.getPartitionFileName(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.getPartitionFileName) CACHE_DIR_PREFIX(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.CACHE_DIR_PREFIX) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) ClusterState(org.apache.ignite.cluster.ClusterState) U(org.apache.ignite.internal.util.typedef.internal.U) CacheExistsException(org.apache.ignite.cache.CacheExistsException) Function(java.util.function.Function) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder) FileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory) IntSupplier(java.util.function.IntSupplier) RESTORE_CACHE_GROUP_SNAPSHOT_PREPARE(org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.RESTORE_CACHE_GROUP_SNAPSHOT_PREPARE) RESTORE_CACHE_GROUP_SNAPSHOT_PRELOAD(org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.RESTORE_CACHE_GROUP_SNAPSHOT_PRELOAD) G(org.apache.ignite.internal.util.typedef.G) OpenOption(java.nio.file.OpenOption) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) IOException(java.io.IOException) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) FILE_SUFFIX(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.FILE_SUFFIX) BinaryType(org.apache.ignite.binary.BinaryType) RESTORE_CACHE_GROUP_SNAPSHOT_START(org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.RESTORE_CACHE_GROUP_SNAPSHOT_START) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException) Paths(java.nio.file.Paths) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Collections(java.util.Collections) IgniteSnapshot(org.apache.ignite.IgniteSnapshot) CacheMode(org.apache.ignite.cache.CacheMode) DynamicCacheChangeBatch(org.apache.ignite.internal.processors.cache.DynamicCacheChangeBatch) CountDownLatch(java.util.concurrent.CountDownLatch) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) BinaryObject(org.apache.ignite.binary.BinaryObject) File(java.io.File) SingleNodeMessage(org.apache.ignite.internal.util.distributed.SingleNodeMessage) RandomAccessFileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory) Test(org.junit.Test)

Aggregations

File (java.io.File)2 IOException (java.io.IOException)2 OpenOption (java.nio.file.OpenOption)2 Path (java.nio.file.Path)2 Paths (java.nio.file.Paths)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 UUID (java.util.UUID)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 TimeUnit (java.util.concurrent.TimeUnit)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Consumer (java.util.function.Consumer)2 Function (java.util.function.Function)2 IntSupplier (java.util.function.IntSupplier)2 Ignite (org.apache.ignite.Ignite)2 IgniteCache (org.apache.ignite.IgniteCache)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 IgniteException (org.apache.ignite.IgniteException)2 IgniteSnapshot (org.apache.ignite.IgniteSnapshot)2 BinaryObject (org.apache.ignite.binary.BinaryObject)2