DataStore implements DataCacheProvider, RolesProvider { void removeHostEntries(Map<String, Set<String>> hostMap) { if (hostMap == null || hostMap.isEmpty()) { return; } for (Map.Entry<String, Set<String>> entry : hostMap.entrySet()) { List<String> services = hostCache.get(entry.getKey()); if (services != null) { services.removeAll(entry.getValue()); } } } DataStore(ChangeLogStore clogStore, CloudStore cloudStore); JWKList getZtsJWKList(Boolean rfc); void init(); boolean processDomain(SignedDomain signedDomain, boolean saveInStore); boolean processDomainDeletes(); void processDomainChecks(); boolean processDomainUpdates(); DomainData getDomainData(String name); void addDomainToCache(String name, DataCache dataCache); @Override DataCache getDataCache(String domainName); List<GroupMember> getGroupMembers(final String groupName); void getAccessibleRoles(DataCache data, String domainName, String identity,
            String[] requestedRoleList, Set<String> accessibleRoles, boolean keepFullName); String getPublicKey(String domain, String service, String keyId); HostServices getHostServices(String host); CloudStore getCloudStore(); void setCloudStore(CloudStore cloudStore); Cache<String, DataCache> getCacheStore(); Map<String, String> getPublicKeyCache(); @Override List<Role> getRolesByDomain(String domain);  }
@Test public void testRemoveHostEntriesNotPresent() { ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0"); DataStore store = new DataStore(clogStore, null); List<String> services = new ArrayList<>(); services.add("coretech.storage"); services.add("coretech.backup"); store.hostCache.put("host1", services); services = new ArrayList<>(); services.add("coretech.storage"); services.add("coretech.backup"); store.hostCache.put("host2", services); Map<String, Set<String>> hostMap = new HashMap<>(); Set<String> newServices = new HashSet<>(); newServices.add("coretech.storage"); newServices.add("coretech.backup"); hostMap.put("host3", newServices); store.removeHostEntries(hostMap); assertEquals(store.hostCache.size(), 2); List<String> retServices = store.hostCache.get("host1"); assertEquals(retServices.size(), 2); assertTrue(retServices.contains("coretech.storage")); assertTrue(retServices.contains("coretech.backup")); retServices = store.hostCache.get("host2"); assertEquals(retServices.size(), 2); assertTrue(retServices.contains("coretech.storage")); assertTrue(retServices.contains("coretech.backup")); }
@Test public void testRemoveHostEntriesRemoveValue() { ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0"); DataStore store = new DataStore(clogStore, null); List<String> services = new ArrayList<>(); services.add("coretech.storage"); services.add("coretech.backup"); store.hostCache.put("host1", services); services = new ArrayList<>(); services.add("coretech.storage"); services.add("coretech.backup"); store.hostCache.put("host2", services); Map<String, Set<String>> hostMap = new HashMap<>(); Set<String> newServices = new HashSet<>(); newServices.add("coretech.storage"); hostMap.put("host1", newServices); newServices = new HashSet<>(); newServices.add("coretech.backup"); hostMap.put("host2", newServices); store.removeHostEntries(hostMap); assertEquals(store.hostCache.size(), 2); List<String> retServices = store.hostCache.get("host1"); assertEquals(retServices.size(), 1); assertTrue(retServices.contains("coretech.backup")); retServices = store.hostCache.get("host2"); assertEquals(retServices.size(), 1); assertTrue(retServices.contains("coretech.storage")); }
@Test public void testRemoveHostEntriesEmptyMap() { ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0"); DataStore store = new DataStore(clogStore, null); List<String> services = new ArrayList<>(); services.add("coretech.storage"); services.add("coretech.backup"); store.hostCache.put("host1", services); Map<String, Set<String>> hostMap = new HashMap<>(); store.removeHostEntries(hostMap); assertEquals(store.hostCache.size(), 1); List<String> retServices = store.hostCache.get("host1"); assertEquals(retServices.size(), 2); assertTrue(retServices.contains("coretech.storage")); assertTrue(retServices.contains("coretech.backup")); }
@Test public void testRemoveHostEntrieNullMap() { ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0"); DataStore store = new DataStore(clogStore, null); List<String> services = new ArrayList<>(); services.add("coretech.storage"); services.add("coretech.backup"); store.hostCache.put("host1", services); services = new ArrayList<>(); services.add("coretech.storage"); services.add("coretech.backup"); store.hostCache.put("host2", services); store.removeHostEntries(null); assertEquals(store.hostCache.size(), 2); List<String> retServices = store.hostCache.get("host1"); assertEquals(retServices.size(), 2); assertTrue(retServices.contains("coretech.storage")); assertTrue(retServices.contains("coretech.backup")); retServices = store.hostCache.get("host2"); assertEquals(retServices.size(), 2); assertTrue(retServices.contains("coretech.storage")); assertTrue(retServices.contains("coretech.backup")); }