DBConsensusManager { public boolean removeFullBlock(OpBlock block) { return txTemplate.execute(new TransactionCallback<Boolean>() { @Override public Boolean doInTransaction(TransactionStatus status) { byte[] blockHash = SecUtils.getHashBytes(block.getRawHash()); int upd = jdbcTemplate.update("WITH moved_rows AS ( DELETE FROM " + BLOCKS_TABLE + " a WHERE hash = ? and superblock is null RETURNING a.*) " + " INSERT INTO " + BLOCKS_TRASH_TABLE + " (hash, phash, blockid, time, content) SELECT hash, phash, blockid, now(), content FROM moved_rows", blockHash); if (upd != 0) { for (OpOperation o : block.getOperations()) { jdbcTemplate.update("UPDATE " + OPERATIONS_TABLE + " set blocks = array_remove(blocks, ?) where hash = ?", blockHash, SecUtils.getHashBytes(o.getRawHash())); } jdbcTemplate.update("DELETE FROM " + OP_OBJ_HISTORY_TABLE + " WHERE blockhash = ?", SecUtils.getHashBytes(block.getFullHash())); orphanedBlocks.remove(block.getRawHash()); blocks.remove(block.getRawHash()); } return upd != 0; } }); }  Map<String, OpBlock> getOrphanedBlocks(); String getSuperblockHash(); OpBlockChain init(MetadataDb metadataDB); OpIndexColumn getIndex(String type, String columnId); Collection<OpIndexColumn> getIndicesForType(String type); void insertBlock(OpBlock opBlock); OpBlockChain saveMainBlockchain(OpBlockChain blc); OpBlockChain compact(int prevSize, OpBlockChain blc, boolean db); int removeOperations(Set<String> ops); boolean removeFullBlock(OpBlock block); OpBlockChain unloadSuperblockFromDB(OpBlockChain blc); ResourceDTO storeResourceObject(ResourceDTO imageDTO); ResourceDTO getResourceObjectIfExists(ResourceDTO imageDTO); List<ResourceDTO> getResources(boolean status, int addedMoreThanSecondsAgo); void removeResource(ResourceDTO resDTO); void updateResourceActiveStatus(ResourceDTO imageDTO, boolean status); Long getAmountResourcesInDB(); boolean validateExistingOperation(OpOperation op); void insertOperation(OpOperation op); OpOperation getOperationByHash(String hash); String getSetting(String key); Map<String, Map<String, OpIndexColumn>> getIndices();  }
@Test public void testRemoveFullBlock() throws FailedVerificationException { OpBlockChain opBlockChain = dbConsensusManager.init(metadataDb); generateOperations(formatter, opBlockChain); OpBlock opBlock = opBlockChain.createBlock(serverName, serverKeyPair); opBlock.getOperations().forEach(opOperation -> dbConsensusManager.insertOperation(opOperation)); dbConsensusManager.insertBlock(opBlock); assertEquals(1, getAmountFromDbByTable(BLOCKS_TABLE)); dbConsensusManager.removeFullBlock(opBlock); assertEquals(0, getAmountFromDbByTable(BLOCKS_TABLE)); assertEquals(1, getAmountFromDbByTable(BLOCKS_TRASH_TABLE)); }