@Test public void selectByQuery_with_empty_list_of_keys_returns_all() { insertOrganization(ORGANIZATION_DTO_1); insertOrganization(ORGANIZATION_DTO_2); OrganizationQuery organizationQuery = newOrganizationQueryBuilder().setKeys(Lists.emptyList()).build(); assertThat(underTest.selectByQuery(dbSession, organizationQuery, forPage(1).andSize(10))) .extracting(OrganizationDto::getUuid) .containsOnly(ORGANIZATION_DTO_1.getUuid(), ORGANIZATION_DTO_2.getUuid()); }
@Override public GuiceTestContext createChildContext(Iterable<State> newStatesIterable) { return createChildContext(newStatesIterable, emptyList()); }
@Override public GuiceTestContext createChildContext(Iterable<State> newStatesIterable) { return createChildContext(newStatesIterable, emptyList()); }
@Override @RunsInCurrentThread @Nonnull public Collection<Component> nonExplicitChildrenOf(@Nonnull Container c) { if (!(c instanceof JDesktopPane)) { return emptyList(); } return internalFramesFromIcons(c); }
@RunsInCurrentThread @Override @Nonnull public Collection<Component> nonExplicitChildrenOf(@Nonnull Container c) { if (!(c instanceof Window)) { return emptyList(); } return ownedWindows((Window) c); }
@Nonnull private Collection<Component> windows(@Nonnull Component[] windows) { if (isNullOrEmpty(windows)) { return emptyList(); } return newArrayList(windows); } }
@RunsInCurrentThread @Nonnull Collection<Component> childrenOf(@Nonnull Component c) { if (!(c instanceof Container)) { return emptyList(); } Container container = (Container) c; List<Component> children = newArrayList(container.getComponents()); children.addAll(nonExplicitChildrenOf(container)); return children; }
@RunsInCurrentThread @Override @Nonnull public Collection<Component> nonExplicitChildrenOf(@Nonnull Container c) { if (!(c instanceof JMenu)) { return emptyList(); } return newArrayList((Component) ((JMenu) c).getPopupMenu()); } }
public Request<?, GetNodesWhitelistResponse> getNodesWhitelist() { return new Request<>( "perm_getNodesWhitelist", Lists.emptyList(), web3jService, GetNodesWhitelistResponse.class); }
@Before public void setup() { ibftMiningCoordinator = new IbftMiningCoordinator(ibftProcessor, ibftBlockCreatorFactory, blockChain, eventQueue); when(block.getBody()).thenReturn(blockBody); when(block.getHeader()).thenReturn(blockHeader); when(blockBody.getTransactions()).thenReturn(Lists.emptyList()); }
@Test public void locallyGeneratedBlockInvalidatesMiningEvenIfInTurn() { // Note also - validators is an hard-ordered LIST, thus in-turn will follow said list - block_1 // should be created by Proposer, and thus will be in-turn. final CliqueMiningCoordinator coordinator = new CliqueMiningCoordinator(blockChain, minerExecutor, syncState, miningTracker); coordinator.enable(); verify(minerExecutor, times(1)).startAsyncMining(any(), any()); reset(minerExecutor); when(minerExecutor.startAsyncMining(any(), any())).thenReturn(blockMiner); final Block importedBlock = createEmptyBlock(1, blockChain.getChainHeadHash(), proposerKeys); blockChain.appendBlock(importedBlock, Lists.emptyList()); // The minerExecutor should not be invoked as the mining operation was conducted by an in-turn // validator, and the created block came from an out-turn validator. ArgumentCaptor<BlockHeader> varArgs = ArgumentCaptor.forClass(BlockHeader.class); verify(minerExecutor, times(1)).startAsyncMining(any(), varArgs.capture()); assertThat(varArgs.getValue()).isEqualTo(blockChain.getChainHeadHeader()); }
@Test public void shouldReturnSuccessResponseWhenListSetAndEmpty() { final JsonRpcRequest request = buildRequest(); final JsonRpcResponse expected = new JsonRpcSuccessResponse(request.getId(), Lists.emptyList()); when(p2pNetwork.getNodeWhitelistController()).thenReturn(nodeWhitelistController); when(nodeWhitelistController.nodeWhitelistSet()).thenReturn(true); when(nodeWhitelistController.getNodesWhitelist()).thenReturn(buildNodesList()); final JsonRpcResponse actual = method.response(request); assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected); verify(nodeWhitelistController, times(1)).nodeWhitelistSet(); verify(nodeWhitelistController, times(1)).getNodesWhitelist(); verifyNoMoreInteractions(nodeWhitelistController); }
@Test public void outOfTurnBlockImportedInterruptsOutOfTurnMiningOperation() { blockChain.appendBlock( createEmptyBlock(1, blockChain.getChainHeadHash(), validatorKeys), Lists.emptyList()); when(blockMiner.getParentHeader()).thenReturn(blockChain.getChainHeadHeader()); // Note also - validators is an hard-ordered LIST, thus in-turn will follow said list - block_2 // should be created by 'validator', thus Proposer is out-of-turn. final CliqueMiningCoordinator coordinator = new CliqueMiningCoordinator(blockChain, minerExecutor, syncState, miningTracker); coordinator.enable(); verify(minerExecutor, times(1)).startAsyncMining(any(), any()); reset(minerExecutor); when(minerExecutor.startAsyncMining(any(), any())).thenReturn(blockMiner); final Block importedBlock = createEmptyBlock(2, blockChain.getChainHeadHash(), validatorKeys); blockChain.appendBlock(importedBlock, Lists.emptyList()); // The minerExecutor should not be invoked as the mining operation was conducted by an in-turn // validator, and the created block came from an out-turn validator. ArgumentCaptor<BlockHeader> varArgs = ArgumentCaptor.forClass(BlockHeader.class); verify(minerExecutor, times(1)).startAsyncMining(any(), varArgs.capture()); assertThat(varArgs.getValue()).isEqualTo(blockChain.getChainHeadHeader()); }
private Block createEmptyBlock( final long blockNumber, final Hash parentHash, final KeyPair signer) { headerTestFixture.number(blockNumber).parentHash(parentHash); final BlockHeader header = TestHelpers.createCliqueSignedBlockHeader(headerTestFixture, signer, validators); return new Block(header, new BlockBody(Lists.emptyList(), Lists.emptyList())); } }
@Test public void outOfTurnBlockImportedInterruptsNonRunningMiner() { blockChain.appendBlock( createEmptyBlock(1, blockChain.getChainHeadHash(), proposerKeys), Lists.emptyList()); when(blockMiner.getParentHeader()).thenReturn(blockChain.getChainHeadHeader()); // Note also - validators is an hard-ordered LIST, thus in-turn will follow said list - block_2 // should be created by 'validator', thus Proposer is out-of-turn. final CliqueMiningCoordinator coordinator = new CliqueMiningCoordinator(blockChain, minerExecutor, syncState, miningTracker); coordinator.enable(); verify(minerExecutor, times(1)).startAsyncMining(any(), any()); reset(minerExecutor); when(minerExecutor.startAsyncMining(any(), any())).thenReturn(blockMiner); final Block importedBlock = createEmptyBlock(2, blockChain.getChainHeadHash(), validatorKeys); blockChain.appendBlock(importedBlock, Lists.emptyList()); // The minerExecutor should not be invoked as the mining operation was conducted by an in-turn // validator, and the created block came from an out-turn validator. ArgumentCaptor<BlockHeader> varArgs = ArgumentCaptor.forClass(BlockHeader.class); verify(minerExecutor, times(1)).startAsyncMining(any(), varArgs.capture()); assertThat(varArgs.getValue()).isEqualTo(blockChain.getChainHeadHeader()); }
@Test public void outOfTurnBlockImportedDoesNotInterruptInTurnMiningOperation() { // As the head of the blockChain is 0 (which effectively doesn't have a signer, all validators // are able to propose. when(blockMiner.getParentHeader()).thenReturn(blockChain.getChainHeadHeader()); // Note also - validators is an hard-ordered LIST, thus in-turn will follow said list - block_1 // should be created by proposer. final CliqueMiningCoordinator coordinator = new CliqueMiningCoordinator(blockChain, minerExecutor, syncState, miningTracker); coordinator.enable(); verify(minerExecutor, times(1)).startAsyncMining(any(), any()); reset(minerExecutor); final Block importedBlock = createEmptyBlock(1, blockChain.getChainHeadHash(), validatorKeys); blockChain.appendBlock(importedBlock, Lists.emptyList()); // The minerExecutor should not be invoked as the mining operation was conducted by an in-turn // validator, and the created block came from an out-turn validator. verify(minerExecutor, never()).startAsyncMining(any(), any()); }
@Test public void shouldDeleteJobInfos() throws Exception { // given repo.createOrUpdate(someJobInfo("http://localhost/foo")); // when repo.deleteAll(); // then assertThat(repo.findAll(), is(Lists.emptyList())); }
@Test public void shouldClearJobInfos() throws Exception { //Given JobInfo stoppedJob = builder() .setJobId("some/job/stopped") .setJobType("test") .setStarted(now(fixed(Instant.now().minusSeconds(10), systemDefault()))) .setStopped(now(fixed(Instant.now().minusSeconds(7), systemDefault()))) .setHostname("localhost") .setStatus(JobStatus.OK) .build(); repository.createOrUpdate(stoppedJob); //When repository.deleteAll(); //Then assertThat(repository.findAll(), is(emptyList())); }
@Before public void constructThreeBlockChain() { for (int i = 0; i < 3; i++) { validators.add(AddressHelpers.ofValue(i)); } headerBuilder.extraData( new CliqueExtraData( BytesValue.wrap(new byte[32]), Signature.create(BigInteger.TEN, BigInteger.TEN, (byte) 1), validators) .encode()); genesisBlock = createEmptyBlock(0, Hash.ZERO); blockChain = createInMemoryBlockchain(genesisBlock); block_1 = createEmptyBlock(1, genesisBlock.getHeader().getHash()); block_2 = createEmptyBlock(1, block_1.getHeader().getHash()); blockChain.appendBlock(block_1, Lists.emptyList()); blockChain.appendBlock(block_2, Lists.emptyList()); }