Search in sources :

Example 1 with ConsulRawClient

use of com.ecwid.consul.v1.ConsulRawClient in project cloudbreak by hortonworks.

the class ConsulHostServiceTypeCheckerTaskTest method checkStatusForConnectionError.

@Test
@SuppressWarnings("unchecked")
public void checkStatusForConnectionError() {
    ConsulRawClient raw1 = mock(ConsulRawClient.class);
    ConsulClient client1 = new ConsulClient(raw1);
    when(raw1.makeGetRequest(SERVICE_ENDPOINT + AMBARI_SERVICE, null, QueryParams.DEFAULT)).thenThrow(TransportException.class);
    boolean result = task.checkStatus(new ConsulContext(stack, client1, Collections.singletonList(AMBARI_SERVICE)));
    assertFalse(result);
}
Also used : ConsulClient(com.ecwid.consul.v1.ConsulClient) ConsulRawClient(com.ecwid.consul.v1.ConsulRawClient) Test(org.junit.Test)

Example 2 with ConsulRawClient

use of com.ecwid.consul.v1.ConsulRawClient in project spring-cloud-consul by spring-cloud.

the class ConsulAutoConfigurationTests method tlsConfigured.

@Test
public void tlsConfigured() {
    appContextRunner.withPropertyValues("spring.cloud.consul.tls.key-store-instance-type=JKS", "spring.cloud.consul.tls.key-store-path=src/test/resources/server.jks", "spring.cloud.consul.tls.key-store-password=letmein", "spring.cloud.consul.tls.certificate-path=src/test/resources/trustStore.jks", "spring.cloud.consul.tls.certificate-password=change_me").run(context -> {
        assertThat(context).hasNotFailed().hasSingleBean(ConsulClient.class);
        ConsulClient consulClient = context.getBean(ConsulClient.class);
        CatalogConsulClient client = (CatalogConsulClient) ReflectionTestUtils.getField(consulClient, "catalogClient");
        ConsulRawClient rawClient = (ConsulRawClient) ReflectionTestUtils.getField(client, "rawClient");
        HttpTransport httpTransport = (HttpTransport) ReflectionTestUtils.getField(rawClient, "httpTransport");
        assertThat(httpTransport).isInstanceOf(DefaultHttpsTransport.class);
    });
}
Also used : HttpTransport(com.ecwid.consul.transport.HttpTransport) ConsulClient(com.ecwid.consul.v1.ConsulClient) CatalogConsulClient(com.ecwid.consul.v1.catalog.CatalogConsulClient) ConsulRawClient(com.ecwid.consul.v1.ConsulRawClient) CatalogConsulClient(com.ecwid.consul.v1.catalog.CatalogConsulClient) Test(org.junit.Test)

Example 3 with ConsulRawClient

use of com.ecwid.consul.v1.ConsulRawClient in project cloudbreak by hortonworks.

the class ConsulUtils method createClient.

public static ConsulClient createClient(String apiAddress, int apiPort, TlsConfiguration tlsConfiguration) throws Exception {
    HttpClient httpClient = createHttpClient(tlsConfiguration.getClientCert(), tlsConfiguration.getClientKey(), tlsConfiguration.getServerCert());
    ConsulRawClient rawClient = new ConsulRawClient("https://" + apiAddress + ':' + apiPort, httpClient);
    Field agentAddress = ReflectionUtils.findField(ConsulRawClient.class, "agentAddress");
    ReflectionUtils.makeAccessible(agentAddress);
    ReflectionUtils.setField(agentAddress, rawClient, "https://" + apiAddress + ':' + apiPort + "/consul");
    return new ConsulClient(rawClient);
}
Also used : Field(java.lang.reflect.Field) ConsulClient(com.ecwid.consul.v1.ConsulClient) ConsulRawClient(com.ecwid.consul.v1.ConsulRawClient) HttpClient(org.apache.http.client.HttpClient)

Example 4 with ConsulRawClient

use of com.ecwid.consul.v1.ConsulRawClient in project cloudbreak by hortonworks.

the class ConsulHostServiceTypeCheckerTaskTest method checkStatusForOneNodeResponse.

@Test
@SuppressWarnings("unchecked")
public void checkStatusForOneNodeResponse() {
    ConsulRawClient raw1 = mock(ConsulRawClient.class);
    RawResponse rawResponse = new RawResponse(200, null, SERVICE_RESPONSE, null, null, null);
    ConsulClient client1 = new ConsulClient(raw1);
    when(raw1.makeGetRequest(SERVICE_ENDPOINT + AMBARI_SERVICE, null, QueryParams.DEFAULT)).thenReturn(rawResponse);
    boolean result = task.checkStatus(new ConsulContext(stack, client1, Collections.singletonList(AMBARI_SERVICE)));
    assertTrue(result);
}
Also used : ConsulClient(com.ecwid.consul.v1.ConsulClient) ConsulRawClient(com.ecwid.consul.v1.ConsulRawClient) RawResponse(com.ecwid.consul.transport.RawResponse) Test(org.junit.Test)

Example 5 with ConsulRawClient

use of com.ecwid.consul.v1.ConsulRawClient in project spring-cloud-consul by spring-cloud.

the class ConsulAutoConfigurationTests method customPathConfigured.

@Test
public void customPathConfigured() {
    appContextRunner.withPropertyValues("spring.cloud.consul.path=/consul/proxy/").run(context -> {
        assertThat(context).hasNotFailed().hasSingleBean(ConsulClient.class);
        ConsulClient consulClient = context.getBean(ConsulClient.class);
        CatalogConsulClient client = (CatalogConsulClient) ReflectionTestUtils.getField(consulClient, "catalogClient");
        ConsulRawClient rawClient = (ConsulRawClient) ReflectionTestUtils.getField(client, "rawClient");
        String agentAddress = (String) ReflectionTestUtils.getField(rawClient, "agentAddress");
        assertThat(agentAddress).isNotNull();
        assertThat(new URL(agentAddress).getPath()).isEqualTo("/consul/proxy");
    });
}
Also used : ConsulClient(com.ecwid.consul.v1.ConsulClient) CatalogConsulClient(com.ecwid.consul.v1.catalog.CatalogConsulClient) ConsulRawClient(com.ecwid.consul.v1.ConsulRawClient) CatalogConsulClient(com.ecwid.consul.v1.catalog.CatalogConsulClient) URL(java.net.URL) Test(org.junit.Test)

Aggregations

ConsulClient (com.ecwid.consul.v1.ConsulClient)5 ConsulRawClient (com.ecwid.consul.v1.ConsulRawClient)5 Test (org.junit.Test)4 CatalogConsulClient (com.ecwid.consul.v1.catalog.CatalogConsulClient)2 HttpTransport (com.ecwid.consul.transport.HttpTransport)1 RawResponse (com.ecwid.consul.transport.RawResponse)1 Field (java.lang.reflect.Field)1 URL (java.net.URL)1 HttpClient (org.apache.http.client.HttpClient)1