OpBlockChain { public synchronized OpBlock createBlock(String user, KeyPair keyPair) throws FailedVerificationException { OpBlock block = rules.createAndSignBlock(getQueueOperations(), getLastBlockHeader(), user, keyPair); validateIsUnlocked(); boolean valid = rules.validateBlock(this, block, getLastBlockHeader(), true); if(!valid) { return null; } locked = LOCKED_OP_IN_PROGRESS; try { atomicCreateBlockFromAllOps(block); locked = UNLOCKED; } finally { if(locked == LOCKED_OP_IN_PROGRESS) { locked = LOCKED_ERROR; } } return block; } private  OpBlockChain(boolean nullParent);  OpBlockChain(OpBlockChain parent, OpBlockchainRules rules);  OpBlockChain(OpBlockChain parent, Collection<OpBlock> headers, BlockDbAccessInterface dbAccess, OpBlockchainRules rules);  OpBlockChain(OpBlockChain copy, OpBlockChain parentToMerge, OpBlockchainRules rules); synchronized void validateLocked(); boolean isQueueEmpty(); boolean isDbAccessed(); int getStatus(); synchronized void lockByUser(); synchronized void unlockByUser(); synchronized OpBlock createBlock(String user, KeyPair keyPair); synchronized boolean removeAllQueueOperations(); synchronized OpBlock replicateBlock(OpBlock block); synchronized OpBlock replicateBlock(OpBlock block, DeletedObjectCtx hctx); synchronized boolean rebaseOperations(OpBlockChain newParent); synchronized boolean changeToEqualParent(OpBlockChain newParent); boolean addOperation(OpOperation op, DeletedObjectCtx historyObjectCtx); boolean addOperation(OpOperation op); boolean validateOperation(OpOperation op); Deque<OpOperation> getQueueOperations(); OpBlockChain getParent(); OpBlockchainRules getRules(); OpBlock getLastBlockHeader(); String getLastBlockFullHash(); String getLastBlockRawHash(); int getLastBlockId(); int getDepth(); boolean isNullBlock(); int getSuperblocksDepth(); Deque<OpBlock> getSuperblockHeaders(); Deque<OpBlock> getSuperblockFullBlocks(); Collection<String> getRawSuperblockTypes(); Stream<Entry<CompoundKey, OpObject>> getRawSuperblockObjects(String type); List<OpBlock> getBlockHeaders(int depth); OpBlock getBlockHeadersById(int id); OpBlock getFullBlockByBlockId(int id); String getSuperBlockHash(); int getSuperblockSize(); int getBlockDepth(OpBlock block); OpBlock getBlockHeaderByRawHash(String hash); OpBlock getFullBlockByRawHash(String hash); OpOperation getOperationByHash(String rawHash); OpObject getObjectByName(String type, String key); OpObject getObjectByName(String type, String key, String secondary); OpObject getObjectByName(String type, List<String> o); void setCacheAfterSearch(ObjectsSearchRequest request, Object cacheObject); int countAllObjects(String type); void fetchAllObjects(String type, ObjectsSearchRequest request); void fetchObjectsByIndex(String type, OpIndexColumn index, ObjectsSearchRequest request, Object... argsToSearch); @Override String toString(); static final String OP_CHANGE_DELETE; static final String OP_CHANGE_INCREMENT; static final String OP_CHANGE_APPEND; static final String OP_CHANGE_SET; static final int LOCKED_ERROR; static final int UNLOCKED; static final int LOCKED_OP_IN_PROGRESS; static final int LOCKED_STATE; static final int LOCKED_BY_USER; static final OpBlockChain NULL; }
@Test @Parameters(method = "parametersWithBlockchain") public void testCreateBlock(OpBlockChain opBlockChain) throws FailedVerificationException { assertFalse(opBlockChain.getQueueOperations().isEmpty()); assertEquals(-1, opBlockChain.getLastBlockId()); assertNotNull(opBlockChain.createBlock(serverName, serverKeyPair)); assertTrue(opBlockChain.getQueueOperations().isEmpty()); assertEquals(0, opBlockChain.getLastBlockId()); }
@Test public void testCreateBlockWithEmptyQueueWithException() throws FailedVerificationException { testRemoveAllQueueOperationsIfQueueNotEmpty(); exceptionRule.expect(BlockchainValidationException.class); blc.createBlock(serverName, serverKeyPair); }