Skip to content

Commit

Permalink
Handle typical topic formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyeh committed Apr 12, 2024
1 parent ae09a43 commit 689c9b7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ public void saveGossipMessageDecodingError(
final String formattedTimestamp = formatOptionalTimestamp(arrivalTimestamp);
final String fileName = String.format("%s.ssz", formattedTimestamp);
final Path topicPath =
Path.of(GOSSIP_MESSAGES_DIR).resolve(DECODING_ERROR_SUB_DIR).resolve(topic);
Path.of(GOSSIP_MESSAGES_DIR)
.resolve(DECODING_ERROR_SUB_DIR)
.resolve(topic.replaceAll("/", "_"));
final String identifiers = String.format("on topic %s at %s", topic, formattedTimestamp);
saveBytesToFile(
"gossip message with decoding error",
Expand All @@ -83,7 +85,8 @@ public void saveGossipRejectedMessageToFile(
}
final String formattedTimestamp = formatOptionalTimestamp(arrivalTimestamp);
final String fileName = String.format("%s.ssz", formattedTimestamp);
final Path topicPath = Path.of(GOSSIP_MESSAGES_DIR).resolve(REJECTED_SUB_DIR).resolve(topic);
final Path topicPath =
Path.of(GOSSIP_MESSAGES_DIR).resolve(REJECTED_SUB_DIR).resolve(topic.replaceAll("/", "_"));
final String identifiers = String.format("on topic %s at %s", topic, formattedTimestamp);
saveBytesToFile(
"rejected gossip message", identifiers, topicPath.resolve(fileName), decodedMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,15 @@ void saveGossipMessageDecodingError_shouldSaveToFile(@TempDir Path tempDir) {
final DebugDataDumper manager = new DebugDataDumper(tempDir, true);
final Bytes messageBytes = dataStructureUtil.stateBuilderPhase0().build().sszSerialize();
final Optional<UInt64> arrivalTimestamp = Optional.of(timeProvider.getTimeInMillis());
final String topic = "test_topic";
manager.saveGossipMessageDecodingError("test_topic", arrivalTimestamp, messageBytes);
manager.saveGossipMessageDecodingError("/eth/test/topic", arrivalTimestamp, messageBytes);

final String fileName =
String.format("%s.ssz", manager.formatTimestamp(timeProvider.getTimeInMillis()));
final Path expectedFile =
tempDir
.resolve("gossip_messages")
.resolve("decoding_error")
.resolve(topic)
.resolve("_eth_test_topic")
.resolve(fileName);
checkBytesSavedToFile(expectedFile, messageBytes);
}
Expand All @@ -66,13 +65,17 @@ void saveGossipMessageDecodingError_shouldNotSaveToFileWhenDisabled(@TempDir Pat
final DebugDataDumper manager = new DebugDataDumper(tempDir, false);
final Bytes messageBytes = dataStructureUtil.stateBuilderPhase0().build().sszSerialize();
final Optional<UInt64> arrivalTimestamp = Optional.of(timeProvider.getTimeInMillis());
manager.saveGossipMessageDecodingError("test_topic", arrivalTimestamp, messageBytes);
manager.saveGossipMessageDecodingError("/eth/test/topic", arrivalTimestamp, messageBytes);
assertThat(manager.isEnabled()).isFalse();

final String fileName =
String.format("%s.ssz", manager.formatTimestamp(timeProvider.getTimeInMillis()));
final Path expectedFile =
tempDir.resolve("gossip_messages").resolve("decoding_error").resolve(fileName);
tempDir
.resolve("gossip_messages")
.resolve("decoding_error")
.resolve("_eth_test_topic")
.resolve(fileName);
checkFileNotExist(expectedFile);
}

Expand All @@ -81,13 +84,16 @@ void saveGossipRejectedMessageToFile_shouldSaveToFile(@TempDir Path tempDir) {
final DebugDataDumper manager = new DebugDataDumper(tempDir, true);
final Bytes messageBytes = dataStructureUtil.stateBuilderPhase0().build().sszSerialize();
final Optional<UInt64> arrivalTimestamp = Optional.of(timeProvider.getTimeInMillis());
final String topic = "test_topic";
manager.saveGossipRejectedMessageToFile("test_topic", arrivalTimestamp, messageBytes);
manager.saveGossipRejectedMessageToFile("/eth/test/topic", arrivalTimestamp, messageBytes);

final String fileName =
String.format("%s.ssz", manager.formatTimestamp(timeProvider.getTimeInMillis()));
final Path expectedFile =
tempDir.resolve("gossip_messages").resolve("rejected").resolve(topic).resolve(fileName);
tempDir
.resolve("gossip_messages")
.resolve("rejected")
.resolve("_eth_test_topic")
.resolve(fileName);
checkBytesSavedToFile(expectedFile, messageBytes);
}

Expand All @@ -96,12 +102,16 @@ void saveGossipRejectedMessageToFile_shouldNotSaveToFileWhenDisabled(@TempDir Pa
final DebugDataDumper manager = new DebugDataDumper(tempDir, false);
final Bytes messageBytes = dataStructureUtil.stateBuilderPhase0().build().sszSerialize();
final Optional<UInt64> arrivalTimestamp = Optional.of(timeProvider.getTimeInMillis());
manager.saveGossipRejectedMessageToFile("test_topic", arrivalTimestamp, messageBytes);
manager.saveGossipRejectedMessageToFile("/eth/test/topic", arrivalTimestamp, messageBytes);
assertThat(manager.isEnabled()).isFalse();

final String fileName = String.format("%s.ssz", arrivalTimestamp);
final Path expectedFile =
tempDir.resolve("gossip_messages").resolve("rejected").resolve(fileName);
tempDir
.resolve("gossip_messages")
.resolve("rejected")
.resolve("_eth_test_topic")
.resolve(fileName);
checkFileNotExist(expectedFile);
}

Expand Down

0 comments on commit 689c9b7

Please sign in to comment.