use of org.apache.ignite.igfs.IgfsOutputStream in project ignite by apache.
the class IgfsAbstractSelfTest method testCreate.
/**
* Test regular create.
*
* @throws Exception If failed.
*/
@SuppressWarnings({ "ConstantConditions", "EmptyTryBlock", "UnusedDeclaration" })
public void testCreate() throws Exception {
create(igfs, paths(DIR, SUBDIR), null);
createFile(igfs, FILE, true, chunk);
checkFile(igfs, igfsSecondary, FILE, chunk);
try (IgfsOutputStream os = igfs.create(new IgfsPath("/r"), false)) {
checkExist(igfs, igfsSecondary, new IgfsPath("/r"));
assert igfs.info(new IgfsPath("/r")).isFile();
}
try (IgfsOutputStream os = igfs.create(new IgfsPath("/k/l"), false)) {
checkExist(igfs, igfsSecondary, new IgfsPath("/k/l"));
assert igfs.info(new IgfsPath("/k/l")).isFile();
}
try {
try (IgfsOutputStream os = igfs.create(new IgfsPath("/k/l"), false)) {
}
fail("Exception expected");
} catch (IgniteException ignored) {
// No-op.
}
checkExist(igfs, igfsSecondary, new IgfsPath("/k/l"));
assert igfs.info(new IgfsPath("/k/l")).isFile();
try {
try (IgfsOutputStream os = igfs.create(new IgfsPath("/k/l/m"), true)) {
}
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();
try {
try (IgfsOutputStream os = igfs.create(new IgfsPath("/k/l/m/n/o/p"), true)) {
}
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();
igfs.mkdirs(new IgfsPath("/x/y"), null);
try {
try (IgfsOutputStream os = igfs.create(new IgfsPath("/x/y"), true)) {
}
fail("Exception expected");
} catch (IgniteException ignored) {
// okay
}
checkExist(igfs, igfsSecondary, new IgfsPath("/x/y"));
assert igfs.info(new IgfsPath("/x/y")).isDirectory();
try (IgfsOutputStream os = igfs.create(new IgfsPath("/x/y/f"), false)) {
assert igfs.info(new IgfsPath("/x/y/f")).isFile();
}
try (IgfsOutputStream os = igfs.create(new IgfsPath("/x/y/z/f"), false)) {
assert igfs.info(new IgfsPath("/x/y/z/f")).isFile();
}
try (IgfsOutputStream os = igfs.create(new IgfsPath("/x/y/z/t/f"), false)) {
assert igfs.info(new IgfsPath("/x/y/z/t/f")).isFile();
}
try (IgfsOutputStream os = igfs.create(new IgfsPath("/x/y/z/t/t2/t3/t4/t5/f"), false)) {
assert igfs.info(new IgfsPath("/x/y/z/t/t2/t3/t4/t5/f")).isFile();
}
}
use of org.apache.ignite.igfs.IgfsOutputStream in project ignite by apache.
the class IgfsAbstractSelfTest method testCreateUpdateNoClose.
/**
* Test update on the file when it was opened for write(create) and is not closed yet.
*
* @throws Exception If failed.
*/
public void testCreateUpdateNoClose() throws Exception {
if (dual)
return;
if (!propertiesSupported())
return;
Map<String, String> props = properties("owner", "group", "0555");
create(igfs, paths(DIR, SUBDIR), null);
IgfsOutputStream os = null;
try {
os = igfs.create(FILE, true);
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 testAppendRenameParentNoClose.
/**
* Test rename on the file parent when it was opened for write(append) and is not closed yet.
*
* @throws Exception If failed.
*/
public void testAppendRenameParentNoClose() 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(SUBDIR, SUBDIR2);
os.close();
} finally {
U.closeQuiet(os);
}
}
}
use of org.apache.ignite.igfs.IgfsOutputStream in project ignite by apache.
the class HadoopExternalTaskExecutionSelfTest method prepareTestFile.
/**
* @param filePath File path to prepare.
* @throws Exception If failed.
*/
private void prepareTestFile(String filePath) throws Exception {
IgniteFileSystem igfs = grid(0).fileSystem(igfsName);
try (IgfsOutputStream out = igfs.create(new IgfsPath(filePath), true)) {
PrintWriter wr = new PrintWriter(new OutputStreamWriter(out));
for (int i = 0; i < 1000; i++) wr.println("Hello, world: " + i);
wr.flush();
}
}
use of org.apache.ignite.igfs.IgfsOutputStream in project ignite by apache.
the class HadoopIgfsInProc method writeData.
/**
* {@inheritDoc}
*/
@Override
public void writeData(HadoopIgfsStreamDelegate delegate, byte[] data, int off, int len) throws IOException {
try {
IgfsOutputStream stream = delegate.target();
stream.write(data, off, len);
} catch (IllegalStateException | IOException e) {
HadoopIgfsStreamEventListener lsnr = lsnrs.get(delegate);
if (lsnr != null)
lsnr.onError(e.getMessage());
if (e instanceof IllegalStateException)
throw new IOException("Failed to write data to IGFS stream because Grid is stopping.", e);
else
throw e;
}
}
Aggregations