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

(5/5) [TESTS] Clean up mockito never() and eq(null) usages #3671

Merged
merged 39 commits into from
Dec 9, 2019

Commits on Dec 3, 2019

  1. [TESTS] Add tests of requestData

    This will allow us to push the GetData creation inside P2PDataStorage
    safely.
    julianknutsen committed Dec 3, 2019
    Configuration menu
    Copy the full SHA
    5fcd18c View commit details
    Browse the repository at this point in the history
  2. [REFACTOR] Introduce buildGetDataRequest variants

    As part of changing the GetData path, we want to move all creation
    and processing of GetData messages inside P2PDataStorage. This will allow
    easier unit testing of the behavior as well as cleaner code in the
    request handlers that can just focus on nonces, connections, etc.
    julianknutsen committed Dec 3, 2019
    Configuration menu
    Copy the full SHA
    1e814d9 View commit details
    Browse the repository at this point in the history
  3. [TESTS] Add tests of new RequestData APIs

    These are identical test cases to the requestHandler tests, but with much
    fewer dependencies. The requestHandler tests will eventually be deleted,
    but they are going to remain throughout development as an extra safety
    net.
    julianknutsen committed Dec 3, 2019
    Configuration menu
    Copy the full SHA
    a927ed4 View commit details
    Browse the repository at this point in the history
  4. [TESTS] Add tests of GetDataRequestHandler

    Add some basic sanity tests prior to the refactor to help catch issues.
    julianknutsen committed Dec 3, 2019
    Configuration menu
    Copy the full SHA
    daffe6d View commit details
    Browse the repository at this point in the history
  5. [REFACTOR] Introduce buildGetDataResponse

    This is just a strict move of code to reduce errors.
    julianknutsen committed Dec 3, 2019
    Configuration menu
    Copy the full SHA
    944b3ff View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    8208f78 View commit details
    Browse the repository at this point in the history
  7. [REFACTOR] Extract getDataResponse logging

    Changed the log to reference getDataResponse instead of getData. Now
    that we might truncate the response, it ins't true that this is exactly
    what the peer asked.
    julianknutsen committed Dec 3, 2019
    Configuration menu
    Copy the full SHA
    5402155 View commit details
    Browse the repository at this point in the history
  8. [REFACTOR] Extract truncation logging

    Move the logging that utilizes connection information into the request
    handler. Now, buildGetDataResponse just returns whether or not the list
    is truncated which will make it easier to test.
    julianknutsen committed Dec 3, 2019
    Configuration menu
    Copy the full SHA
    a6e8868 View commit details
    Browse the repository at this point in the history
  9. [REFACTOR] Pass peerCapabilities into buildGetDataResponse

    Remove the dependence on the connection object by having the handler
    pass in the peer's capabilities. This now allows unit testing of
    buildGetDataResponse without any connection dependencies.
    julianknutsen committed Dec 3, 2019
    Configuration menu
    Copy the full SHA
    dafc762 View commit details
    Browse the repository at this point in the history
  10. [TESTS] Unit tests of buildGetDataResponse

    Write a full set of unit tests for buildGetDataResponse. This provides
    a safety net with additional refactoring work.
    julianknutsen committed Dec 3, 2019
    Configuration menu
    Copy the full SHA
    5630b35 View commit details
    Browse the repository at this point in the history
  11. Remove redundant HashSet lookups in filter functions

    The appendOnlyDataStoreService and map already have unique keys that
    are based on the hash of the payload. This would catch instances
    where:
    
    PersistableNetworkPayload
    - None: The key is based on ByteArray(payload.getHash()) which is the
            same as this check.
    
    ProtectedStorageEntry
    - Cases where multiple PSEs contain payloads that have equivalent
      hashCode(), but different data.toProtoMessage().toByteArray().
      I don't think it is a good idea to keep 2 "unique" methods on
      payloads. This is likely left over from a time when
      Payload hashCode() needed to be different than the hash of
      the payload.
    julianknutsen committed Dec 3, 2019
    Configuration menu
    Copy the full SHA
    caf946d View commit details
    Browse the repository at this point in the history
  12. [REFACTOR] Move required capabilities log

    Move the logging function to the common capabilities check
    so it can run on both ProtectedStoragePayload and
    PersistableNetworkPayload objects
    julianknutsen committed Dec 3, 2019
    Configuration menu
    Copy the full SHA
    703a9a0 View commit details
    Browse the repository at this point in the history
  13. [REFACTOR] Inline capability check for ProtectedStorageEntries

    Move the capability check inside the stream operation. This should
    improve performance slightly, but more importantly it makes the
    two filter functions almost identical so they can be combined.
    julianknutsen committed Dec 3, 2019
    Configuration menu
    Copy the full SHA
    3aaf8a2 View commit details
    Browse the repository at this point in the history
  14. [REFACTOR] Inline filtering functions

    Removes unnecessary calculations converting Set<byte[]> into
    Set<ByteArray> and allows additional deduplication of stream operations.
    julianknutsen committed Dec 3, 2019
    Configuration menu
    Copy the full SHA
    4c5d818 View commit details
    Browse the repository at this point in the history
  15. [REFACTOR] Remove duplication in filtering functions

    Introduce a generic function that can be used to filter
    Map<ByteArray, PersistableNetworkPayload> or
    Map<ByteArray, ProtectedStorageEntry>.
    
    Used to deduplicate the GetData code paths and ensure the logic is the
    same between the two payload types.
    julianknutsen committed Dec 3, 2019
    Configuration menu
    Copy the full SHA
    e767340 View commit details
    Browse the repository at this point in the history
  16. [BUGFIX] Fix off-by-one in truncation logic

    Now, the truncation is only triggered if more than MAX_ENTRIES could
    have been returned.
    julianknutsen committed Dec 3, 2019
    Configuration menu
    Copy the full SHA
    00128d9 View commit details
    Browse the repository at this point in the history
  17. [TESTS] Add test of RequestDataHandler::onMessage

    Add heavy-handed test that exercises the logic to use as a safeguard
    for refactoring.
    julianknutsen committed Dec 3, 2019
    Configuration menu
    Copy the full SHA
    c7bce9e View commit details
    Browse the repository at this point in the history
  18. [REFACTOR] Introduce processGetDataResponse

    Just a code move for now.
    julianknutsen committed Dec 3, 2019
    Configuration menu
    Copy the full SHA
    873271c View commit details
    Browse the repository at this point in the history
  19. [TESTS] Make verify() functions more flexible

    Now that we want to unit test the GetData path which has different
    behavior w.r.t. broadcasts, the tests need a way to verify that
    state was updated, but not broadcast during an add.
    
    This patch changes all verification function to take each state update
    explicitly so the tests can do the proper verification.
    julianknutsen committed Dec 3, 2019
    Configuration menu
    Copy the full SHA
    690b980 View commit details
    Browse the repository at this point in the history
  20. [TESTS] Add unit tests for processGetDataResponse

    Add a full set of unit tests that uncovered some unexpected
    behavior w.r.t. signalers.
    julianknutsen committed Dec 3, 2019
    Configuration menu
    Copy the full SHA
    a34488b View commit details
    Browse the repository at this point in the history
  21. Remove static from initialRequestApplied

    Previously, multiple handlers needed to signal off one global variable.
    Now, that this check is inside the singleton P2PDataStorage, make it
    non-static and private.
    julianknutsen committed Dec 3, 2019
    Configuration menu
    Copy the full SHA
    3d6e9fb View commit details
    Browse the repository at this point in the history
  22. [TESTS] Write synchronization integration tests

    Write a few integration test that exercises the exercise interesting
    synchronization states including the lost remove bug. This fails
    with the proper validation, but will pass at the end of the new feature
    development.
    julianknutsen committed Dec 3, 2019
    Configuration menu
    Copy the full SHA
    f92893b View commit details
    Browse the repository at this point in the history
  23. [REFACTOR] Clean up processGetDataResponse

    - Add more comments
    - Use Clock instead of System
    - Remove unnecessary AtomicInteger
    julianknutsen committed Dec 3, 2019
    Configuration menu
    Copy the full SHA
    5db1285 View commit details
    Browse the repository at this point in the history
  24. [RENAME] LazyProcessedPayload to ProcessOncePersistableNetworkPayload

    Name is left over from previous implementation. Change it to be more
    relevant to the current code and update comments to indicate the
    current usage.
    julianknutsen committed Dec 3, 2019
    Configuration menu
    Copy the full SHA
    ecae31e View commit details
    Browse the repository at this point in the history
  25. Remove @nullable around persistableNetworkPayloadSet

    Checking for null creates hard-to-read code and it is simpler to just
    create an empty set if we receive a pre-v0.6 GetDataResponse protobuf
    message that does not have the field set.
    julianknutsen committed Dec 3, 2019
    Configuration menu
    Copy the full SHA
    a0fae12 View commit details
    Browse the repository at this point in the history
  26. Remove @nullable around supportedCapabilities in GetDataResponse

    The only two users of this constructor are the fromProto path which
    already creates an empty Capabilities object if one is not provided and
    the internal usage of Capabilities.app which is initialized to empty.
    
    Remove the @nullable so future readers aren't confused.
    julianknutsen committed Dec 3, 2019
    Configuration menu
    Copy the full SHA
    c503bcb View commit details
    Browse the repository at this point in the history
  27. Remove @nullable around supportedCapabilities in PreliminaryGetDataRe…

    …quest
    
    The only two users of this constructor are the fromProto path which
    now creates an empty Capabilities object similar to GetDataResponse.
    The other internal usage of Capabilities.app which is initialized to empty.
    julianknutsen committed Dec 3, 2019
    Configuration menu
    Copy the full SHA
    b1a06fe View commit details
    Browse the repository at this point in the history
  28. [DEADCODE] Remove old request handler tests

    Now that all the implementations are unit tested in P2PDataStorage,
    the old tests can be removed.
    julianknutsen committed Dec 3, 2019
    Configuration menu
    Copy the full SHA
    4fe19ae View commit details
    Browse the repository at this point in the history
  29. Make addPersistableNetworkPayloadFromInitialRequest private

    Now that the only user is internal, the API can be made private and the
    tests can be removed. This involved adding a few test cases to
    processGetDataResponse to ensure the invalid hash size condition was
    still covered.
    julianknutsen committed Dec 3, 2019
    Configuration menu
    Copy the full SHA
    0649323 View commit details
    Browse the repository at this point in the history
  30. [REFACTOR] Clean up ClientAPI for addPersistableNetworkPayload

    Now that more callers have moved internal, the public facing API
    can be cleaner and more simple. This should lead to a more maintainable
    API and less sharp edges with future development work.
    julianknutsen committed Dec 3, 2019
    Configuration menu
    Copy the full SHA
    56a7661 View commit details
    Browse the repository at this point in the history
  31. [REFACTOR] Clean up ClientAPI for addProtectedStorageEntry

    Remove isDataOwner from the client API. All users pass in true. All test
    users don't care.
    julianknutsen committed Dec 3, 2019
    Configuration menu
    Copy the full SHA
    0e6b1a2 View commit details
    Browse the repository at this point in the history
  32. [REFACTOR] Clean up ClientAPI for remove

    Remove isDataOwner from the client API. All users pass in true. All test
    users don't care.
    julianknutsen committed Dec 3, 2019
    Configuration menu
    Copy the full SHA
    77413c9 View commit details
    Browse the repository at this point in the history
  33. [REFACTOR] Clean up ClientAPI for refreshTTL

    Remove isDataOwner from the client API. All users pass in true. All test
    users don't care.
    julianknutsen committed Dec 3, 2019
    Configuration menu
    Copy the full SHA
    9f69134 View commit details
    Browse the repository at this point in the history
  34. Make isDataOwner a private policy decision in BroadcastHandler

    isDataOwner is used when deciding how many peer nodes should receive
    a BroadcastMessage. If the BroadcastMessage originated
    on the local node it is sent to ALL peer nodes with a small delay.
    
    If the node is only relaying the message (it originated on a different
    node) it is sent to MAX(peers.size(), 7) peers with a delay that is
    twice as long.
    
    All the information needed to determine whether or not the
    BroadcastMessage originated on the local node is available at the final
    broadcast site and there is no reason to have callers pass it in.
    
    In the event that the sender address is not known during broadcast (which
    is only a remote possibility due to how early the local node address
    is set during startup) we can default to relay mode.
    
    This first patch just removes the deep parameters. The next will remove
    everything else. There is one real change in LiteNodeNetworkService.java
    where it was using the local node when it should have been using the
    peer node. This was updated to the correct behavior.
    julianknutsen committed Dec 3, 2019
    Configuration menu
    Copy the full SHA
    bfdb8f5 View commit details
    Browse the repository at this point in the history
  35. Remove isDataOwner from P2PDataStorage

    Remove all usages in code and tests now that the behavior is
    internal to the BroadcastHandler
    julianknutsen committed Dec 3, 2019
    Configuration menu
    Copy the full SHA
    4dc4532 View commit details
    Browse the repository at this point in the history
  36. [REFACTOR] inline broadcast() private function

    Now that it is identical the the broadcaster version it can be
    inlined.
    julianknutsen committed Dec 3, 2019
    Configuration menu
    Copy the full SHA
    6ff8756 View commit details
    Browse the repository at this point in the history
  37. [REFACTOR] inline broadcastProtectedStorageEntry() private function

    Now that it is identical the the broadcaster version it can be
    inlined.
    julianknutsen committed Dec 3, 2019
    Configuration menu
    Copy the full SHA
    5a174d5 View commit details
    Browse the repository at this point in the history
  38. [REFACTOR] inline maybeAddToRemoveAddOncePayloads() private function

    Now that there is only one user it can be inlined.
    julianknutsen committed Dec 3, 2019
    Configuration menu
    Copy the full SHA
    1bd450b View commit details
    Browse the repository at this point in the history
  39. [TESTS] Clean up mockito never() and eq(null) usages

    never() and any() don't play well together for nullable types. Change
    the broadcast mocks to user nullable() and fixup tests.
    julianknutsen committed Dec 3, 2019
    Configuration menu
    Copy the full SHA
    17f4b70 View commit details
    Browse the repository at this point in the history