use of io.strimzi.operator.common.operator.resource.PodOperator in project strimzi by strimzi.
the class KafkaRollerTest method pod3NotReadyAfterRolling.
@Test
public void pod3NotReadyAfterRolling(VertxTestContext testContext) throws InterruptedException {
PodOperator podOps = mockPodOps(podId -> podId == 3 ? failedFuture(new TimeoutException("Timeout")) : succeededFuture());
StatefulSet sts = buildStatefulSet();
TestingKafkaRoller kafkaRoller = rollerWithControllers(sts, podOps, 2);
// On the first reconciliation we expect it to abort when it gets to pod 3 (but not 2, which is controller)
doFailingRollingRestart(testContext, kafkaRoller, asList(0, 1, 2, 3, 4), KafkaRoller.FatalProblem.class, "Error while waiting for restarted pod c-kafka-3 to become ready", asList(3));
// On the next reconciliation only pods 2 (controller) and 4 would need rolling, and we expect it to fail in the same way
kafkaRoller = rollerWithControllers(sts, podOps, 2);
clearRestarted();
doFailingRollingRestart(testContext, kafkaRoller, asList(0, 1, 2, 4), KafkaRoller.FatalProblem.class, "Error while waiting for non-restarted pod c-kafka-3 to become ready", emptyList());
}
use of io.strimzi.operator.common.operator.resource.PodOperator in project strimzi by strimzi.
the class KafkaRollerTest method testRollHandlesErrorWhenAlteringConfig.
@Test
public void testRollHandlesErrorWhenAlteringConfig(VertxTestContext testContext) {
PodOperator podOps = mockPodOps(podId -> succeededFuture());
StatefulSet sts = buildStatefulSet();
TestingKafkaRoller kafkaRoller = new TestingKafkaRoller(sts, null, null, addPodNames(sts.getSpec().getReplicas()), podOps, noException(), null, noException(), podId -> new KafkaRoller.ForceableProblem("could not get alter exception"), noException(), brokerId -> succeededFuture(true), 2);
// The algorithm should carry on rolling the pods
doSuccessfulRollingRestart(testContext, kafkaRoller, asList(0, 1, 2, 3, 4), asList(0, 1, 3, 4, 2));
}
use of io.strimzi.operator.common.operator.resource.PodOperator in project strimzi by strimzi.
the class KafkaRollerTest method mockPodOps.
private PodOperator mockPodOps(Function<Integer, Future<Void>> readiness) {
PodOperator podOps = mock(PodOperator.class);
when(podOps.get(any(), any())).thenAnswer(invocation -> new PodBuilder().withNewMetadata().withNamespace(invocation.getArgument(0)).withName(invocation.getArgument(1)).endMetadata().build());
when(podOps.readiness(any(), any(), any(), anyLong(), anyLong())).thenAnswer(invocationOnMock -> {
String podName = invocationOnMock.getArgument(2);
return readiness.apply(podName2Number(podName));
});
when(podOps.isReady(anyString(), anyString())).thenAnswer(invocationOnMock -> {
String podName = invocationOnMock.getArgument(1);
Future<Void> ready = readiness.apply(podName2Number(podName));
if (ready.succeeded()) {
return true;
} else {
if (ready.cause() instanceof TimeoutException) {
return false;
} else {
throw ready.cause();
}
}
});
return podOps;
}
use of io.strimzi.operator.common.operator.resource.PodOperator in project strimzi by strimzi.
the class KafkaRollerTest method testRollHandlesErrorWhenGettingControllerFromNonController.
@Test
public void testRollHandlesErrorWhenGettingControllerFromNonController(VertxTestContext testContext) {
int controller = 2;
int nonController = 1;
PodOperator podOps = mockPodOps(podId -> succeededFuture());
StatefulSet sts = buildStatefulSet();
TestingKafkaRoller kafkaRoller = new TestingKafkaRoller(sts, null, null, addPodNames(sts.getSpec().getReplicas()), podOps, noException(), null, podId -> podId == nonController ? new RuntimeException("Test Exception") : null, noException(), noException(), brokerId -> succeededFuture(true), controller);
// The algorithm should carry on rolling the pods (errors are logged),
// because we never find the controller we get ascending order
doSuccessfulRollingRestart(testContext, kafkaRoller, asList(0, 1, 2, 3, 4), asList(0, 3, 4, nonController, controller));
}
use of io.strimzi.operator.common.operator.resource.PodOperator in project strimzi by strimzi.
the class KafkaRollerTest method testRollHandlesErrorWhenOpeningAdminClient.
@Test
public void testRollHandlesErrorWhenOpeningAdminClient(VertxTestContext testContext) {
PodOperator podOps = mockPodOps(podId -> succeededFuture());
StatefulSet sts = buildStatefulSet();
TestingKafkaRoller kafkaRoller = new TestingKafkaRoller(sts, null, null, addPodNames(sts.getSpec().getReplicas()), podOps, bootstrapBrokers -> bootstrapBrokers != null && bootstrapBrokers.equals(singletonList(1)) ? new RuntimeException("Test Exception") : null, null, noException(), noException(), noException(), brokerId -> succeededFuture(true), 2);
// The algorithm should carry on rolling the pods (errors are logged),
// because we never find the controller we get ascending order
doSuccessfulRollingRestart(testContext, kafkaRoller, asList(0, 1, 2, 3, 4), asList(0, 1, 3, 4, 2));
}
Aggregations