use of io.fabric8.kubernetes.client.dsl.internal.OperationContext 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.OperationContext 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.OperationContext in project kubernetes-client by fabric8io.
the class BaseOperationTest method testSimpleFieldQueryParamConcatenation.
@Test
void testSimpleFieldQueryParamConcatenation() {
Map<String, String> fieldsMap = new HashMap<>();
fieldsMap.put("yesKey1", "yesValue1");
fieldsMap.put("yesKey2", "yesValue2");
PodOperationsImpl operation = new PodOperationsImpl(new PodOperationContext(), new OperationContext());
operation = (PodOperationsImpl) operation.withFields(fieldsMap).withField("yesKey2", "overrideValue2").withoutField("noKey1", "noValue1").withoutField("noKey2", "noValue2");
final String fieldQueryParam = operation.getFieldQueryParam();
// Use contains to not be depending on map key/value pair ordering
assertThat(fieldQueryParam, containsString("yesKey1=yesValue1"));
assertThat(fieldQueryParam, containsString("yesKey2=overrideValue2"));
assertThat(fieldQueryParam, containsString("noKey1!=noValue1"));
assertThat(fieldQueryParam, containsString("noKey2!=noValue2"));
}
use of io.fabric8.kubernetes.client.dsl.internal.OperationContext 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.OperationContext 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());
}
Aggregations