Ejemplo n.º 1
0
  /**
   * Submits a query via the session.
   *
   * @param query The query to submit.
   * @param <T> The query output type.
   * @return A completable future to be completed with the query output.
   */
  public <T> CompletableFuture<T> submit(Query<T> query) {
    if (!isOpen()) return Futures.exceptionalFuture(new IllegalStateException("session not open"));

    CompletableFuture<T> future = new CompletableFuture<>();
    context
        .executor()
        .execute(
            () -> {
              QueryRequest request;
              if (query.consistency() == Query.ConsistencyLevel.CAUSAL) {
                request =
                    QueryRequest.builder()
                        .withSession(id)
                        .withSequence(commandResponse)
                        .withVersion(responseVersion)
                        .withQuery(query)
                        .build();
              } else {
                request =
                    QueryRequest.builder()
                        .withSession(id)
                        .withSequence(commandRequest)
                        .withVersion(responseVersion)
                        .withQuery(query)
                        .build();
              }

              submit(request, future);
            });
    return future;
  }
Ejemplo n.º 2
0
  @Test
  public void limitMustBePositive() {
    thrown.expect(IllegalArgumentException.class);
    thrown.expectMessage("limit should be positive: was 0");

    QueryRequest.builder().serviceName("foo").limit(0).build();
  }
Ejemplo n.º 3
0
  @Test
  public void endTsMustBePositive() {
    thrown.expect(IllegalArgumentException.class);
    thrown.expectMessage("endTs should be positive, in epoch microseconds: was 0");

    QueryRequest.builder().serviceName("foo").endTs(0L).build();
  }
Ejemplo n.º 4
0
  @Test
  public void binaryAnnotationValueCantBeEmpty() {
    thrown.expect(IllegalArgumentException.class);
    thrown.expectMessage("binary annotation value for foo was empty");

    QueryRequest.builder().serviceName("foo").addBinaryAnnotation("foo", "").build();
  }
Ejemplo n.º 5
0
  /**
   * Particularly in the case of cassandra, indexing boundary annotations isn't fruitful work, and
   * not helpful to users. Nevertheless we should ensure an unlikely caller gets an exception.
   */
  @Test
  public void annotationCantBeCore() {
    thrown.expect(IllegalArgumentException.class);
    thrown.expectMessage("queries cannot be refined by core annotations: sr");

    QueryRequest.builder().serviceName("foo").addAnnotation(Constants.SERVER_RECV).build();
  }
Ejemplo n.º 6
0
  @Test
  public void annotationCantBeEmpty() {
    thrown.expect(IllegalArgumentException.class);
    thrown.expectMessage("annotation was empty");

    QueryRequest.builder().serviceName("foo").addAnnotation("").build();
  }
Ejemplo n.º 7
0
  @Test
  public void spanNameCantBeEmpty() {
    thrown.expect(IllegalArgumentException.class);
    thrown.expectMessage("spanName was empty");

    QueryRequest.builder().serviceName("foo").spanName("").build();
  }
Ejemplo n.º 8
0
  @Test
  public void maxDuration_greaterThanOrEqualToMinDuration() {
    thrown.expect(IllegalArgumentException.class);
    thrown.expectMessage("maxDuration should be >= minDuration");

    QueryRequest.builder().serviceName("foo").minDuration(1L).maxDuration(0L).build();
  }
Ejemplo n.º 9
0
  @Test
  public void maxDuration_onlyWithMinDuration() {
    thrown.expect(IllegalArgumentException.class);
    thrown.expectMessage("maxDuration is only valid with minDuration");

    QueryRequest.builder().serviceName("foo").maxDuration(0L).build();
  }
Ejemplo n.º 10
0
  @Test
  public void minDuration_mustBePositive() {
    thrown.expect(IllegalArgumentException.class);
    thrown.expectMessage("minDuration must be a positive number of microseconds");

    QueryRequest.builder().serviceName("foo").minDuration(0L).build();
  }
Ejemplo n.º 11
0
  @Test
  public void annotationQuery_roundTrip() {
    String annotationQuery = "http.method=GET and error";

    QueryRequest request =
        QueryRequest.builder()
            .serviceName("security-service")
            .parseAnnotationQuery(annotationQuery)
            .build();

    assertThat(request.binaryAnnotations).containsEntry(HTTP_METHOD, "GET").hasSize(1);
    assertThat(request.annotations).containsExactly(Constants.ERROR);

    assertThat(request.toAnnotationQuery()).isEqualTo(annotationQuery);
  }
Ejemplo n.º 12
0
  @Test
  public void annotationQuery_missingValue() {
    thrown.expect(IllegalArgumentException.class);
    thrown.expectMessage("binary annotation value for http.method was empty");

    String annotationQuery = "http.method=";

    QueryRequest request =
        QueryRequest.builder()
            .serviceName("security-service")
            .parseAnnotationQuery(annotationQuery)
            .build();

    assertThat(request.annotations).containsExactly(HTTP_METHOD);
  }
Ejemplo n.º 13
0
 @Test
 public void serviceNameCanBeNull() {
   assertThat(QueryRequest.builder().build().serviceName).isNull();
 }
Ejemplo n.º 14
0
  @Test
  public void toAnnotationQueryWhenNoInputIsNull() {
    QueryRequest request = QueryRequest.builder().serviceName("security-service").build();

    assertThat(request.toAnnotationQuery()).isNull();
  }