Search in sources :

Example 96 with Resource

use of io.fabric8.support.api.Resource 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 97 with Resource

use of io.fabric8.support.api.Resource 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 98 with Resource

use of io.fabric8.support.api.Resource in project strimzi by strimzi.

the class PodOperatorTest method testCreateReadUpdate.

@Test
public void testCreateReadUpdate(TestContext context) {
    vertx.createSharedWorkerExecutor("kubernetes-ops-pool", 10);
    KubernetesClient client = server.getKubernetesClient();
    PodOperator pr = new PodOperator(vertx, client);
    context.assertEquals(emptyList(), pr.list(NAMESPACE, Labels.EMPTY));
    Async async = context.async(1);
    pr.createOrUpdate(resource()).setHandler(createResult -> {
        context.assertTrue(createResult.succeeded());
        context.assertEquals(singletonList(RESOURCE_NAME), pr.list(NAMESPACE, Labels.EMPTY).stream().map(p -> p.getMetadata().getName()).collect(Collectors.toList()));
        // Pod got = pr.get(NAMESPACE, RESOURCE_NAME);
        // context.assertNotNull(got);
        // context.assertNotNull(got.getMetadata());
        // context.assertEquals(RESOURCE_NAME, got.getMetadata().getName());
        context.assertFalse(pr.isReady(NAMESPACE, RESOURCE_NAME));
        /*pr.watch(NAMESPACE, RESOURCE_NAME, new Watcher<Pod>() {
                @Override
                public void eventReceived(Action action, Pod resource) {
                    if (action == Action.DELETED) {
                        context.assertEquals(RESOURCE_NAME, resource.getMetadata().getName());
                    } else {
                        context.fail();
                    }
                    async.countDown();
                }

                @Override
                public void onClose(KubernetesClientException cause) {

                }
            });*/
        /*Pod modified = resource();
            modified.getSpec().setHostname("bar");
            Async patchAsync = context.async();
            pr.patch(NAMESPACE, RESOURCE_NAME, modified, patchResult -> {
                context.assertTrue(patchResult.succeeded());
                patchAsync.complete();
            });
            patchAsync.await();*/
        pr.reconcile(NAMESPACE, RESOURCE_NAME, null).setHandler(deleteResult -> {
            context.assertTrue(deleteResult.succeeded());
            async.countDown();
        });
    });
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Async(io.vertx.ext.unit.Async) Test(org.junit.Test)

Example 99 with Resource

use of io.fabric8.support.api.Resource 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 100 with Resource

use of io.fabric8.support.api.Resource 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)

Aggregations

HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)25 Resource (io.fabric8.kubernetes.client.dsl.Resource)25 Map (java.util.Map)20 Test (org.junit.Test)20 IOException (java.io.IOException)19 HashMap (java.util.HashMap)16 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)14 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)14 MixedOperation (io.fabric8.kubernetes.client.dsl.MixedOperation)14 Resource (org.osgi.resource.Resource)14 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)13 NonNamespaceOperation (io.fabric8.kubernetes.client.dsl.NonNamespaceOperation)13 ArrayList (java.util.ArrayList)13 Async (io.vertx.ext.unit.Async)12 File (java.io.File)10 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)9 Service (io.fabric8.kubernetes.api.model.Service)9 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)9 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)8 Bundle (org.osgi.framework.Bundle)7