use of com.wavefront.api.ProxyV2API in project java by wavefrontHQ.
the class ProxyCheckInSchedulerTest method testDontRetryCheckinOnBadCredentials.
@Test
public void testDontRetryCheckinOnBadCredentials() {
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();
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 ClientErrorException(Response.status(401).build())).once();
replay(proxyV2API, apiContainer);
try {
ProxyCheckInScheduler scheduler = new ProxyCheckInScheduler(proxyId, proxyConfig, apiContainer, x -> fail("We are not supposed to get here"), () -> {
}, () -> {
});
fail("We're not supposed to get here");
} catch (RuntimeException e) {
//
}
verify(proxyConfig, proxyV2API, apiContainer);
}
use of com.wavefront.api.ProxyV2API in project java by wavefrontHQ.
the class ProxyCheckInSchedulerTest method testDontRetryCheckinOnMisconfiguredUrlThatEndsWithApi.
@Test
public void testDontRetryCheckinOnMisconfiguredUrlThatEndsWithApi() {
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();
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 ClientErrorException(Response.status(404).build())).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);
}
use of com.wavefront.api.ProxyV2API in project java by wavefrontHQ.
the class ProxyCheckInSchedulerTest method testNormalCheckinWithRemoteShutdown.
@Test
public void testNormalCheckinWithRemoteShutdown() {
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();
returnConfig.setShutOffAgents(true);
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);
AtomicBoolean shutdown = new AtomicBoolean(false);
ProxyCheckInScheduler scheduler = new ProxyCheckInScheduler(proxyId, proxyConfig, apiContainer, x -> {
}, () -> shutdown.set(true), () -> {
});
scheduler.updateProxyMetrics();
scheduler.updateConfiguration();
verify(proxyConfig, proxyV2API, apiContainer);
assertTrue(shutdown.get());
}
use of com.wavefront.api.ProxyV2API in project java by wavefrontHQ.
the class ProxyCheckInSchedulerTest method testHttpErrors.
@Test
public void testHttpErrors() {
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();
replay(proxyConfig);
UUID proxyId = ProxyUtil.getOrCreateProxyId(proxyConfig);
expect(apiContainer.getProxyV2API()).andReturn(proxyV2API).anyTimes();
// we need to allow 1 successful checking to prevent early termination
expect(proxyV2API.proxyCheckin(eq(proxyId), eq(authHeader), eq("proxyHost"), eq(getBuildVersion()), anyLong(), anyObject(), eq(true))).andReturn(returnConfig).once();
expect(proxyV2API.proxyCheckin(eq(proxyId), eq(authHeader), eq("proxyHost"), eq(getBuildVersion()), anyLong(), anyObject(), eq(true))).andThrow(new ClientErrorException(Response.status(401).build())).once();
expect(proxyV2API.proxyCheckin(eq(proxyId), eq(authHeader), eq("proxyHost"), eq(getBuildVersion()), anyLong(), anyObject(), eq(true))).andThrow(new ClientErrorException(Response.status(403).build())).once();
expect(proxyV2API.proxyCheckin(eq(proxyId), eq(authHeader), eq("proxyHost"), eq(getBuildVersion()), anyLong(), anyObject(), eq(true))).andThrow(new ClientErrorException(Response.status(407).build())).once();
expect(proxyV2API.proxyCheckin(eq(proxyId), eq(authHeader), eq("proxyHost"), eq(getBuildVersion()), anyLong(), anyObject(), eq(true))).andThrow(new ClientErrorException(Response.status(408).build())).once();
expect(proxyV2API.proxyCheckin(eq(proxyId), eq(authHeader), eq("proxyHost"), eq(getBuildVersion()), anyLong(), anyObject(), eq(true))).andThrow(new ClientErrorException(Response.status(429).build())).once();
expect(proxyV2API.proxyCheckin(eq(proxyId), eq(authHeader), eq("proxyHost"), eq(getBuildVersion()), anyLong(), anyObject(), eq(true))).andThrow(new ServerErrorException(Response.status(500).build())).once();
expect(proxyV2API.proxyCheckin(eq(proxyId), eq(authHeader), eq("proxyHost"), eq(getBuildVersion()), anyLong(), anyObject(), eq(true))).andThrow(new ServerErrorException(Response.status(502).build())).once();
replay(proxyV2API, apiContainer);
ProxyCheckInScheduler scheduler = new ProxyCheckInScheduler(proxyId, proxyConfig, apiContainer, x -> assertNull(x.getPointsPerBatch()), () -> {
}, () -> {
});
scheduler.updateProxyMetrics();
scheduler.updateConfiguration();
scheduler.updateProxyMetrics();
scheduler.updateConfiguration();
scheduler.updateProxyMetrics();
scheduler.updateConfiguration();
scheduler.updateProxyMetrics();
scheduler.updateConfiguration();
scheduler.updateProxyMetrics();
scheduler.updateConfiguration();
scheduler.updateProxyMetrics();
scheduler.updateConfiguration();
scheduler.updateProxyMetrics();
scheduler.updateConfiguration();
verify(proxyConfig, proxyV2API, apiContainer);
}
use of com.wavefront.api.ProxyV2API in project java by wavefrontHQ.
the class ProxyCheckInSchedulerTest method testNormalCheckin.
@Test
public void testNormalCheckin() {
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();
returnConfig.setPointsPerBatch(1234567L);
returnConfig.currentTime = System.currentTimeMillis();
replay(proxyConfig);
UUID proxyId = ProxyUtil.getOrCreateProxyId(proxyConfig);
expect(proxyV2API.proxyCheckin(eq(proxyId), eq(authHeader), eq("proxyHost"), eq(getBuildVersion()), anyLong(), anyObject(), eq(true))).andReturn(returnConfig).once();
expect(apiContainer.getProxyV2API()).andReturn(proxyV2API).anyTimes();
replay(proxyV2API, apiContainer);
ProxyCheckInScheduler scheduler = new ProxyCheckInScheduler(proxyId, proxyConfig, apiContainer, x -> assertEquals(1234567L, x.getPointsPerBatch().longValue()), () -> {
}, () -> {
});
scheduler.scheduleCheckins();
verify(proxyConfig, proxyV2API, apiContainer);
assertEquals(1, scheduler.getSuccessfulCheckinCount());
scheduler.shutdown();
}
Aggregations