/** {@inheritDoc} */ @Override protected void beforeTest() throws Exception { igfs.clear(); }
/** * Dump IGFS content. * * @param igfs IGFS. * @param path Path. * @throws Exception If failed. */ private static void dumpIgfs(IgniteFileSystem igfs, IgfsPath path) throws Exception { IgfsFile file = igfs.info(path); assert file != null; System.out.println(file.path()); if (file.isDirectory()) { for (IgfsPath child : igfs.listPaths(path)) dumpIgfs(igfs, child); } else { try (BufferedReader br = new BufferedReader(new InputStreamReader(igfs.open(path)))) { String line = br.readLine(); while (line != null) { System.out.println(line); line = br.readLine(); } } } }
@Nullable @Override public IgniteBiTuple<Long, Long> execute() { IgniteFileSystem igfs = ((IgniteKernal)g).context().igfs().igfs(igfsName); if (igfs == null) return F.t(0L, 0L); IgfsMetrics metrics = igfs.metrics(); long loc = metrics.localSpaceSize(); return F.t(loc, metrics.maxSpaceSize()); } });
/** * Create data transfer object. * * @param igfs Source IGFS. */ public VisorIgfs(IgniteFileSystem igfs) { assert igfs != null; name = igfs.name(); mode = igfs.configuration().getDefaultMode(); metrics = new VisorIgfsMetrics(igfs); secondaryFsConfigured = igfs.configuration().getSecondaryFileSystem() != null; }
/** * @throws Exception If failed. */ private void beforeJob() throws Exception { IgniteFileSystem igfs = grid(0).fileSystem(HadoopAbstractSelfTest.igfsName); igfs.clear(); igfs.mkdirs(new IgfsPath(PATH_INPUT)); try (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(igfs.create( new IgfsPath(PATH_INPUT + "/test.file"), true)))) { bw.write("word"); } }
IgfsMetrics m = fs.metrics(); fs.mkdirs(new IgfsPath("/primary/dir1")); m = fs.metrics(); fs.mkdirs(new IgfsPath("/primary/dir1/dir2/dir3")); fs.mkdirs(new IgfsPath("/primary/dir4")); m = fs.metrics(); 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(); m = fs.metrics(); m = fs.metrics(); IgfsOutputStream out = fs.append(new IgfsPath("/primary/dir1/file1"), false); m = fs.metrics(); m = fs.metrics(); IgfsInputStream in1 = fs.open(new IgfsPath("/primary/dir1/file1")); IgfsInputStream in2 = fs.open(new IgfsPath("/primary/dir1/file2"));
public void testRename() throws Exception { igfs.mkdirs(path("/A/B1/C1")); final IgfsPath p2 = path(e.get2()); assertTrue("Entry: " + e, igfs.exists(p1)); igfs.rename(p1, p2); assertFalse("Entry: " + e, igfs.exists(p1)); assertTrue("Entry: " + e, igfs.exists(p2)); igfs.rename(p1, p1); igfs.rename(p2, p2); assertEquals(Arrays.asList(path("/A")), sorted(igfs.listPaths(root))); assertEquals(Arrays.asList(path("/A/B1")), sorted(igfs.listPaths(path("/A")))); assertEquals(Arrays.asList(path("/A/B1/C1")), sorted(igfs.listPaths(path("/A/B1")))); try (IgfsInputStream in0 = igfs.open(path("/A/a"))) { igfs.rename(path("/A/a"), path("/b")); igfs.clear(); assertTrue(F.isEmpty(igfs.listPaths(root)));
public void testCreateFileFragmented() throws Exception { IgfsEx impl = (IgfsEx)grid(0).fileSystem("igfs"); String metaCacheName = grid(0).igfsx("igfs").configuration().getMetaCacheConfiguration().getName(); final String dataCacheName = grid(0).igfsx("igfs").configuration().getDataCacheConfiguration() .getName(); IgniteFileSystem fs2 = grid(2).fileSystem("igfs"); try (IgfsOutputStream out = fs0.create(path, 128, false, 1, CFG_GRP_SIZE, F.asMap(IgfsUtils.PROP_PREFER_LOCAL_WRITES, "true"))) { try (IgfsOutputStream out = fs1.append(path, false)) { IgfsFileImpl fileImpl = (IgfsFileImpl)fs.info(path); try (IgfsInputStream in = fs2.open(path)) { fs.delete(path, true);
/** @throws Exception If failed. */ @Test public void testCreateFileColocated() throws Exception { IgfsPath path = new IgfsPath("/colocated"); UUID uuid = UUID.randomUUID(); IgniteUuid affKey; long idx = 0; while (true) { affKey = new IgniteUuid(uuid, idx); if (grid(0).affinity(grid(0).igfsx("igfs").configuration().getDataCacheConfiguration() .getName()).mapKeyToNode(affKey).id().equals(grid(0).localNode().id())) break; idx++; } try (IgfsOutputStream out = fs.create(path, 1024, true, affKey, 0, 1024, null)) { // Write 5M, should be enough to test distribution. for (int i = 0; i < 15; i++) out.write(new byte[1024 * 1024]); } IgfsFile info = fs.info(path); Collection<IgfsBlockLocation> affNodes = fs.affinity(path, 0, info.length()); assertEquals(1, affNodes.size()); Collection<UUID> nodeIds = F.first(affNodes).nodeIds(); assertEquals(1, nodeIds.size()); assertEquals(grid(0).localNode().id(), F.first(nodeIds)); }
igfs.mkdirs(path("/A/B1/C1")); igfs.mkdirs(path("/A/B1/C2")); igfs.mkdirs(path("/A/B1/C3")); igfs.mkdirs(path("/A/B2/C1")); igfs.mkdirs(path("/A/B2/C2")); igfs.mkdirs(path("/A1/B1/C1")); igfs.mkdirs(path("/A1/B1/C2")); igfs.mkdirs(path("/A1/B1/C3")); igfs.mkdirs(path("/A2/B2/C1")); igfs.mkdirs(path("/A2/B2/C2")); assert igfs.exists(path("/A/B1/C1")); Collection<IgfsPath> paths = igfs.listPaths(path("/")); paths = igfs.listPaths(path("/A")); paths = igfs.listPaths(path("/A/B1")); igfs.delete(path("/A1/B1/C1"), false); assertNull(igfs.info(path("/A1/B1/C1"))); igfs.delete(path("/A1/B1/C2"), false); assertNull(igfs.info(path("/A1/B1/C2"))); igfs.delete(path("/A1/B1/C3"), false); assertNull(igfs.info(path("/A1/B1/C3")));
/** @throws Exception If failed. */ @Test 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()); }
IgfsPath path = new IgfsPath("/someFile"); String metaCacheName = grid(0).igfsx("igfs").configuration().getMetaCacheConfiguration().getName(); String dataCacheName = grid(0).igfsx("igfs").configuration().getDataCacheConfiguration().getName(); try (IgfsOutputStream out = igfs.create(path, true)) { out.write(new byte[10 * 1024 * 1024]); IgniteUuid fileId = U.field(igfs.info(path), "fileId"); assertNotNull(dataCache.get(dataMgr.blockKey(i, info))); igfs.delete(path, true);
/** * Get data cache for node. * * @param node Node. * @return Data cache. * @throws Exception If failed. */ private GridCacheAdapter dataCache(Ignite node) throws Exception { return ((IgniteKernal)node).internalCache(((IgniteKernal)node).igfsx(IGFS_NAME).configuration() .getDataCacheConfiguration().getName()); }
/** @throws Exception If failed. */ @Test 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()); } }
/** * Test format operation on non-empty file system. * * @throws Exception If failed. */ @Test public void testFormatNonEmpty() throws Exception { String dirPath = "/A/B/C"; igfs.mkdirs(path(dirPath)); String filePath = "/someFile"; create(filePath, false, "Some text."); igfs.clear(); assert !igfs.exists(path(dirPath)); assert !igfs.exists(path(filePath)); GridTestUtils.waitForCondition(new GridAbsPredicate() { @Override public boolean apply() { int metaSize = 0; for (Object metaId : grid(0).cachex(igfs.configuration().getMetaCacheConfiguration().getName()) .keySet()) { if (!IgfsUtils.isRootOrTrashId((IgniteUuid)metaId)) metaSize++; } return metaSize == 0; } }, 5000); }
/** * Test properties management in meta-cache. * * @throws Exception If failed. */ @Test public void testUpdateProperties() throws Exception { IgfsPath p = path("/tmp/my"); igfs.mkdirs(p); Map<String, String> oldProps = igfs.info(p).properties(); igfs.update(p, F.asMap("a", "1")); igfs.update(p, F.asMap("b", "2")); assertEquals("1", igfs.info(p).property("a")); assertEquals("2", igfs.info(p).property("b")); igfs.update(p, F.asMap("b", "3")); Map<String, String> expProps = new HashMap<>(oldProps); expProps.put("a", "1"); expProps.put("b", "3"); assertEquals("3", igfs.info(p).property("b")); assertEquals(expProps, igfs.info(p).properties()); assertEquals("5", igfs.info(p).property("c", "5")); assertUpdatePropertiesFails(null, null, NullPointerException.class, "Ouch! Argument cannot be null"); assertUpdatePropertiesFails(p, null, NullPointerException.class, "Ouch! Argument cannot be null"); assertUpdatePropertiesFails(null, F.asMap("x", "9"), NullPointerException.class, "Ouch! Argument cannot be null"); assertUpdatePropertiesFails(p, Collections.<String, String>emptyMap(), IllegalArgumentException.class, "Ouch! Argument is invalid"); }
@Override public Object call() throws Exception { igfs.open(path(path)); return false; } }, IgniteException.class, msg);