use of org.apache.ignite.igfs.IgfsOutputStream 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.igfs.IgfsOutputStream in project ignite by apache.
the class IgfsAbstractSelfTest method testCreateRenameNoClose.
/**
* Test rename on the file when it was opened for write(create) and is not closed yet.
*
* @throws Exception If failed.
*/
public void testCreateRenameNoClose() throws Exception {
if (dual)
return;
create(igfs, paths(DIR, SUBDIR), null);
IgfsOutputStream os = null;
try {
os = igfs.create(FILE, true);
igfs.rename(FILE, FILE2);
os.close();
} finally {
U.closeQuiet(os);
}
}
use of org.apache.ignite.igfs.IgfsOutputStream in project ignite by apache.
the class IgfsAbstractSelfTest method testStop.
/**
* Ensure that IGFS is able to stop in case not closed output stream exist.
*
* @throws Exception If failed.
*/
public void testStop() throws Exception {
create(igfs, paths(DIR, SUBDIR), null);
IgfsOutputStream os = igfs.create(FILE, true);
os.write(chunk);
igfs.stop(true);
// Reset test state.
afterTestsStopped();
beforeTestsStarted();
}
use of org.apache.ignite.igfs.IgfsOutputStream in project ignite by apache.
the class IgfsAbstractSelfTest method testAppendUpdateNoClose.
/**
* Test update on the file when it was opened for write(create) and is not closed yet.
*
* @throws Exception If failed.
*/
public void testAppendUpdateNoClose() throws Exception {
if (dual)
return;
if (appendSupported()) {
Map<String, String> props = properties("owner", "group", "0555");
create(igfs, paths(DIR, SUBDIR), null);
createFile(igfs, FILE, false);
IgfsOutputStream os = null;
try {
os = igfs.append(FILE, false);
if (permissionsSupported())
igfs.update(FILE, props);
os.close();
} finally {
U.closeQuiet(os);
}
}
}
use of org.apache.ignite.igfs.IgfsOutputStream 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);
}
}
Aggregations