@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(); }
@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(); }
@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(); }