@Test public void getIdentityWithUnorderedFields () { Container badlyConstructedContainer = new Container() { @Identifier private String field1 = "firstField"; @Identifier private String field2 = "secondField"; @Identifier private String field3 = "thirdField"; @Override public Platform getPlatform () { return null; } @Override protected ContainerHealth updateContainerHealthImpl (ExperimentType experimentType) { return null; } @Override public String getSimpleName () { return null; } @Override public String getAggregationIdentifier () { return null; } @Override public DataDogIdentifier getDataDogIdentifier () { return null; } @Override protected boolean compareUniqueIdentifierInner (@NotNull String uniqueIdentifier) { return false; } }; assertEquals(2890670807L, badlyConstructedContainer.getIdentity()); }
public long getIdentity () { final List<Field> identifyingFields = getIdentifyingFields(); final List<String> identifyingFieldValues = identifyingFields.stream().map(field -> { try { return field.get(this); } catch (IllegalAccessException e) { log.error("Caught IllegalAccessException ", e); return null; } }).filter(Objects::nonNull).map(Object::toString).filter(s -> s.length() > 0).collect(Collectors.toUnmodifiableList()); String identity = String.join("$$$$$", identifyingFieldValues); byte[] primitiveByteArray = identity.getBytes(); CRC32 checksum = new CRC32(); checksum.update(primitiveByteArray); return checksum.getValue(); }
Container implements ExperimentalObject { public long getIdentity () { final List<Field> identifyingFields = getIdentifyingFields(); final List<String> identifyingFieldValues = identifyingFields.stream().map(field -> { try { return field.get(this); } catch (IllegalAccessException e) { log.error("Caught IllegalAccessException ", e); return null; } }).filter(Objects::nonNull).map(Object::toString).filter(s -> s.length() > 0).collect(Collectors.toUnmodifiableList()); String identity = String.join("$$$$$", identifyingFieldValues); byte[] primitiveByteArray = identity.getBytes(); CRC32 checksum = new CRC32(); checksum.update(primitiveByteArray); return checksum.getValue(); } }
Container implements ExperimentalObject { public long getIdentity () { final List<Field> identifyingFields = getIdentifyingFields(); final List<String> identifyingFieldValues = identifyingFields.stream().map(field -> { try { return field.get(this); } catch (IllegalAccessException e) { log.error("Caught IllegalAccessException ", e); return null; } }).filter(Objects::nonNull).map(Object::toString).filter(s -> s.length() > 0).collect(Collectors.toUnmodifiableList()); String identity = String.join("$$$$$", identifyingFieldValues); byte[] primitiveByteArray = identity.getBytes(); CRC32 checksum = new CRC32(); checksum.update(primitiveByteArray); return checksum.getValue(); }  }
Container implements ExperimentalObject { public long getIdentity () { final List<Field> identifyingFields = getIdentifyingFields(); final List<String> identifyingFieldValues = identifyingFields.stream().map(field -> { try { return field.get(this); } catch (IllegalAccessException e) { log.error("Caught IllegalAccessException ", e); return null; } }).filter(Objects::nonNull).map(Object::toString).filter(s -> s.length() > 0).collect(Collectors.toUnmodifiableList()); String identity = String.join("$$$$$", identifyingFieldValues); byte[] primitiveByteArray = identity.getBytes(); CRC32 checksum = new CRC32(); checksum.update(primitiveByteArray); return checksum.getValue(); }  Map<String, Boolean> getShellCapabilities(); @JsonIgnore Map<String, String> getDataDogTags(); @Override boolean canExperiment(); @JsonIgnore abstract Platform getPlatform(); boolean eligibleForExperiments(); Experiment createExperiment(); @Override boolean equals(Object o); @Override int hashCode(); long getIdentity(); @Override String toString(); ContainerHealth getContainerHealth(ExperimentType experimentType); Experiment createExperiment(String experimentMethod); void startExperiment(Experiment experiment); abstract String getSimpleName(); abstract String getAggregationIdentifier(); String getContainerType(); @JsonIgnore Duration getMinimumSelfHealingInterval(); @JsonIgnore abstract DataDogIdentifier getDataDogIdentifier(); boolean compareUniqueIdentifier(String uniqueIdentifier); void setMappedDiagnosticContext(); void clearMappedDiagnosticContext(); @JsonIgnore List<Method> getExperimentMethods(); @SuppressWarnings("unchecked") Runnable recycleCattle(); boolean isCattle(); boolean supportsShellBasedExperiments(); @SuppressWarnings("unchecked") ShellOutput runCommand(String command); @JsonIgnore Boolean isContainerRecycled(); @SuppressWarnings("unchecked") String runScript(Script script); Instant getExperimentStartTime(); Collection<String> getKnownMissingCapabilities(); void clearExperiment(); boolean supportsExperimentScope(ExperimentScope experimentScope); }
Container implements ExperimentalObject { public long getIdentity () { final List<Field> identifyingFields = getIdentifyingFields(); final List<String> identifyingFieldValues = identifyingFields.stream().map(field -> { try { return field.get(this); } catch (IllegalAccessException e) { log.error("Caught IllegalAccessException ", e); return null; } }).filter(Objects::nonNull).map(Object::toString).filter(s -> s.length() > 0).collect(Collectors.toUnmodifiableList()); String identity = String.join("$$$$$", identifyingFieldValues); byte[] primitiveByteArray = identity.getBytes(); CRC32 checksum = new CRC32(); checksum.update(primitiveByteArray); return checksum.getValue(); }  Map<String, Boolean> getShellCapabilities(); @JsonIgnore Map<String, String> getDataDogTags(); @Override boolean canExperiment(); @JsonIgnore abstract Platform getPlatform(); boolean eligibleForExperiments(); Experiment createExperiment(); @Override boolean equals(Object o); @Override int hashCode(); long getIdentity(); @Override String toString(); ContainerHealth getContainerHealth(ExperimentType experimentType); Experiment createExperiment(String experimentMethod); void startExperiment(Experiment experiment); abstract String getSimpleName(); abstract String getAggregationIdentifier(); String getContainerType(); @JsonIgnore Duration getMinimumSelfHealingInterval(); @JsonIgnore abstract DataDogIdentifier getDataDogIdentifier(); boolean compareUniqueIdentifier(String uniqueIdentifier); void setMappedDiagnosticContext(); void clearMappedDiagnosticContext(); @JsonIgnore List<Method> getExperimentMethods(); @SuppressWarnings("unchecked") Runnable recycleCattle(); boolean isCattle(); boolean supportsShellBasedExperiments(); @SuppressWarnings("unchecked") ShellOutput runCommand(String command); @JsonIgnore Boolean isContainerRecycled(); @SuppressWarnings("unchecked") String runScript(Script script); Instant getExperimentStartTime(); Collection<String> getKnownMissingCapabilities(); void clearExperiment(); boolean supportsExperimentScope(ExperimentScope experimentScope);  }