Class Capture

java.lang.Object
io.kubfly.sdk.test.Capture

public final class Capture extends Object
The telemetry of one test as the types of reflector: a body runs in a root frame of its own, and its capture is everything of the trace of that frame — the frames under it, by their parent, in any thread; the frames of other services of the process it called, by their caller (HTTP, Kafka, RabbitMQ in the same JVM); the events and the ends of all of them. Tests in parallel do not see one another: each has its own trace.
Capture capture = Capture.run("ship", () -> orders.ship(42));
for (Item item : capture.items()) {
    if (item instanceof Event event && event.level() == Level.ERROR) {
        fail(event.message());
    }
}
The records go through the real collector of a bucket into a bucket in memory and are read by reflector, as the bucket of a stand is read: a test sees what Navigator would see, the format included. Only the events and the frames have a trace; metrics, alerts, health, traffic and profiles are of the whole process — process(). An event outside any frame belongs to no capture either: it is in process() only.
  • Method Details

    • run

      public static <X extends Throwable> Capture run(Scope.Op<X> body) throws X
      Runs a body in a new root frame (sdk/test/capture/run, even inside another frame) and captures its trace.
      Type Parameters:
      X - the exception the body may throw
      Parameters:
      body - the body
      Returns:
      the capture
      Throws:
      X - the body's exception, unchanged
      IllegalStateException - if the collector of kubfly-sdk-test was not found
    • run

      public static <X extends Throwable> Capture run(String name, Scope.Op<X> body) throws X
      Runs a body in a new root frame with the tag test — the name of the test — and captures its trace.
      Type Parameters:
      X - the exception the body may throw
      Parameters:
      name - the name of the test
      body - the body
      Returns:
      the capture
      Throws:
      X - the body's exception, unchanged
      IllegalStateException - if the collector of kubfly-sdk-test was not found
    • trace

      public UUID trace()
      The trace of the capture: that of its root frame.
      Returns:
      the trace
    • items

      public Timeline<Item> items()
      The items of the capture so far, in the order of time: Begin, End and Event of the frames of its trace, the root frame sdk/test/capture/run included. Everything the collector received until now is written and read anew; what another thread is still doing — the end of a frame of a server after its response, a consumer of a broker — may come later: items(Predicate, Duration) waits for it.
      Returns:
      the items, read once: a list behind the timeline
    • items

      public Timeline<Item> items(Predicate<? super Item> until, Duration timeout)
      The items of the capture once one of them matches, read anew every 10 ms.
      Parameters:
      until - the item awaited
      timeout - how long to wait for it
      Returns:
      the items, that one among them
      Throws:
      AssertionError - if none matched in time; the message tells how many items there were
    • process

      public static Query process()
      The whole process as reflector reads it: every stream — metrics, alerts, health, traffic, profiles, and the events outside any frame. The interval of metrics is taken now (Collectors.flush() — for every collector of the process), then everything received is written.
      Returns:
      the requests to the instance of the process
      Throws:
      IllegalStateException - if the collector of kubfly-sdk-test was not found
    • stand

      public static Stand stand()
      The stand of the recording as reflector reads it: for what an item refers to beyond its segments — the attachments of events (Stand.attachment(Origin, Attachment)). Read after items() or process(): they write what was received.
      Returns:
      the stand
      Throws:
      IllegalStateException - if the collector of kubfly-sdk-test was not found
    • toString

      public String toString()
      The text form.
      Overrides:
      toString in class Object
      Returns:
      the trace