use of com.yahoo.athenz.common.server.workload.WorkloadRecord in project athenz by yahoo.
the class DynamoDBWorkloadRecordStoreConnectionTest method testGetWorkloadRecordsByIpNotFoundException.
@Test
public void testGetWorkloadRecordsByIpNotFoundException() {
Mockito.doThrow(new AmazonDynamoDBException("item not found")).when(ipIndex).query(Mockito.any(QuerySpec.class));
DynamoDBWorkloadRecordStoreConnection dbConn = getDBConnection();
List<WorkloadRecord> wlRecordList = dbConn.getWorkloadRecordsByIp("10.0.0.1");
Assert.assertTrue(wlRecordList.isEmpty());
dbConn.close();
}
use of com.yahoo.athenz.common.server.workload.WorkloadRecord in project athenz by yahoo.
the class DynamoDBWorkloadRecordStoreConnectionTest method testInsertWorkloadRecord.
@Test
public void testInsertWorkloadRecord() {
DynamoDBWorkloadRecordStoreConnection dbConn = getDBConnection();
WorkloadRecord workloadRecord = new WorkloadRecord();
workloadRecord.setInstanceId("1234");
workloadRecord.setService("athenz.api");
workloadRecord.setProvider("openstack");
workloadRecord.setIp("10.0.0.1");
workloadRecord.setHostname("test-host.corp.yahoo.com");
long currTime = System.currentTimeMillis();
Date currDate = new Date(currTime);
workloadRecord.setCreationTime(currDate);
workloadRecord.setUpdateTime(currDate);
Item item = ItemUtils.toItem(ZTSTestUtils.generateWorkloadAttributeValues("athenz.api", "1234", "opensack", "10.0.0.1", "test-host.corp.yahoo.com", Long.toString(currTime), Long.toString(currTime), Long.toString(currTime)));
Mockito.doReturn(putOutcome).when(table).putItem(item);
boolean requestSuccess = dbConn.insertWorkloadRecord(workloadRecord);
Assert.assertTrue(requestSuccess);
dbConn.close();
}
use of com.yahoo.athenz.common.server.workload.WorkloadRecord in project athenz by yahoo.
the class JDBCWorkloadRecordStoreConnectionTest method testInsertWorkloadRecordException.
@Test
public void testInsertWorkloadRecordException() throws Exception {
JDBCWorkloadRecordStoreConnection jdbcConn = new JDBCWorkloadRecordStoreConnection(mockConn);
Date now = new Date();
WorkloadRecord workloadRecord = getRecordWithNonNullableColumns(now);
Mockito.when(mockPrepStmt.executeUpdate()).thenThrow(new SQLException("sql error"));
try {
jdbcConn.insertWorkloadRecord(workloadRecord);
fail();
} catch (RuntimeException se) {
assertTrue(se.getMessage().contains("sql error"));
}
jdbcConn.close();
}
use of com.yahoo.athenz.common.server.workload.WorkloadRecord in project athenz by yahoo.
the class JDBCWorkloadRecordStoreConnectionTest method testGetWorkloadRecordsByIp.
@Test
public void testGetWorkloadRecordsByIp() throws Exception {
Date now = new Date();
Mockito.when(mockResultSet.next()).thenReturn(true, false);
mockNonNullableColumns(now);
Mockito.doReturn("athenz.api").when(mockResultSet).getString(JDBCWorkloadRecordStoreConnection.DB_COLUMN_SERVICE);
JDBCWorkloadRecordStoreConnection jdbcConn = new JDBCWorkloadRecordStoreConnection(mockConn);
List<WorkloadRecord> workloadRecordList = jdbcConn.getWorkloadRecordsByIp("10.0.0.1");
assertNotNull(workloadRecordList);
assertNonNullableColumns(now, workloadRecordList.get(0));
assertEquals(workloadRecordList.get(0).getService(), "athenz.api");
jdbcConn.close();
}
use of com.yahoo.athenz.common.server.workload.WorkloadRecord in project athenz by yahoo.
the class JDBCWorkloadRecordStoreConnectionTest method testUpdateWorkloadRecordException.
@Test
public void testUpdateWorkloadRecordException() throws Exception {
JDBCWorkloadRecordStoreConnection jdbcConn = new JDBCWorkloadRecordStoreConnection(mockConn);
Date now = new Date();
WorkloadRecord workloadRecord = getRecordWithNonNullableColumns(now);
Mockito.when(mockPrepStmt.executeUpdate()).thenThrow(new SQLException("sql error"));
try {
jdbcConn.updateWorkloadRecord(workloadRecord);
fail();
} catch (RuntimeException se) {
assertTrue(se.getMessage().contains("sql error"));
}
jdbcConn.close();
}
Aggregations