Skip to content

Commit

Permalink
Change the file name for preconsensus event stream files.
Browse files Browse the repository at this point in the history
Signed-off-by: Cody Littley <cody@swirldslabs.com>
  • Loading branch information
cody-littley committed Apr 6, 2023
1 parent c43b5f1 commit d175439
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
* will be unable to correctly read files with a different format.
* </p>
* <pre>
* seq[sequence number]-ming[minimum legal generation]-maxg[maximum legal generation]-[Instant.toString().replace(":", "+")].pces
* [Instant.toString().replace(":", "+")]-seq[sequence number]-ming[minimum legal generation]-maxg[maximum legal generation].pces
* </pre>
* <p>
* By default, files are stored with the following directory structure. Note that files are not required to be stored
Expand Down Expand Up @@ -141,10 +141,10 @@ public static PreConsensusEventFile of(final Path filePath) throws IOException {

try {
return new PreConsensusEventFile(
Long.parseLong(elements[0].replace(SEQUENCE_NUMBER_PREFIX, "")),
Long.parseLong(elements[1].replace(MINIMUM_GENERATION_PREFIX, "")),
Long.parseLong(elements[2].replace(MAXIMUM_GENERATION_PREFIX, "")),
parseSanitizedTimestamp(elements[3]),
Long.parseLong(elements[1].replace(SEQUENCE_NUMBER_PREFIX, "")),
Long.parseLong(elements[2].replace(MINIMUM_GENERATION_PREFIX, "")),
Long.parseLong(elements[3].replace(MAXIMUM_GENERATION_PREFIX, "")),
parseSanitizedTimestamp(elements[0]),
filePath);
} catch (final NumberFormatException | DateTimeParseException ex) {
throw new IOException("unable to parse " + filePath, ex);
Expand Down Expand Up @@ -234,16 +234,16 @@ private static String buildFileName(
final long maximumGeneration,
final Instant timestamp) {

return SEQUENCE_NUMBER_PREFIX
return sanitizeTimestamp(timestamp)
+ EVENT_FILE_SEPARATOR
+ SEQUENCE_NUMBER_PREFIX
+ sequenceNumber
+ EVENT_FILE_SEPARATOR
+ MINIMUM_GENERATION_PREFIX
+ minimumGeneration
+ EVENT_FILE_SEPARATOR
+ MAXIMUM_GENERATION_PREFIX
+ maximumGeneration
+ EVENT_FILE_SEPARATOR
+ sanitizeTimestamp(timestamp)
+ EVENT_FILE_EXTENSION;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,10 @@ void fileNameTest() {
final Instant timestamp = RandomUtils.randomInstant(random);

final String expectedName =
SEQUENCE_NUMBER_PREFIX + sequenceNumber + EVENT_FILE_SEPARATOR + MINIMUM_GENERATION_PREFIX
timestamp.toString().replace(":", "+") + EVENT_FILE_SEPARATOR + SEQUENCE_NUMBER_PREFIX
+ sequenceNumber + EVENT_FILE_SEPARATOR + MINIMUM_GENERATION_PREFIX
+ minimumGeneration + EVENT_FILE_SEPARATOR + MAXIMUM_GENERATION_PREFIX
+ maximumGeneration + EVENT_FILE_SEPARATOR
+ timestamp.toString().replace(":", "+")
+ ".pces";
+ maximumGeneration + ".pces";

Assertions.assertEquals(
expectedName,
Expand Down

0 comments on commit d175439

Please sign in to comment.