/** * Check if a resource is in the Ready state. * * @param namespace The namespace. * @param name The resource name. */ public boolean isReady(String namespace, String name) { R resourceOp = operation().inNamespace(namespace).withName(name); T resource = resourceOp.get(); if (resource != null) { if (Readiness.isReadinessApplicable(resource.getClass())) { return Boolean.TRUE.equals(resourceOp.isReady()); } else { return true; } } else { return false; } } }
@Test public void waitUntilReadyUnsuccessful(TestContext context) { T resource = resource(); if (!Readiness.isReadinessApplicable(resource.getClass())) { 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> 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(); }); }
@Test public void waitUntilReadyExistenceCheckThrows(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); AbstractReadyResourceOperator<C, T, L, D, R> 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, never()).isReady(); async.complete(); }); }
@Test public void waitUntilReadyWhenDoesNotExist(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); AbstractReadyResourceOperator<C, T, L, D, R> op = createResourceOperations(vertx, mockClient); Async async = context.async(); Future<Void> fut = op.readiness(NAMESPACE, RESOURCE_NAME, 20, 100); fut.setHandler(ar -> { assertTrue(ar.failed()); assertThat(ar.cause(), instanceOf(TimeoutException.class)); verify(mockResource, atLeastOnce()).get(); verify(mockResource, never()).isReady(); async.complete(); }); }
when(mockResource.isReady()).thenThrow(ex);