/** * Test expected failures for 'append' operation. * * @param path File path to append. * @param create Create file if it doesn't exist yet. */ private void assertAppendFails(final String path, final boolean create) { GridTestUtils.assertThrowsInherited(log, new Callable<Object>() { @Override public Object call() throws Exception { igfs.append(path(path), create); return false; } }, IgfsException.class, null); }
/** * Test expected failures for 'create' operation. * * @param path File path to create. * @param overwrite Overwrite file if it already exists. Note: you cannot overwrite an existent directory. */ private void assertCreateFails(final String path, final boolean overwrite) { GridTestUtils.assertThrowsInherited(log, new Callable<Object>() { @Override public Object call() throws Exception { igfs.create(path(path), overwrite); return false; } }, IgfsException.class, null); }
/** * Test expected failures for 'open' operation. * * @param path File path to read. * @param msg Failure message if expected exception was not thrown. */ private void assertOpenFails(final String path, @Nullable String msg) { GridTestUtils.assertThrowsInherited(log, new Callable<Object>() { @Override public Object call() throws Exception { igfs.open(path(path)); return false; } }, IgniteException.class, msg); }
/** * Test expected failures for 'move file' operation. */ private void expectsRenameFail(final String src, final String dst) { Throwable err = assertThrowsInherited(log, new Callable() { @Override public Object call() throws Exception { mgr.move(new IgfsPath(src), new IgfsPath(dst)); return null; } }, IgfsException.class, null); assertTrue("Unexpected cause: " + err, err instanceof IgfsException); } }
/** @throws Exception If failed. */ @Test public void testAppendIfPathPointsToDirectory() throws Exception { final Path fsHome = new Path(primaryFsUri); final Path dir = new Path(fsHome, "/tmp"); Path file = new Path(dir, "my"); FSDataOutputStream os = fs.create(file); os.close(); GridTestUtils.assertThrowsInherited(log, new Callable<Object>() { @Override public Object call() throws Exception { return fs.append(new Path(fsHome, dir), 1024); } }, IOException.class, null); }
/** * @throws Exception If failed. */ @Test public void testFailWhenConfiguredCacheExists() throws Exception { GridTestUtils.assertThrowsInherited(log, new Callable<Object>() { @Override public Object call() throws Exception { final Ignite kernal = grid(0); CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME); ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); // Cache is already configured, should fail. ccfg.setName(STATIC_CACHE_NAME); ccfg.setNodeFilter(NODE_FILTER); return kernal.createCache(ccfg); } }, CacheExistsException.class, null); }
/** @throws Exception If failed. */ @Test public void testAppendIfPathPointsToDirectory() throws Exception { final Path fsHome = new Path(primaryFsUri); final Path dir = new Path(fsHome, "/tmp"); Path file = new Path(dir, "my"); FSDataOutputStream os = fs.create(file, EnumSet.noneOf(CreateFlag.class), Options.CreateOpts.perms(FsPermission.getDefault())); os.close(); GridTestUtils.assertThrowsInherited(log, new Callable<Object>() { @Override public Object call() throws Exception { return fs.create(new Path(fsHome, dir), EnumSet.of(CreateFlag.APPEND), Options.CreateOpts.perms(FsPermission.getDefault())); } }, IOException.class, null); }
/** * Ensure that rename doesn't occur in case source doesn't exist remotely. * * @throws Exception If failed. */ @Test public void testMoveRenameSourceDoesNotExist() throws Exception { create(igfs, paths(DIR, DIR_NEW), null); GridTestUtils.assertThrowsInherited(log, new Callable<Object>() { @Override public Object call() throws Exception { igfs.rename(SUBDIR, SUBDIR_NEW); return null; } }, IgfsException.class, null); checkNotExist(igfs, igfsSecondary, SUBDIR, SUBDIR_NEW); }
/** * @throws Exception If failed. */ @Test public void testFailWhenOneOfConfiguredCacheExists() throws Exception { GridTestUtils.assertThrowsInherited(log, new Callable<Object>() { @Override public Object call() throws Exception { final Ignite kernal = grid(0); CacheConfiguration ccfgDynamic = new CacheConfiguration(DEFAULT_CACHE_NAME); ccfgDynamic.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); ccfgDynamic.setName(DYNAMIC_CACHE_NAME); ccfgDynamic.setNodeFilter(NODE_FILTER); CacheConfiguration ccfgStatic = new CacheConfiguration(DEFAULT_CACHE_NAME); ccfgStatic.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); // Cache is already configured, should fail. ccfgStatic.setName(STATIC_CACHE_NAME); ccfgStatic.setNodeFilter(NODE_FILTER); return kernal.createCaches(F.asList(ccfgDynamic, ccfgStatic)); } }, CacheExistsException.class, null); assertNull(grid(0).cache(DYNAMIC_CACHE_NAME)); }
/** * Test subsequent "append" commands on the same file without closing the output streams. * * @throws Exception If failed. */ @Test public void testAppendNoClose() throws Exception { if (mode != PRIMARY) return; if (appendSupported()) { create(igfs, paths(DIR, SUBDIR), null); createFile(igfs, FILE, false); GridTestUtils.assertThrowsInherited(log(), new Callable<Object>() { @Override public Object call() throws Exception { IgfsOutputStream os1 = null; IgfsOutputStream os2 = null; try { os1 = igfs.append(FILE, false); os2 = igfs.append(FILE, false); } finally { U.closeQuiet(os1); U.closeQuiet(os2); } return null; } }, IgniteException.class, null); } }
GridTestUtils.assertThrowsInherited(log, new Callable<Object>() { @Override public Object call() throws Exception { igfs.rename(path("/A/B1/C1"), path("/A/B1/C1/C2")); GridTestUtils.assertThrowsInherited(log, new Callable<Object>() { @Override public Object call() throws Exception { igfs.rename(path("/A/B1/C1"), path("/A/B1/C1/D/C2")); GridTestUtils.assertThrowsInherited(log, new Callable<Object>() { @Override public Object call() throws Exception { GridTestUtils.assertThrowsInherited(log, new Callable<Object>() { @Override public Object call() throws Exception { igfs.rename(root, p1); GridTestUtils.assertThrowsInherited(log, new Callable<Object>() { @Override public Object call() throws Exception { igfs.rename(p1, root); GridTestUtils.assertThrowsInherited(log, new Callable<Object>() { @Override public Object call() throws Exception { igfs.rename(root, p2);