use of com.yahoo.athenz.common.server.workload.WorkloadRecord in project athenz by yahoo.
the class JDBCWorkloadRecordStoreConnectionTest method testGetWorkloadRecordsByService.
@Test
public void testGetWorkloadRecordsByService() throws Exception {
Date now = new Date();
Mockito.when(mockResultSet.next()).thenReturn(true, false);
mockNonNullableColumns(now);
Mockito.doReturn("10.0.0.1").when(mockResultSet).getString(JDBCWorkloadRecordStoreConnection.DB_COLUMN_IP);
JDBCWorkloadRecordStoreConnection jdbcConn = new JDBCWorkloadRecordStoreConnection(mockConn);
List<WorkloadRecord> workloadRecordList = jdbcConn.getWorkloadRecordsByService("athenz", "api");
assertNotNull(workloadRecordList);
assertNonNullableColumns(now, workloadRecordList.get(0));
assertEquals(workloadRecordList.get(0).getIp(), "10.0.0.1");
jdbcConn.close();
}
use of com.yahoo.athenz.common.server.workload.WorkloadRecord in project athenz by yahoo.
the class FileWorkloadRecordStoreConnectionTest method testWorkloadOperations.
@Test
public void testWorkloadOperations() {
ZTSTestUtils.deleteDirectory(new File("/tmp/zts-workload-tests"));
File rootDir = new File("/tmp/zts-workload-tests");
rootDir.deleteOnExit();
FileWorkloadRecordStore store = new FileWorkloadRecordStore(rootDir);
FileWorkloadRecordStoreConnection con = (FileWorkloadRecordStoreConnection) store.getConnection();
assertNotNull(con);
con.setOperationTimeout(10);
// first verify that we don't have the entry
List<WorkloadRecord> wlRecordCheck = con.getWorkloadRecordsByService("athenz", "api");
assertTrue(wlRecordCheck.isEmpty());
WorkloadRecord workloadRecord = new WorkloadRecord();
Date now = new Date();
workloadRecord.setService("athenz.api");
workloadRecord.setProvider("openstack");
workloadRecord.setInstanceId("instance-id");
workloadRecord.setIp("10.0.0.1");
workloadRecord.setHostname("test-host.corp.yahoo.com");
workloadRecord.setCreationTime(now);
workloadRecord.setUpdateTime(now);
boolean result = con.insertWorkloadRecord(workloadRecord);
assertTrue(result);
wlRecordCheck = con.getWorkloadRecordsByService("athenz", "api");
assertNotNull(wlRecordCheck);
assertEquals(wlRecordCheck.get(0).getProvider(), "openstack");
assertEquals(wlRecordCheck.get(0).getInstanceId(), "instance-id");
assertEquals(wlRecordCheck.get(0).getIp(), "10.0.0.1");
assertEquals(wlRecordCheck.get(0).getHostname(), "test-host.corp.yahoo.com");
assertEquals(wlRecordCheck.get(0).getCreationTime().getTime(), now.getTime());
assertEquals(wlRecordCheck.get(0).getUpdateTime().getTime(), now.getTime());
wlRecordCheck = con.getWorkloadRecordsByIp("10.0.0.1");
assertNotNull(wlRecordCheck);
assertEquals(wlRecordCheck.get(0).getProvider(), "openstack");
assertEquals(wlRecordCheck.get(0).getInstanceId(), "instance-id");
assertEquals(wlRecordCheck.get(0).getService(), "athenz.api");
assertEquals(wlRecordCheck.get(0).getHostname(), "test-host.corp.yahoo.com");
assertEquals(wlRecordCheck.get(0).getCreationTime().getTime(), now.getTime());
assertEquals(wlRecordCheck.get(0).getUpdateTime().getTime(), now.getTime());
workloadRecord.setProvider("kubernetes");
result = con.updateWorkloadRecord(workloadRecord);
assertTrue(result);
wlRecordCheck = con.getWorkloadRecordsByIp("10.0.0.1");
assertNotNull(wlRecordCheck);
assertEquals(wlRecordCheck.get(0).getProvider(), "kubernetes");
assertTrue(con.getWorkloadRecordsByService("xyz", "abc").isEmpty());
assertTrue(con.getWorkloadRecordsByIp("172.10.0.131").isEmpty());
assertNull(con.getWorkloadRecord(new File("/proc/root")));
try {
con.writeWorkloadRecord(new File("/proc/root"), "xyz");
} catch (Exception ignored) {
fail();
}
con.close();
}
use of com.yahoo.athenz.common.server.workload.WorkloadRecord in project athenz by yahoo.
the class InstanceCertManagerTest method nullWorkloadsStoreTest.
@Test
public void nullWorkloadsStoreTest() {
InstanceCertManager instance = new InstanceCertManager(null, null, null, true, null);
instance.setWorkloadStore(null);
WorkloadRecord wlr = new WorkloadRecord();
assertFalse(instance.insertWorkloadRecord(wlr));
assertFalse(instance.updateWorkloadRecord(wlr));
instance.shutdown();
}
use of com.yahoo.athenz.common.server.workload.WorkloadRecord 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();
}
use of com.yahoo.athenz.common.server.workload.WorkloadRecord 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();
}
Aggregations