Search in sources :

Example 1 with MockHttpResponse

use of com.microsoft.applicationinsights.agent.internal.MockHttpResponse in project ApplicationInsights-Java by microsoft.

the class QuickPulseDataFetcherTests method endpointChangesWithRedirectHeaderAndGetNewPingInterval.

@Test
void endpointChangesWithRedirectHeaderAndGetNewPingInterval() {
    Map<String, String> headers = new HashMap<>();
    headers.put("x-ms-qps-service-polling-interval-hint", "1000");
    headers.put("x-ms-qps-service-endpoint-redirect", "https://new.endpoint.com");
    headers.put("x-ms-qps-subscribed", "true");
    HttpHeaders httpHeaders = new HttpHeaders(headers);
    TelemetryClient telemetryClient = TelemetryClient.createForTest();
    telemetryClient.setInstrumentationKey("fake-key");
    HttpPipeline httpPipeline = new HttpPipelineBuilder().httpClient(request -> Mono.just(new MockHttpResponse(request, 200, httpHeaders))).build();
    QuickPulsePingSender quickPulsePingSender = new QuickPulsePingSender(httpPipeline, telemetryClient, "machine1", "instance1", "qpid123");
    QuickPulseHeaderInfo quickPulseHeaderInfo = quickPulsePingSender.ping(null);
    assertThat(QuickPulseStatus.QP_IS_ON).isEqualTo(quickPulseHeaderInfo.getQuickPulseStatus());
    assertThat(1000).isEqualTo(quickPulseHeaderInfo.getQpsServicePollingInterval());
    assertThat("https://new.endpoint.com").isEqualTo(quickPulseHeaderInfo.getQpsServiceEndpointRedirect());
}
Also used : Test(org.junit.jupiter.api.Test) TelemetryClient(com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HttpPipeline(com.azure.core.http.HttpPipeline) URISyntaxException(java.net.URISyntaxException) Map(java.util.Map) MockHttpResponse(com.microsoft.applicationinsights.agent.internal.MockHttpResponse) HashMap(java.util.HashMap) Mono(reactor.core.publisher.Mono) HttpHeaders(com.azure.core.http.HttpHeaders) URI(java.net.URI) HttpPipelineBuilder(com.azure.core.http.HttpPipelineBuilder) HttpHeaders(com.azure.core.http.HttpHeaders) HashMap(java.util.HashMap) HttpPipeline(com.azure.core.http.HttpPipeline) HttpPipelineBuilder(com.azure.core.http.HttpPipelineBuilder) TelemetryClient(com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient) MockHttpResponse(com.microsoft.applicationinsights.agent.internal.MockHttpResponse) Test(org.junit.jupiter.api.Test)

Example 2 with MockHttpResponse

use of com.microsoft.applicationinsights.agent.internal.MockHttpResponse in project ApplicationInsights-Java by microsoft.

the class QuickPulsePingSenderTests method endpointChangesWithRedirectHeaderAndGetNewPingInterval.

@Test
void endpointChangesWithRedirectHeaderAndGetNewPingInterval() {
    Map<String, String> headers = new HashMap<>();
    headers.put("x-ms-qps-service-polling-interval-hint", "1000");
    headers.put("x-ms-qps-service-endpoint-redirect", "https://new.endpoint.com");
    headers.put("x-ms-qps-subscribed", "true");
    HttpHeaders httpHeaders = new HttpHeaders(headers);
    TelemetryClient telemetryClient = TelemetryClient.createForTest();
    telemetryClient.setInstrumentationKey("fake-ikey");
    HttpPipeline httpPipeline = new HttpPipelineBuilder().httpClient(request -> Mono.just(new MockHttpResponse(request, 200, httpHeaders))).build();
    QuickPulsePingSender quickPulsePingSender = new QuickPulsePingSender(httpPipeline, telemetryClient, "machine1", "instance1", "qpid123");
    QuickPulseHeaderInfo quickPulseHeaderInfo = quickPulsePingSender.ping(null);
    assertThat(QuickPulseStatus.QP_IS_ON).isEqualTo(quickPulseHeaderInfo.getQuickPulseStatus());
    assertThat(1000).isEqualTo(quickPulseHeaderInfo.getQpsServicePollingInterval());
    assertThat("https://new.endpoint.com").isEqualTo(quickPulseHeaderInfo.getQpsServiceEndpointRedirect());
}
Also used : Test(org.junit.jupiter.api.Test) TelemetryClient(com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HttpPipeline(com.azure.core.http.HttpPipeline) URISyntaxException(java.net.URISyntaxException) Map(java.util.Map) MockHttpResponse(com.microsoft.applicationinsights.agent.internal.MockHttpResponse) HashMap(java.util.HashMap) Mono(reactor.core.publisher.Mono) HttpHeaders(com.azure.core.http.HttpHeaders) URI(java.net.URI) HttpPipelineBuilder(com.azure.core.http.HttpPipelineBuilder) HttpHeaders(com.azure.core.http.HttpHeaders) HashMap(java.util.HashMap) HttpPipeline(com.azure.core.http.HttpPipeline) HttpPipelineBuilder(com.azure.core.http.HttpPipelineBuilder) TelemetryClient(com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient) MockHttpResponse(com.microsoft.applicationinsights.agent.internal.MockHttpResponse) Test(org.junit.jupiter.api.Test)

Aggregations

HttpHeaders (com.azure.core.http.HttpHeaders)2 HttpPipeline (com.azure.core.http.HttpPipeline)2 HttpPipelineBuilder (com.azure.core.http.HttpPipelineBuilder)2 MockHttpResponse (com.microsoft.applicationinsights.agent.internal.MockHttpResponse)2 TelemetryClient (com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Test (org.junit.jupiter.api.Test)2 Mono (reactor.core.publisher.Mono)2