use of io.nem.symbol.sdk.api.BlockPaginationStreamer in project nem2-sdk-java by nemtech.
the class BlockRepositoryIntegrationTest method searchOrderByHeightDesc.
@ParameterizedTest
@EnumSource(RepositoryType.class)
void searchOrderByHeightDesc(RepositoryType type) {
BlockSearchCriteria criteria = new BlockSearchCriteria();
criteria.setOrderBy(BlockOrderBy.HEIGHT);
criteria.setOrder(OrderBy.DESC);
BlockPaginationStreamer streamer = new BlockPaginationStreamer(getBlockRepository(type));
List<BlockInfo> blocks = get(streamer.search(criteria).toList().toObservable());
List<BlockInfo> sorted = blocks.stream().sorted(Comparator.comparing(BlockInfo::getHeight).reversed()).collect(Collectors.toList());
Assertions.assertEquals(blocks, sorted);
}
use of io.nem.symbol.sdk.api.BlockPaginationStreamer in project nem2-sdk-java by nemtech.
the class BlockRepositoryIntegrationTest method searchUsingOffset.
@ParameterizedTest
@EnumSource(RepositoryType.class)
void searchUsingOffset(RepositoryType type) {
BlockRepository blockRepository = getBlockRepository(type);
BlockPaginationStreamer streamer = new BlockPaginationStreamer(blockRepository);
BlockSearchCriteria criteria = new BlockSearchCriteria();
criteria.setPageSize(10);
criteria.setOrderBy(BlockOrderBy.HEIGHT);
int offsetIndex = 2;
List<BlockInfo> blocksWithoutOffset = get(streamer.search(criteria).toList().toObservable());
String offset = blocksWithoutOffset.get(offsetIndex).getHeight().toString();
criteria.setOffset(offset);
List<BlockInfo> blockFromOffsets = get(streamer.search(criteria).toList().toObservable());
List<BlockInfo> expectedList = blocksWithoutOffset.stream().skip(offsetIndex + 1).collect(Collectors.toList());
// If the block grows when running the last search
PaginationTester.sameEntities(expectedList, blockFromOffsets.subList(0, expectedList.size()));
}
Aggregations