Class OtlpTestCollector
java.lang.Object
com.codename1.backend.test.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.
-
Method Summary
Modifier and TypeMethodDescriptionbooleanWaits untilcountrequests have arrived atpath; false whentimeoutMillispassed first.List<byte[]> The bodies that arrived atpath, oldest first.voidclear()Forgets what arrived so far.intHow many requests arrived atpath,/v1/tracesor/v1/metrics.The base URL forcn1.otel.endpoint,http://127.0.0.1:<port>.intgetPort()The port it listens on.static OtlpTestCollectorstart()A collector on a free loopback port.static OtlpTestCollectorstart(int port) A collector onport, for an endpoint a test names in its properties.voidstop()Stops listening.
-
Method Details
-
start
A collector on a free loopback port.- Throws:
IOException
-
start
A collector onport, for an endpoint a test names in its properties.- Throws:
IOException
-
getPort
public int getPort()The port it listens on. -
getEndpoint
The base URL forcn1.otel.endpoint,http://127.0.0.1:<port>. -
count
How many requests arrived atpath,/v1/tracesor/v1/metrics. -
bodies
-
await
Waits untilcountrequests have arrived atpath; false whentimeoutMillispassed first.- Throws:
InterruptedException
-
clear
public void clear()Forgets what arrived so far. -
stop
public void stop()Stops listening.
-