Search in sources :

Example 6 with ProxyV2API

use of com.wavefront.api.ProxyV2API in project java by wavefrontHQ.

the class ProxyCheckInSchedulerTest method testRetryCheckinOnMisconfiguredUrl.

@Test
public void testRetryCheckinOnMisconfiguredUrl() {
    ProxyConfig proxyConfig = EasyMock.createMock(ProxyConfig.class);
    ProxyV2API proxyV2API = EasyMock.createMock(ProxyV2API.class);
    APIContainer apiContainer = EasyMock.createMock(APIContainer.class);
    reset(proxyConfig, proxyV2API, proxyConfig);
    expect(proxyConfig.getServer()).andReturn("https://acme.corp/zzz").anyTimes();
    expect(proxyConfig.getToken()).andReturn("abcde12345").anyTimes();
    expect(proxyConfig.getHostname()).andReturn("proxyHost").anyTimes();
    expect(proxyConfig.isEphemeral()).andReturn(true).anyTimes();
    expect(proxyConfig.getAgentMetricsPointTags()).andReturn(Collections.emptyMap()).anyTimes();
    String authHeader = "Bearer abcde12345";
    AgentConfiguration returnConfig = new AgentConfiguration();
    returnConfig.setPointsPerBatch(1234567L);
    replay(proxyConfig);
    UUID proxyId = ProxyUtil.getOrCreateProxyId(proxyConfig);
    expect(proxyV2API.proxyCheckin(eq(proxyId), eq(authHeader), eq("proxyHost"), eq(getBuildVersion()), anyLong(), anyObject(), eq(true))).andThrow(new ClientErrorException(Response.status(404).build())).once();
    expect(apiContainer.getProxyV2API()).andReturn(proxyV2API).anyTimes();
    apiContainer.updateServerEndpointURL("https://acme.corp/zzz/api/");
    expectLastCall().once();
    expect(proxyV2API.proxyCheckin(eq(proxyId), eq(authHeader), eq("proxyHost"), eq(getBuildVersion()), anyLong(), anyObject(), eq(true))).andReturn(returnConfig).once();
    replay(proxyV2API, apiContainer);
    ProxyCheckInScheduler scheduler = new ProxyCheckInScheduler(proxyId, proxyConfig, apiContainer, x -> assertEquals(1234567L, x.getPointsPerBatch().longValue()), () -> {
    }, () -> {
    });
    verify(proxyConfig, proxyV2API, apiContainer);
}
Also used : APIContainer(com.wavefront.agent.api.APIContainer) ProxyV2API(com.wavefront.api.ProxyV2API) AgentConfiguration(com.wavefront.api.agent.AgentConfiguration) ClientErrorException(javax.ws.rs.ClientErrorException) UUID(java.util.UUID) Test(org.junit.Test)

Example 7 with ProxyV2API

use of com.wavefront.api.ProxyV2API in project java by wavefrontHQ.

the class ProxyCheckInSchedulerTest method testRetryCheckinOnMisconfiguredUrlFailsTwiceTerminates.

@Test
public void testRetryCheckinOnMisconfiguredUrlFailsTwiceTerminates() {
    ProxyConfig proxyConfig = EasyMock.createMock(ProxyConfig.class);
    ProxyV2API proxyV2API = EasyMock.createMock(ProxyV2API.class);
    APIContainer apiContainer = EasyMock.createMock(APIContainer.class);
    reset(proxyConfig, proxyV2API, proxyConfig);
    expect(proxyConfig.getServer()).andReturn("https://acme.corp/zzz").anyTimes();
    expect(proxyConfig.getToken()).andReturn("abcde12345").anyTimes();
    expect(proxyConfig.getHostname()).andReturn("proxyHost").anyTimes();
    expect(proxyConfig.isEphemeral()).andReturn(true).anyTimes();
    expect(proxyConfig.getAgentMetricsPointTags()).andReturn(Collections.emptyMap()).anyTimes();
    String authHeader = "Bearer abcde12345";
    AgentConfiguration returnConfig = new AgentConfiguration();
    returnConfig.setPointsPerBatch(1234567L);
    replay(proxyConfig);
    UUID proxyId = ProxyUtil.getOrCreateProxyId(proxyConfig);
    expect(proxyV2API.proxyCheckin(eq(proxyId), eq(authHeader), eq("proxyHost"), eq(getBuildVersion()), anyLong(), anyObject(), eq(true))).andThrow(new ClientErrorException(Response.status(404).build())).times(2);
    expect(apiContainer.getProxyV2API()).andReturn(proxyV2API).anyTimes();
    apiContainer.updateServerEndpointURL("https://acme.corp/zzz/api/");
    expectLastCall().once();
    replay(proxyV2API, apiContainer);
    try {
        ProxyCheckInScheduler scheduler = new ProxyCheckInScheduler(proxyId, proxyConfig, apiContainer, x -> fail("We are not supposed to get here"), () -> {
        }, () -> {
        });
        fail();
    } catch (RuntimeException e) {
    // 
    }
    verify(proxyConfig, proxyV2API, apiContainer);
}
Also used : APIContainer(com.wavefront.agent.api.APIContainer) ProxyV2API(com.wavefront.api.ProxyV2API) AgentConfiguration(com.wavefront.api.agent.AgentConfiguration) ClientErrorException(javax.ws.rs.ClientErrorException) UUID(java.util.UUID) Test(org.junit.Test)

Example 8 with ProxyV2API

use of com.wavefront.api.ProxyV2API in project java by wavefrontHQ.

the class ProxyCheckInSchedulerTest method testNetworkErrors.

@Test
public void testNetworkErrors() {
    ProxyConfig proxyConfig = EasyMock.createMock(ProxyConfig.class);
    ProxyV2API proxyV2API = EasyMock.createMock(ProxyV2API.class);
    APIContainer apiContainer = EasyMock.createMock(APIContainer.class);
    reset(proxyConfig, proxyV2API, proxyConfig);
    expect(proxyConfig.getServer()).andReturn("https://acme.corp/zzz").anyTimes();
    expect(proxyConfig.getToken()).andReturn("abcde12345").anyTimes();
    expect(proxyConfig.getHostname()).andReturn("proxyHost").anyTimes();
    expect(proxyConfig.isEphemeral()).andReturn(true).anyTimes();
    expect(proxyConfig.getAgentMetricsPointTags()).andReturn(Collections.emptyMap()).anyTimes();
    String authHeader = "Bearer abcde12345";
    AgentConfiguration returnConfig = new AgentConfiguration();
    returnConfig.setPointsPerBatch(1234567L);
    replay(proxyConfig);
    UUID proxyId = ProxyUtil.getOrCreateProxyId(proxyConfig);
    expect(apiContainer.getProxyV2API()).andReturn(proxyV2API).anyTimes();
    expect(proxyV2API.proxyCheckin(eq(proxyId), eq(authHeader), eq("proxyHost"), eq(getBuildVersion()), anyLong(), anyObject(), eq(true))).andThrow(new ProcessingException(new UnknownHostException())).once();
    expect(proxyV2API.proxyCheckin(eq(proxyId), eq(authHeader), eq("proxyHost"), eq(getBuildVersion()), anyLong(), anyObject(), eq(true))).andThrow(new ProcessingException(new SocketTimeoutException())).once();
    expect(proxyV2API.proxyCheckin(eq(proxyId), eq(authHeader), eq("proxyHost"), eq(getBuildVersion()), anyLong(), anyObject(), eq(true))).andThrow(new ProcessingException(new ConnectException())).once();
    expect(proxyV2API.proxyCheckin(eq(proxyId), eq(authHeader), eq("proxyHost"), eq(getBuildVersion()), anyLong(), anyObject(), eq(true))).andThrow(new ProcessingException(new NullPointerException())).once();
    expect(proxyV2API.proxyCheckin(eq(proxyId), eq(authHeader), eq("proxyHost"), eq(getBuildVersion()), anyLong(), anyObject(), eq(true))).andThrow(new NullPointerException()).once();
    replay(proxyV2API, apiContainer);
    ProxyCheckInScheduler scheduler = new ProxyCheckInScheduler(proxyId, proxyConfig, apiContainer, x -> fail("We are not supposed to get here"), () -> {
    }, () -> {
    });
    scheduler.updateConfiguration();
    scheduler.updateConfiguration();
    scheduler.updateConfiguration();
    scheduler.updateConfiguration();
    verify(proxyConfig, proxyV2API, apiContainer);
}
Also used : APIContainer(com.wavefront.agent.api.APIContainer) SocketTimeoutException(java.net.SocketTimeoutException) UnknownHostException(java.net.UnknownHostException) ProxyV2API(com.wavefront.api.ProxyV2API) AgentConfiguration(com.wavefront.api.agent.AgentConfiguration) UUID(java.util.UUID) ProcessingException(javax.ws.rs.ProcessingException) ConnectException(java.net.ConnectException) Test(org.junit.Test)

Example 9 with ProxyV2API

use of com.wavefront.api.ProxyV2API in project java by wavefrontHQ.

the class ProxyCheckInSchedulerTest method testNormalCheckinWithBadConsumer.

@Test
public void testNormalCheckinWithBadConsumer() {
    ProxyConfig proxyConfig = EasyMock.createMock(ProxyConfig.class);
    ProxyV2API proxyV2API = EasyMock.createMock(ProxyV2API.class);
    APIContainer apiContainer = EasyMock.createMock(APIContainer.class);
    reset(proxyConfig, proxyV2API, proxyConfig);
    expect(proxyConfig.getServer()).andReturn("https://acme.corp/api/").anyTimes();
    expect(proxyConfig.getToken()).andReturn("abcde12345").anyTimes();
    expect(proxyConfig.getHostname()).andReturn("proxyHost").anyTimes();
    expect(proxyConfig.isEphemeral()).andReturn(true).anyTimes();
    expect(proxyConfig.getAgentMetricsPointTags()).andReturn(Collections.emptyMap()).anyTimes();
    String authHeader = "Bearer abcde12345";
    AgentConfiguration returnConfig = new AgentConfiguration();
    replay(proxyConfig);
    UUID proxyId = ProxyUtil.getOrCreateProxyId(proxyConfig);
    expect(proxyV2API.proxyCheckin(eq(proxyId), eq(authHeader), eq("proxyHost"), eq(getBuildVersion()), anyLong(), anyObject(), eq(true))).andReturn(returnConfig).anyTimes();
    expect(apiContainer.getProxyV2API()).andReturn(proxyV2API).anyTimes();
    replay(proxyV2API, apiContainer);
    try {
        ProxyCheckInScheduler scheduler = new ProxyCheckInScheduler(proxyId, proxyConfig, apiContainer, x -> {
            throw new NullPointerException("gotcha!");
        }, () -> {
        }, () -> {
        });
        scheduler.updateProxyMetrics();
        ;
        scheduler.updateConfiguration();
        verify(proxyConfig, proxyV2API, apiContainer);
        fail("We're not supposed to get here");
    } catch (NullPointerException e) {
    // NPE caught, we're good
    }
}
Also used : APIContainer(com.wavefront.agent.api.APIContainer) ProxyV2API(com.wavefront.api.ProxyV2API) AgentConfiguration(com.wavefront.api.agent.AgentConfiguration) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

APIContainer (com.wavefront.agent.api.APIContainer)9 ProxyV2API (com.wavefront.api.ProxyV2API)9 AgentConfiguration (com.wavefront.api.agent.AgentConfiguration)9 UUID (java.util.UUID)9 Test (org.junit.Test)9 ClientErrorException (javax.ws.rs.ClientErrorException)5 ConnectException (java.net.ConnectException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 UnknownHostException (java.net.UnknownHostException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ProcessingException (javax.ws.rs.ProcessingException)1 ServerErrorException (javax.ws.rs.ServerErrorException)1