Search in sources :

Example 6 with APIContainer

use of com.wavefront.agent.api.APIContainer 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 APIContainer

use of com.wavefront.agent.api.APIContainer 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 APIContainer

use of com.wavefront.agent.api.APIContainer 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 APIContainer

use of com.wavefront.agent.api.APIContainer 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)

Example 10 with APIContainer

use of com.wavefront.agent.api.APIContainer in project java by wavefrontHQ.

the class ReportSourceTagHandlerTest method setup.

@Before
public void setup() {
    mockAgentAPI = EasyMock.createMock(SourceTagAPI.class);
    taskQueueFactory = new TaskQueueFactory() {

        @Override
        public <T extends DataSubmissionTask<T>> TaskQueue<T> getTaskQueue(@Nonnull HandlerKey handlerKey, int threadNum) {
            return null;
        }
    };
    newAgentId = UUID.randomUUID();
    senderTaskFactory = new SenderTaskFactoryImpl(new APIContainer(null, mockAgentAPI, null), newAgentId, taskQueueFactory, null, new DefaultEntityPropertiesFactoryForTesting());
    handlerKey = HandlerKey.of(ReportableEntityType.SOURCE_TAG, "4878");
    sourceTagHandler = new ReportSourceTagHandlerImpl(handlerKey, 10, senderTaskFactory.createSenderTasks(handlerKey), null, blockedLogger);
}
Also used : APIContainer(com.wavefront.agent.api.APIContainer) TaskQueueFactory(com.wavefront.agent.queueing.TaskQueueFactory) SourceTagAPI(com.wavefront.api.SourceTagAPI) TaskQueue(com.wavefront.agent.queueing.TaskQueue) DefaultEntityPropertiesFactoryForTesting(com.wavefront.agent.data.DefaultEntityPropertiesFactoryForTesting) Before(org.junit.Before)

Aggregations

APIContainer (com.wavefront.agent.api.APIContainer)11 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 TaskQueueFactory (com.wavefront.agent.queueing.TaskQueueFactory)2 ParameterException (com.beust.jcommander.ParameterException)1 UnrecognizedPropertyException (com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException)1 DefaultEntityPropertiesFactoryForTesting (com.wavefront.agent.data.DefaultEntityPropertiesFactoryForTesting)1 EntityPropertiesFactory (com.wavefront.agent.data.EntityPropertiesFactory)1 EntityPropertiesFactoryImpl (com.wavefront.agent.data.EntityPropertiesFactoryImpl)1 InteractiveLogsTester (com.wavefront.agent.logsharvesting.InteractiveLogsTester)1 InteractivePreprocessorTester (com.wavefront.agent.preprocessor.InteractivePreprocessorTester)1 QueueExporter (com.wavefront.agent.queueing.QueueExporter)1 TaskQueue (com.wavefront.agent.queueing.TaskQueue)1 TaskQueueFactoryImpl (com.wavefront.agent.queueing.TaskQueueFactoryImpl)1 SourceTagAPI (com.wavefront.api.SourceTagAPI)1 FileNotFoundException (java.io.FileNotFoundException)1 ConnectException (java.net.ConnectException)1