FSRegistryOperationsService extends CompositeService implements RegistryOperations { @Override public boolean mknode(String path, boolean createParents) throws PathNotFoundException, InvalidPathnameException, IOException { Path registryPath = makePath(path); try { fs.getFileStatus(registryPath); return false; } catch (FileNotFoundException e) { } if (createParents) { fs.mkdirs(registryPath); } else { FileStatus parentStatus = null; if (registryPath.getParent() != null) { parentStatus = fs.getFileStatus(registryPath.getParent()); } if (registryPath.getParent() == null || parentStatus.isDirectory()) { fs.mkdirs(registryPath); } else { throw new PathNotFoundException("no parent for " + path); } } return true; } FSRegistryOperationsService(); @VisibleForTesting FileSystem getFs(); @Override boolean mknode(String path, boolean createParents); @Override void bind(String path, ServiceRecord record, int flags); @Override ServiceRecord resolve(String path); @Override RegistryPathStatus stat(String path); @Override boolean exists(String path); @Override List<String> list(String path); @Override void delete(String path, boolean recursive); @Override boolean addWriteAccessor(String id, String pass); @Override void clearWriteAccessors();  }
@Test public void testMkNodeAlreadyExists() throws IOException { System.out.println("pre-create test path"); fs.mkdirs(new Path("test/registryTestNode")); System.out.println( "Try to mknode existing path -- should be noop and return false"); Assert.assertFalse(registry.mknode("test/registryTestNode", true)); Assert.assertFalse(registry.mknode("test/registryTestNode", false)); }