Search in sources :

Example 6 with HostServices

use of com.yahoo.athenz.zts.HostServices in project athenz by yahoo.

the class DataStoreTest method testAddDomainToCacheRemovedHosts.

@Test
public void testAddDomainToCacheRemovedHosts() {
    ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
    DataStore store = new DataStore(clogStore, null, ztsMetric);
    DataCache dataCache = new DataCache();
    ServiceIdentity service = new ServiceIdentity();
    service.setName("coretech.storage");
    List<String> hosts = new ArrayList<>();
    hosts.add("host1");
    hosts.add("host2");
    hosts.add("host3");
    service.setHosts(hosts);
    List<ServiceIdentity> services = new ArrayList<>();
    services.add(service);
    dataCache.processServiceIdentity(service);
    DomainData domainData = new DomainData();
    domainData.setServices(services);
    dataCache.setDomainData(domainData);
    store.addDomainToCache("coretech", dataCache);
    /* removed hosts */
    dataCache = new DataCache();
    service = new ServiceIdentity();
    service.setName("coretech.storage");
    hosts = new ArrayList<>();
    hosts.add("host1");
    service.setHosts(hosts);
    services = new ArrayList<>();
    services.add(service);
    dataCache.processServiceIdentity(service);
    domainData = new DomainData();
    domainData.setServices(services);
    dataCache.setDomainData(domainData);
    store.addDomainToCache("coretech", dataCache);
    HostServices hostServices = store.getHostServices("host1");
    hosts = hostServices.getNames();
    assertEquals(hosts.size(), 1);
    assertTrue(hosts.contains("coretech.storage"));
    hostServices = store.getHostServices("host2");
    hosts = hostServices.getNames();
    assertEquals(hosts.size(), 0);
    hostServices = store.getHostServices("host3");
    hosts = hostServices.getNames();
    assertEquals(hosts.size(), 0);
}
Also used : ChangeLogStore(com.yahoo.athenz.common.server.store.ChangeLogStore) HostServices(com.yahoo.athenz.zts.HostServices) DataCache(com.yahoo.athenz.zts.cache.DataCache) Test(org.testng.annotations.Test)

Example 7 with HostServices

use of com.yahoo.athenz.zts.HostServices in project athenz by yahoo.

the class DataStoreTest method testAddDomainToCacheSameHosts.

@Test
public void testAddDomainToCacheSameHosts() {
    ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
    DataStore store = new DataStore(clogStore, null, ztsMetric);
    DataCache dataCache = new DataCache();
    ServiceIdentity service = new ServiceIdentity();
    service.setName("coretech.storage");
    List<String> hosts = new ArrayList<>();
    hosts.add("host1");
    service.setHosts(hosts);
    List<ServiceIdentity> services = new ArrayList<>();
    services.add(service);
    dataCache.processServiceIdentity(service);
    DomainData domainData = new DomainData();
    domainData.setServices(services);
    dataCache.setDomainData(domainData);
    store.addDomainToCache("coretech", dataCache);
    /* same hosts - no changes */
    dataCache = new DataCache();
    service = new ServiceIdentity();
    service.setName("coretech.storage");
    hosts = new ArrayList<>();
    hosts.add("host1");
    service.setHosts(hosts);
    services = new ArrayList<>();
    services.add(service);
    dataCache.processServiceIdentity(service);
    domainData = new DomainData();
    domainData.setServices(services);
    dataCache.setDomainData(domainData);
    store.addDomainToCache("coretech", dataCache);
    HostServices hostServices = store.getHostServices("host1");
    hosts = hostServices.getNames();
    assertEquals(hosts.size(), 1);
    assertTrue(hosts.contains("coretech.storage"));
}
Also used : ChangeLogStore(com.yahoo.athenz.common.server.store.ChangeLogStore) HostServices(com.yahoo.athenz.zts.HostServices) DataCache(com.yahoo.athenz.zts.cache.DataCache) Test(org.testng.annotations.Test)

Example 8 with HostServices

use of com.yahoo.athenz.zts.HostServices in project athenz by yahoo.

the class DataStoreTest method testGetHostServicesInvalid.

@Test
public void testGetHostServicesInvalid() {
    ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
    DataStore store = new DataStore(clogStore, null, ztsMetric);
    List<String> services = new ArrayList<>();
    services.add("coretech.storage");
    services.add("sports.storage");
    store.hostCache.put("host1", services);
    services = new ArrayList<>();
    services.add("coretech.storage");
    services.add("sports.storage");
    store.hostCache.put("host2", services);
    HostServices hostServices = store.getHostServices("host3");
    List<String> hosts = hostServices.getNames();
    assertNull(hosts);
}
Also used : ChangeLogStore(com.yahoo.athenz.common.server.store.ChangeLogStore) HostServices(com.yahoo.athenz.zts.HostServices) Test(org.testng.annotations.Test)

Example 9 with HostServices

use of com.yahoo.athenz.zts.HostServices in project athenz by yahoo.

the class DataStoreTest method testGetHostServices.

@Test
public void testGetHostServices() {
    ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
    DataStore store = new DataStore(clogStore, null, ztsMetric);
    List<String> services = new ArrayList<>();
    services.add("coretech.storage");
    services.add("sports.storage");
    store.hostCache.put("host1", services);
    services = new ArrayList<>();
    services.add("coretech.storage");
    services.add("sports.storage");
    store.hostCache.put("host2", services);
    HostServices hostServices = store.getHostServices("host1");
    List<String> hosts = hostServices.getNames();
    assertEquals(hosts.size(), 2);
    assertTrue(hosts.contains("coretech.storage"));
    assertTrue(hosts.contains("sports.storage"));
    hostServices = store.getHostServices("host2");
    hosts = hostServices.getNames();
    assertEquals(hosts.size(), 2);
    assertTrue(hosts.contains("coretech.storage"));
    assertTrue(hosts.contains("sports.storage"));
}
Also used : ChangeLogStore(com.yahoo.athenz.common.server.store.ChangeLogStore) HostServices(com.yahoo.athenz.zts.HostServices) Test(org.testng.annotations.Test)

Example 10 with HostServices

use of com.yahoo.athenz.zts.HostServices in project athenz by yahoo.

the class DataStoreTest method testDeleteDomainFromCacheHosts.

@Test
public void testDeleteDomainFromCacheHosts() {
    ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
    DataStore store = new DataStore(clogStore, null, ztsMetric);
    DataCache dataCache = new DataCache();
    ServiceIdentity service = new ServiceIdentity();
    service.setName("coretech.storage");
    List<String> hosts = new ArrayList<>();
    hosts.add("host1");
    service.setHosts(hosts);
    List<ServiceIdentity> services = new ArrayList<>();
    dataCache.processServiceIdentity(service);
    services.add(service);
    DomainData domainData = new DomainData();
    domainData.setServices(services);
    dataCache.setDomainData(domainData);
    store.addDomainToCache("coretech", dataCache);
    store.deleteDomainFromCache("coretech");
    HostServices hostServices = store.getHostServices("host1");
    hosts = hostServices.getNames();
    assertEquals(hosts.size(), 0);
}
Also used : ChangeLogStore(com.yahoo.athenz.common.server.store.ChangeLogStore) HostServices(com.yahoo.athenz.zts.HostServices) DataCache(com.yahoo.athenz.zts.cache.DataCache) Test(org.testng.annotations.Test)

Aggregations

HostServices (com.yahoo.athenz.zts.HostServices)10 ChangeLogStore (com.yahoo.athenz.common.server.store.ChangeLogStore)9 Test (org.testng.annotations.Test)9 DataCache (com.yahoo.athenz.zts.cache.DataCache)6