Search in sources :

Example 1 with ClusterIdEvaluatorContext

use of com.sequenceiq.periscope.monitor.context.ClusterIdEvaluatorContext in project cloudbreak by hortonworks.

the class CronTimeEvaluatorTest method testRunCallsFinished.

@Test
public void testRunCallsFinished() {
    underTest.setContext(new ClusterIdEvaluatorContext(CLUSTER_ID));
    when(clusterService.findById(anyLong())).thenThrow(new RuntimeException("exception from the test"));
    try {
        underTest.run();
        fail("expected runtimeException");
    } catch (RuntimeException e) {
        assertEquals("exception from the test", e.getMessage());
    }
    verify(executorServiceWithRegistry).finished(underTest, CLUSTER_ID);
}
Also used : ClusterIdEvaluatorContext(com.sequenceiq.periscope.monitor.context.ClusterIdEvaluatorContext) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with ClusterIdEvaluatorContext

use of com.sequenceiq.periscope.monitor.context.ClusterIdEvaluatorContext in project cloudbreak by hortonworks.

the class YarnLoadEvaluatorTest method testRunCallsFinished.

@Test
public void testRunCallsFinished() {
    underTest.setContext(new ClusterIdEvaluatorContext(AUTOSCALE_CLUSTER_ID));
    when(clusterService.findById(anyLong())).thenThrow(new RuntimeException("exception from the test"));
    underTest.run();
    verify(executorServiceWithRegistry).finished(underTest, AUTOSCALE_CLUSTER_ID);
    verify(eventPublisher).publishEvent(any(UpdateFailedEvent.class));
}
Also used : UpdateFailedEvent(com.sequenceiq.periscope.monitor.event.UpdateFailedEvent) ClusterIdEvaluatorContext(com.sequenceiq.periscope.monitor.context.ClusterIdEvaluatorContext) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with ClusterIdEvaluatorContext

use of com.sequenceiq.periscope.monitor.context.ClusterIdEvaluatorContext in project cloudbreak by hortonworks.

the class YarnLoadEvaluatorTest method testExecuteBeforeCoolDownPeriod.

@Test
public void testExecuteBeforeCoolDownPeriod() {
    Cluster cluster = getARunningCluster();
    cluster.setLastScalingActivity(Instant.now().minus(2, ChronoUnit.MINUTES).toEpochMilli());
    when(clusterService.findById(anyLong())).thenReturn(cluster);
    underTest.setContext(new ClusterIdEvaluatorContext(AUTOSCALE_CLUSTER_ID));
    underTest.execute();
    verify(eventPublisher, never()).publishEvent(any());
}
Also used : Cluster(com.sequenceiq.periscope.domain.Cluster) ClusterIdEvaluatorContext(com.sequenceiq.periscope.monitor.context.ClusterIdEvaluatorContext) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with ClusterIdEvaluatorContext

use of com.sequenceiq.periscope.monitor.context.ClusterIdEvaluatorContext in project cloudbreak by hortonworks.

the class YarnLoadEvaluatorTest method captureScalingEvent.

private Optional<ScalingEvent> captureScalingEvent(int runningNodeHostGroupCount, int stoppedNodeHostGroupCount, int yarnUpscaleCount, int yarnDownscaleCount, boolean scalingEventExpected) throws Exception {
    MockitoAnnotations.openMocks(this);
    Cluster cluster = getARunningCluster();
    cluster.setStopStartScalingEnabled(true);
    String hostGroup = "compute";
    StackV4Response stackV4Response = MockStackResponseGenerator.getMockStackV4ResponseWithStoppedAndRunningNodes(CLOUDBREAK_STACK_CRN, hostGroup, fqdnBase, runningNodeHostGroupCount, stoppedNodeHostGroupCount);
    YarnScalingServiceV1Response upScale = getMockYarnScalingResponse(hostGroup, yarnUpscaleCount, yarnDownscaleCount);
    setupMocks(cluster, upScale, stackV4Response);
    underTest.setContext(new ClusterIdEvaluatorContext(AUTOSCALE_CLUSTER_ID));
    underTest.execute();
    Optional<ScalingEvent> scalingEventCaptured = Optional.empty();
    if (scalingEventExpected) {
        ArgumentCaptor<ScalingEvent> captor = ArgumentCaptor.forClass(ScalingEvent.class);
        verify(eventPublisher).publishEvent(captor.capture());
        scalingEventCaptured = Optional.of(captor.getValue());
    }
    return scalingEventCaptured;
}
Also used : StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) YarnScalingServiceV1Response(com.sequenceiq.periscope.model.yarn.YarnScalingServiceV1Response) ScalingEvent(com.sequenceiq.periscope.monitor.event.ScalingEvent) Cluster(com.sequenceiq.periscope.domain.Cluster) ClusterIdEvaluatorContext(com.sequenceiq.periscope.monitor.context.ClusterIdEvaluatorContext) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString)

Aggregations

ClusterIdEvaluatorContext (com.sequenceiq.periscope.monitor.context.ClusterIdEvaluatorContext)4 Test (org.junit.jupiter.api.Test)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 Cluster (com.sequenceiq.periscope.domain.Cluster)2 StackV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response)1 YarnScalingServiceV1Response (com.sequenceiq.periscope.model.yarn.YarnScalingServiceV1Response)1 ScalingEvent (com.sequenceiq.periscope.monitor.event.ScalingEvent)1 UpdateFailedEvent (com.sequenceiq.periscope.monitor.event.UpdateFailedEvent)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1