Search in sources :

Example 21 with MixedOperation

use of io.fabric8.kubernetes.client.dsl.MixedOperation in project strimzi by strimzi.

the class AbtractReadyResourceOperatorTest method waitUntilReadyUnsuccessful.

@Test
public void waitUntilReadyUnsuccessful(TestContext context) {
    T resource = resource();
    if (!Readiness.isReadinessApplicable(resource)) {
        return;
    }
    Resource mockResource = mock(resourceType());
    when(mockResource.get()).thenReturn(resource);
    when(mockResource.isReady()).thenReturn(Boolean.FALSE);
    NonNamespaceOperation mockNameable = mock(NonNamespaceOperation.class);
    when(mockNameable.withName(matches(resource.getMetadata().getName()))).thenReturn(mockResource);
    MixedOperation mockCms = mock(MixedOperation.class);
    when(mockCms.inNamespace(matches(resource.getMetadata().getNamespace()))).thenReturn(mockNameable);
    C mockClient = mock(clientType());
    mocker(mockClient, mockCms);
    AbstractReadyResourceOperator<C, T, L, D, R, P> op = createResourceOperations(vertx, mockClient);
    Async async = context.async();
    op.readiness(NAMESPACE, RESOURCE_NAME, 20, 100).setHandler(ar -> {
        assertTrue(ar.failed());
        assertThat(ar.cause(), instanceOf(TimeoutException.class));
        verify(mockResource, atLeastOnce()).get();
        verify(mockResource, atLeastOnce()).isReady();
        async.complete();
    });
}
Also used : Async(io.vertx.ext.unit.Async) Resource(io.fabric8.kubernetes.client.dsl.Resource) MixedOperation(io.fabric8.kubernetes.client.dsl.MixedOperation) NonNamespaceOperation(io.fabric8.kubernetes.client.dsl.NonNamespaceOperation) Test(org.junit.Test)

Example 22 with MixedOperation

use of io.fabric8.kubernetes.client.dsl.MixedOperation in project strimzi by strimzi.

the class AbtractReadyResourceOperatorTest method waitUntilReadyThrows.

@Test
public void waitUntilReadyThrows(TestContext context) {
    T resource = resource();
    if (!Readiness.isReadinessApplicable(resource)) {
        return;
    }
    RuntimeException ex = new RuntimeException();
    Resource mockResource = mock(resourceType());
    when(mockResource.get()).thenReturn(resource());
    when(mockResource.isReady()).thenThrow(ex);
    NonNamespaceOperation mockNameable = mock(NonNamespaceOperation.class);
    when(mockNameable.withName(matches(resource.getMetadata().getName()))).thenReturn(mockResource);
    MixedOperation mockCms = mock(MixedOperation.class);
    when(mockCms.inNamespace(matches(resource.getMetadata().getNamespace()))).thenReturn(mockNameable);
    C mockClient = mock(clientType());
    mocker(mockClient, mockCms);
    AbstractReadyResourceOperator<C, T, L, D, R, P> op = createResourceOperations(vertx, mockClient);
    Async async = context.async();
    op.readiness(NAMESPACE, RESOURCE_NAME, 20, 100).setHandler(ar -> {
        assertTrue(ar.failed());
        assertThat(ar.cause(), instanceOf(TimeoutException.class));
        async.complete();
    });
}
Also used : Resource(io.fabric8.kubernetes.client.dsl.Resource) NonNamespaceOperation(io.fabric8.kubernetes.client.dsl.NonNamespaceOperation) Async(io.vertx.ext.unit.Async) MixedOperation(io.fabric8.kubernetes.client.dsl.MixedOperation) Test(org.junit.Test)

Example 23 with MixedOperation

use of io.fabric8.kubernetes.client.dsl.MixedOperation in project strimzi by strimzi.

the class AbstractResourceOperatorTest method creationThrows.

@Test
public void creationThrows(TestContext context) {
    T resource = resource();
    RuntimeException ex = new RuntimeException();
    Resource mockResource = mock(resourceType());
    when(mockResource.get()).thenReturn(null);
    NonNamespaceOperation mockNameable = mock(NonNamespaceOperation.class);
    when(mockNameable.withName(matches(resource.getMetadata().getName()))).thenReturn(mockResource);
    MixedOperation mockCms = mock(MixedOperation.class);
    when(mockCms.inNamespace(matches(resource.getMetadata().getNamespace()))).thenReturn(mockNameable);
    when(mockResource.create(any())).thenThrow(ex);
    C mockClient = mock(clientType());
    mocker(mockClient, mockCms);
    AbstractResourceOperator<C, T, L, D, R, P> op = createResourceOperations(vertx, mockClient);
    Async async = context.async();
    op.createOrUpdate(resource).setHandler(ar -> {
        assertTrue(ar.failed());
        assertEquals(ex, ar.cause());
        async.complete();
    });
}
Also used : Async(io.vertx.ext.unit.Async) Resource(io.fabric8.kubernetes.client.dsl.Resource) MixedOperation(io.fabric8.kubernetes.client.dsl.MixedOperation) NonNamespaceOperation(io.fabric8.kubernetes.client.dsl.NonNamespaceOperation) Test(org.junit.Test)

Example 24 with MixedOperation

use of io.fabric8.kubernetes.client.dsl.MixedOperation in project strimzi by strimzi.

the class AbstractResourceOperatorTest method successfulCreation.

@Test
public void successfulCreation(TestContext context) {
    T resource = resource();
    Resource mockResource = mock(resourceType());
    when(mockResource.get()).thenReturn(null);
    NonNamespaceOperation mockNameable = mock(NonNamespaceOperation.class);
    when(mockNameable.withName(matches(resource.getMetadata().getName()))).thenReturn(mockResource);
    MixedOperation mockCms = mock(MixedOperation.class);
    when(mockCms.inNamespace(matches(resource.getMetadata().getNamespace()))).thenReturn(mockNameable);
    C mockClient = mock(clientType());
    mocker(mockClient, mockCms);
    AbstractResourceOperator<C, T, L, D, R, P> op = createResourceOperations(vertx, mockClient);
    Async async = context.async();
    op.createOrUpdate(resource).setHandler(ar -> {
        if (ar.failed())
            ar.cause().printStackTrace();
        assertTrue(ar.succeeded());
        verify(mockResource).get();
        verify(mockResource).create(eq(resource));
        async.complete();
    });
}
Also used : Async(io.vertx.ext.unit.Async) Resource(io.fabric8.kubernetes.client.dsl.Resource) MixedOperation(io.fabric8.kubernetes.client.dsl.MixedOperation) NonNamespaceOperation(io.fabric8.kubernetes.client.dsl.NonNamespaceOperation) Test(org.junit.Test)

Example 25 with MixedOperation

use of io.fabric8.kubernetes.client.dsl.MixedOperation in project strimzi by strimzi.

the class AbstractResourceOperatorTest method existenceCheckThrows.

@Test
public void existenceCheckThrows(TestContext context) {
    T resource = resource();
    RuntimeException ex = new RuntimeException();
    Resource mockResource = mock(resourceType());
    when(mockResource.get()).thenThrow(ex);
    NonNamespaceOperation mockNameable = mock(NonNamespaceOperation.class);
    when(mockNameable.withName(matches(resource.getMetadata().getName()))).thenReturn(mockResource);
    MixedOperation mockCms = mock(MixedOperation.class);
    when(mockCms.inNamespace(matches(resource.getMetadata().getNamespace()))).thenReturn(mockNameable);
    C mockClient = mock(clientType());
    mocker(mockClient, mockCms);
    AbstractResourceOperator<C, T, L, D, R, P> op = createResourceOperations(vertx, mockClient);
    Async async = context.async();
    op.createOrUpdate(resource).setHandler(ar -> {
        assertTrue(ar.failed());
        assertEquals(ex, ar.cause());
        async.complete();
    });
}
Also used : Async(io.vertx.ext.unit.Async) Resource(io.fabric8.kubernetes.client.dsl.Resource) MixedOperation(io.fabric8.kubernetes.client.dsl.MixedOperation) NonNamespaceOperation(io.fabric8.kubernetes.client.dsl.NonNamespaceOperation) Test(org.junit.Test)

Aggregations

Resource (io.fabric8.kubernetes.client.dsl.Resource)21 MixedOperation (io.fabric8.kubernetes.client.dsl.MixedOperation)15 Async (io.vertx.ext.unit.Async)15 NonNamespaceOperation (io.fabric8.kubernetes.client.dsl.NonNamespaceOperation)13 Test (org.junit.Test)12 Map (java.util.Map)10 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)4 DeploymentList (io.fabric8.kubernetes.api.model.extensions.DeploymentList)4 DoneableDeployment (io.fabric8.kubernetes.api.model.extensions.DoneableDeployment)4 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)4 ScalableResource (io.fabric8.kubernetes.client.dsl.ScalableResource)4 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)3 ConfigMapList (io.fabric8.kubernetes.api.model.ConfigMapList)3 DoneableConfigMap (io.fabric8.kubernetes.api.model.DoneableConfigMap)3 DoneablePersistentVolumeClaim (io.fabric8.kubernetes.api.model.DoneablePersistentVolumeClaim)3 DoneablePod (io.fabric8.kubernetes.api.model.DoneablePod)3 DoneableService (io.fabric8.kubernetes.api.model.DoneableService)3 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)3 PersistentVolumeClaimList (io.fabric8.kubernetes.api.model.PersistentVolumeClaimList)3 Pod (io.fabric8.kubernetes.api.model.Pod)3