use of org.apache.ignite.IgniteException in project ignite by apache.
the class IgfsAbstractSelfTest method testFormat.
/**
* Ensure that formatting is not propagated to the secondary file system.
*
* @throws Exception If failed.
*/
@SuppressWarnings("ConstantConditions")
public void testFormat() throws Exception {
if (mode == PROXY)
return;
final GridCacheAdapter<IgfsBlockKey, byte[]> dataCache = getDataCache(igfs);
assert dataCache != null;
int size0 = dataCache.size(new CachePeekMode[] { CachePeekMode.ALL });
assert size0 == 0 : "Initial data cache size = " + size0;
if (dual)
create(igfsSecondary, paths(DIR, SUBDIR, DIR_NEW, SUBDIR_NEW), paths(FILE, FILE_NEW));
create(igfs, paths(DIR, SUBDIR), paths(FILE));
try (IgfsOutputStream os = igfs.create(FILE, true)) {
os.write(new byte[10 * 1024 * 1024]);
}
awaitFileClose(igfs, FILE);
if (dual)
checkExist(igfsSecondary, DIR, SUBDIR, FILE, DIR_NEW, SUBDIR_NEW, FILE_NEW);
checkExist(igfs, DIR, SUBDIR, FILE);
assertEquals(10 * 1024 * 1024, igfs.info(FILE).length());
assert dataCache.size(new CachePeekMode[] { CachePeekMode.ALL }) > 0;
igfs.clear();
// Ensure format is not propagated to the secondary file system.
if (dual) {
checkExist(igfsSecondary, DIR, SUBDIR, FILE, DIR_NEW, SUBDIR_NEW, FILE_NEW);
igfsSecondary.format();
}
// Ensure entries deletion in the primary file system.
checkNotExist(igfs, DIR, SUBDIR, FILE);
if (!GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
try {
return dataCache.size(new CachePeekMode[] { CachePeekMode.ALL }) == 0;
} catch (IgniteCheckedException ice) {
throw new IgniteException(ice);
}
}
}, 10_000)) {
Iterable<? extends GridCacheEntryEx> entries = dataCache.allEntries();
for (GridCacheEntryEx e : entries) {
X.println("deleted = " + e.deleted());
X.println("detached = " + e.detached());
X.println("info = " + e.info());
X.println("k = " + e.key() + ", v = " + e.valueBytes());
}
assert false;
}
}
use of org.apache.ignite.IgniteException in project ignite by apache.
the class IgfsAbstractSelfTest method testConcurrentRenameDeleteSource.
/**
* Ensure that in case we rename the folder A and delete it at the same time, only one of these requests succeed.
*
* @throws Exception If failed.
*/
public void testConcurrentRenameDeleteSource() throws Exception {
for (int i = 0; i < REPEAT_CNT; i++) {
final CyclicBarrier barrier = new CyclicBarrier(2);
create(igfs, paths(DIR, SUBDIR, DIR_NEW), paths());
IgniteInternalFuture<Boolean> res1 = execute(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
U.awaitQuiet(barrier);
try {
igfs.rename(SUBDIR, SUBDIR_NEW);
return true;
} catch (IgniteException ignored) {
return false;
}
}
});
IgniteInternalFuture<Boolean> res2 = execute(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
U.awaitQuiet(barrier);
try {
return igfs.delete(SUBDIR, true);
} catch (IgniteException ignored) {
return false;
}
}
});
res1.get();
res2.get();
if (res1.get()) {
// Rename succeeded, so delete must fail.
assert !res2.get();
checkExist(igfs, igfsSecondary, DIR, DIR_NEW, SUBDIR_NEW);
checkNotExist(igfs, igfsSecondary, SUBDIR);
} else {
// Rename failed because delete succeeded.
assert res2.get();
// DIR_NEW should not be synchronized with he primary IGFS.
checkExist(igfs, DIR);
if (dual)
checkExist(igfsSecondary, DIR, DIR_NEW);
checkNotExist(igfs, igfsSecondary, SUBDIR, SUBDIR_NEW);
}
clear(igfs, igfsSecondary);
}
}
use of org.apache.ignite.IgniteException in project ignite by apache.
the class IgfsAbstractSelfTest method testCreateConsistencyMultithreaded.
/**
* Ensure create consistency when multiple threads writes to the same file.
*
* @throws Exception If failed.
*/
public void testCreateConsistencyMultithreaded() throws Exception {
final AtomicBoolean stop = new AtomicBoolean();
// How many times the file was re-created.
final AtomicInteger createCtr = new AtomicInteger();
final AtomicReference<Exception> err = new AtomicReference<>();
igfs.create(FILE, false).close();
int threadCnt = 50;
IgniteInternalFuture<?> fut = multithreadedAsync(new Runnable() {
@SuppressWarnings("ThrowFromFinallyBlock")
@Override
public void run() {
while (!stop.get() && err.get() == null) {
IgfsOutputStream os = null;
try {
os = igfs.create(FILE, true);
os.write(chunk);
os.close();
createCtr.incrementAndGet();
} catch (IgniteException ignored) {
// No-op.
} catch (IOException e) {
err.compareAndSet(null, e);
Throwable[] chain = X.getThrowables(e);
Throwable cause = chain[chain.length - 1];
System.out.println("Failed due to IOException exception. Cause:");
cause.printStackTrace(System.out);
} finally {
if (os != null)
try {
os.close();
} catch (IOException ioe) {
throw new IgniteException(ioe);
}
}
}
}
}, threadCnt);
long startTime = U.currentTimeMillis();
while (err.get() == null && createCtr.get() < 500 && U.currentTimeMillis() - startTime < 60 * 1000) U.sleep(100);
stop.set(true);
fut.get();
awaitFileClose(igfs.asSecondary(), FILE);
if (err.get() != null) {
X.println("Test failed: rethrowing first error: " + err.get());
throw err.get();
}
checkFileContent(igfs, FILE, chunk);
}
use of org.apache.ignite.IgniteException in project ignite by apache.
the class IgfsAbstractSelfTest method testConcurrentRenameDeleteDestination.
/**
* Ensure that in case we rename the folder A to B and delete B at the same time, FS consistency is not
* compromised.
*
* @throws Exception If failed.
*/
public void testConcurrentRenameDeleteDestination() throws Exception {
for (int i = 0; i < REPEAT_CNT; i++) {
final CyclicBarrier barrier = new CyclicBarrier(2);
create(igfs, paths(DIR, SUBDIR, DIR_NEW), paths());
IgniteInternalFuture<Boolean> res1 = execute(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
U.awaitQuiet(barrier);
try {
igfs.rename(SUBDIR, SUBDIR_NEW);
return true;
} catch (IgniteException ignored) {
return false;
}
}
});
IgniteInternalFuture<Boolean> res2 = execute(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
U.awaitQuiet(barrier);
try {
return igfs.delete(SUBDIR_NEW, true);
} catch (IgniteException ignored) {
return false;
}
}
});
assert res1.get();
if (res2.get()) {
// Delete after rename.
checkExist(igfs, igfsSecondary, DIR, DIR_NEW);
checkNotExist(igfs, igfsSecondary, SUBDIR, SUBDIR_NEW);
} else {
// Delete before rename.
checkExist(igfs, igfsSecondary, DIR, DIR_NEW, SUBDIR_NEW);
checkNotExist(igfs, igfsSecondary, SUBDIR);
}
clear(igfs, igfsSecondary);
}
}
use of org.apache.ignite.IgniteException in project ignite by apache.
the class GridSharedFsCheckpointSpiMultipleDirectoriesSelfTest method testMultipleSharedDirectories.
/**
* @throws Exception If failed.
*/
public void testMultipleSharedDirectories() throws Exception {
String data = "Test check point data.";
GridCheckpointTestState state = new GridCheckpointTestState(data);
getSpi().saveCheckpoint(CHECK_POINT_KEY_PREFIX, GridTestIoUtils.serializeJdk(state), 0, true);
info("Saved check point [key=" + CHECK_POINT_KEY_PREFIX + ", data=" + state + ']');
String curSpiPath1 = getSpi().getCurrentDirectoryPath();
File folder1 = U.resolveWorkDirectory(U.defaultWorkDirectory(), curSpiPath1, false);
assert folder1.exists() : "Checkpoint folder doesn't exist.";
boolean rewritten = getSpi().saveCheckpoint(CHECK_POINT_KEY_PREFIX, GridTestIoUtils.serializeJdk(state), 0, true);
assert rewritten : "Check point was not rewritten.";
info("Rewrite check point [key=" + CHECK_POINT_KEY_PREFIX + ", data=" + state + ']');
String curSpiPath2 = getSpi().getCurrentDirectoryPath();
File folder2 = U.resolveWorkDirectory(U.defaultWorkDirectory(), curSpiPath2, false);
assert folder2.exists() : "Check point folder doesn't exist.";
assert folder1.getAbsoluteFile().equals(folder2.getAbsoluteFile()) : "folder1 should be equal folder2.";
U.delete(folder2);
getSpi().saveCheckpoint(CHECK_POINT_KEY_PREFIX, GridTestIoUtils.serializeJdk(state), 0, true);
info("Saved check point to other folder [key=" + CHECK_POINT_KEY_PREFIX + ", data=" + state + ']');
String newCurSpiPath = getSpi().getCurrentDirectoryPath();
File changedFolder = U.resolveWorkDirectory(U.defaultWorkDirectory(), newCurSpiPath, false);
assert changedFolder.exists() : "Check point folder doesn't exist.";
assert !folder2.getAbsolutePath().equals(changedFolder.getAbsolutePath()) : "Directories should not be equal.";
U.delete(changedFolder);
boolean error = false;
// Try save after delete all directories.
try {
getSpi().saveCheckpoint(CHECK_POINT_KEY_PREFIX, GridTestIoUtils.serializeJdk(state), 0, true);
} catch (IgniteException ignored) {
error = true;
}
assert error : "Check point should not be saved.";
}
Aggregations