use of io.strimzi.operator.common.operator.resource.PodOperator in project strimzi-kafka-operator by strimzi.
the class StatefulSetOperatorTest method testNonCascadingDeleteAsync.
@Test
public void testNonCascadingDeleteAsync(VertxTestContext context) {
Deletable mockDeletable = mock(Deletable.class);
when(mockDeletable.delete()).thenReturn(Boolean.TRUE);
Resource mockERPD = mock(resourceType());
when(mockERPD.withPropagationPolicy(any(DeletionPropagation.class))).thenReturn(mockDeletable);
when(mockERPD.withGracePeriod(anyLong())).thenReturn(mockDeletable);
RollableScalableResource mockRSR = mock(RollableScalableResource.class);
ArgumentCaptor<DeletionPropagation> cascadingCaptor = ArgumentCaptor.forClass(DeletionPropagation.class);
when(mockRSR.withPropagationPolicy(cascadingCaptor.capture())).thenReturn(mockERPD);
ArgumentCaptor<Watcher> watcherCaptor = ArgumentCaptor.forClass(Watcher.class);
when(mockRSR.watch(watcherCaptor.capture())).thenReturn(mock(Watch.class));
NonNamespaceOperation mockNameable = mock(NonNamespaceOperation.class);
when(mockNameable.withName(matches(RESOURCE_NAME))).thenReturn(mockRSR);
MixedOperation mockCms = mock(MixedOperation.class);
when(mockCms.inNamespace(matches(NAMESPACE))).thenReturn(mockNameable);
PodOperator podOperator = mock(PodOperator.class);
PvcOperator pvcOperator = mock(PvcOperator.class);
KubernetesClient mockClient = mock(KubernetesClient.class);
mocker(mockClient, mockCms);
StatefulSetOperator op = new StatefulSetOperator(AbstractResourceOperatorTest.vertx, mockClient, 5_000L, podOperator) {
@Override
protected boolean shouldIncrementGeneration(Reconciliation reconciliation, StatefulSetDiff diff) {
return true;
}
};
Checkpoint a = context.checkpoint();
op.deleteAsync(new Reconciliation("test", "kind", "namespace", "name"), NAMESPACE, RESOURCE_NAME, false).onComplete(context.succeeding(v -> context.verify(() -> {
assertThat(cascadingCaptor.getValue(), is(DeletionPropagation.ORPHAN));
a.flag();
})));
}
use of io.strimzi.operator.common.operator.resource.PodOperator in project strimzi-kafka-operator by strimzi.
the class ZooKeeperRollerTest method testAllPodsAreRolled.
@Test
public void testAllPodsAreRolled(VertxTestContext context) {
PodOperator podOperator = mock(PodOperator.class);
when(podOperator.listAsync(any(), any(Labels.class))).thenReturn(Future.succeededFuture(PODS));
ZookeeperLeaderFinder leaderFinder = mock(ZookeeperLeaderFinder.class);
when(leaderFinder.findZookeeperLeader(any(), any(), any(), any())).thenReturn(Future.succeededFuture(ZookeeperLeaderFinder.UNKNOWN_LEADER));
MockZooKeeperRoller roller = new MockZooKeeperRoller(podOperator, leaderFinder, 300_00L);
Checkpoint async = context.checkpoint();
roller.maybeRollingUpdate(Reconciliation.DUMMY_RECONCILIATION, DUMMY_SELECTOR, pod -> List.of("Should restart"), new Secret(), new Secret()).onComplete(context.succeeding(v -> context.verify(() -> {
assertThat(roller.podRestarts.size(), is(3));
assertThat(roller.podRestarts.contains("my-cluster-zookeeper-0"), is(true));
assertThat(roller.podRestarts.contains("my-cluster-zookeeper-1"), is(true));
assertThat(roller.podRestarts.contains("my-cluster-zookeeper-2"), is(true));
async.flag();
})));
}
use of io.strimzi.operator.common.operator.resource.PodOperator in project strimzi-kafka-operator by strimzi.
the class ZooKeeperRollerTest method testLeaderIsLast.
@Test
public void testLeaderIsLast(VertxTestContext context) {
PodOperator podOperator = mock(PodOperator.class);
when(podOperator.listAsync(any(), any(Labels.class))).thenReturn(Future.succeededFuture(PODS));
ZookeeperLeaderFinder leaderFinder = mock(ZookeeperLeaderFinder.class);
when(leaderFinder.findZookeeperLeader(any(), any(), any(), any())).thenReturn(Future.succeededFuture("my-cluster-zookeeper-1"));
MockZooKeeperRoller roller = new MockZooKeeperRoller(podOperator, leaderFinder, 300_00L);
Checkpoint async = context.checkpoint();
roller.maybeRollingUpdate(Reconciliation.DUMMY_RECONCILIATION, DUMMY_SELECTOR, pod -> List.of("Should restart"), new Secret(), new Secret()).onComplete(context.succeeding(v -> context.verify(() -> {
assertThat(roller.podRestarts.size(), is(3));
assertThat(roller.podRestarts.removeLast(), is("my-cluster-zookeeper-1"));
assertThat(roller.podRestarts.contains("my-cluster-zookeeper-2"), is(true));
assertThat(roller.podRestarts.contains("my-cluster-zookeeper-0"), is(true));
async.flag();
})));
}
use of io.strimzi.operator.common.operator.resource.PodOperator in project strimzi-kafka-operator by strimzi.
the class KafkaRollerTest method pod0NotReadyAfterRolling.
@Test
public void pod0NotReadyAfterRolling(VertxTestContext testContext) throws InterruptedException {
PodOperator podOps = mockPodOps(podId -> podId == 0 ? failedFuture(new TimeoutException("Timeout")) : succeededFuture());
StatefulSet sts = buildStatefulSet();
TestingKafkaRoller kafkaRoller = rollerWithControllers(sts, podOps, 2);
// What does/did the ZK algo do?
doFailingRollingRestart(testContext, kafkaRoller, asList(0, 1, 2, 3, 4), KafkaRoller.FatalProblem.class, "Error while waiting for restarted pod c-kafka-0 to become ready", singletonList(0));
// TODO assert subsequent rolls
}
use of io.strimzi.operator.common.operator.resource.PodOperator in project strimzi-kafka-operator by strimzi.
the class KafkaRollerTest method testRollHandlesErrorWhenGettingConfigFromController.
@Test
public void testRollHandlesErrorWhenGettingConfigFromController(VertxTestContext testContext) {
int controller = 2;
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 == controller ? new KafkaRoller.ForceableProblem("could not get config exception") : null, brokerId -> succeededFuture(true), controller);
// The algorithm should carry on rolling the pods
doSuccessfulRollingRestart(testContext, kafkaRoller, asList(0, 1, 2, 3, 4), asList(0, 1, 3, 4, controller));
}
Aggregations