Search in sources :

Example 6 with BlockPaginationStreamer

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);
}
Also used : BlockSearchCriteria(io.nem.symbol.sdk.api.BlockSearchCriteria) BlockInfo(io.nem.symbol.sdk.model.blockchain.BlockInfo) BlockPaginationStreamer(io.nem.symbol.sdk.api.BlockPaginationStreamer) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with BlockPaginationStreamer

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()));
}
Also used : BlockRepository(io.nem.symbol.sdk.api.BlockRepository) BlockSearchCriteria(io.nem.symbol.sdk.api.BlockSearchCriteria) BlockInfo(io.nem.symbol.sdk.model.blockchain.BlockInfo) BlockPaginationStreamer(io.nem.symbol.sdk.api.BlockPaginationStreamer) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

BlockPaginationStreamer (io.nem.symbol.sdk.api.BlockPaginationStreamer)7 BlockSearchCriteria (io.nem.symbol.sdk.api.BlockSearchCriteria)7 BlockInfo (io.nem.symbol.sdk.model.blockchain.BlockInfo)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 EnumSource (org.junit.jupiter.params.provider.EnumSource)7 BlockRepository (io.nem.symbol.sdk.api.BlockRepository)5 PublicKey (io.nem.symbol.core.crypto.PublicKey)2 Address (io.nem.symbol.sdk.model.account.Address)2