Skip to content
This repository has been archived by the owner on Aug 23, 2020. It is now read-only.

Test: Local Snapshot unit tests #1364

Merged
merged 10 commits into from
May 12, 2019

Conversation

kwek20
Copy link
Contributor

@kwek20 kwek20 commented Feb 27, 2019

Description

Added unit tests to all other local snapshot files
Added javadoc to LS related config

Fixes #1091

Cannot be merged before merging of #1363

Type of change

  • Enhancement (a non-breaking change which adds functionality)
  • Documentation Fix

Checklist:

  • My code follows the style guidelines for this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@kwek20 kwek20 changed the title Ls extra unit tests Test: Local Snapshot unit tests Feb 27, 2019
@iotaledger iotaledger deleted a comment Feb 28, 2019
@iotaledger iotaledger deleted a comment Feb 28, 2019
@iotaledger iotaledger deleted a comment Feb 28, 2019
@iotaledger iotaledger deleted a comment Feb 28, 2019
@iotaledger iotaledger deleted a comment Feb 28, 2019
@iotaledger iotaledger deleted a comment Feb 28, 2019
@iotaledger iotaledger deleted a comment Feb 28, 2019
@iotaledger iotaledger deleted a comment Feb 28, 2019
@iotaledger iotaledger deleted a comment Feb 28, 2019
@kwek20 kwek20 force-pushed the ls-extra-unit-tests branch from a2fe772 to f054f90 Compare March 15, 2019 00:24
@kwek20 kwek20 force-pushed the ls-extra-unit-tests branch from f054f90 to 19a2465 Compare April 24, 2019 16:28
double getpSendMilestone();

/**
* @return Descriptions#P_PROPAGATE_REQUEST
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

It is missing @value annotation.
You made this mistake because you copy pasted code that was never reviewed (I guess this is why reviews are important).

Anyhows #1159 should fix this so you can simply discard the changes to this file

@@ -128,7 +129,8 @@ public void shutdown() {
*
* @param latestMilestoneTracker tracker for the milestones to determine when a new local snapshot is due
*/
private void monitorThread(LatestMilestoneTracker latestMilestoneTracker) {
//Package Private For Testing
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use the @VisibleForTesting no?

@@ -154,38 +156,42 @@ private void monitorThread(LatestMilestoneTracker latestMilestoneTracker) {
* @param inSync if this node is in sync
* @return the current interval in which we take local snapshots
*/
private int getSnapshotInterval(boolean inSync) {
//Package Private For Testing
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

*
* @param latestMilestoneTracker tracker we use to determine milestones
* @return <code>true</code> if we are in sync, otherwise <code>false</code>
*/
private boolean isInSync(LatestMilestoneTracker latestMilestoneTracker) {
// Package Private For Testing
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

lsManager.monitorThread(milestoneTracker);

}
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use lambda?
new Thread( () -> lsManager.monitorThread(milestoneTracker))

}

@After
public void tearDown() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

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

throws Exception should be deleted...
Doesn't your IDE tell you this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It did not! :(

Copy link
Contributor

Choose a reason for hiding this comment

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

So why didn't you delete?

@Test
public void testGetBalances() {
assertEquals("State should not have balances", new HashMap<>(), state.getBalances());
assertEquals("State should have the ballances it was created with", map, balanceState.getBalances());
Copy link
Contributor

Choose a reason for hiding this comment

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

typo "ballances"

state.applyStateDiff(diff);

long balance = state.getBalance(Hash.NULL_HASH);
assertEquals("Applying state to an empty state should have 5 for genisis", 5l, balance);
Copy link
Contributor

Choose a reason for hiding this comment

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

"genesis"

patchedState = balanceState.patchedState(diff);

long balance = patchedState.getBalance(Hash.NULL_HASH);
assertEquals("5 should have been added to genisis", TransactionViewModel.SUPPLY - 5l, balance);
Copy link
Contributor

Choose a reason for hiding this comment

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

"genesis"

@@ -62,7 +62,8 @@
* snapshot multiple times while creating their own version of the LocalSnapshotManager, we cache the instance
* here so they don't have to rebuild it from the scratch every time (massively speeds up the unit tests).
*/
private static SnapshotImpl builtinSnapshot = null;
// Package private For Testing
static SnapshotImpl builtinSnapshot = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be better to have @VisibleForTesting method that nullfies the bulitinSnapshot

Let's not expose more than we need to

Copy link
Contributor

Choose a reason for hiding this comment

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

You know something. This shouldn't be a static field. Can you open an issue for that please?

@kwek20 kwek20 force-pushed the ls-extra-unit-tests branch from 19a2465 to 203dd16 Compare April 29, 2019 17:57
Copy link
Contributor

@GalRogozinski GalRogozinski left a comment

Choose a reason for hiding this comment

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

Looks pretty good.
Just delete the throws, add a comment, and open an issue and I shall approve

}

@After
public void tearDown() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

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

So why didn't you delete?

this.lsManager = new LocalSnapshotManagerImpl();

lsManager.init(snapshotProvider, snapshotService, transactionPruner, config);
when(snapshotProvider.getLatestSnapshot().getIndex()).thenReturn(-5, -1, 10, 998, 999, 1999, 2000);
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm I don't know....
I would add a comment in the test code that we don't really support negative indexes

@@ -62,7 +62,8 @@
* snapshot multiple times while creating their own version of the LocalSnapshotManager, we cache the instance
* here so they don't have to rebuild it from the scratch every time (massively speeds up the unit tests).
*/
private static SnapshotImpl builtinSnapshot = null;
// Package private For Testing
static SnapshotImpl builtinSnapshot = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

You know something. This shouldn't be a static field. Can you open an issue for that please?

@GalRogozinski GalRogozinski merged commit 2b40917 into iotaledger:dev May 12, 2019
@jakubcech jakubcech mentioned this pull request May 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Write missing unit tests for local snapshots integration
2 participants