@Test public void road_name_too_long_gets_truncated() throws Exception { PodNameFactory factory = new PodNameFactory(); LanderConfiguration configuration = new LanderConfiguration("ten-------twenty----thirty----forty-----fifty-----", "topicName", singletonMap(0, null), "s3KeyPrefix", false, "ninechars", false); String name = factory.newName(configuration); assertThat(name.length(), is(63)); assertThat(namePattern.matcher(name).matches(), is(true)); }
String newName(LanderConfiguration config) { String prefix = TRUCK_PARK + "-"; int partition = Iterables.getFirst(config.getOffsets().keySet(), 0); String suffix = "-" + config.getAcquisitionInstant().toLowerCase(Locale.ROOT) + "-" + partition; String roadName = config.getRoadName().toLowerCase().replaceAll("_", "-"); String hash = hashFunction .hashString(roadName, StandardCharsets.UTF_8) .toString() .substring(0, MAX_HASH_STRING_LENGTH) .toLowerCase(Locale.ROOT); int remainingChars = MAX_POD_NAME_LENGTH - prefix.length() - suffix.length(); checkState(remainingChars > MAX_HASH_STRING_LENGTH, "between the process name and partition column value there is not enough room for the road name"); if (remainingChars < roadName.length()) { roadName = roadName.substring(0, remainingChars - hash.length()) + hash; } return prefix + roadName + suffix; }
PodNameFactory { String newName(LanderConfiguration config) { String prefix = TRUCK_PARK + "-"; int partition = Iterables.getFirst(config.getOffsets().keySet(), 0); String suffix = "-" + config.getAcquisitionInstant().toLowerCase(Locale.ROOT) + "-" + partition; String roadName = config.getRoadName().toLowerCase().replaceAll("_", "-"); String hash = hashFunction .hashString(roadName, StandardCharsets.UTF_8) .toString() .substring(0, MAX_HASH_STRING_LENGTH) .toLowerCase(Locale.ROOT); int remainingChars = MAX_POD_NAME_LENGTH - prefix.length() - suffix.length(); checkState(remainingChars > MAX_HASH_STRING_LENGTH, "between the process name and partition column value there is not enough room for the road name"); if (remainingChars < roadName.length()) { roadName = roadName.substring(0, remainingChars - hash.length()) + hash; } return prefix + roadName + suffix; } }
PodNameFactory { String newName(LanderConfiguration config) { String prefix = TRUCK_PARK + "-"; int partition = Iterables.getFirst(config.getOffsets().keySet(), 0); String suffix = "-" + config.getAcquisitionInstant().toLowerCase(Locale.ROOT) + "-" + partition; String roadName = config.getRoadName().toLowerCase().replaceAll("_", "-"); String hash = hashFunction .hashString(roadName, StandardCharsets.UTF_8) .toString() .substring(0, MAX_HASH_STRING_LENGTH) .toLowerCase(Locale.ROOT); int remainingChars = MAX_POD_NAME_LENGTH - prefix.length() - suffix.length(); checkState(remainingChars > MAX_HASH_STRING_LENGTH, "between the process name and partition column value there is not enough room for the road name"); if (remainingChars < roadName.length()) { roadName = roadName.substring(0, remainingChars - hash.length()) + hash; } return prefix + roadName + suffix; }  }
PodNameFactory { String newName(LanderConfiguration config) { String prefix = TRUCK_PARK + "-"; int partition = Iterables.getFirst(config.getOffsets().keySet(), 0); String suffix = "-" + config.getAcquisitionInstant().toLowerCase(Locale.ROOT) + "-" + partition; String roadName = config.getRoadName().toLowerCase().replaceAll("_", "-"); String hash = hashFunction .hashString(roadName, StandardCharsets.UTF_8) .toString() .substring(0, MAX_HASH_STRING_LENGTH) .toLowerCase(Locale.ROOT); int remainingChars = MAX_POD_NAME_LENGTH - prefix.length() - suffix.length(); checkState(remainingChars > MAX_HASH_STRING_LENGTH, "between the process name and partition column value there is not enough room for the road name"); if (remainingChars < roadName.length()) { roadName = roadName.substring(0, remainingChars - hash.length()) + hash; } return prefix + roadName + suffix; }   }
PodNameFactory { String newName(LanderConfiguration config) { String prefix = TRUCK_PARK + "-"; int partition = Iterables.getFirst(config.getOffsets().keySet(), 0); String suffix = "-" + config.getAcquisitionInstant().toLowerCase(Locale.ROOT) + "-" + partition; String roadName = config.getRoadName().toLowerCase().replaceAll("_", "-"); String hash = hashFunction .hashString(roadName, StandardCharsets.UTF_8) .toString() .substring(0, MAX_HASH_STRING_LENGTH) .toLowerCase(Locale.ROOT); int remainingChars = MAX_POD_NAME_LENGTH - prefix.length() - suffix.length(); checkState(remainingChars > MAX_HASH_STRING_LENGTH, "between the process name and partition column value there is not enough room for the road name"); if (remainingChars < roadName.length()) { roadName = roadName.substring(0, remainingChars - hash.length()) + hash; } return prefix + roadName + suffix; }    }