use of org.apache.ignite.IgniteCheckedException in project ignite by apache.
the class IgfsAbstractSelfTest method testAppendDeleteParentNoClose.
/**
* Test delete on the file parent when it was opened for write(append) and is not closed yet.
*
* @throws Exception If failed.
*/
public void testAppendDeleteParentNoClose() throws Exception {
if (mode != PRIMARY)
return;
if (appendSupported()) {
create(igfs, paths(DIR, SUBDIR), null);
createFile(igfs, FILE, false);
IgfsOutputStream os = null;
IgniteUuid id = null;
try {
id = igfs.context().meta().fileId(FILE);
os = igfs.append(FILE, false);
// Since GG-4911 we allow deletes in this case.
boolean del = igfs.delete(SUBDIR, true);
assertTrue(del);
assertFalse(igfs.exists(FILE));
// id still exists in meta cache since
assertTrue(igfs.context().meta().exists(id));
// it is locked for writing and just moved to TRASH.
// Delete worker cannot delete it for that reason.
os.write(chunk);
os.close();
} finally {
U.closeQuiet(os);
}
assert id != null;
final IgniteUuid id0 = id;
// Delete worker should delete the file once its output stream is finally closed:
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
try {
return !igfs.context().meta().exists(id0);
} catch (IgniteCheckedException ice) {
throw new IgniteException(ice);
}
}
}, 5_000L);
}
}
use of org.apache.ignite.IgniteCheckedException 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.IgniteCheckedException in project ignite by apache.
the class IgfsAbstractSelfTest method testCreateConsistency.
/**
* Ensure consistency of data during file creation.
*
* @throws Exception If failed.
*/
public void testCreateConsistency() throws Exception {
final AtomicInteger ctr = new AtomicInteger();
final AtomicReference<Exception> err = new AtomicReference<>();
final int threadCnt = 10;
multithreaded(new Runnable() {
@Override
public void run() {
int idx = ctr.incrementAndGet();
final IgfsPath path = new IgfsPath("/file" + idx);
try {
for (int i = 0; i < REPEAT_CNT; i++) {
IgfsOutputStream os = igfs.create(path, 128, true, /*overwrite*/
null, 0, 256, null);
os.write(chunk);
os.close();
assert igfs.exists(path);
}
awaitFileClose(igfs, path);
checkFileContent(igfs, path, chunk);
} catch (IOException | IgniteCheckedException e) {
// Log the very first error.
err.compareAndSet(null, e);
}
}
}, threadCnt);
if (err.get() != null)
throw err.get();
}
use of org.apache.ignite.IgniteCheckedException in project ignite by apache.
the class TxDeadlockCauseTest method testCauseObject.
/**
* @param nodes Nodes count.
* @param keysCnt Keys count.
* @param timeout Timeout.
* @param isolation TransactionIsolation.
* @param oneOp Determines whether {@link IgniteCache#getAndPut(java.lang.Object, java.lang.Object)}
* instead of {@link IgniteCache#get(java.lang.Object)} and {@link IgniteCache#put(java.lang.Object, java.lang.Object)} operations sequence.
* @throws Exception If failed.
*/
public void testCauseObject(int nodes, final int keysCnt, final long timeout, final TransactionIsolation isolation, final boolean oneOp) throws Exception {
final Ignite ignite = grid(new Random().nextInt(nodes));
final IgniteCache<Integer, Account> cache = ignite.cache(DEFAULT_CACHE_NAME);
final List<Integer> keys = new ArrayList<>(keysCnt);
for (int i = 0; i < keysCnt; i++) {
keys.add(i);
cache.put(i, new Account(i, i * 100));
}
final List<Integer> keysReversed = new ArrayList<>(keys);
Collections.reverse(keysReversed);
final AtomicBoolean reverse = new AtomicBoolean();
final AtomicReference<Exception> ex = new AtomicReference<>();
final CyclicBarrier barrier = new CyclicBarrier(2);
IgniteInternalFuture<Long> fut = GridTestUtils.runMultiThreadedAsync(new CAX() {
@Override
public void applyx() throws IgniteCheckedException {
try (Transaction tx = ignite.transactions().txStart(TransactionConcurrency.PESSIMISTIC, isolation, timeout, keys.size())) {
List<Integer> keys0 = getAndFlip(reverse) ? keys : keysReversed;
for (int i = 0; i < keys0.size(); i++) {
Integer key = keys0.get(i);
if (oneOp)
cache.getAndPut(key, new Account(key, (key + 1) * 100));
else
cache.put(key, new Account(cache.get(key).id, (key + 1) * 100));
if (i == 0)
barrier.await(timeout >> 1, TimeUnit.MILLISECONDS);
}
tx.commit();
} catch (Exception e) {
ex.compareAndSet(null, e);
}
}
}, 2, "tx");
fut.get(timeout << 1);
Exception e = ex.get();
assertNotNull(e);
boolean detected = X.hasCause(e, TransactionDeadlockException.class);
if (!detected)
U.error(log, "Failed to detect a deadlock.", e);
else
log.info(X.cause(e, TransactionDeadlockException.class).getMessage());
assertTrue(detected);
try {
assertEquals(TransactionTimeoutException.class, e.getCause().getClass());
assertEquals(TransactionDeadlockException.class, e.getCause().getCause().getClass());
} catch (AssertionError err) {
U.error(log, "Unexpected exception structure.", e);
throw err;
}
}
use of org.apache.ignite.IgniteCheckedException in project ignite by apache.
the class IgfsModeResolverSelfTest method testModesValidation.
/**
* @throws Exception If failed.
*/
public void testModesValidation() throws Exception {
// Another mode inside PRIMARY directory:
try {
IgfsUtils.preparePathModes(DUAL_SYNC, Arrays.asList(new T2<>(new IgfsPath("/a/"), PRIMARY), new T2<>(new IgfsPath("/a/b/"), DUAL_ASYNC)), new HashSet<IgfsPath>());
fail("IgniteCheckedException expected");
} catch (IgniteCheckedException ignored) {
// No-op.
}
// PRIMARY default mode and non-primary subfolder:
for (IgfsMode m : IgfsMode.values()) {
if (m != IgfsMode.PRIMARY) {
try {
IgfsUtils.preparePathModes(PRIMARY, Arrays.asList(new T2<>(new IgfsPath("/a/"), DUAL_ASYNC)), new HashSet<IgfsPath>());
fail("IgniteCheckedException expected");
} catch (IgniteCheckedException ignored) {
// No-op.
}
}
}
// Duplicated sub-folders should be ignored:
List<T2<IgfsPath, IgfsMode>> modes = IgfsUtils.preparePathModes(DUAL_SYNC, Arrays.asList(new T2<>(new IgfsPath("/a"), PRIMARY), new T2<>(new IgfsPath("/c/d/"), PRIMARY), new T2<>(new IgfsPath("/c/d/e/f"), PRIMARY)), new HashSet<IgfsPath>());
assertNotNull(modes);
assertEquals(2, modes.size());
assertEquals(modes, Arrays.asList(new T2<>(new IgfsPath("/c/d/"), PRIMARY), new T2<>(new IgfsPath("/a"), PRIMARY)));
// Non-duplicated sub-folders should not be ignored:
modes = IgfsUtils.preparePathModes(DUAL_SYNC, Arrays.asList(new T2<>(new IgfsPath("/a/b"), DUAL_ASYNC), new T2<>(new IgfsPath("/a/b/c"), DUAL_SYNC), new T2<>(new IgfsPath("/a/b/c/d"), DUAL_ASYNC)), new HashSet<IgfsPath>());
assertNotNull(modes);
assertEquals(modes.size(), 3);
assertEquals(modes, Arrays.asList(new T2<>(new IgfsPath("/a/b/c/d"), DUAL_ASYNC), new T2<>(new IgfsPath("/a/b/c"), DUAL_SYNC), new T2<>(new IgfsPath("/a/b"), DUAL_ASYNC)));
}
Aggregations