use of io.fabric8.kubernetes.client.dsl.Deletable in project strimzi 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, pvcOperator) {
@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.fabric8.kubernetes.client.dsl.Deletable 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, pvcOperator) {
@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.fabric8.kubernetes.client.dsl.Deletable in project kubernetes-client by fabric8io.
the class StatefulSetTest method testDeleteLoadedResource.
@Test
public void testDeleteLoadedResource() {
StatefulSet response = client.apps().statefulSets().load(getClass().getResourceAsStream("/test-statefulset.yml")).get();
server.expect().delete().withPath("/apis/apps/v1beta1/namespaces/test/statefulsets/example").andReturn(200, response).once();
Deletable items = client.load(getClass().getResourceAsStream("/test-statefulset.yml"));
assertTrue(items.delete());
}
use of io.fabric8.kubernetes.client.dsl.Deletable in project devspaces-images by redhat-developer.
the class AsyncStoragePodInterceptorTest method shouldDoDeletePodIfWorkspaceConfigureToPersistentStorage.
@Test
public void shouldDoDeletePodIfWorkspaceConfigureToPersistentStorage() throws InfrastructureException {
when(identity.getWorkspaceId()).thenReturn(WORKSPACE_ID);
when(identity.getInfrastructureNamespace()).thenReturn(NAMESPACE);
when(clientFactory.create(WORKSPACE_ID)).thenReturn(kubernetesClient);
when(kubernetesEnvironment.getAttributes()).thenReturn(ImmutableMap.of(PERSIST_VOLUMES_ATTRIBUTE, "true"));
when(kubernetesClient.pods()).thenReturn(mixedOperationPod);
when(mixedOperationPod.inNamespace(NAMESPACE)).thenReturn(namespacePodOperation);
when(namespacePodOperation.withName(ASYNC_STORAGE)).thenReturn(podResource);
when(podResource.get()).thenReturn(null);
when(kubernetesClient.apps()).thenReturn(apps);
when(apps.deployments()).thenReturn(mixedOperation);
when(mixedOperation.inNamespace(NAMESPACE)).thenReturn(namespaceOperation);
when(namespaceOperation.withName(ASYNC_STORAGE)).thenReturn(deploymentResource);
ObjectMeta meta = new ObjectMeta();
meta.setName(ASYNC_STORAGE);
Deployment deployment = new Deployment();
deployment.setMetadata(meta);
when(deploymentResource.get()).thenReturn(deployment);
when(deploymentResource.withPropagationPolicy(BACKGROUND)).thenReturn(deletable);
Watch watch = mock(Watch.class);
when(deploymentResource.watch(any())).thenReturn(watch);
asyncStoragePodInterceptor.intercept(kubernetesEnvironment, identity);
verify(deletable).delete();
verify(watch).close();
}
use of io.fabric8.kubernetes.client.dsl.Deletable in project strimzi by strimzi.
the class StatefulSetOperatorTest method testDeleteAsyncFailing.
@Test
public void testDeleteAsyncFailing(VertxTestContext context) {
Deletable mockDeletable = mock(Deletable.class);
when(mockDeletable.delete()).thenThrow(new MockitoException("Something failed"));
Resource mockERPD = mock(resourceType());
when(mockERPD.withPropagationPolicy(any(DeletionPropagation.class))).thenReturn(mockDeletable);
when(mockERPD.withGracePeriod(anyLong())).thenReturn(mockDeletable);
RollableScalableResource mockRSR = mock(RollableScalableResource.class);
when(mockRSR.withPropagationPolicy(any(DeletionPropagation.class))).thenReturn(mockERPD);
when(mockRSR.watch(any())).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, pvcOperator) {
@Override
protected boolean shouldIncrementGeneration(Reconciliation reconciliation, StatefulSetDiff diff) {
return true;
}
};
Checkpoint async = context.checkpoint();
op.deleteAsync(new Reconciliation("test", "kind", "namespace", "name"), NAMESPACE, RESOURCE_NAME, false).onComplete(context.failing(e -> context.verify(() -> {
assertThat(e, instanceOf(MockitoException.class));
assertThat(e.getMessage(), is("Something failed"));
async.flag();
})));
}
Aggregations