CentralCollector implements Collector { @VisibleForTesting static boolean isAgentVersionGreaterThanCentralVersion(String agentVersion, String centralVersion) { Pattern pattern = Pattern.compile("(\\d+)\\.(\\d+)\\.(\\d+)\\b.*"); Matcher matcher = pattern.matcher(agentVersion); if (!matcher.matches()) { if (!agentVersion.equals(Version.UNKNOWN_VERSION)) { startupLogger.warn("could not parse agent version: {}", agentVersion); } return false; } int agentMajor = Integer.parseInt(checkNotNull(matcher.group(1))); int agentMinor = Integer.parseInt(checkNotNull(matcher.group(2))); int agentPatch = Integer.parseInt(checkNotNull(matcher.group(3))); matcher = pattern.matcher(centralVersion); if (!matcher.matches()) { if (!centralVersion.equals("")) { startupLogger.warn("could not parse central version: {}", centralVersion); } return false; } int centralMajor = Integer.parseInt(checkNotNull(matcher.group(1))); int centralMinor = Integer.parseInt(checkNotNull(matcher.group(2))); int centralPatch = Integer.parseInt(checkNotNull(matcher.group(3))); if (agentMajor > centralMajor) { return true; } if (agentMajor < centralMajor) { return false; } if (agentMinor > centralMinor) { return true; } if (agentMinor < centralMinor) { return false; } return agentPatch > centralPatch; } 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 shouldCheckAgentVersionAgainstCentralVersion() { assertThat(CentralCollector.isAgentVersionGreaterThanCentralVersion("1.10.2", "1.10.1")) .isTrue(); assertThat(CentralCollector.isAgentVersionGreaterThanCentralVersion("1.10.2", "1.10.2")) .isFalse(); assertThat(CentralCollector.isAgentVersionGreaterThanCentralVersion("1.10.2", "1.10.3")) .isFalse(); assertThat(CentralCollector.isAgentVersionGreaterThanCentralVersion("1.10.2", "1.9.2")) .isTrue(); assertThat(CentralCollector.isAgentVersionGreaterThanCentralVersion("1.10.2", "1.10.2")) .isFalse(); assertThat(CentralCollector.isAgentVersionGreaterThanCentralVersion("1.10.2", "1.11.2")) .isFalse(); assertThat(CentralCollector.isAgentVersionGreaterThanCentralVersion("1.10.2", "0.10.2")) .isTrue(); assertThat(CentralCollector.isAgentVersionGreaterThanCentralVersion("1.10.2", "1.10.2")) .isFalse(); assertThat(CentralCollector.isAgentVersionGreaterThanCentralVersion("1.10.2", "2.10.2")) .isFalse(); }