FSRegistryOperationsService extends CompositeService implements RegistryOperations { @Override public ServiceRecord resolve(String path) throws PathNotFoundException, NoRecordException, InvalidRecordException, IOException { Long size = fs.getFileStatus(formatDataPath(path)).getLen(); byte[] bytes = new byte[size.intValue()]; FSDataInputStream instream = fs.open(formatDataPath(path)); int bytesRead = instream.read(bytes); instream.close(); if (bytesRead < size) { throw new InvalidRecordException(path, "Expected " + size + " bytes, but read " + bytesRead); } ServiceRecord record = serviceRecordMarshal.fromBytes(path, bytes); RegistryTypeUtils.validateServiceRecord(path, record); return record; } 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 testResolve() throws IOException { ServiceRecord record = createRecord("0"); registry.bind("test/registryTestNode", record, 1); Assert.assertTrue(fs.exists(new Path("test/registryTestNode/_record"))); System.out.println("Read record that exists"); ServiceRecord readRecord = registry.resolve("test/registryTestNode"); Assert.assertNotNull(readRecord); Assert.assertTrue(record.equals(readRecord)); System.out.println("Try to read record that does not exist"); try { readRecord = registry.resolve("test/nonExistentNode"); Assert.fail("Should throw an error, record does not exist"); } catch (IOException e) { } }