use of io.fabric8.kubernetes.client.dsl.internal.BaseOperation in project kubernetes-client by fabric8io.
the class BaseOperationTest method testGetWriteOperationUrlWithDryRunDisabled.
@Test
void testGetWriteOperationUrlWithDryRunDisabled() throws MalformedURLException {
// Given
BaseOperation baseOp = new BaseOperation(new OperationContext().withConfig(new ConfigBuilder().withMasterUrl("https://172.17.0.2:8443").build()).withPlural("pods"));
baseOp.setType(Pod.class);
baseOp.setListType(PodList.class);
// When
URL result = baseOp.getResourceURLForWriteOperation(new URL("https://172.17.0.2:8443/api/v1/namespaces/ns1/pods/foo"));
// Then
assertNotNull(result);
assertEquals("https://172.17.0.2:8443/api/v1/namespaces/ns1/pods/foo", result.toString());
}
use of io.fabric8.kubernetes.client.dsl.internal.BaseOperation in project kubernetes-client by fabric8io.
the class BaseOperationTest method testHttpRetryWithLessFailuresThanRetries.
@Test
void testHttpRetryWithLessFailuresThanRetries() throws MalformedURLException, IOException {
final AtomicInteger httpExecutionCounter = new AtomicInteger(0);
HttpClient mockClient = newHttpClientWithSomeFailures(httpExecutionCounter, 2);
BaseOperation<Pod, PodList, Resource<Pod>> baseOp = new BaseOperation(new OperationContext().withConfig(new ConfigBuilder().withMasterUrl("https://172.17.0.2:8443").withRequestRetryBackoffLimit(3).build()).withPlural("pods").withName("test-pod").withHttpClient(mockClient));
baseOp.setType(Pod.class);
// When
Pod result = baseOp.get();
// Then
assertNotNull(result);
assertEquals(3, httpExecutionCounter.get(), "Expected 3 calls: 2 failures and 1 success!");
}
use of io.fabric8.kubernetes.client.dsl.internal.BaseOperation in project kubernetes-client by fabric8io.
the class BaseOperationTest method testChainingGracePeriodAndPropagationPolicy.
@Test
void testChainingGracePeriodAndPropagationPolicy() {
final BaseOperation operation = new BaseOperation(new OperationContext());
EditReplacePatchDeletable<?> operationWithPropagationPolicy = operation.withPropagationPolicy(DeletionPropagation.FOREGROUND);
assertThat(operationWithPropagationPolicy, is(notNullValue()));
assertNotNull(operationWithPropagationPolicy.withGracePeriod(10));
}
use of io.fabric8.kubernetes.client.dsl.internal.BaseOperation in project kubernetes-client by fabric8io.
the class BaseOperationTest method testNoHttpRetryWithDefaultConfig.
@Test
void testNoHttpRetryWithDefaultConfig() throws MalformedURLException, IOException {
final AtomicInteger httpExecutionCounter = new AtomicInteger(0);
HttpClient mockClient = newHttpClientWithSomeFailures(httpExecutionCounter, 1000);
BaseOperation<Pod, PodList, Resource<Pod>> baseOp = new BaseOperation(new OperationContext().withConfig(new ConfigBuilder().withMasterUrl("https://172.17.0.2:8443").build()).withPlural("pods").withName("test-pod").withHttpClient(mockClient));
baseOp.setType(Pod.class);
// When
Exception exception = assertThrows(KubernetesClientException.class, () -> {
Pod result = baseOp.get();
});
// Then
assertTrue(exception.getCause().getMessage().contains("For example java.net.ConnectException"), "As the first failure is an IOException the message of the causedBy expected to contain the given text: 'For example java.net.ConnectException'!");
assertEquals(1, httpExecutionCounter.get());
}
use of io.fabric8.kubernetes.client.dsl.internal.BaseOperation in project kubernetes-client by fabric8io.
the class BaseOperationTest method testWaitUntilFailureCompletion.
@Test
void testWaitUntilFailureCompletion() throws MalformedURLException, IOException {
final AtomicInteger httpExecutionCounter = new AtomicInteger(0);
HttpClient mockClient = newHttpClientWithSomeFailures(httpExecutionCounter, 2);
CompletableFuture<List<Pod>> future = new CompletableFuture<>();
BaseOperation<Pod, PodList, Resource<Pod>> baseOp = new BaseOperation(new OperationContext().withConfig(new ConfigBuilder().withMasterUrl("https://172.17.0.2:8443").build()).withPlural("pods").withName("test-pod").withHttpClient(mockClient)) {
@Override
public CompletableFuture<List<Pod>> informOnCondition(Predicate condition) {
return future;
}
};
baseOp.setType(Pod.class);
// When
try {
baseOp.waitUntilCondition(Objects::isNull, 1, TimeUnit.MILLISECONDS);
fail("should timeout");
} catch (KubernetesClientTimeoutException e) {
}
// Then
assertTrue(future.isCancelled());
}
Aggregations