Package zipkin2.junit

Class ZipkinRule

  • All Implemented Interfaces:
    org.junit.rules.TestRule

    public final class ZipkinRule
    extends java.lang.Object
    implements org.junit.rules.TestRule
    Starts up a local Zipkin server, listening for http requests on httpUrl().

    This can be used to test instrumentation. For example, you can POST spans directly to this server.

    See http://openzipkin.github.io/zipkin-api/#/

    • Constructor Summary

      Constructors 
      Constructor Description
      ZipkinRule()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      org.junit.runners.model.Statement apply​(org.junit.runners.model.Statement base, org.junit.runner.Description description)  
      InMemoryCollectorMetrics collectorMetrics()
      Use this to see how many spans or serialized bytes were collected on the http endpoint.
      ZipkinRule enqueueFailure​(HttpFailure failure)
      Adds a one-time failure to the http endpoint.
      java.util.List<DependencyLink> getDependencies()
      Retrieves all service links between traces this zipkin server has received.
      java.util.List<Span> getTrace​(java.lang.String traceId)
      Retrieves a trace by ID which zipkin server has received, or null if not present.
      java.util.List<java.util.List<Span>> getTraces()
      Retrieves all traces this zipkin server has received.
      int httpRequestCount()
      Use this to see how many requests you've sent to any zipkin http endpoint.
      java.lang.String httpUrl()
      Use this to connect.
      void shutdown()
      Used to manually stop the server.
      void start​(int httpPort)
      Used to manually start the server.
      ZipkinRule storeSpans​(java.util.List<Span> spans)
      Stores the given spans directly, to setup preconditions for a test.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ZipkinRule

        public ZipkinRule()
    • Method Detail

      • httpUrl

        public java.lang.String httpUrl()
        Use this to connect. The zipkin v1 interface will be under "/api/v1"
      • httpRequestCount

        public int httpRequestCount()
        Use this to see how many requests you've sent to any zipkin http endpoint.
      • collectorMetrics

        public InMemoryCollectorMetrics collectorMetrics()
        Use this to see how many spans or serialized bytes were collected on the http endpoint.
      • storeSpans

        public ZipkinRule storeSpans​(java.util.List<Span> spans)
        Stores the given spans directly, to setup preconditions for a test.

        For example, if you are testing what happens when instrumentation adds a child to a trace, you'd add the parent here.

      • enqueueFailure

        public ZipkinRule enqueueFailure​(HttpFailure failure)
        Adds a one-time failure to the http endpoint.

        Ex. If you want to test that you don't repeatedly send bad data, you could send a 400 back.

        
         zipkin.enqueueFailure(sendErrorResponse(400, "bad format"));
         
        Parameters:
        failure - type of failure the next call to the http endpoint responds with
      • getTraces

        public java.util.List<java.util.List<Span>> getTraces()
        Retrieves all traces this zipkin server has received.
      • getTrace

        @Nullable
        public java.util.List<Span> getTrace​(java.lang.String traceId)
        Retrieves a trace by ID which zipkin server has received, or null if not present.
      • getDependencies

        public java.util.List<DependencyLink> getDependencies()
        Retrieves all service links between traces this zipkin server has received.
      • start

        public void start​(int httpPort)
                   throws java.io.IOException
        Used to manually start the server.
        Parameters:
        httpPort - choose 0 to select an available port
        Throws:
        java.io.IOException
      • shutdown

        public void shutdown()
                      throws java.io.IOException
        Used to manually stop the server.
        Throws:
        java.io.IOException
      • apply

        public org.junit.runners.model.Statement apply​(org.junit.runners.model.Statement base,
                                                       org.junit.runner.Description description)
        Specified by:
        apply in interface org.junit.rules.TestRule