net.i2p.router.tunnel.pool

## Class TestJob

- java.lang.Object
- - net.i2p.router.JobImpl
  - - net.i2p.router.tunnel.pool.TestJob

- All Implemented Interfaces:
    Job

      public class TestJob
      extends JobImpl

  Repeatedly tests a single tunnel for its lifetime to ensure it remains functional. Sends a garlic-encrypted DeliveryStatusMessage through the tunnel and validates the reply. Now includes adaptive backoff, avoids over-penalizing peers on transient failures, and limits the number of concurrent tunnel tests to avoid overwhelming the router.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `MAX_TEST_JOB_LIMIT` Maximum hard limit for total TestJob instances (queued + active).
    `static int` | `maxQueuedTests`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `TestJob(RouterContext ctx, PooledTunnelCreatorConfig cfg, TunnelPool pool)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `dropped()` Called when the job is dropped due to router overload.
    `String` | `getName()` Descriptive name of the task
    `boolean` | `isValid()` Check if this TestJob instance is valid and should be queued.
    `void` | `runJob()` Actually perform the task.
    `static boolean` | `shouldSchedule(RouterContext ctx, PooledTunnelCreatorConfig cfg)` Static method to check if a TestJob should be created and scheduled.
    `void` | `testSuccessful(int ms)` Called when the tunnel test completes successfully.

    - ### Methods inherited from class net.i2p.router.JobImpl

      `getContext, getJobId, getMadeReadyOn, getTiming, madeReady, requeue, toString`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### MAX_TEST_JOB_LIMIT

          public static final int MAX_TEST_JOB_LIMIT

      Maximum hard limit for total TestJob instances (queued + active). Above this threshold, no new tests are scheduled until count decreases. Prevents ever-increasing backlogs that could cause job lag. Dynamic limit varies between this and BASE_TEST_JOB_LIMIT based on job lag.

    - #### maxQueuedTests

          public static int maxQueuedTests

  - ### Constructor Detail

    - #### TestJob

          public TestJob(RouterContext ctx,
                         PooledTunnelCreatorConfig cfg,
                         TunnelPool pool)

  - ### Method Detail

    - #### dropped

          public void dropped()

      Called when the job is dropped due to router overload. Ensure we clean up the total job counter when dropped.
      Specified by:
        `dropped` in interface `Job`
      Overrides:
        `dropped` in class `JobImpl`

    - #### getName

          public String getName()

      Description copied from interface: `Job`
      Descriptive name of the task
      Returns:
        the descriptive name of the task

    - #### isValid

          public boolean isValid()

      Check if this TestJob instance is valid and should be queued.
      Returns:
        true if valid, false if it should not be queued

    - #### runJob

          public void runJob()

      Description copied from interface: `Job`
      Actually perform the task. This call blocks until the Job is complete.

    - #### shouldSchedule

          public static boolean shouldSchedule(RouterContext ctx,
                                               PooledTunnelCreatorConfig cfg)

      Static method to check if a TestJob should be created and scheduled. This prevents creating invalid job objects that would have timing issues.
      Parameters:
        `ctx` - the router context
        `cfg` - the tunnel config
      Returns:
        true if the job should be created and scheduled, false otherwise

    - #### testSuccessful

          public void testSuccessful(int ms)

      Called when the tunnel test completes successfully. Updates statistics and schedules the next test.
      Parameters:
        `ms` - time in milliseconds the test took to succeed