use of com.quorum.tessera.data.EncryptedTransaction in project tessera by ConsenSys.
the class BatchResendManagerImplTest method useMaxResultsWhenBatchSizeNotProvided.
@Test
public void useMaxResultsWhenBatchSizeNotProvided() {
final ResendBatchRequest request = ResendBatchRequest.Builder.create().withPublicKey(KEY_STRING).build();
List<EncryptedTransaction> transactions = IntStream.range(0, 5).mapToObj(i -> mock(EncryptedTransaction.class)).collect(Collectors.toUnmodifiableList());
when(encryptedTransactionDAO.transactionCount()).thenReturn(101L);
BatchWorkflow batchWorkflow = mock(BatchWorkflow.class);
when(batchWorkflow.getPublishedMessageCount()).thenReturn(// arbitary total that's returned as result.getTotal()
999L);
when(batchWorkflowFactory.create(101L)).thenReturn(batchWorkflow);
when(encryptedTransactionDAO.retrieveTransactions(lt(100), anyInt())).thenReturn(transactions);
when(encryptedTransactionDAO.retrieveTransactions(gt(99), anyInt())).thenReturn(List.of(mock(EncryptedTransaction.class)));
final ResendBatchResponse result = manager.resendBatch(request);
assertThat(result.getTotal()).isEqualTo(999L);
verify(batchWorkflow, times(101)).execute(any(BatchWorkflowContext.class));
verify(encryptedTransactionDAO, times(21)).retrieveTransactions(anyInt(), anyInt());
verify(encryptedTransactionDAO).transactionCount();
verify(batchWorkflowFactory).create(101L);
}
use of com.quorum.tessera.data.EncryptedTransaction in project tessera by ConsenSys.
the class EncryptedTransactionDAOImpl method update.
@Override
public EncryptedTransaction update(final EncryptedTransaction entity) {
return entityManagerTemplate.execute(entityManager -> {
EncryptedTransaction existing = entityManager.find(EncryptedTransaction.class, entity.getHash());
existing.setPayload(entity.getPayload());
existing.setEncodedPayload(null);
existing.setHash(entity.getHash());
EncryptedTransaction merged = entityManager.merge(existing);
LOGGER.debug("Updated transaction {}", entity.getHash());
return merged;
});
}
use of com.quorum.tessera.data.EncryptedTransaction in project tessera by ConsenSys.
the class EncryptedTransactionDAOImpl method delete.
@Override
public void delete(final MessageHash hash) {
LOGGER.info("Deleting transaction with hash {}", hash);
entityManagerTemplate.execute(entityManager -> {
final EncryptedTransaction message = entityManager.createNamedQuery("EncryptedTransaction.FindByHash", EncryptedTransaction.class).setParameter("hash", hash.getHashBytes()).getResultStream().findAny().orElseThrow(EntityNotFoundException::new);
entityManager.remove(message);
return message;
});
}
use of com.quorum.tessera.data.EncryptedTransaction in project tessera by ConsenSys.
the class EncryptedTransactionDAOImpl method findByHashes.
@Override
public List<EncryptedTransaction> findByHashes(Collection<MessageHash> messageHashes) {
if (Objects.isNull(messageHashes) || messageHashes.isEmpty()) {
return Collections.EMPTY_LIST;
}
return entityManagerTemplate.execute(entityManager -> {
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<EncryptedTransaction> query = criteriaBuilder.createQuery(EncryptedTransaction.class);
Root<EncryptedTransaction> root = query.from(EncryptedTransaction.class);
return entityManager.createQuery(query.select(root).where(root.get("hash").in(messageHashes))).getResultList();
});
}
use of com.quorum.tessera.data.EncryptedTransaction in project tessera by ConsenSys.
the class MigrationTest method beforeTest.
@Before
public void beforeTest() throws IOException {
Config primaryConfig = new Config();
primaryConfig.setJdbcConfig(new JdbcConfig());
primaryConfig.getJdbcConfig().setUsername("junit");
primaryConfig.getJdbcConfig().setPassword("junit");
String primaryJdbcUrl = "jdbc:h2:" + workDir.getRoot().toPath().resolve("primary.db").toString();
primaryConfig.getJdbcConfig().setUrl(primaryJdbcUrl);
Config secondaryConfig = new Config();
secondaryConfig.setJdbcConfig(new JdbcConfig());
secondaryConfig.getJdbcConfig().setUsername("junit");
secondaryConfig.getJdbcConfig().setPassword("junit");
String secondaryJdbcUrl = "jdbc:h2:" + workDir.getRoot().toPath().resolve("secondary.db").toString();
secondaryConfig.getJdbcConfig().setUrl(secondaryJdbcUrl);
primaryConfigPath = workDir.getRoot().toPath().toAbsolutePath().resolve("primary-confg.json");
try (OutputStream outputStream = Files.newOutputStream(primaryConfigPath)) {
JaxbUtil.marshalWithNoValidation(primaryConfig, outputStream);
}
secondaryConfigPath = workDir.getRoot().toPath().toAbsolutePath().resolve("secondary-confg.json");
try (OutputStream outputStream = Files.newOutputStream(secondaryConfigPath)) {
JaxbUtil.marshalWithNoValidation(secondaryConfig, outputStream);
}
args = List.of("--primary", primaryConfigPath.toString(), "--secondary", secondaryConfigPath.toString());
primaryEntityManagerFactory = Optional.of(primaryConfig).map(Config::getJdbcConfig).map(JdbcConfigUtil::toMap).map(m -> new HashMap(m)).map(p -> {
p.put("jakarta.persistence.schema-generation.database.action", "drop-and-create");
EntityManagerFactory emf = Persistence.createEntityManagerFactory("tessera", p);
emf.createEntityManager();
return emf;
}).get();
secondaryEntityManagerFactory = Optional.of(secondaryConfig).map(Config::getJdbcConfig).map(JdbcConfigUtil::toMap).map(m -> new HashMap(m)).map(p -> {
p.put("jakarta.persistence.schema-generation.database.action", "create");
EntityManagerFactory emf = Persistence.createEntityManagerFactory("tessera", p);
return emf;
}).get();
EntityManager secondaryEntityManager = secondaryEntityManagerFactory.createEntityManager();
secondaryEntityManager.getTransaction().begin();
IntStream.range(0, encryptedTransactionCount).forEach(i -> {
EncryptedTransaction encryptedTransaction = generateEncryptedTransaction();
secondaryEntityManager.persist(encryptedTransaction);
});
secondaryEntityManager.getTransaction().commit();
secondaryEntityManager.getTransaction().begin();
IntStream.range(0, encryptedRawTransactionCount).forEach(i -> {
EncryptedRawTransaction encryptedRawTransaction = generateEncryptedRawTransaction();
secondaryEntityManager.persist(encryptedRawTransaction);
});
secondaryEntityManager.getTransaction().commit();
}
Aggregations