@Test public void testValidateExistingOperation() throws FailedVerificationException { OpBlockChain opBlockChain = dbConsensusManager.init(metadataDb); generateOperations(formatter, opBlockChain); OpBlock opBlock = opBlockChain.createBlock(serverName, serverKeyPair); opBlock.getOperations().forEach(opOperation -> dbConsensusManager.insertOperation(opOperation)); OpOperation opOperation = opBlock.getOperations().get(0); assertTrue(dbConsensusManager.validateExistingOperation(opOperation)); assertEquals(1, dbConsensusManager.removeOperations(new HashSet<>(Collections.singletonList(opOperation.getHash())))); assertFalse(dbConsensusManager.validateExistingOperation(opOperation)); }
public boolean validateExistingOperation(OpOperation op) { String js = formatter.opToJson(op); OpOperation existingOperation = getOperationByHash(op.getHash()); if (existingOperation != null && !js.equals(formatter.opToJson(existingOperation))) { throw new IllegalArgumentException(String.format( "Operation is duplicated with '%s' hash but different content: \n'%s'\n'%s'", op.getHash(), formatter.opToJson(existingOperation).replace("\n", ""), js.replace("\n", ""))); } return existingOperation != null; }
DBConsensusManager { public boolean validateExistingOperation(OpOperation op) { String js = formatter.opToJson(op); OpOperation existingOperation = getOperationByHash(op.getHash()); if (existingOperation != null && !js.equals(formatter.opToJson(existingOperation))) { throw new IllegalArgumentException(String.format( "Operation is duplicated with '%s' hash but different content: \n'%s'\n'%s'", op.getHash(), formatter.opToJson(existingOperation).replace("\n", ""), js.replace("\n", ""))); } return existingOperation != null; } }
DBConsensusManager { public boolean validateExistingOperation(OpOperation op) { String js = formatter.opToJson(op); OpOperation existingOperation = getOperationByHash(op.getHash()); if (existingOperation != null && !js.equals(formatter.opToJson(existingOperation))) { throw new IllegalArgumentException(String.format( "Operation is duplicated with '%s' hash but different content: \n'%s'\n'%s'", op.getHash(), formatter.opToJson(existingOperation).replace("\n", ""), js.replace("\n", ""))); } return existingOperation != null; }  }
DBConsensusManager { public boolean validateExistingOperation(OpOperation op) { String js = formatter.opToJson(op); OpOperation existingOperation = getOperationByHash(op.getHash()); if (existingOperation != null && !js.equals(formatter.opToJson(existingOperation))) { throw new IllegalArgumentException(String.format( "Operation is duplicated with '%s' hash but different content: \n'%s'\n'%s'", op.getHash(), formatter.opToJson(existingOperation).replace("\n", ""), js.replace("\n", ""))); } return existingOperation != null; }  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(); }
DBConsensusManager { public boolean validateExistingOperation(OpOperation op) { String js = formatter.opToJson(op); OpOperation existingOperation = getOperationByHash(op.getHash()); if (existingOperation != null && !js.equals(formatter.opToJson(existingOperation))) { throw new IllegalArgumentException(String.format( "Operation is duplicated with '%s' hash but different content: \n'%s'\n'%s'", op.getHash(), formatter.opToJson(existingOperation).replace("\n", ""), js.replace("\n", ""))); } return existingOperation != null; }  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();  }