/** {@inheritDoc} */ @Override public void handleFile(String strPath) throws Exception { IgfsPath path = new IgfsPath(strPath); IgfsFile info = fs.info(path); assert info != null : "Info must be not null for exists file. All files must be exists for benchmark"; }
/** {@inheritDoc} */ @Override public void postHandleDir(String strPath) throws Exception { IgfsPath path = new IgfsPath(strPath); IgfsFile info = fs.info(path); assert info != null : "Info must be not null for exists dir. All dirs must be exists for benchmark"; } }
@Override public Object call() throws Exception { for (int cur = cnt.incrementAndGet(); cur < max; cur = cnt.incrementAndGet()) { IgfsFile info = igfs.info(path(cur)); assertNotNull("Expects file exist: " + cur, info); assertTrue("Expects file is a directory: " + cur, info.isDirectory()); } return null; } }, threads, "grid-test-check-directories-exist");
/** * 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(); } } } }
/** * Create file and write specified text to. * * @param path File path to create. * @param overwrite Overwrite file if it already exists. * @param text Text to write into file. * @return Content of this file. * @throws IgniteCheckedException In case of error. */ private String create(String path, boolean overwrite, String text) throws Exception { try (IgfsOutputStream out = igfs.create(path(path), overwrite)) { IOUtils.write(text, out, UTF_8); } assertNotNull(igfs.info(path(path))); return read(path); }
/** * Appent text to the file. * * @param path File path to create. * @param create Create file if it doesn't exist yet. * @param text Text to append to file. * @return Content of this file. * @throws IgniteCheckedException In case of error. */ private String append(String path, boolean create, String text) throws Exception { try (IgfsOutputStream out = igfs.append(path(path), create)) { IOUtils.write(text, out, UTF_8); } assertNotNull(igfs.info(path(path))); return read(path); }
/** @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 task. * * @throws Exception If failed. */ @SuppressWarnings("ConstantConditions") @Test public void testTask() throws Exception { String arg = DICTIONARY[new Random(System.currentTimeMillis()).nextInt(DICTIONARY.length)]; generateFile(TOTAL_WORDS); Long genLen = igfs.info(FILE).length(); IgniteBiTuple<Long, Integer> taskRes = igfs.execute(new Task(), new IgfsStringDelimiterRecordResolver(" "), Collections.singleton(FILE), arg); assert F.eq(genLen, taskRes.getKey()); assert F.eq(TOTAL_WORDS, taskRes.getValue()); }
/** * Test task. * * @throws Exception If failed. */ @SuppressWarnings("ConstantConditions") @Test public void testTaskAsync() throws Exception { String arg = DICTIONARY[new Random(System.currentTimeMillis()).nextInt(DICTIONARY.length)]; generateFile(TOTAL_WORDS); Long genLen = igfs.info(FILE).length(); IgniteBiTuple<Long, Integer> taskRes = igfs.executeAsync(new Task(), new IgfsStringDelimiterRecordResolver(" "), Collections.singleton(FILE), arg).get(); assert F.eq(genLen, taskRes.getKey()); assert F.eq(TOTAL_WORDS, taskRes.getValue()); }
/** * 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"); }
/** @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(primaryFsUri); Path file = new Path(igfsHome, "someFile"); try (FSDataOutputStream out = fs.create(file, EnumSet.noneOf(CreateFlag.class), Options.CreateOpts.perms(FsPermission.getDefault()), Options.CreateOpts.repFac((short)1))) { out.write(new byte[1024 * 1024]); } IgniteFileSystem igfs = grid(0).fileSystem("igfs"); IgfsPath filePath = new IgfsPath("/someFile"); IgfsFile fileInfo = igfs.info(filePath); Collection<IgfsBlockLocation> locations = igfs.affinity(filePath, 0, fileInfo.length()); assertEquals(1, locations.size()); IgfsBlockLocation location = F.first(locations); assertEquals(1, location.nodeIds().size()); } }
IgfsFile file = fs.info(path);
/** @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)); }
/** @throws Exception If failed. */ @Test 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); assertNotNull(fileInfo); assertNotNull(fileInfo.listing()); } } finally { igfs.delete(path("/"), true); } }
IgfsFileImpl fileImpl = (IgfsFileImpl)fs.info(path);
IgniteUuid fileId = U.field(igfs.info(path), "fileId");
IgfsFile file = fs.info(path);