Search in sources :

Example 6 with EmrDao

use of org.finra.herd.dao.EmrDao in project herd by FINRAOS.

the class EmrHelperTest method testGetActiveEmrClusterIdAssertReturnActualClusterIdWhenClusterStateActiveAndNameNotSpecified.

@Test
public void testGetActiveEmrClusterIdAssertReturnActualClusterIdWhenClusterStateActiveAndNameNotSpecified() {
    EmrDao originalEmrDao = emrHelper.getEmrDao();
    EmrDao mockEmrDao = mock(EmrDao.class);
    emrHelper.setEmrDao(mockEmrDao);
    try {
        String emrClusterId = "emrClusterId";
        String emrClusterName = null;
        String expectedEmrClusterId = "expectedEmrClusterId";
        String actualEmrClusterName = "actualEmrClusterName";
        when(mockEmrDao.getEmrClusterById(any(), any())).thenReturn(new Cluster().withId(expectedEmrClusterId).withName(actualEmrClusterName).withStatus(new ClusterStatus().withState(ClusterState.RUNNING)));
        assertEquals(expectedEmrClusterId, emrHelper.getActiveEmrClusterId(emrClusterId, emrClusterName, null));
        verify(mockEmrDao).getEmrClusterById(eq(emrClusterId), any());
        verifyNoMoreInteractions(mockEmrDao);
    } finally {
        emrHelper.setEmrDao(originalEmrDao);
    }
}
Also used : Cluster(com.amazonaws.services.elasticmapreduce.model.Cluster) EmrDao(org.finra.herd.dao.EmrDao) ClusterStatus(com.amazonaws.services.elasticmapreduce.model.ClusterStatus) Test(org.junit.Test) AbstractDaoTest(org.finra.herd.dao.AbstractDaoTest)

Example 7 with EmrDao

use of org.finra.herd.dao.EmrDao in project herd by FINRAOS.

the class EmrHelperTest method testGetActiveEmrClusterIdAssertErrorWhenClusterIdSpecifiedAndNameMismatch.

@Test
public void testGetActiveEmrClusterIdAssertErrorWhenClusterIdSpecifiedAndNameMismatch() {
    EmrDao originalEmrDao = emrHelper.getEmrDao();
    EmrDao mockEmrDao = mock(EmrDao.class);
    emrHelper.setEmrDao(mockEmrDao);
    try {
        String emrClusterId = "emrClusterId";
        String emrClusterName = "emrClusterName";
        String expectedEmrClusterId = "expectedEmrClusterId";
        String actualEmrClusterName = "actualEmrClusterName";
        when(mockEmrDao.getEmrClusterById(any(), any())).thenReturn(new Cluster().withId(expectedEmrClusterId).withName(actualEmrClusterName).withStatus(new ClusterStatus().withState(ClusterState.RUNNING)));
        try {
            emrHelper.getActiveEmrClusterId(emrClusterId, emrClusterName, null);
            fail();
        } catch (IllegalArgumentException e) {
            assertEquals(String.format("The cluster with ID \"%s\" does not match the expected name \"%s\". The actual name is \"%s\".", expectedEmrClusterId, emrClusterName, actualEmrClusterName), e.getMessage());
        }
        verify(mockEmrDao).getEmrClusterById(eq(emrClusterId.trim()), any());
        verifyNoMoreInteractions(mockEmrDao);
    } finally {
        emrHelper.setEmrDao(originalEmrDao);
    }
}
Also used : Cluster(com.amazonaws.services.elasticmapreduce.model.Cluster) EmrDao(org.finra.herd.dao.EmrDao) ClusterStatus(com.amazonaws.services.elasticmapreduce.model.ClusterStatus) Test(org.junit.Test) AbstractDaoTest(org.finra.herd.dao.AbstractDaoTest)

Example 8 with EmrDao

use of org.finra.herd.dao.EmrDao in project herd by FINRAOS.

the class EmrHelperTest method testGetActiveEmrClusterIdAssertParametersTrimmed.

@Test
public void testGetActiveEmrClusterIdAssertParametersTrimmed() {
    EmrDao originalEmrDao = emrHelper.getEmrDao();
    EmrDao mockEmrDao = mock(EmrDao.class);
    emrHelper.setEmrDao(mockEmrDao);
    try {
        String emrClusterId = "emrClusterId";
        String emrClusterName = "emrClusterName";
        String expectedEmrClusterId = "expectedEmrClusterId";
        when(mockEmrDao.getEmrClusterById(any(), any())).thenReturn(new Cluster().withId(expectedEmrClusterId).withName(emrClusterName).withStatus(new ClusterStatus().withState(ClusterState.RUNNING)));
        assertEquals(expectedEmrClusterId, emrHelper.getActiveEmrClusterId(StringUtils.wrap(emrClusterId, BLANK_TEXT), StringUtils.wrap(emrClusterName, BLANK_TEXT), null));
        verify(mockEmrDao).getEmrClusterById(eq(emrClusterId.trim()), any());
        verifyNoMoreInteractions(mockEmrDao);
    } finally {
        emrHelper.setEmrDao(originalEmrDao);
    }
}
Also used : Cluster(com.amazonaws.services.elasticmapreduce.model.Cluster) EmrDao(org.finra.herd.dao.EmrDao) ClusterStatus(com.amazonaws.services.elasticmapreduce.model.ClusterStatus) Test(org.junit.Test) AbstractDaoTest(org.finra.herd.dao.AbstractDaoTest)

Example 9 with EmrDao

use of org.finra.herd.dao.EmrDao in project herd by FINRAOS.

the class EmrHelperTest method testGetActiveEmrClusterIdNoIdSpecifiedAssertReturnActualClusterId.

@Test
public void testGetActiveEmrClusterIdNoIdSpecifiedAssertReturnActualClusterId() {
    EmrDao originalEmrDao = emrHelper.getEmrDao();
    EmrDao mockEmrDao = mock(EmrDao.class);
    emrHelper.setEmrDao(mockEmrDao);
    try {
        String emrClusterId = null;
        String emrClusterName = "emrClusterName";
        String expectedEmrClusterId = "expectedEmrClusterId";
        when(mockEmrDao.getActiveEmrClusterByName(any(), any())).thenReturn(new ClusterSummary().withId(expectedEmrClusterId).withName(emrClusterName));
        assertEquals(expectedEmrClusterId, emrHelper.getActiveEmrClusterId(emrClusterId, emrClusterName, null));
        verify(mockEmrDao).getActiveEmrClusterByName(eq(emrClusterName), any());
        verifyNoMoreInteractions(mockEmrDao);
    } finally {
        emrHelper.setEmrDao(originalEmrDao);
    }
}
Also used : ClusterSummary(com.amazonaws.services.elasticmapreduce.model.ClusterSummary) EmrDao(org.finra.herd.dao.EmrDao) Test(org.junit.Test) AbstractDaoTest(org.finra.herd.dao.AbstractDaoTest)

Example 10 with EmrDao

use of org.finra.herd.dao.EmrDao in project herd by FINRAOS.

the class EmrHelperTest method testGetActiveEmrClusterIdAssertErrorWhenClusterIdSpecifiedAndClusterStateNotActive.

@Test
public void testGetActiveEmrClusterIdAssertErrorWhenClusterIdSpecifiedAndClusterStateNotActive() {
    EmrDao originalEmrDao = emrHelper.getEmrDao();
    EmrDao mockEmrDao = mock(EmrDao.class);
    emrHelper.setEmrDao(mockEmrDao);
    try {
        String emrClusterId = "emrClusterId";
        String emrClusterName = "emrClusterName";
        String expectedEmrClusterId = "expectedEmrClusterId";
        ClusterState actualClusterState = ClusterState.TERMINATED;
        when(mockEmrDao.getEmrClusterById(any(), any())).thenReturn(new Cluster().withId(expectedEmrClusterId).withName(emrClusterName).withStatus(new ClusterStatus().withState(actualClusterState)));
        try {
            emrHelper.getActiveEmrClusterId(emrClusterId, emrClusterName, null);
            fail();
        } catch (IllegalArgumentException e) {
            assertEquals(String.format("The cluster with ID \"%s\" is not active. The cluster state must be in one of [STARTING, BOOTSTRAPPING, RUNNING, " + "WAITING]. Current state is \"%s\"", emrClusterId, actualClusterState), e.getMessage());
        }
        verify(mockEmrDao).getEmrClusterById(eq(emrClusterId), any());
        verifyNoMoreInteractions(mockEmrDao);
    } finally {
        emrHelper.setEmrDao(originalEmrDao);
    }
}
Also used : ClusterState(com.amazonaws.services.elasticmapreduce.model.ClusterState) Cluster(com.amazonaws.services.elasticmapreduce.model.Cluster) EmrDao(org.finra.herd.dao.EmrDao) ClusterStatus(com.amazonaws.services.elasticmapreduce.model.ClusterStatus) Test(org.junit.Test) AbstractDaoTest(org.finra.herd.dao.AbstractDaoTest)

Aggregations

EmrDao (org.finra.herd.dao.EmrDao)11 Test (org.junit.Test)11 AbstractDaoTest (org.finra.herd.dao.AbstractDaoTest)10 Cluster (com.amazonaws.services.elasticmapreduce.model.Cluster)6 ClusterStatus (com.amazonaws.services.elasticmapreduce.model.ClusterStatus)6 ClusterState (com.amazonaws.services.elasticmapreduce.model.ClusterState)1 ClusterSummary (com.amazonaws.services.elasticmapreduce.model.ClusterSummary)1 EmrHelper (org.finra.herd.dao.helper.EmrHelper)1 AwsParamsDto (org.finra.herd.model.dto.AwsParamsDto)1 EmrClusterAlternateKeyDto (org.finra.herd.model.dto.EmrClusterAlternateKeyDto)1 EmrClusterDefinitionEntity (org.finra.herd.model.jpa.EmrClusterDefinitionEntity)1 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)1 AlternateKeyHelper (org.finra.herd.service.helper.AlternateKeyHelper)1 EmrClusterDefinitionDaoHelper (org.finra.herd.service.helper.EmrClusterDefinitionDaoHelper)1 NamespaceDaoHelper (org.finra.herd.service.helper.NamespaceDaoHelper)1 EmrServiceImpl (org.finra.herd.service.impl.EmrServiceImpl)1