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));
}
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);
}
Aggregations