use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.AutoscaleStackV4Response in project cloudbreak by hortonworks.
the class StackServiceTest method testGetAllForAutoscaleWithDeleteInProgressStack.
@Test
public void testGetAllForAutoscaleWithDeleteInProgressStack() throws TransactionExecutionException {
when(transactionService.required(any(Supplier.class))).thenAnswer(invocation -> {
Supplier<AutoscaleStackV4Response> callback = invocation.getArgument(0);
return callback.get();
});
AutoscaleStack availableStack = mock(AutoscaleStack.class);
when(availableStack.getStackStatus()).thenReturn(Status.AVAILABLE);
AutoscaleStack deleteInProgressStack = mock(AutoscaleStack.class);
when(deleteInProgressStack.getStackStatus()).thenReturn(Status.AVAILABLE);
when(stackRepository.findAliveOnesWithClusterManager()).thenReturn(Set.of(availableStack, deleteInProgressStack));
ArgumentCaptor<AutoscaleStack> aliveStackCaptor = ArgumentCaptor.forClass(AutoscaleStack.class);
AutoscaleStackV4Response autoscaleStackResponse = new AutoscaleStackV4Response();
when(autoscaleStackToAutoscaleStackResponseJsonConverter.convert(aliveStackCaptor.capture())).thenReturn(autoscaleStackResponse);
Set<AutoscaleStackV4Response> allForAutoscale = underTest.getAllForAutoscale();
assertNotNull(allForAutoscale);
assertEquals(autoscaleStackResponse, allForAutoscale.iterator().next());
AutoscaleStack stackSet = aliveStackCaptor.getValue();
assertNotNull(stackSet);
assertEquals(availableStack.getStackStatus(), stackSet.getStackStatus());
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.AutoscaleStackV4Response in project cloudbreak by hortonworks.
the class StackServiceTest method testGetAllForAutoscaleWithAvailableStack.
@Test
public void testGetAllForAutoscaleWithAvailableStack() throws TransactionExecutionException {
when(transactionService.required(any(Supplier.class))).thenAnswer(invocation -> {
Supplier<AutoscaleStackV4Response> callback = invocation.getArgument(0);
return callback.get();
});
AutoscaleStack stack = mock(AutoscaleStack.class);
when(stack.getStackStatus()).thenReturn(Status.AVAILABLE);
when(stackRepository.findAliveOnesWithClusterManager()).thenReturn(Set.of(stack));
ArgumentCaptor<AutoscaleStack> aliveStackCaptor = ArgumentCaptor.forClass(AutoscaleStack.class);
AutoscaleStackV4Response autoscaleStackResponse = new AutoscaleStackV4Response();
when(autoscaleStackToAutoscaleStackResponseJsonConverter.convert(aliveStackCaptor.capture())).thenReturn(autoscaleStackResponse);
Set<AutoscaleStackV4Response> allForAutoscale = underTest.getAllForAutoscale();
assertNotNull(allForAutoscale);
assertEquals(autoscaleStackResponse, allForAutoscale.iterator().next());
AutoscaleStack stackSet = aliveStackCaptor.getValue();
assertNotNull(stackSet);
assertEquals(stack.getStackStatus(), stackSet.getStackStatus());
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.AutoscaleStackV4Response in project cloudbreak by hortonworks.
the class ClusterStatusSyncHandlerTest method testOnApplicationEventWhenCBStackStatusActiveCBClusterStatusActive.
@Test
public void testOnApplicationEventWhenCBStackStatusActiveCBClusterStatusActive() {
Cluster cluster = getACluster(ClusterState.SUSPENDED);
when(clusterService.findById(anyLong())).thenReturn(cluster);
AutoscaleStackV4Response mockAutoscaleResponse = mock(AutoscaleStackV4Response.class);
StackStatusV4Response stackStatusV4Response = new StackStatusV4Response();
stackStatusV4Response.setStatus(Status.AVAILABLE);
stackStatusV4Response.setClusterStatus(Status.AVAILABLE);
when(cloudbreakCommunicator.getStackStatusByCrn(anyString())).thenReturn(stackStatusV4Response);
when(cloudbreakCommunicator.getAutoscaleClusterByCrn(CLOUDBREAK_STACK_CRN)).thenReturn(mockAutoscaleResponse);
when(mockAutoscaleResponse.getEnvironmentCrn()).thenReturn("environmentcrn");
underTest.onApplicationEvent(new ClusterStatusSyncEvent(AUTOSCALE_CLUSTER_ID));
verify(clusterService).setState(AUTOSCALE_CLUSTER_ID, ClusterState.RUNNING);
verify(cloudbreakCommunicator).getStackStatusByCrn(CLOUDBREAK_STACK_CRN);
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.AutoscaleStackV4Response in project cloudbreak by hortonworks.
the class RejectedThreadServiceTest method testCreateWhenAutoscaleStackResponseAndRemove.
@Test
public void testCreateWhenAutoscaleStackResponseAndRemove() {
AutoscaleStackV4Response response = new AutoscaleStackV4Response();
response.setStackId(1L);
EvaluatorExecutor task = new TestEvaluatorExecutor(getContext(response));
underTest.create(task);
List<RejectedThread> allRejectedCluster = underTest.getAllRejectedCluster();
Assert.assertFalse(allRejectedCluster.isEmpty());
Assert.assertEquals(1L, allRejectedCluster.get(0).getId());
underTest.remove(response);
allRejectedCluster = underTest.getAllRejectedCluster();
Assert.assertTrue(allRejectedCluster.isEmpty());
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.AutoscaleStackV4Response in project cloudbreak by hortonworks.
the class RejectedThreadServiceTest method testCreateWhenAutoscaleStackResponseCountEqualsTwo.
@Test
public void testCreateWhenAutoscaleStackResponseCountEqualsTwo() {
AutoscaleStackV4Response response = new AutoscaleStackV4Response();
response.setStackId(1L);
EvaluatorExecutor task = new TestEvaluatorExecutor(getContext(response));
underTest.create(task);
underTest.create(task);
List<RejectedThread> allRejectedCluster = underTest.getAllRejectedCluster();
Assert.assertFalse(allRejectedCluster.isEmpty());
Assert.assertEquals(1L, allRejectedCluster.get(0).getId());
Assert.assertEquals(2L, allRejectedCluster.get(0).getRejectedCount());
}
Aggregations