Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.

public final class OtlpTestCollector

  1. Object
  2. OtlpTestCollector

An OTLP/HTTP receiver for tests: what a test points the exporters of a BackendTest.Feature.TELEMETRY application at, to see that they send and that they flush when the application stops.

It accepts every POST, answers 200 with an empty body, and keeps each request’s path and body. It decodes nothing – the exporters’ encoding has its own tests – so a test asserts on what arrived where, and how much.

static final OtlpTestCollector COLLECTOR = OtlpTestCollector.start();

@BackendTest(features = BackendTest.Feature.TELEMETRY,
        properties = {"cn1.otel.endpoint=http://127.0.0.1:4318",
                      "cn1.otel.metrics.intervalMillis=200"})

A fixed endpoint in properties needs a fixed port: start(int) takes one. Runs on the JVM and compiled alike; it is an ordinary HttpServer.

Methods

public static OtlpTestCollector start() throws IOExceptionA collector on a free loopback port.
public static OtlpTestCollector start(int port) throws IOExceptionA collector on port, for an endpoint a test names in its properties.
public int getPort()The port it listens on.
public String getEndpoint()The base URL for cn1.otel.endpoint, http://127.0.0.1:<port>.
public synchronized int count(String path)How many requests arrived at path, /v1/traces or /v1/metrics.
public synchronized List<byte[]> bodies(String path)The bodies that arrived at path, oldest first.
public synchronized boolean await(String path, int count, long timeoutMillis) throws InterruptedExceptionWaits until count requests have arrived at path; false when timeoutMillis passed first.
public synchronized void clear()Forgets what arrived so far.
public void stop()Stops listening.

Inherited methods

Method details

start

public static OtlpTestCollector start() throws IOException
A collector on a free loopback port.

start

public static OtlpTestCollector start(int port) throws IOException
A collector on port, for an endpoint a test names in its properties.

getPort

public int getPort()
The port it listens on.

getEndpoint

public String getEndpoint()
The base URL for cn1.otel.endpoint, http://127.0.0.1:<port>.

count

public synchronized int count(String path)
How many requests arrived at path, /v1/traces or /v1/metrics.

bodies

public synchronized List<byte[]> bodies(String path)
The bodies that arrived at path, oldest first.

await

public synchronized boolean await(String path, int count, long timeoutMillis) throws InterruptedException
Waits until count requests have arrived at path; false when timeoutMillis passed first.

clear

public synchronized void clear()
Forgets what arrived so far.

stop

public void stop()
Stops listening.