typesense / typesense-java

Java client for Typesense
https://typesense.org/docs/latest/api/
Apache License 2.0
60 stars 29 forks source link

Fix Node health checks referencing a null pointer #62

Closed tharropoulos closed 2 months ago

tharropoulos commented 2 months ago

What is this?

This pull request aims to improve the reliability and efficiency of the Typesense Java client by enhancing node health checks and API call logic. It's addressing potential issues (#61) with node selection and improving testing coverage to ensure more robust behavior in cluster configuration scenarios.

Changes

Added Features:

  1. New Methods in APICallTest.java:

    • setUpNoNearestNode(): Sets up test scenarios without a nearest node.
    • setUpNearestNode(): Sets up test scenarios with a nearest node.
  2. New Test Cases in APICallTest.java:

    • testUnhealthyNearestNode(): Verifies correct node selection when the nearest node is unhealthy.
    • testHealthyNearestNode(): Ensures the nearest node is selected when healthy.
    • testUnhealthyNearestNodeDueForHealthCheck(): Checks if an unhealthy nearest node is selected for a health check after a certain time.

Code Changes:

  1. In Node.java:

    • Added initialization of lastAccessTimestamp in the constructor to support health check scheduling.
  2. In ApiCall.java:

    • Adjusted the condition in getNode() method to prioritize checking if the nearest node is healthy before checking if it's due for a health check, to avoid running more checks, as the first OR statement that resolves to true will make the condition exit.

PR Checklist