use of org.apache.ignite.igfs.IgfsOutputStream in project ignite by apache.
the class IgfsAbstractSelfTest method testCreateDeleteNoClose.
/**
* Test delete on the file when it was opened for write(create) and is not closed yet.
*
* @throws Exception If failed.
*/
public void testCreateDeleteNoClose() throws Exception {
if (mode != PRIMARY)
return;
create(igfs, paths(DIR, SUBDIR), null);
IgfsOutputStream os = null;
IgniteUuid id = null;
try {
os = igfs.create(FILE, false);
id = igfs.context().meta().fileId(FILE);
assert id != null;
boolean del = igfs.delete(FILE, false);
assertTrue(del);
assertFalse(igfs.exists(FILE));
// The id still exists in meta cache since
// it is locked for writing and just moved to TRASH.
// Delete worker cannot delete it for that reason:
assertTrue(igfs.context().meta().exists(id));
os.write(chunk);
os.close();
} finally {
U.closeQuiet(os);
}
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.igfs.IgfsOutputStream in project ignite by apache.
the class IgfsAbstractSelfTest method testCreateRenameParentNoClose.
/**
* Test rename on the file parent when it was opened for write(create) and is not closed yet.
*
* @throws Exception If failed.
*/
public void testCreateRenameParentNoClose() throws Exception {
if (dual)
return;
create(igfs, paths(DIR, SUBDIR), null);
IgfsOutputStream os = null;
try {
os = igfs.create(FILE, true);
igfs.rename(SUBDIR, SUBDIR2);
os.close();
} finally {
U.closeQuiet(os);
}
}
use of org.apache.ignite.igfs.IgfsOutputStream in project ignite by apache.
the class IgfsAbstractSelfTest method testCreateDeleteParentNoClose.
/**
* Test delete on the file parent when it was opened for write(create) and is not closed yet.
*
* @throws Exception If failed.
*/
public void testCreateDeleteParentNoClose() throws Exception {
if (mode != PRIMARY)
return;
create(igfs, paths(DIR, SUBDIR), null);
IgfsOutputStream os = null;
IgniteUuid id = null;
try {
os = igfs.create(FILE, false);
id = igfs.context().meta().fileId(FILE);
assert id != null;
boolean del = igfs.delete(SUBDIR, true);
assertTrue(del);
assertFalse(igfs.exists(FILE));
// The id still exists in meta cache since
// it is locked for writing and just moved to TRASH.
// Delete worker cannot delete it for that reason:
assertTrue(igfs.context().meta().exists(id));
os.write(chunk);
os.close();
} finally {
U.closeQuiet(os);
}
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.igfs.IgfsOutputStream in project ignite by apache.
the class IgfsAbstractSelfTest method testAppend.
/**
* Test regular append.
*
* @throws Exception If failed.
*/
@SuppressWarnings({ "TryFinallyCanBeTryWithResources", "EmptyTryBlock" })
public void testAppend() throws Exception {
if (appendSupported()) {
create(igfs, paths(DIR, SUBDIR), null);
assert igfs.exists(SUBDIR);
createFile(igfs, FILE, true, BLOCK_SIZE, chunk);
checkFile(igfs, igfsSecondary, FILE, chunk);
appendFile(igfs, FILE, chunk);
checkFile(igfs, igfsSecondary, FILE, chunk, chunk);
// Test create via append:
IgfsPath path2 = FILE2;
IgfsOutputStream os = null;
try {
os = igfs.append(path2, true);
writeFileChunks(os, chunk);
} finally {
U.closeQuiet(os);
awaitFileClose(igfs, path2);
}
try {
os = igfs.append(path2, false);
writeFileChunks(os, chunk);
} finally {
U.closeQuiet(os);
awaitFileClose(igfs, path2);
}
checkFile(igfs, igfsSecondary, path2, chunk, chunk);
// Negative append (create == false):
try {
try (IgfsOutputStream ignored = igfs.append(new IgfsPath("/should-not-be-created"), false)) {
// No-op.
}
fail("Exception expected");
} catch (IgniteException ignored) {
// okay
}
checkNotExist(igfs, igfsSecondary, new IgfsPath("/d1"));
// Positive mkdirs via append:
try (IgfsOutputStream ignored = igfs.append(new IgfsPath("/k/l"), true)) {
checkExist(igfs, igfsSecondary, new IgfsPath("/k/l"));
assert igfs.info(new IgfsPath("/k/l")).isFile();
}
// Negative append (file is immediate parent):
try {
try (IgfsOutputStream ignored = igfs.append(new IgfsPath("/k/l/m"), true)) {
// No-op.
}
fail("Exception expected");
} catch (IgniteException ignored) {
// okay
}
checkNotExist(igfs, igfsSecondary, new IgfsPath("/k/l/m"));
checkExist(igfs, igfsSecondary, new IgfsPath("/k/l"));
assert igfs.info(new IgfsPath("/k/l")).isFile();
// Negative append (file is in the parent chain):
try {
try (IgfsOutputStream ignored = igfs.append(new IgfsPath("/k/l/m/n/o/p"), true)) {
// No-op.
}
fail("Exception expected");
} catch (IgniteException ignored) {
// okay
}
checkNotExist(igfs, igfsSecondary, new IgfsPath("/k/l/m"));
checkExist(igfs, igfsSecondary, new IgfsPath("/k/l"));
assert igfs.info(new IgfsPath("/k/l")).isFile();
// Negative append (target is a directory):
igfs.mkdirs(new IgfsPath("/x/y"), null);
checkExist(igfs, igfsSecondary, new IgfsPath("/x/y"));
assert igfs.info(new IgfsPath("/x/y")).isDirectory();
try {
try (IgfsOutputStream ignored = igfs.append(new IgfsPath("/x/y"), true)) {
// No-op.
}
fail("Exception expected");
} catch (IgniteException ignored) {
// okay
}
// Positive append with create
try (IgfsOutputStream ignored = igfs.append(new IgfsPath("/x/y/f"), true)) {
assert igfs.info(new IgfsPath("/x/y/f")).isFile();
}
// Positive append with create & 1 mkdirs:
try (IgfsOutputStream ignored = igfs.append(new IgfsPath("/x/y/z/f"), true)) {
assert igfs.info(new IgfsPath("/x/y/z/f")).isFile();
}
// Positive append with create & 2 mkdirs:
try (IgfsOutputStream ignored = igfs.append(new IgfsPath("/x/y/z/t/f"), true)) {
assert igfs.info(new IgfsPath("/x/y/z/t/f")).isFile();
}
// Positive mkdirs create & many mkdirs:
try (IgfsOutputStream ignored = igfs.append(new IgfsPath("/x/y/z/t/t2/t3/t4/t5/f"), true)) {
assert igfs.info(new IgfsPath("/x/y/z/t/t2/t3/t4/t5/f")).isFile();
}
// Negative mkdirs via append (create == false):
try {
try (IgfsOutputStream ignored = igfs.append(new IgfsPath("/d1/d2/d3/f"), false)) {
// No-op.
}
fail("Exception expected");
} catch (IgniteException ignored) {
// okay
}
checkNotExist(igfs, igfsSecondary, new IgfsPath("/d1"));
}
}
use of org.apache.ignite.igfs.IgfsOutputStream in project ignite by apache.
the class IgfsAbstractSelfTest method testAppendRenameNoClose.
/**
* Test rename on the file when it was opened for write(append) and is not closed yet.
*
* @throws Exception If failed.
*/
public void testAppendRenameNoClose() throws Exception {
if (dual)
return;
if (appendSupported()) {
create(igfs, paths(DIR, SUBDIR), null);
createFile(igfs, FILE, false);
IgfsOutputStream os = null;
try {
os = igfs.append(FILE, false);
igfs.rename(FILE, FILE2);
os.close();
} finally {
U.closeQuiet(os);
}
}
}
Aggregations