Search in sources :

Example 1 with Ec2DaoImpl

use of org.finra.herd.dao.impl.Ec2DaoImpl in project herd by FINRAOS.

the class Ec2DaoTest method testGetLatestSpotPricesAssertConstructsCorrectDescribeSpotPriceHistoryRequest.

@Test
public void testGetLatestSpotPricesAssertConstructsCorrectDescribeSpotPriceHistoryRequest() {
    // Initialize inputs.
    String availabilityZone = "a";
    Collection<String> instanceTypes = Arrays.asList("a", "b", "c");
    Collection<String> productDescriptions = Arrays.asList("b", "c", "d");
    // Set up mock.
    mock(RetryPolicyFactory.class);
    Ec2Operations ec2Operations = mock(Ec2Operations.class);
    ((Ec2DaoImpl) ec2Dao).setEc2Operations(ec2Operations);
    DescribeSpotPriceHistoryResult describeSpotPriceHistoryResult = new DescribeSpotPriceHistoryResult();
    when(ec2Operations.describeSpotPriceHistory(any(), any())).thenReturn(describeSpotPriceHistoryResult);
    // Execute MUT.
    ec2Dao.getLatestSpotPrices(availabilityZone, instanceTypes, productDescriptions, new AwsParamsDto());
    // Verify that the dependency was called with the correct parameters.
    verify(ec2Operations).describeSpotPriceHistory(any(), equalsDescribeSpotPriceHistoryRequest(availabilityZone, instanceTypes, productDescriptions));
}
Also used : DescribeSpotPriceHistoryResult(com.amazonaws.services.ec2.model.DescribeSpotPriceHistoryResult) AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) Ec2DaoImpl(org.finra.herd.dao.impl.Ec2DaoImpl) Test(org.junit.Test)

Example 2 with Ec2DaoImpl

use of org.finra.herd.dao.impl.Ec2DaoImpl in project herd by FINRAOS.

the class Ec2DaoTest method testGetLatestSpotPricesSpotPriceHistoryContainDuplicateTypeInstances.

@Test
public void testGetLatestSpotPricesSpotPriceHistoryContainDuplicateTypeInstances() {
    // Initialize inputs.
    Collection<String> instanceTypes = Arrays.asList(MockEc2OperationsImpl.INSTANCE_TYPE_1, MockEc2OperationsImpl.INSTANCE_TYPE_2);
    Collection<String> productDescriptions = Arrays.asList("b", "c");
    // Set up mock.
    mock(RetryPolicyFactory.class);
    Ec2Operations ec2Operations = mock(Ec2Operations.class);
    ((Ec2DaoImpl) ec2Dao).setEc2Operations(ec2Operations);
    DescribeSpotPriceHistoryResult describeSpotPriceHistoryResult = new DescribeSpotPriceHistoryResult();
    List<SpotPrice> spotPrices = new ArrayList<>();
    spotPrices.add(new MockSpotPrice(MockEc2OperationsImpl.INSTANCE_TYPE_1, MockEc2OperationsImpl.AVAILABILITY_ZONE_1, MockEc2OperationsImpl.SPOT_PRICE_HIGH).toAwsObject());
    spotPrices.add(new MockSpotPrice(MockEc2OperationsImpl.INSTANCE_TYPE_1, MockEc2OperationsImpl.AVAILABILITY_ZONE_2, MockEc2OperationsImpl.SPOT_PRICE_HIGH).toAwsObject());
    describeSpotPriceHistoryResult.setSpotPriceHistory(spotPrices);
    when(ec2Operations.describeSpotPriceHistory(any(), any())).thenReturn(describeSpotPriceHistoryResult);
    // Execute MUT.
    List<SpotPrice> result = ec2Dao.getLatestSpotPrices(MockEc2OperationsImpl.AVAILABILITY_ZONE_1, instanceTypes, productDescriptions, new AwsParamsDto());
    // Verify that the dependency was called with the correct parameters.
    verify(ec2Operations).describeSpotPriceHistory(any(), equalsDescribeSpotPriceHistoryRequest(MockEc2OperationsImpl.AVAILABILITY_ZONE_1, instanceTypes, productDescriptions));
    // Verify that result contains only one spot price entry.
    assertEquals(1, CollectionUtils.size(result));
}
Also used : DescribeSpotPriceHistoryResult(com.amazonaws.services.ec2.model.DescribeSpotPriceHistoryResult) MockSpotPrice(org.finra.herd.dao.impl.MockSpotPrice) SpotPrice(com.amazonaws.services.ec2.model.SpotPrice) AwsParamsDto(org.finra.herd.model.dto.AwsParamsDto) Ec2DaoImpl(org.finra.herd.dao.impl.Ec2DaoImpl) MockSpotPrice(org.finra.herd.dao.impl.MockSpotPrice) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

DescribeSpotPriceHistoryResult (com.amazonaws.services.ec2.model.DescribeSpotPriceHistoryResult)2 Ec2DaoImpl (org.finra.herd.dao.impl.Ec2DaoImpl)2 AwsParamsDto (org.finra.herd.model.dto.AwsParamsDto)2 Test (org.junit.Test)2 SpotPrice (com.amazonaws.services.ec2.model.SpotPrice)1 ArrayList (java.util.ArrayList)1 MockSpotPrice (org.finra.herd.dao.impl.MockSpotPrice)1