use of org.apache.ignite.igfs.IgfsOutputStream in project ignite by apache.
the class IgfsMetricsSelfTest method testMultipleClose.
/** @throws Exception If failed. */
public void testMultipleClose() throws Exception {
IgniteFileSystem fs = igfsPrimary[0];
IgfsOutputStream out = fs.create(new IgfsPath("/primary/file"), false);
out.close();
out.close();
IgfsInputStream in = fs.open(new IgfsPath("/primary/file"));
in.close();
in.close();
IgfsMetrics m = fs.metrics();
assertEquals(0, m.filesOpenedForWrite());
assertEquals(0, m.filesOpenedForRead());
}
use of org.apache.ignite.igfs.IgfsOutputStream in project ignite by apache.
the class IgfsMetricsSelfTest method testMetrics.
/** @throws Exception If failed. */
public void testMetrics() throws Exception {
IgniteFileSystem fs = igfsPrimary[0];
assertNotNull(fs);
IgfsMetrics m = fs.metrics();
assertNotNull(m);
assertEquals(0, m.directoriesCount());
assertEquals(0, m.filesCount());
assertEquals(0, m.filesOpenedForRead());
assertEquals(0, m.filesOpenedForWrite());
fs.mkdirs(new IgfsPath("/primary/dir1"));
m = fs.metrics();
assertNotNull(m);
assertEquals(2, m.directoriesCount());
assertEquals(0, m.filesCount());
assertEquals(0, m.filesOpenedForRead());
assertEquals(0, m.filesOpenedForWrite());
fs.mkdirs(new IgfsPath("/primary/dir1/dir2/dir3"));
fs.mkdirs(new IgfsPath("/primary/dir4"));
m = fs.metrics();
assertNotNull(m);
assertEquals(5, m.directoriesCount());
assertEquals(0, m.filesCount());
assertEquals(0, m.filesOpenedForRead());
assertEquals(0, m.filesOpenedForWrite());
IgfsOutputStream out1 = fs.create(new IgfsPath("/primary/dir1/file1"), false);
IgfsOutputStream out2 = fs.create(new IgfsPath("/primary/dir1/file2"), false);
IgfsOutputStream out3 = fs.create(new IgfsPath("/primary/dir1/dir2/file"), false);
m = fs.metrics();
assertNotNull(m);
assertEquals(5, m.directoriesCount());
assertEquals(3, m.filesCount());
assertEquals(0, m.filesOpenedForRead());
assertEquals(3, m.filesOpenedForWrite());
out1.write(new byte[10]);
out2.write(new byte[20]);
out3.write(new byte[30]);
out1.close();
m = fs.metrics();
assertNotNull(m);
assertEquals(5, m.directoriesCount());
assertEquals(3, m.filesCount());
assertEquals(0, m.filesOpenedForRead());
assertEquals(2, m.filesOpenedForWrite());
out2.close();
out3.close();
m = fs.metrics();
assertNotNull(m);
assertEquals(5, m.directoriesCount());
assertEquals(3, m.filesCount());
assertEquals(0, m.filesOpenedForRead());
assertEquals(0, m.filesOpenedForWrite());
IgfsOutputStream out = fs.append(new IgfsPath("/primary/dir1/file1"), false);
out.write(new byte[20]);
m = fs.metrics();
assertNotNull(m);
assertEquals(5, m.directoriesCount());
assertEquals(3, m.filesCount());
assertEquals(0, m.filesOpenedForRead());
assertEquals(1, m.filesOpenedForWrite());
out.write(new byte[20]);
out.close();
m = fs.metrics();
assertNotNull(m);
assertEquals(5, m.directoriesCount());
assertEquals(3, m.filesCount());
assertEquals(0, m.filesOpenedForRead());
assertEquals(0, m.filesOpenedForWrite());
IgfsInputStream in1 = fs.open(new IgfsPath("/primary/dir1/file1"));
IgfsInputStream in2 = fs.open(new IgfsPath("/primary/dir1/file2"));
m = fs.metrics();
assertNotNull(m);
assertEquals(5, m.directoriesCount());
assertEquals(3, m.filesCount());
assertEquals(2, m.filesOpenedForRead());
assertEquals(0, m.filesOpenedForWrite());
in1.close();
in2.close();
m = fs.metrics();
assertNotNull(m);
assertEquals(5, m.directoriesCount());
assertEquals(3, m.filesCount());
assertEquals(0, m.filesOpenedForRead());
assertEquals(0, m.filesOpenedForWrite());
fs.delete(new IgfsPath("/primary/dir1/file1"), false);
fs.delete(new IgfsPath("/primary/dir1/dir2"), true);
m = fs.metrics();
assertNotNull(m);
assertEquals(3, m.directoriesCount());
assertEquals(1, m.filesCount());
assertEquals(0, m.filesOpenedForRead());
assertEquals(0, m.filesOpenedForWrite());
fs.clear();
m = fs.metrics();
assertNotNull(m);
assertEquals(0, m.directoriesCount());
assertEquals(0, m.filesCount());
assertEquals(0, m.filesOpenedForRead());
assertEquals(0, m.filesOpenedForWrite());
}
use of org.apache.ignite.igfs.IgfsOutputStream in project ignite by apache.
the class IgfsProcessorSelfTest method testCreate.
/** @throws Exception If failed. */
public void testCreate() throws Exception {
IgfsPath path = path("/file");
try (IgfsOutputStream os = igfs.create(path, false)) {
assert os != null;
IgfsFileImpl info = (IgfsFileImpl) igfs.info(path);
for (int i = 0; i < nodesCount(); i++) {
IgfsEntryInfo fileInfo = (IgfsEntryInfo) grid(i).cachex(metaCacheName).localPeek(info.fileId(), null, null);
assertNotNull(fileInfo);
assertNotNull(fileInfo.listing());
}
} finally {
igfs.delete(path("/"), true);
}
}
use of org.apache.ignite.igfs.IgfsOutputStream in project ignite by apache.
the class IgfsAbstractBaseSelfTest method createFile.
/**
* Create the file in the given IGFS and write provided data chunks to it.
*
* @param igfs IGFS.
* @param file File.
* @param overwrite Overwrite flag.
* @param blockSize Block size.
* @param chunks Data chunks.
* @throws Exception If failed.
*/
protected static void createFile(IgfsImpl igfs, IgfsPath file, boolean overwrite, long blockSize, @Nullable byte[]... chunks) throws Exception {
IgfsOutputStream os = null;
try {
os = igfs.create(file, 256, overwrite, null, 0, blockSize, null);
writeFileChunks(os, chunks);
} finally {
U.closeQuiet(os);
awaitFileClose(igfs, file);
}
}
use of org.apache.ignite.igfs.IgfsOutputStream in project ignite by apache.
the class IgfsBackupFailoverSelfTest method testWriteFailoverAfterStopMultipleNodes.
/**
* Checks possibility to append the data to files *after* N-1 nodes are stopped.
* First, some data written to files.
* After that N-1 nodes are stopped.
* Then data are attempted to append to the streams opened before the nodes stop.
* If failed, the streams are attempted to reopen and the files are attempted to append.
* After that the read operation is performed to check data correctness.
*
* The test is temporarily disabled due to issues .... .
*
* @throws Exception On error.
*/
public void testWriteFailoverAfterStopMultipleNodes() throws Exception {
final IgfsImpl igfs0 = nodeDatas[0].igfsImpl;
clear(igfs0);
IgfsAbstractSelfTest.create(igfs0, paths(DIR, SUBDIR), null);
final IgfsOutputStream[] outStreams = new IgfsOutputStream[files];
// Create files:
for (int f = 0; f < files; f++) {
final byte[] data = createChunk(fileSize, f);
IgfsOutputStream os = null;
try {
os = igfs0.create(filePath(f), 256, true, null, 0, -1, null);
assert os != null;
writeFileChunks(os, data);
} finally {
if (os != null)
os.flush();
}
outStreams[f] = os;
X.println("write #1 completed: " + f);
}
// Now stop all the nodes but the 1st:
for (int n = 1; n < numIgfsNodes; n++) {
stopGrid(n);
X.println("#### grid " + n + " stopped.");
}
// Create files:
for (int f0 = 0; f0 < files; f0++) {
final IgfsOutputStream os = outStreams[f0];
assert os != null;
final int f = f0;
int att = doWithRetries(1, new Callable<Void>() {
@Override
public Void call() throws Exception {
IgfsOutputStream ios = os;
try {
writeChunks0(igfs0, ios, f);
} catch (IOException ioe) {
log().warning("Attempt to append the data to existing stream failed: ", ioe);
ios = igfs0.append(filePath(f), false);
assert ios != null;
writeChunks0(igfs0, ios, f);
}
return null;
}
});
assert att == 1;
X.println("write #2 completed: " + f0 + " in " + att + " attempts.");
}
// Check files:
for (int f = 0; f < files; f++) {
IgfsPath path = filePath(f);
byte[] data = createChunk(fileSize, f);
// Check through 1st node:
checkExist(igfs0, path);
assertEquals("File length mismatch.", data.length * 2, igfs0.size(path));
checkFileContent(igfs0, path, data, data);
X.println("Read test completed: " + f);
}
}
Aggregations