use of org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory in project ignite by apache.
the class IgniteDataIntegrityTests method setUp.
/**
*/
@Before
public void setUp() throws Exception {
File file = File.createTempFile("integrity", "dat");
file.deleteOnExit();
expBuf = new ByteBufferExpander(1024, ByteOrder.BIG_ENDIAN);
FileIOFactory factory = new RandomAccessFileIOFactory();
fileInput = new SimpleFileInput(factory.create(file), expBuf);
ByteBuffer buf = ByteBuffer.allocate(1024);
ThreadLocalRandom curr = ThreadLocalRandom.current();
for (int i = 0; i < 1024; i += 16) {
buf.putInt(curr.nextInt());
buf.putInt(curr.nextInt());
buf.putInt(curr.nextInt());
buf.position(i);
buf.putInt(FastCrc.calcCrc(buf, 12));
}
buf.rewind();
fileInput.io().writeFully(buf);
fileInput.io().force();
}
use of org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory in project ignite by apache.
the class IgniteWalConverterArgumentsTest method testCorruptedPagesFile.
/**
* Checks that the file generated by the diagnostics is correct for the "pages" argument.
*
* @throws IOException If failed.
*/
@Test
public void testCorruptedPagesFile() throws IOException {
File tmpDir = new File(System.getProperty("java.io.tmpdir"), getName());
try {
int grpId = 10;
long[] pageIds = { 20, 40 };
File f = corruptedPagesFile(tmpDir.toPath(), new RandomAccessFileIOFactory(), grpId, pageIds);
assertTrue(f.exists());
assertTrue(f.isFile());
assertTrue(f.length() > 0);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
IgniteWalConverterArguments args = parse(ps, "walDir=" + tmpDir.getAbsolutePath(), "pages=" + f.getAbsolutePath());
assertNotNull(args.getPages());
assertEqualsCollections(LongStream.of(pageIds).mapToObj(pageId -> new T2<>(grpId, pageId)).collect(toList()), args.getPages());
} finally {
if (tmpDir.exists())
assertTrue(U.delete(tmpDir));
}
}
use of org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory in project ignite by apache.
the class IgniteClusterSnapshotRestoreMetricsTest method testRestoreSnapshotError.
/**
* @throws Exception If fails.
*/
@Test
public void testRestoreSnapshotError() throws Exception {
dfltCacheCfg.setCacheMode(CacheMode.REPLICATED);
IgniteEx ignite = startGridsWithSnapshot(2, CACHE_KEYS_RANGE);
String failingFilePath = Paths.get(FilePageStoreManager.cacheDirName(dfltCacheCfg), PART_FILE_PREFIX + (dfltCacheCfg.getAffinity().partitions() / 2) + FILE_SUFFIX).toString();
FileIOFactory ioFactory = new RandomAccessFileIOFactory();
String testErrMsg = "Test exception";
ignite.context().cache().context().snapshotMgr().ioFactory((file, modes) -> {
FileIO delegate = ioFactory.create(file, modes);
if (file.getPath().endsWith(failingFilePath))
throw new RuntimeException(testErrMsg);
return delegate;
});
checkMetricsDefaults();
ignite.snapshot().restoreSnapshot(SNAPSHOT_NAME, null);
for (Ignite grid : G.allGrids()) {
DynamicMBean mReg = metricRegistry(grid.name(), null, SNAPSHOT_RESTORE_METRICS);
String nodeNameMsg = "node=" + grid.name();
assertTrue(nodeNameMsg, GridTestUtils.waitForCondition(() -> getNumMetric("endTime", mReg) > 0, TIMEOUT));
long startTime = getNumMetric("startTime", mReg);
long endTime = getNumMetric("endTime", mReg);
assertEquals(nodeNameMsg, SNAPSHOT_NAME, mReg.getAttribute("snapshotName"));
assertFalse(nodeNameMsg, ((String) mReg.getAttribute("requestId")).isEmpty());
assertTrue(nodeNameMsg, startTime > 0);
assertTrue(nodeNameMsg, endTime >= startTime);
assertTrue(nodeNameMsg, ((String) mReg.getAttribute("error")).contains(testErrMsg));
}
}
Aggregations