use of io.strimzi.operator.common.operator.resource.PodOperator in project strimzi-kafka-operator by strimzi.
the class KafkaRollerTest method controllerNotReadyAfterRolling.
@Test
public void controllerNotReadyAfterRolling(VertxTestContext testContext) throws InterruptedException {
PodOperator podOps = mockPodOps(podId -> podId == 2 ? failedFuture(new TimeoutException("Timeout")) : succeededFuture());
StatefulSet sts = buildStatefulSet();
TestingKafkaRoller kafkaRoller = rollerWithControllers(sts, podOps, 2);
// On the first reconciliation we expect it to fail when rolling the controller (i.e. as rolling all the rest)
doFailingRollingRestart(testContext, kafkaRoller, asList(0, 1, 2, 3, 4), KafkaRoller.FatalProblem.class, "Error while waiting for restarted pod c-kafka-2 to become ready", asList(0, 1, 3, 4, 2));
// On the next reconciliation only pod 2 would need rolling, and we expect it to fail in the same way
kafkaRoller = rollerWithControllers(sts, podOps, 2);
clearRestarted();
doFailingRollingRestart(testContext, kafkaRoller, singletonList(2), KafkaRoller.FatalProblem.class, "Error while waiting for restarted pod c-kafka-2 to become ready", singletonList(2));
}
use of io.strimzi.operator.common.operator.resource.PodOperator in project strimzi-kafka-operator by strimzi.
the class KafkaRollerTest method testRollHandlesErrorWhenGettingConfigFromNonController.
@Test
public void testRollHandlesErrorWhenGettingConfigFromNonController(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(), noException(), podId -> podId == 1 ? new KafkaRoller.ForceableProblem("could not get config exception") : null, brokerId -> succeededFuture(true), 2);
// The algorithm should carry on rolling the pods
doSuccessfulRollingRestart(testContext, kafkaRoller, asList(0, 1, 2, 3, 4), asList(0, 3, 4, 1, 2));
}
use of io.strimzi.operator.common.operator.resource.PodOperator in project strimzi-kafka-operator by strimzi.
the class KafkaRollerTest method testRollWithPod2AsController.
@Test
public void testRollWithPod2AsController(VertxTestContext testContext) {
PodOperator podOps = mockPodOps(podId -> succeededFuture());
StatefulSet sts = buildStatefulSet();
TestingKafkaRoller kafkaRoller = rollerWithControllers(sts, podOps, 2);
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-kafka-operator by strimzi.
the class KafkaRollerTest method testNonControllerNotInitiallyRollable.
@Test
public void testNonControllerNotInitiallyRollable(VertxTestContext testContext) {
PodOperator podOps = mockPodOps(podId -> succeededFuture());
StatefulSet sts = buildStatefulSet();
AtomicInteger count = new AtomicInteger(3);
TestingKafkaRoller kafkaRoller = new TestingKafkaRoller(sts, null, null, addPodNames(sts.getSpec().getReplicas()), podOps, noException(), null, noException(), noException(), noException(), brokerId -> brokerId == 1 ? succeededFuture(count.getAndDecrement() == 0) : succeededFuture(true), 2);
doSuccessfulRollingRestart(testContext, kafkaRoller, asList(0, 1, 2, 3, 4), asList(0, 3, 4, 1, 2));
}
use of io.strimzi.operator.common.operator.resource.PodOperator in project strimzi-kafka-operator 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;
}
Aggregations