ZMSFileChangeLogStoreCommon { List<SignedDomain> getSignedDomainList(ZMSClient zmsClient, SignedDomains domainList) { List<SignedDomain> domains = new ArrayList<>(); for (SignedDomain domain : domainList.getDomains()) { final String domainName = domain.getDomain().getName(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("getSignedDomainList: fetching domain {}", domainName); } while (true) { try { SignedDomains singleDomain = zmsClient.getSignedDomains(domainName, null, null, null); if (singleDomain != null && !singleDomain.getDomains().isEmpty()) { domains.addAll(singleDomain.getDomains()); } break; } catch (ZMSClientException ex) { LOGGER.error("Error fetching domain {} from ZMS: {}", domainName, ex.getMessage()); if (ex.getCode() != ZMSClientException.TOO_MANY_REQUESTS) { break; } try { Thread.sleep(1000); } catch (InterruptedException ignored) { } } } } return domains; } ZMSFileChangeLogStoreCommon(final String rootDirectory); boolean supportsFullRefresh(); SignedDomain getLocalSignedDomain(final String domainName); SignedDomain getServerSignedDomain(ZMSClient zmsClient, final String domainName); void removeLocalDomain(String domainName); void saveLocalDomain(String domainName, SignedDomain signedDomain); synchronized T get(String name, Class<T> classType); synchronized void put(String name, byte[] data); synchronized void delete(String name); List<String> getLocalDomainList(); Set<String> getServerDomainList(ZMSClient zmsClient); SignedDomains getServerDomainModifiedList(ZMSClient zmsClient); String retrieveLastModificationTime(); void setLastModificationTimestamp(String newLastModTime); String retrieveTagHeader(Map<String, List<String>> responseHeaders); SignedDomains getUpdatedSignedDomains(ZMSClient zmsClient, StringBuilder lastModTimeBuffer); public String lastModTime; }
@Test public void testGetSignedDomainList() { ZMSFileChangeLogStoreCommon fstore = new ZMSFileChangeLogStoreCommon(FSTORE_PATH); ZMSClient zmsClient = Mockito.mock(ZMSClient.class); List<SignedDomain> domains = new ArrayList<>(); DomainData domData = new DomainData().setName("athenz"); SignedDomain domain = new SignedDomain().setDomain(domData); domains.add(domain); SignedDomains domainList = new SignedDomains().setDomains(domains); Mockito.when(zmsClient.getSignedDomains("athenz", null, null, null)).thenReturn(domainList); List<SignedDomain> returnList = fstore.getSignedDomainList(zmsClient, domainList); assertEquals(returnList.size(), 1); assertEquals(returnList.get(0).getDomain().getName(), "athenz"); }
@Test public void testGetSignedDomainListNonRateFailure() { ZMSFileChangeLogStoreCommon fstore = new ZMSFileChangeLogStoreCommon(FSTORE_PATH); ZMSClient zmsClient = Mockito.mock(ZMSClient.class); List<SignedDomain> domains = new ArrayList<>(); DomainData domData = new DomainData().setName("athenz"); SignedDomain domain = new SignedDomain().setDomain(domData); domains.add(domain); SignedDomains domainList = new SignedDomains().setDomains(domains); Mockito.when(zmsClient.getSignedDomains("athenz", null, null, null)) .thenThrow(new ZMSClientException(401, "invalid credentials")); List<SignedDomain> returnList = fstore.getSignedDomainList(zmsClient, domainList); assertEquals(returnList.size(), 0); }