Search in sources :

Example 11 with WorkloadRecord

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();
}
Also used : AmazonDynamoDBException(com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException) QuerySpec(com.amazonaws.services.dynamodbv2.document.spec.QuerySpec) WorkloadRecord(com.yahoo.athenz.common.server.workload.WorkloadRecord) Test(org.testng.annotations.Test)

Example 12 with WorkloadRecord

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();
}
Also used : WorkloadRecord(com.yahoo.athenz.common.server.workload.WorkloadRecord) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 13 with WorkloadRecord

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();
}
Also used : Date(java.util.Date) WorkloadRecord(com.yahoo.athenz.common.server.workload.WorkloadRecord) Test(org.testng.annotations.Test)

Example 14 with WorkloadRecord

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();
}
Also used : Date(java.util.Date) WorkloadRecord(com.yahoo.athenz.common.server.workload.WorkloadRecord) Test(org.testng.annotations.Test)

Example 15 with WorkloadRecord

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();
}
Also used : Date(java.util.Date) WorkloadRecord(com.yahoo.athenz.common.server.workload.WorkloadRecord) Test(org.testng.annotations.Test)

Aggregations

WorkloadRecord (com.yahoo.athenz.common.server.workload.WorkloadRecord)27 Test (org.testng.annotations.Test)18 Date (java.util.Date)12 QuerySpec (com.amazonaws.services.dynamodbv2.document.spec.QuerySpec)4 AmazonDynamoDBException (com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException)4 WorkloadRecordStore (com.yahoo.athenz.common.server.workload.WorkloadRecordStore)3 WorkloadRecordStoreConnection (com.yahoo.athenz.common.server.workload.WorkloadRecordStoreConnection)3 UpdateItemSpec (com.amazonaws.services.dynamodbv2.document.spec.UpdateItemSpec)2 java.sql (java.sql)2 ArrayList (java.util.ArrayList)2 DeserializationFeature (com.fasterxml.jackson.databind.DeserializationFeature)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 InetAddresses (com.google.common.net.InetAddresses)1 Authority (com.yahoo.athenz.auth.Authority)1 Authorizer (com.yahoo.athenz.auth.Authorizer)1 Principal (com.yahoo.athenz.auth.Principal)1 PrivateKeyStore (com.yahoo.athenz.auth.PrivateKeyStore)1 AthenzUtils (com.yahoo.athenz.auth.util.AthenzUtils)1 Crypto (com.yahoo.athenz.auth.util.Crypto)1 CryptoException (com.yahoo.athenz.auth.util.CryptoException)1