@Test
  protected void getTraces_multipleAnnotationsBecomeAndFilter(TestInfo testInfo) throws Exception {
    String testSuffix = testSuffix(testInfo);
    Endpoint frontend = suffixServiceName(TestObjects.FRONTEND, testSuffix);

    Span foo = Span.newBuilder().traceId(newTraceId()).name("call1").id(1)
      .timestamp((TODAY + 1) * 1000L)
      .localEndpoint(frontend)
      .addAnnotation((TODAY + 1) * 1000L, "foo").build();
    // would be foo bar, except lexicographically bar precedes foo
    Span barAndFoo = Span.newBuilder().traceId(newTraceId()).name("call2").id(2)
      .timestamp((TODAY + 2) * 1000L)
      .localEndpoint(frontend)
      .addAnnotation((TODAY + 2) * 1000L, "bar")
      .addAnnotation((TODAY + 2) * 1000L, "foo").build();
    Span fooAndBazAndQux = Span.newBuilder().traceId(newTraceId()).name("call3").id(3)
      .timestamp((TODAY + 3) * 1000L)
      .localEndpoint(frontend)
      .addAnnotation((TODAY + 3) * 1000L, "foo")
      .putTag("baz", "qux")
      .build();
    Span barAndFooAndBazAndQux = Span.newBuilder().traceId(newTraceId()).name("call4").id(4)
      .timestamp((TODAY + 4) * 1000L)
      .localEndpoint(frontend)
      .addAnnotation((TODAY + 4) * 1000L, "bar")
      .addAnnotation((TODAY + 4) * 1000L, "foo")
      .putTag("baz", "qux")
      .build();

    accept(foo, barAndFoo, fooAndBazAndQux, barAndFooAndBazAndQux);

    assertGetTracesReturns(
      requestBuilder().serviceName(frontend.serviceName()).parseAnnotationQuery("foo").build(),
      List.of(foo), List.of(barAndFoo), List.of(fooAndBazAndQux), List.of(barAndFooAndBazAndQux)
    );

    assertGetTracesReturns(
      requestBuilder().serviceName(frontend.serviceName())
        .parseAnnotationQuery("foo and bar")
        .build(),
      List.of(barAndFoo), List.of(barAndFooAndBazAndQux)
    );

    assertGetTracesReturns(
      requestBuilder().serviceName(frontend.serviceName())
        .parseAnnotationQuery("foo and bar and baz=qux")
        .build(),
      List.of(barAndFooAndBazAndQux));

    // ensure we can search only by tag key
    assertGetTracesReturns(
      requestBuilder().serviceName(frontend.serviceName()).parseAnnotationQuery("baz").build(),
      List.of(fooAndBazAndQux), List.of(barAndFooAndBazAndQux)
    );
  }
Prevents subtle bugs which can result in mixed-length traces from linking.
zipkin-tests/src/main/java/zipkin2/storage/ITSpanStore.java