### Question:
AwsRDSUtils { public static String generateSnapshotName (@NotNull String identifier) { String timestamp = new DateTimeFormatterBuilder().appendInstant(3).toFormatter().format(Instant.now()); String output = String.format("ChaosSnapshot-%s-%s", identifier, timestamp).replace(":", "-").replace(",", "-") .replaceAll("\\.", "-") .replaceAll("--+", "-"); int identifierTrim = 0; while (!isValidSnapshotName(output)) { output = String.format("ChaosSnapshot-%s-%s", identifier.substring(0, identifier.length() - ++identifierTrim), timestamp).replace(":", "-").replace(",", "-") .replaceAll("\\.", "-") .replaceAll("--+", "-"); if (identifierTrim == identifier.length()) { throw new ChaosException(AwsChaosErrorCode.INVALID_SNAPSHOT_NAME); } } return output; } private  AwsRDSUtils(); static String generateSnapshotName(@NotNull String identifier); static boolean isChaosSnapshot(String snapshotIdentifier); static Instant getInstantFromNameSegment(String segment);  }### Answer:
@Test public void generateSnapshotName () { IntStream.range(0, 100).parallel().forEach(i -> { String identifier = randomUUID().toString(); String snapshotName = AwsRDSUtils.generateSnapshotName(identifier); assertTrue(AwsRDSUtils.isChaosSnapshot(snapshotName)); }); IntStream.range(0, 100).parallel().forEach(i -> { String identifier = randomUUID().toString() + "-"; String snapshotName = AwsRDSUtils.generateSnapshotName(identifier); assertTrue(AwsRDSUtils.isChaosSnapshot(snapshotName)); }); IntStream.range(0, 100).parallel().forEach(i -> { String identifier = randomUUID().toString() + "--" + randomUUID().toString(); String snapshotName = AwsRDSUtils.generateSnapshotName(identifier); assertTrue(AwsRDSUtils.isChaosSnapshot(snapshotName)); }); IntStream.range(0, 100).parallel().forEach(i -> { StringBuilder identifier = new StringBuilder(randomUUID().toString()); while (identifier.length() < 300) { identifier.append(randomUUID().toString()); } String snapshotName = AwsRDSUtils.generateSnapshotName(identifier.toString()); assertTrue(AwsRDSUtils.isChaosSnapshot(snapshotName)); }); }
@Test public void rdsSnapshotNameConstraints () { IntStream.range(0, 100).parallel().mapToObj(i -> AwsRDSUtils.generateSnapshotName(randomUUID().toString())).forEach(s -> { assertTrue("Snapshot name cannot exceed 255 letters", s.length() <= 255); assertNotNull("Snapshot name cannot be null", s); assertNotEquals("Snapshot name cannot be blank", "", s); assertFalse("Cannot contain two consecutive hypens", s.contains("--")); assertFalse("Cannot end with a hypen", s.endsWith("-")); assertTrue("Unexpected name pattern (Can contain letters, numbers, and hyphens)" + s, Pattern.compile("^[A-Za-z0-9-]+$") .matcher(s) .matches()); }); }