use of io.kubernetes.client.openapi.ApiClient in project java by kubernetes-client.
the class ConfigTest method testDefaultClientNothingPresent.
@Test
public void testDefaultClientNothingPresent() {
try {
String path = withEnvironmentVariable("HOME", "/non-existent").and("HOMEDRIVE", null).and("USERPROFILE", null).execute(() -> {
ApiClient client = Config.defaultClient();
return client.getBasePath();
});
assertEquals("http://localhost:8080", path);
} catch (Exception ex) {
fail("Unexpected exception: " + ex);
}
}
use of io.kubernetes.client.openapi.ApiClient in project java by kubernetes-client.
the class ConfigTest method testDefaultClientHomeDir.
@Test
public void testDefaultClientHomeDir() {
try {
String path = withEnvironmentVariable("HOME", dir.getCanonicalPath()).execute(() -> {
ApiClient client = Config.defaultClient();
return client.getBasePath();
});
assertEquals("http://home.dir.com", path);
} catch (Exception ex) {
ex.printStackTrace();
fail("Unexpected exception: " + ex);
}
}
use of io.kubernetes.client.openapi.ApiClient in project java by kubernetes-client.
the class ConfigTest method testDefaultClientPrecedence.
@Test
public void testDefaultClientPrecedence() {
try {
String path = withEnvironmentVariable("HOME", dir.getCanonicalPath()).and("KUBECONFIG", configFile.getCanonicalPath()).execute(() -> {
ApiClient client = Config.defaultClient();
return client.getBasePath();
});
// $KUBECONFIG should take precedence over $HOME/.kube/config
assertEquals("http://kubeconfig.dir.com", path);
} catch (Exception ex) {
ex.printStackTrace();
fail("Unexpected exception: " + ex);
}
}
use of io.kubernetes.client.openapi.ApiClient in project java by kubernetes-client.
the class GenericKubernetesApiForCoreApiTest method setup.
@Before
public void setup() throws IOException {
ApiClient apiClient = new ClientBuilder().setBasePath("http://localhost:" + 8181).build();
podClient = new GenericKubernetesApi<>(V1Pod.class, V1PodList.class, "", "v1", "pods", apiClient);
}
use of io.kubernetes.client.openapi.ApiClient in project java by kubernetes-client.
the class GenericKubernetesApiForCoreApiTest method testReadTimeoutShouldThrowException.
@Test
public void testReadTimeoutShouldThrowException() {
ApiClient apiClient = new ClientBuilder().setBasePath("http://localhost:" + 8181).build();
apiClient.setHttpClient(apiClient.getHttpClient().newBuilder().readTimeout(1, // timeout everytime
TimeUnit.MILLISECONDS).build());
stubFor(get(urlEqualTo("/api/v1/namespaces/foo/pods/test")).willReturn(aResponse().withFixedDelay(99999).withStatus(200).withBody("")));
podClient = new GenericKubernetesApi<>(V1Pod.class, V1PodList.class, "", "v1", "pods", apiClient);
try {
KubernetesApiResponse<V1Pod> response = podClient.get("foo", "test");
} catch (Throwable t) {
assertTrue(t.getCause() instanceof SocketTimeoutException);
return;
}
fail("no exception happened");
}
Aggregations