Skip to content
This repository was archived by the owner on Jan 14, 2026. It is now read-only.
This repository was archived by the owner on Jan 14, 2026. It is now read-only.

(Discuss) Abstract the FastForward client used in FastForwardReporter #76

@clairemcginty

Description

@clairemcginty

public Builder fastForward(FastForward client) {
this.client = client;
return this;
}

The current setup for FastForwardReporter requires a user to pass in a real FastForward client, which is not easily unit testable -- in a production environment the FastForward client would be already running within the container, but in a local unit testing environment this can be pretty cumbersome to set up.

It would be simpler if we had some kind of interface or abstract class to allow the user to sub in different implementations of the FastForward client -- the only method it would have to implement is public void send(Metric metric) { }.

Quick code sketch of what I'm thinking:

public abstract class FastForwardClient {
  public abstract void send(Metric metric) throws IOException;

  // Default implementation
  public static FastForwardClient create(String host, int port) throws UnknownHostException, SocketException {
    return new FastForwardClient() {
      private final FastForward underlying = FastForward.setup(host, port);
      
      @Override
      public void send(Metric metric) throws IOException {
        underlying.send(metric);
      }
    };
  }
}

Then the FastForwardReporter's builder would look like:

public Builder fastForward(FastForwardClient client) {
  this.client = client;
  return this;
}

public FastForwardReporter build() throws IOException {
  final FastForwardClient client = this.client != null ? this.client : FastForwardClient.create(host, port);
  ...
}

And in a unit-testing context we could easily sub in something like this that's easy to validate:

public class StubbedFastForwardClient extends FastForwardClient {
  private final List<Metric> collectedMetrics;

  public StubbedFastForwardClient(List<Metric> collectedMetrics) {
    this.collectedMetrics = new ArrayList<>();
  }

  @Override
  public void send(Metric metric) throws IOException {
    collectedMetrics.add(metric);
  }

  public List<Metric> getCollectedMetrics() {
    return collectedMetrics;
  }
}

lmk what you think! I'm happy to make the PR myself if this seems reasonable.

(Not sure if this issue belongs more in ffwd-client-java... it would probably be better to fix it there, but it's also a bigger/more impactful change to make.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions