/** * Gets MPath object that has the given path value. * TODO: Try to avoid loop lookup in future for performance improvement. * * @param path the given path name * @return an Path object that has the given path value. */ public MPath getPathsPersisted(String path) { for (MPath mPath : pathsPersisted) { if (mPath.getPath().equals(path)) { return mPath; } } return null; }
/** * @return collection of paths strings contained in this object. */ public Collection<String> getPathStrings() { Collection<String> pathValues = new ArrayList<>(this.pathsPersisted.size()); for (MPath path : this.pathsPersisted) { pathValues.add(path.getPath()); } return pathValues; }
@Test public void testAddAuthzPathsMapping() throws Exception { Set<MPath> paths; // Persist an empty image so that we can add paths to it. sentryStore.persistFullPathsImage(new HashMap<String, Collection<String>>(), 0); // Check the latest persisted ID matches to both the path updates long latestID = sentryStore.getCurrentAuthzPathsSnapshotID(); // Persist the path sentryStore.addAuthzPathsMapping("db1.tb1", Arrays.asList("/hive/db1/tb1"), null); paths = sentryStore.getMAuthzPaths(latestID, "db1.tb1"); // Verify that mapping is been added assertEquals(paths.size(), 1); assertTrue(paths.stream().anyMatch(x -> x.getPath().equalsIgnoreCase("/hive/db1/tb1"))); // Add new path to an existing mapping sentryStore.addAuthzPathsMapping("db1.tb1", Arrays.asList("/hive/db1/tb1/par1"), null); paths = sentryStore.getMAuthzPaths(latestID, "db1.tb1"); // Verify that mapping is been updated with the new path assertEquals(paths.size(), 2); assertTrue(paths.stream().anyMatch(x -> x.getPath().equalsIgnoreCase("/hive/db1/tb1/par1"))); // Add multiples path to an existing mapping sentryStore.addAuthzPathsMapping("db1.tb1", Arrays.asList("/hive/db1/tb1/par2","/hive/db1/tb1/par3"), null); paths = sentryStore.getMAuthzPaths(latestID, "db1.tb1"); // Verify that mapping is been updated with the new path assertEquals(paths.size(), 4); assertTrue(paths.stream().anyMatch(x -> x.getPath().equalsIgnoreCase("/hive/db1/tb1/par2"))); assertTrue(paths.stream().anyMatch(x -> x.getPath().equalsIgnoreCase("/hive/db1/tb1/par3"))); }