@Test
  public void should_query_with_default_params() throws Exception {
    long partitionKey = RandomUtils.nextLong();
    List<ClusteredEntityWithReverseClustering> entities =
        manager
            .sliceQuery(ClusteredEntityWithReverseClustering.class)
            .partitionComponents(partitionKey)
            .getFirst(5);
    assertThat(entities).isEmpty();

    insertValues(partitionKey, 5);

    entities =
        manager
            .sliceQuery(ClusteredEntityWithReverseClustering.class)
            .partitionComponents(partitionKey)
            .fromClusterings(4)
            .toClusterings(2)
            .get();

    assertThat(entities).hasSize(3);

    assertThat(entities.get(0).getValue()).isEqualTo("value4");
    assertThat(entities.get(0).getId().getId()).isEqualTo(partitionKey);
    assertThat(entities.get(0).getId().getCount()).isEqualTo(4);
    assertThat(entities.get(0).getId().getName()).isEqualTo("name4");
    assertThat(entities.get(1).getValue()).isEqualTo("value3");
    assertThat(entities.get(1).getId().getId()).isEqualTo(partitionKey);
    assertThat(entities.get(1).getId().getCount()).isEqualTo(3);
    assertThat(entities.get(1).getId().getName()).isEqualTo("name3");
    assertThat(entities.get(2).getValue()).isEqualTo("value2");
    assertThat(entities.get(2).getId().getId()).isEqualTo(partitionKey);
    assertThat(entities.get(2).getId().getCount()).isEqualTo(2);
    assertThat(entities.get(2).getId().getName()).isEqualTo("name2");

    entities =
        manager
            .sliceQuery(ClusteredEntityWithReverseClustering.class)
            .fromEmbeddedId(new ClusteredKey(partitionKey, 4, null))
            .toEmbeddedId(new ClusteredKey(partitionKey, 2, null))
            .get();

    assertThat(entities).hasSize(3);

    assertThat(entities.get(0).getValue()).isEqualTo("value4");
    assertThat(entities.get(0).getId().getId()).isEqualTo(partitionKey);
    assertThat(entities.get(0).getId().getCount()).isEqualTo(4);
    assertThat(entities.get(0).getId().getName()).isEqualTo("name4");
    assertThat(entities.get(1).getValue()).isEqualTo("value3");
    assertThat(entities.get(1).getId().getId()).isEqualTo(partitionKey);
    assertThat(entities.get(1).getId().getCount()).isEqualTo(3);
    assertThat(entities.get(1).getId().getName()).isEqualTo("name3");
    assertThat(entities.get(2).getValue()).isEqualTo("value2");
    assertThat(entities.get(2).getId().getId()).isEqualTo(partitionKey);
    assertThat(entities.get(2).getId().getCount()).isEqualTo(2);
    assertThat(entities.get(2).getId().getName()).isEqualTo("name2");
  }
  @Test
  public void should_query_with_reverse_ordering() throws Exception {
    long partitionKey = RandomUtils.nextLong();
    insertValues(partitionKey, 5);

    List<ClusteredEntityWithReverseClustering> entities =
        manager
            .sliceQuery(ClusteredEntityWithReverseClustering.class)
            .partitionComponents(partitionKey)
            .fromClusterings(2)
            .toClusterings(4)
            .ordering(DESCENDING)
            .get();

    assertThat(entities).hasSize(3);

    assertThat(entities.get(0).getValue()).isEqualTo("value2");
    assertThat(entities.get(0).getId().getId()).isEqualTo(partitionKey);
    assertThat(entities.get(0).getId().getCount()).isEqualTo(2);
    assertThat(entities.get(0).getId().getName()).isEqualTo("name2");
    assertThat(entities.get(1).getValue()).isEqualTo("value3");
    assertThat(entities.get(1).getId().getId()).isEqualTo(partitionKey);
    assertThat(entities.get(1).getId().getCount()).isEqualTo(3);
    assertThat(entities.get(1).getId().getName()).isEqualTo("name3");
    assertThat(entities.get(2).getValue()).isEqualTo("value4");
    assertThat(entities.get(2).getId().getId()).isEqualTo(partitionKey);
    assertThat(entities.get(2).getId().getCount()).isEqualTo(4);
    assertThat(entities.get(2).getId().getName()).isEqualTo("name4");
  }
Пример #3
0
  @Test
  public void should_check_for_common_operation_on_found_clustered_entity_by_iterator()
      throws Exception {
    long partitionKey = RandomUtils.nextLong(0, Long.MAX_VALUE);
    insertClusteredValues(partitionKey, 1, "name1", 1);

    Iterator<ClusteredEntity> iter =
        manager
            .sliceQuery(ClusteredEntity.class)
            .forIteration()
            .withPartitionComponents(partitionKey)
            .iterator();

    iter.hasNext();
    ClusteredEntity clusteredEntity = iter.next();

    // Check for update
    clusteredEntity.setValue("dirty");
    manager.update(clusteredEntity);

    ClusteredEntity check = manager.find(ClusteredEntity.class, clusteredEntity.getId());
    assertThat(check.getValue()).isEqualTo("dirty");

    // Check for refresh
    check.setValue("dirty_again");
    manager.update(check);

    manager.refresh(clusteredEntity);
    assertThat(clusteredEntity.getValue()).isEqualTo("dirty_again");

    // Check for remove
    manager.delete(clusteredEntity);
    assertThat(manager.find(ClusteredEntity.class, clusteredEntity.getId())).isNull();
  }
Пример #4
0
  @Test
  public void should_iterate_with_partition_keys_and_partition_keys_IN_and_from_clusterings()
      throws Exception {
    // Given
    long partitionKey = RandomUtils.nextLong(0, Long.MAX_VALUE);

    insertCompositeClusteredValues(partitionKey, "bucket1", 1, "abc", 1);
    insertCompositeClusteredValues(partitionKey, "bucket2", 1, "name", 1);
    insertCompositeClusteredValues(partitionKey, "bucket3", 1, "name", 1);

    // When
    final Iterator<CompositeClusteredEntity> iterator =
        manager
            .sliceQuery(CompositeClusteredEntity.class)
            .forIteration()
            .withPartitionComponents(partitionKey)
            .andPartitionComponentsIN("bucket1", "bucket3")
            .fromClusterings(1, "name1")
            .iterator();

    // Then
    assertThat(iterator.hasNext()).isTrue();
    CompositeClusteredEntity next = iterator.next();
    assertThat(next.getId().getBucket()).isEqualTo("bucket3");
    assertThat(next.getId().getName()).isEqualTo("name1");
    assertThat(next.getValue()).isEqualTo("value11");
  }
Пример #5
0
  @Test
  public void should_iterate_with_custom_params() throws Exception {
    long partitionKey = RandomUtils.nextLong(0, Long.MAX_VALUE);
    insertClusteredValues(partitionKey, 1, "name1", 5);
    insertClusteredValues(partitionKey, 1, "name2", 5);

    Iterator<ClusteredEntity> iter =
        manager
            .sliceQuery(ClusteredEntity.class)
            .forIteration()
            .withPartitionComponents(partitionKey)
            .fromClusterings(1, "name13")
            .toClusterings(1, "name21")
            .iterator(2);

    assertThat(iter.hasNext()).isTrue();
    assertThat(iter.next().getValue()).isEqualTo("value13");

    assertThat(iter.hasNext()).isTrue();
    assertThat(iter.next().getValue()).isEqualTo("value14");

    assertThat(iter.hasNext()).isTrue();
    assertThat(iter.next().getValue()).isEqualTo("value15");

    assertThat(iter.hasNext()).isTrue();
    final ClusteredEntity next = iter.next();
    assertThat(next.getId().getName()).isEqualTo("name21");
    assertThat(next.getValue()).isEqualTo("value11");

    assertThat(iter.hasNext()).isFalse();
  }
Пример #6
0
  @Test
  public void should_iterate_with_clustering_IN() throws Exception {
    // Given
    long partitionKey = RandomUtils.nextLong(0, Long.MAX_VALUE);
    insertClusteredValues(partitionKey, 1, "name1", 3);
    insertClusteredValues(partitionKey, 1, "name2", 2);
    insertClusteredValues(partitionKey, 1, "name3", 1);
    insertClusteredValues(partitionKey, 1, "name4", 1);

    // When
    final Iterator<ClusteredEntity> iterator =
        manager
            .sliceQuery(ClusteredEntity.class)
            .forIteration()
            .withPartitionComponents(partitionKey)
            .withClusterings(1)
            .andClusteringsIN("name11", "name12", "name13", "name41")
            .limit(100)
            .iterator(2);

    // Then
    assertThat(iterator.hasNext()).isTrue();
    ClusteredEntity next = iterator.next();
    assertThat(next.getId().getName()).isEqualTo("name11");
    assertThat(next.getValue()).isEqualTo("value11");

    assertThat(iterator.hasNext()).isTrue();
    next = iterator.next();
    assertThat(next.getId().getName()).isEqualTo("name12");
    assertThat(next.getValue()).isEqualTo("value12");

    assertThat(iterator.hasNext()).isTrue();
    next = iterator.next();
    assertThat(next.getId().getName()).isEqualTo("name13");
    assertThat(next.getValue()).isEqualTo("value13");

    assertThat(iterator.hasNext()).isTrue();
    next = iterator.next();
    assertThat(next.getId().getName()).isEqualTo("name41");
    assertThat(next.getValue()).isEqualTo("value11");

    assertThat(iterator.hasNext()).isFalse();
  }
Пример #7
0
  @Test
  public void should_iterate_over_clusterings_components() throws Exception {
    // Given
    long partitionKey = RandomUtils.nextLong(0, Long.MAX_VALUE);
    insertClusteredValues(partitionKey, 1, "name1", 3);
    insertClusteredValues(partitionKey, 2, "name2", 2);
    insertClusteredValues(partitionKey, 3, "name3", 1);
    insertClusteredValues(partitionKey, 4, "name4", 1);

    // When
    final Iterator<ClusteredEntity> iterator =
        manager
            .sliceQuery(ClusteredEntity.class)
            .forIteration()
            .withPartitionComponents(partitionKey)
            .fromClusterings(1)
            .fromInclusiveToExclusiveBounds()
            .limit(6)
            .iterator(2);

    // Then
    assertThat(iterator.hasNext()).isTrue();
    assertThat(iterator.next().getValue()).isEqualTo("value11");

    assertThat(iterator.hasNext()).isTrue();
    assertThat(iterator.next().getValue()).isEqualTo("value12");

    assertThat(iterator.hasNext()).isTrue();
    assertThat(iterator.next().getValue()).isEqualTo("value13");

    assertThat(iterator.hasNext()).isTrue();
    assertThat(iterator.next().getValue()).isEqualTo("value21");

    assertThat(iterator.hasNext()).isTrue();
    assertThat(iterator.next().getValue()).isEqualTo("value22");

    assertThat(iterator.hasNext()).isTrue();
    assertThat(iterator.next().getValue()).isEqualTo("value31");

    assertThat(iterator.hasNext()).isFalse();
  }