Search in sources :

Example 1 with WorkloadRecordStore

use of com.yahoo.athenz.common.server.workload.WorkloadRecordStore in project athenz by yahoo.

the class InstanceCertManagerTest method testInsertWorkloadRecord.

@Test
public void testInsertWorkloadRecord() {
    InstanceCertManager instance = new InstanceCertManager(null, null, null, true, null);
    WorkloadRecordStore store = Mockito.mock(WorkloadRecordStore.class);
    instance.setWorkloadStore(store);
    WorkloadRecordStoreConnection storeConn = Mockito.mock(WorkloadRecordStoreConnection.class);
    Mockito.when(store.getConnection()).thenReturn(storeConn);
    Mockito.when(storeConn.insertWorkloadRecord(any())).thenReturn(true);
    Date d = new Date();
    assertTrue(instance.insertWorkloadRecord(ZTSTestUtils.createWorkloadRecord(d, d, "aws", "i-123", "test-host1.corp.yahoo.com", "10.0.0.1", "athenz.api", d)));
    instance.shutdown();
}
Also used : WorkloadRecordStore(com.yahoo.athenz.common.server.workload.WorkloadRecordStore) WorkloadRecordStoreConnection(com.yahoo.athenz.common.server.workload.WorkloadRecordStoreConnection) Test(org.testng.annotations.Test)

Example 2 with WorkloadRecordStore

use of com.yahoo.athenz.common.server.workload.WorkloadRecordStore in project athenz by yahoo.

the class InstanceCertManagerTest method testGetWorkloadsByIp.

@Test
public void testGetWorkloadsByIp() {
    InstanceCertManager instance = new InstanceCertManager(null, null, null, true, null);
    WorkloadRecordStore store = Mockito.mock(WorkloadRecordStore.class);
    instance.setWorkloadStore(store);
    WorkloadRecordStoreConnection storeConn = Mockito.mock(WorkloadRecordStoreConnection.class);
    Mockito.when(store.getConnection()).thenReturn(storeConn);
    long currTime = System.currentTimeMillis();
    Date d = new Date(currTime);
    WorkloadRecord w1 = ZTSTestUtils.createWorkloadRecord(d, d, "aws", "i-123", "test-host1.corp.yahoo.com", "10.0.0.1", "athenz.api", d);
    WorkloadRecord w5 = ZTSTestUtils.createWorkloadRecord(d, d, "aws", "i-123", "test-host2.corp.yahoo.com", "10.0.0.1", "athenz.secondapi", d);
    List<WorkloadRecord> workloadRecordList = new ArrayList<>();
    workloadRecordList.add(w1);
    workloadRecordList.add(w5);
    Mockito.when(storeConn.getWorkloadRecordsByIp(any())).thenReturn(workloadRecordList);
    List<Workload> workloadList = instance.getWorkloadsByIp("10.0.0.1");
    assertNotNull(workloadList);
    assertEquals(workloadList.size(), 2);
    List<String> expectedServices = workloadList.stream().map(Workload::getServiceName).collect(Collectors.toList());
    assertTrue(expectedServices.contains("api"));
    assertTrue(expectedServices.contains("secondapi"));
    instance.shutdown();
}
Also used : WorkloadRecordStore(com.yahoo.athenz.common.server.workload.WorkloadRecordStore) WorkloadRecordStoreConnection(com.yahoo.athenz.common.server.workload.WorkloadRecordStoreConnection) WorkloadRecord(com.yahoo.athenz.common.server.workload.WorkloadRecord) Test(org.testng.annotations.Test)

Example 3 with WorkloadRecordStore

use of com.yahoo.athenz.common.server.workload.WorkloadRecordStore in project athenz by yahoo.

the class InstanceCertManagerTest method testGetWorkloadsByService.

@Test
public void testGetWorkloadsByService() {
    InstanceCertManager instance = new InstanceCertManager(null, null, null, true, null);
    WorkloadRecordStore store = Mockito.mock(WorkloadRecordStore.class);
    instance.setWorkloadStore(store);
    WorkloadRecordStoreConnection storeConn = Mockito.mock(WorkloadRecordStoreConnection.class);
    Mockito.when(store.getConnection()).thenReturn(storeConn);
    long currTime = System.currentTimeMillis();
    Date d = new Date(currTime);
    WorkloadRecord w1 = ZTSTestUtils.createWorkloadRecord(d, d, "aws", "i-123", "test-host1.corp.yahoo.com", "10.0.0.1", "athenz.api", d);
    WorkloadRecord w2 = ZTSTestUtils.createWorkloadRecord(d, d, "aws", "i-234", "test-host2.corp.yahoo.com", "10.0.0.2", "athenz.api", d);
    WorkloadRecord w3 = ZTSTestUtils.createWorkloadRecord(d, d, "aws", "i-234", "test-host2.corp.yahoo.com", "2001:0db8:85a3:0000:0000:8a2e:0370:7334", "athenz.api", d);
    List<WorkloadRecord> workloadRecordList = new ArrayList<>();
    workloadRecordList.add(w1);
    workloadRecordList.add(w2);
    workloadRecordList.add(w3);
    Mockito.when(storeConn.getWorkloadRecordsByService(any(), any())).thenReturn(workloadRecordList);
    List<Workload> workloadList = instance.getWorkloadsByService("athenz", "api");
    assertNotNull(workloadList);
    assertEquals(workloadList.size(), 2);
    instance.shutdown();
}
Also used : WorkloadRecordStore(com.yahoo.athenz.common.server.workload.WorkloadRecordStore) WorkloadRecordStoreConnection(com.yahoo.athenz.common.server.workload.WorkloadRecordStoreConnection) WorkloadRecord(com.yahoo.athenz.common.server.workload.WorkloadRecord) Test(org.testng.annotations.Test)

Example 4 with WorkloadRecordStore

use of com.yahoo.athenz.common.server.workload.WorkloadRecordStore in project athenz by yahoo.

the class InstanceCertManagerTest method testUpdateWorkloadRecord.

@Test
public void testUpdateWorkloadRecord() {
    InstanceCertManager instance = new InstanceCertManager(null, null, null, true, null);
    WorkloadRecordStore store = Mockito.mock(WorkloadRecordStore.class);
    instance.setWorkloadStore(store);
    WorkloadRecordStoreConnection storeConn = Mockito.mock(WorkloadRecordStoreConnection.class);
    Mockito.when(store.getConnection()).thenReturn(storeConn);
    Mockito.when(storeConn.updateWorkloadRecord(any())).thenReturn(true);
    Date d = new Date();
    assertTrue(instance.updateWorkloadRecord(ZTSTestUtils.createWorkloadRecord(d, d, "aws", "i-123", "test-host1.corp.yahoo.com", "10.0.0.1", "athenz.api", d)));
    Mockito.when(storeConn.updateWorkloadRecord(any())).thenReturn(false);
    Mockito.when(storeConn.insertWorkloadRecord(any())).thenReturn(true);
    assertTrue(instance.updateWorkloadRecord(ZTSTestUtils.createWorkloadRecord(d, d, "aws", "i-123", "test-host1.corp.yahoo.com", "10.0.0.1", "athenz.api", d)));
    instance.shutdown();
}
Also used : WorkloadRecordStore(com.yahoo.athenz.common.server.workload.WorkloadRecordStore) WorkloadRecordStoreConnection(com.yahoo.athenz.common.server.workload.WorkloadRecordStoreConnection) Test(org.testng.annotations.Test)

Example 5 with WorkloadRecordStore

use of com.yahoo.athenz.common.server.workload.WorkloadRecordStore in project athenz by yahoo.

the class DynamoDBWorkloadRecordStoreFactoryTest method testCreate.

@Test
public void testCreate() {
    System.setProperty(ZTSConsts.ZTS_PROP_WORKLOAD_DYNAMODB_TABLE_NAME, "Workload-Table");
    System.setProperty(ZTSConsts.ZTS_PROP_WORKLOAD_DYNAMODB_INDEX_SERVICE_NAME, "Workload-Service-Index");
    System.setProperty(ZTSConsts.ZTS_PROP_WORKLOAD_DYNAMODB_INDEX_IP_NAME, "Workload-Ip-Index");
    PrivateKeyStore keyStore = Mockito.mock(PrivateKeyStore.class);
    DynamoDBWorkloadRecordStoreFactoryTest.TestDynamoDBWorkloadRecordStoreFactory factory = new DynamoDBWorkloadRecordStoreFactoryTest.TestDynamoDBWorkloadRecordStoreFactory();
    WorkloadRecordStore store = factory.create(keyStore);
    Assert.assertNotNull(store);
    System.clearProperty(ZTSConsts.ZTS_PROP_WORKLOAD_DYNAMODB_TABLE_NAME);
    System.clearProperty(ZTSConsts.ZTS_PROP_WORKLOAD_DYNAMODB_INDEX_SERVICE_NAME);
    System.clearProperty(ZTSConsts.ZTS_PROP_WORKLOAD_DYNAMODB_INDEX_IP_NAME);
}
Also used : PrivateKeyStore(com.yahoo.athenz.auth.PrivateKeyStore) WorkloadRecordStore(com.yahoo.athenz.common.server.workload.WorkloadRecordStore) Test(org.testng.annotations.Test)

Aggregations

WorkloadRecordStore (com.yahoo.athenz.common.server.workload.WorkloadRecordStore)7 Test (org.testng.annotations.Test)7 WorkloadRecordStoreConnection (com.yahoo.athenz.common.server.workload.WorkloadRecordStoreConnection)4 PrivateKeyStore (com.yahoo.athenz.auth.PrivateKeyStore)3 WorkloadRecord (com.yahoo.athenz.common.server.workload.WorkloadRecord)2 File (java.io.File)1