CentralCollector implements Collector { @VisibleForTesting static String escapeHostname(String hostname) { hostname = hostname.replace("\\", "\\\\"); if (hostname.startsWith(":")) { hostname = "\\" + hostname; } while (hostname.contains("::")) { hostname = hostname.replace("::", ":\\:"); } return hostname; } CentralCollector(Map<String, String> properties, String collectorAddress,
            @Nullable String collectorAuthority, List<File> confDirs, boolean configReadOnly,
            LiveJvmServiceImpl liveJvmService, LiveWeavingServiceImpl liveWeavingService,
            LiveTraceRepositoryImpl liveTraceRepository, AgentConfigUpdater agentConfigUpdater,
            ConfigService configService); @Override void init(List<File> confDirs, final Environment environment, AgentConfig agentConfig,
            final AgentConfigUpdater agentConfigUpdater); @Override void collectAggregates(AggregateReader aggregateReader); @Override void collectGaugeValues(List<GaugeValue> gaugeValues); @Override void collectTrace(TraceReader traceReader); @Override void log(LogEvent logEvent); @OnlyUsedByTests void close(); @OnlyUsedByTests void awaitClose();  }
@Test public void shouldEscape() { assertThat(CentralCollector.escapeHostname("")).isEqualTo(""); assertThat(CentralCollector.escapeHostname("abc")).isEqualTo("abc"); assertThat(CentralCollector.escapeHostname("a:b:c")).isEqualTo("a:b:c"); assertThat(CentralCollector.escapeHostname(":a:b:c:")).isEqualTo("\\:a:b:c:"); assertThat(CentralCollector.escapeHostname("::a::b::c::")) .isEqualTo("\\:\\:a:\\:b:\\:c:\\:"); assertThat(CentralCollector.escapeHostname(":::a:::b:::c:::")) .isEqualTo("\\:\\:\\:a:\\:\\:b:\\:\\:c:\\:\\:"); assertThat(CentralCollector.escapeHostname("::::")).isEqualTo("\\:\\:\\:\\:"); assertThat(CentralCollector.escapeHostname("a\\b\\c")).isEqualTo("a\\\\b\\\\c"); }