use of org.apache.ignite.IgniteFileSystem 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.IgniteFileSystem in project ignite by apache.
the class IgniteHadoopFileSystemHandshakeSelfTest method startUp.
/**
* Perform startup.
*
* @param dfltIgniteInstanceName Default Ignite instance name.
* @param dfltIgfsName Default IGFS name.
* @throws Exception If failed.
*/
private void startUp(boolean dfltIgniteInstanceName, boolean dfltIgfsName) throws Exception {
Ignite ignite = G.start(gridConfiguration(dfltIgniteInstanceName));
IgniteFileSystem igfs = ignite.fileSystem(dfltIgfsName ? "" : IGFS_NAME);
igfs.mkdirs(PATH);
}
use of org.apache.ignite.IgniteFileSystem 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.IgniteFileSystem in project ignite by apache.
the class IgniteHadoopFileSystemAbstractSelfTest method testZeroReplicationFactor.
/**
* @throws Exception If failed.
*/
public void testZeroReplicationFactor() throws Exception {
// This test doesn't make sense for any mode except of PRIMARY.
if (mode == PRIMARY) {
Path igfsHome = new Path(PRIMARY_URI);
Path file = new Path(igfsHome, "someFile");
try (FSDataOutputStream out = fs.create(file, (short) 0)) {
out.write(new byte[1024 * 1024]);
}
IgniteFileSystem igfs = grid(0).fileSystem("igfs");
IgfsPath filePath = new IgfsPath("/someFile");
IgfsFile fileInfo = igfs.info(filePath);
awaitPartitionMapExchange();
Collection<IgfsBlockLocation> locations = igfs.affinity(filePath, 0, fileInfo.length());
assertEquals(1, locations.size());
IgfsBlockLocation location = F.first(locations);
assertEquals(1, location.nodeIds().size());
}
}
use of org.apache.ignite.IgniteFileSystem in project ignite by apache.
the class HadoopIgfs20FileSystemAbstractSelfTest method testStatus.
/**
* @throws Exception If failed.
*/
public void testStatus() throws Exception {
Path file1 = new Path("/file1");
try (FSDataOutputStream file = fs.create(file1, EnumSet.noneOf(CreateFlag.class), Options.CreateOpts.perms(FsPermission.getDefault()))) {
file.write(new byte[1024 * 1024]);
}
FsStatus status = fs.getFsStatus();
assertEquals(getClientFsUser(), fs.getFileStatus(file1).getOwner());
assertEquals(4, grid(0).cluster().nodes().size());
long used = 0, max = 0;
for (int i = 0; i < 4; i++) {
IgniteFileSystem igfs = grid(i).fileSystem("igfs");
IgfsMetrics metrics = igfs.metrics();
used += metrics.localSpaceSize();
max += metrics.maxSpaceSize();
}
assertEquals(used, status.getUsed());
assertEquals(max, status.getCapacity());
}
Aggregations