Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: simulator entry point to be flexible as test driver #226

Conversation

georgi-l95
Copy link
Contributor

Description:
This PR aims to refactor the simulator entry point and add flexabilty, in terms of how it can be started.
Adding two new constructors and moving the dagger initialization in the applicaiton itself, rather being in the main method.
This allows us to use it easy in the suites module, where we have the E2E tests.

Related issue(s):

Fixes #190

Notes for reviewer:

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

@georgi-l95 georgi-l95 added the Simulator Issue related to Block Stream Simulator label Oct 2, 2024
@georgi-l95 georgi-l95 added this to the 0.1.0 milestone Oct 2, 2024
@georgi-l95 georgi-l95 self-assigned this Oct 2, 2024
@georgi-l95 georgi-l95 linked an issue Oct 2, 2024 that may be closed by this pull request
@georgi-l95 georgi-l95 marked this pull request as ready for review October 2, 2024 14:38
@georgi-l95 georgi-l95 requested a review from a team as a code owner October 2, 2024 14:38
ata-nas

This comment was marked as duplicate.

Copy link
Contributor

@ata-nas ata-nas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a blocker, but please consider to use the final keyword on all places including local variables (inside methods) and method parameters as well. It is best that we are as strict as possible by default. One of the best reasons to use final for parameters and local vars is so that we do not accidentally change the reference, which could lead to silent bugs. With final if we try to change the ref, we get a compilation error.

Signed-off-by: georgi-l95 <[email protected]>

spotless

Signed-off-by: georgi-l95 <[email protected]>
@georgi-l95 georgi-l95 force-pushed the 190-modify-simulator-entry-point-to-be-flexible-as-test-driver branch from 8b1015c to e780607 Compare October 7, 2024 11:05
Signed-off-by: georgi-l95 <[email protected]>
Copy link
Contributor

@ata-nas ata-nas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved for me.

Copy link
Contributor

@AlfredoG87 AlfredoG87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@mattp-swirldslabs mattp-swirldslabs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some questions about DI versus new constructors

@@ -92,10 +92,24 @@ void start_exitByBlockNull() throws InterruptedException, ParseException, IOExce
assertTrue(blockStreamSimulator.isRunning());
}

void start_usingConfigurationConstructor()
throws InterruptedException, ParseException, IOException {
blockStreamSimulator = new BlockStreamSimulatorApp(configuration);
Copy link
Contributor

@mattp-swirldslabs mattp-swirldslabs Oct 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps use local variables rather than member variables to ensure deterministic behavior here. Like changing to final BlockStreamSimulatorApp() blockStreamSimulator = new BlockStreamSimulatorApp(configuration);

private static Configuration loadDefaultConfiguration() throws IOException {
ConfigurationBuilder configurationBuilder =
ConfigurationBuilder.create()
.withSource(SystemEnvironmentConfigSource.getInstance())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code looks like it's from Server.java. We're going to change how we bring in environment variables. Perhaps coordinate with Atanas to make the same changes here

void start_usingEmptyConstructor() throws IOException, InterruptedException, ParseException {
blockStreamSimulator = new BlockStreamSimulatorApp();
blockStreamSimulator.start();
assertTrue(blockStreamSimulator.isRunning());
Copy link
Contributor

@mattp-swirldslabs mattp-swirldslabs Oct 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can expand these tests using mocks or other techniques to check that get default configuration is actually present and correct, that overriding properties and env variables result in expected values, test the stop() method, etc

@georgi-l95
Copy link
Contributor Author

Closing in favor of #242

@georgi-l95 georgi-l95 closed this Oct 10, 2024
Copy link

codecov bot commented Oct 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.67%. Comparing base (a3a97cc) to head (b57f8af).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##               main     #226   +/-   ##
=========================================
  Coverage     99.66%   99.67%           
- Complexity      247      252    +5     
=========================================
  Files            50       50           
  Lines           903      917   +14     
  Branches         61       61           
=========================================
+ Hits            900      914   +14     
  Misses            3        3           
Files with missing lines Coverage Δ
...edera/block/simulator/BlockStreamSimulatorApp.java 100.00% <100.00%> (ø)
...ain/java/com/hedera/block/simulator/Constants.java 0.00% <ø> (ø)

@georgi-l95 georgi-l95 deleted the 190-modify-simulator-entry-point-to-be-flexible-as-test-driver branch October 24, 2024 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Simulator Issue related to Block Stream Simulator
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants