use of com.amazonaws.services.elasticmapreduce.AmazonElasticMapReduceClient in project herd by FINRAOS.
the class EmrDaoImplTest method testGetListInstanceFleetsResult.
@Test
public void testGetListInstanceFleetsResult() {
// Create an AWS parameters DTO.
AwsParamsDto awsParamsDto = new AwsParamsDto(AWS_ASSUMED_ROLE_ACCESS_KEY, AWS_ASSUMED_ROLE_SECRET_KEY, AWS_ASSUMED_ROLE_SESSION_TOKEN, HTTP_PROXY_HOST, HTTP_PROXY_PORT);
// Create a mock AmazonElasticMapReduceClient.
AmazonElasticMapReduceClient amazonElasticMapReduceClient = mock(AmazonElasticMapReduceClient.class);
// Create a list instance fleets request.
ListInstanceFleetsRequest listInstanceFleetsRequest = new ListInstanceFleetsRequest().withClusterId(EMR_CLUSTER_ID);
// Create a list instance fleets result.
ListInstanceFleetsResult listInstanceFleetsResult = new ListInstanceFleetsResult().withMarker(MARKER);
// Mock the external calls.
when(awsClientFactory.getEmrClient(awsParamsDto)).thenReturn(amazonElasticMapReduceClient);
when(emrOperations.listInstanceFleets(amazonElasticMapReduceClient, listInstanceFleetsRequest)).thenReturn(listInstanceFleetsResult);
// Call the method under test.
ListInstanceFleetsResult result = emrDaoImpl.getListInstanceFleetsResult(EMR_CLUSTER_ID, awsParamsDto);
// Verify the external calls.
verify(awsClientFactory).getEmrClient(awsParamsDto);
verify(emrOperations).listInstanceFleets(amazonElasticMapReduceClient, listInstanceFleetsRequest);
verifyNoMoreInteractionsHelper();
// Validate the results.
assertEquals(listInstanceFleetsResult, result);
}
use of com.amazonaws.services.elasticmapreduce.AmazonElasticMapReduceClient in project herd by FINRAOS.
the class EmrDaoImplTest method testGetActiveEmrClusterByName.
@Test
public void testGetActiveEmrClusterByName() {
// Create an AWS parameters DTO.
AwsParamsDto awsParamsDto = new AwsParamsDto(AWS_ASSUMED_ROLE_ACCESS_KEY, AWS_ASSUMED_ROLE_SECRET_KEY, AWS_ASSUMED_ROLE_SESSION_TOKEN, HTTP_PROXY_HOST, HTTP_PROXY_PORT);
// Create a mock AmazonElasticMapReduceClient.
AmazonElasticMapReduceClient amazonElasticMapReduceClient = mock(AmazonElasticMapReduceClient.class);
// Create a list cluster request.
ListClustersRequest listClustersRequest = new ListClustersRequest().withClusterStates(EMR_VALID_STATE);
// Create a list cluster result with a non-matching cluster and a marker.
ListClustersResult listClusterResultWithMarker = new ListClustersResult().withClusters(new ClusterSummary().withName(INVALID_VALUE)).withMarker(MARKER);
// Create a list cluster request with marker.
ListClustersRequest listClustersRequestWithMarker = new ListClustersRequest().withClusterStates(EMR_VALID_STATE).withMarker(MARKER);
// Create a cluster summary.
ClusterSummary clusterSummary = new ClusterSummary().withName(EMR_CLUSTER_NAME);
// Create a list cluster result with the matching cluster.
ListClustersResult listClusterResult = new ListClustersResult().withClusters(clusterSummary);
// Mock the external calls.
when(configurationHelper.getProperty(ConfigurationValue.EMR_VALID_STATES)).thenReturn(EMR_VALID_STATE);
when(configurationHelper.getProperty(ConfigurationValue.FIELD_DATA_DELIMITER)).thenReturn((String) ConfigurationValue.FIELD_DATA_DELIMITER.getDefaultValue());
when(awsClientFactory.getEmrClient(awsParamsDto)).thenReturn(amazonElasticMapReduceClient);
when(emrOperations.listEmrClusters(amazonElasticMapReduceClient, listClustersRequest)).thenReturn(listClusterResultWithMarker);
when(emrOperations.listEmrClusters(amazonElasticMapReduceClient, listClustersRequestWithMarker)).thenReturn(listClusterResult);
// Call the method under test.
ClusterSummary result = emrDaoImpl.getActiveEmrClusterByName(EMR_CLUSTER_NAME, awsParamsDto);
// Verify the external calls.
verify(configurationHelper).getProperty(ConfigurationValue.EMR_VALID_STATES);
verify(configurationHelper).getProperty(ConfigurationValue.FIELD_DATA_DELIMITER);
verify(awsClientFactory, times(2)).getEmrClient(awsParamsDto);
verify(emrOperations, times(2)).listEmrClusters(eq(amazonElasticMapReduceClient), any(ListClustersRequest.class));
verifyNoMoreInteractionsHelper();
// Validate the results.
assertEquals(clusterSummary, result);
}
use of com.amazonaws.services.elasticmapreduce.AmazonElasticMapReduceClient in project herd by FINRAOS.
the class EmrDaoTest method getEmrClientAssertClientConfigurationNotSetWhenProxyPortIsNull.
@Test
public void getEmrClientAssertClientConfigurationNotSetWhenProxyPortIsNull() throws Exception {
String httpProxyHost = "httpProxyHost";
Integer httpProxyPort = null;
AwsParamsDto awsParamsDto = new AwsParamsDto();
awsParamsDto.setHttpProxyHost(httpProxyHost);
awsParamsDto.setHttpProxyPort(httpProxyPort);
AmazonElasticMapReduceClient amazonElasticMapReduceClient = emrDao.getEmrClient(awsParamsDto);
ClientConfiguration clientConfiguration = (ClientConfiguration) ReflectionTestUtils.getField(amazonElasticMapReduceClient, "clientConfiguration");
assertNotNull(clientConfiguration);
assertNull(clientConfiguration.getProxyHost());
}
use of com.amazonaws.services.elasticmapreduce.AmazonElasticMapReduceClient in project herd by FINRAOS.
the class EmrDaoTest method getEmrClientAssertClientConfigurationSet.
@Test
public void getEmrClientAssertClientConfigurationSet() throws Exception {
String httpProxyHost = "httpProxyHost";
Integer httpProxyPort = 1234;
AwsParamsDto awsParamsDto = new AwsParamsDto();
awsParamsDto.setHttpProxyHost(httpProxyHost);
awsParamsDto.setHttpProxyPort(httpProxyPort);
AmazonElasticMapReduceClient amazonElasticMapReduceClient = emrDao.getEmrClient(awsParamsDto);
ClientConfiguration clientConfiguration = (ClientConfiguration) ReflectionTestUtils.getField(amazonElasticMapReduceClient, "clientConfiguration");
assertNotNull(clientConfiguration);
assertEquals(httpProxyHost, clientConfiguration.getProxyHost());
assertEquals(httpProxyPort.intValue(), clientConfiguration.getProxyPort());
}
use of com.amazonaws.services.elasticmapreduce.AmazonElasticMapReduceClient in project herd by FINRAOS.
the class AwsClientFactoryTest method testGetEmrClientCacheHitMiss.
@Test
public void testGetEmrClientCacheHitMiss() {
// Create an AWS parameters DTO that contains both AWS credentials and proxy information.
AwsParamsDto awsParamsDto = new AwsParamsDto(AWS_ASSUMED_ROLE_ACCESS_KEY, AWS_ASSUMED_ROLE_SECRET_KEY, AWS_ASSUMED_ROLE_SESSION_TOKEN, HTTP_PROXY_HOST, HTTP_PROXY_PORT);
// Get an Amazon EMR client.
AmazonElasticMapReduceClient amazonElasticMapReduceClient = awsClientFactory.getEmrClient(awsParamsDto);
// Confirm a cache hit.
assertEquals(amazonElasticMapReduceClient, awsClientFactory.getEmrClient(new AwsParamsDto(AWS_ASSUMED_ROLE_ACCESS_KEY, AWS_ASSUMED_ROLE_SECRET_KEY, AWS_ASSUMED_ROLE_SESSION_TOKEN, HTTP_PROXY_HOST, HTTP_PROXY_PORT)));
// Confirm a cache miss due to AWS credentials.
assertNotEquals(amazonElasticMapReduceClient, awsClientFactory.getEmrClient(new AwsParamsDto(AWS_ASSUMED_ROLE_ACCESS_KEY_2, AWS_ASSUMED_ROLE_SECRET_KEY_2, AWS_ASSUMED_ROLE_SESSION_TOKEN_2, HTTP_PROXY_HOST, HTTP_PROXY_PORT)));
// Confirm a cache miss due to http proxy information.
assertNotEquals(amazonElasticMapReduceClient, awsClientFactory.getEmrClient(new AwsParamsDto(AWS_ASSUMED_ROLE_ACCESS_KEY, AWS_ASSUMED_ROLE_SECRET_KEY, AWS_ASSUMED_ROLE_SESSION_TOKEN, HTTP_PROXY_HOST_2, HTTP_PROXY_PORT_2)));
// Clear the cache.
cacheManager.getCache(DaoSpringModuleConfig.HERD_CACHE_NAME).clear();
// Confirm a cache miss due to cleared cache.
assertNotEquals(amazonElasticMapReduceClient, awsClientFactory.getEmrClient(awsParamsDto));
}
Aggregations