@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: 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); }
@VisibleForTesting void updateConfiguration() { try { AgentConfiguration config = checkin(); if (config != null) { if (config.getShutOffAgents()) { logger.severe(firstNonNull(config.getShutOffMessage(), "Shutting down: Server side flag indicating proxy has to shut down.")); shutdownHook.run(); } else { agentConfigurationConsumer.accept(config); } } } catch (Exception e) { logger.log(Level.SEVERE, "Exception occurred during configuration update", e); } }
ProxyCheckInScheduler { @VisibleForTesting void updateConfiguration() { try { AgentConfiguration config = checkin(); if (config != null) { if (config.getShutOffAgents()) { logger.severe(firstNonNull(config.getShutOffMessage(), "Shutting down: Server side flag indicating proxy has to shut down.")); shutdownHook.run(); } else { agentConfigurationConsumer.accept(config); } } } catch (Exception e) { logger.log(Level.SEVERE, "Exception occurred during configuration update", e); } } }
ProxyCheckInScheduler { @VisibleForTesting void updateConfiguration() { try { AgentConfiguration config = checkin(); if (config != null) { if (config.getShutOffAgents()) { logger.severe(firstNonNull(config.getShutOffMessage(), "Shutting down: Server side flag indicating proxy has to shut down.")); shutdownHook.run(); } else { agentConfigurationConsumer.accept(config); } } } catch (Exception e) { logger.log(Level.SEVERE, "Exception occurred during configuration update", e); } } ProxyCheckInScheduler(UUID proxyId,
                               ProxyConfig proxyConfig,
                               APIContainer apiContainer,
                               Consumer<AgentConfiguration> agentConfigurationConsumer,
                               Runnable shutdownHook); }
ProxyCheckInScheduler { @VisibleForTesting void updateConfiguration() { try { AgentConfiguration config = checkin(); if (config != null) { if (config.getShutOffAgents()) { logger.severe(firstNonNull(config.getShutOffMessage(), "Shutting down: Server side flag indicating proxy has to shut down.")); shutdownHook.run(); } else { agentConfigurationConsumer.accept(config); } } } catch (Exception e) { logger.log(Level.SEVERE, "Exception occurred during configuration update", e); } } ProxyCheckInScheduler(UUID proxyId,
                               ProxyConfig proxyConfig,
                               APIContainer apiContainer,
                               Consumer<AgentConfiguration> agentConfigurationConsumer,
                               Runnable shutdownHook); void scheduleCheckins(); long getSuccessfulCheckinCount(); void shutdown(); }
ProxyCheckInScheduler { @VisibleForTesting void updateConfiguration() { try { AgentConfiguration config = checkin(); if (config != null) { if (config.getShutOffAgents()) { logger.severe(firstNonNull(config.getShutOffMessage(), "Shutting down: Server side flag indicating proxy has to shut down.")); shutdownHook.run(); } else { agentConfigurationConsumer.accept(config); } } } catch (Exception e) { logger.log(Level.SEVERE, "Exception occurred during configuration update", e); } } ProxyCheckInScheduler(UUID proxyId,
                               ProxyConfig proxyConfig,
                               APIContainer apiContainer,
                               Consumer<AgentConfiguration> agentConfigurationConsumer,
                               Runnable shutdownHook); void scheduleCheckins(); long getSuccessfulCheckinCount(); void shutdown();  }