use of com.quorum.tessera.data.staging.StagingTransaction in project tessera by ConsenSys.
the class StagingEntityDAOTest method testSave.
@Test
public void testSave() {
String txHash = Utils.createHashStr();
final StagingTransaction stagingTransaction = new StagingTransaction();
stagingTransaction.setHash(txHash);
stagingTransaction.setPrivacyMode(PrivacyMode.STANDARD_PRIVATE);
stagingTransaction.setEncodedPayloadCodec(CODEC);
stagingTransaction.setPayload(payloadData);
final StagingAffectedTransaction affected1 = new StagingAffectedTransaction();
affected1.setSourceTransaction(stagingTransaction);
affected1.setHash("affected1");
final StagingAffectedTransaction affected2 = new StagingAffectedTransaction();
affected2.setId(123L);
affected2.setSourceTransaction(stagingTransaction);
affected2.setHash("affected2");
stagingTransaction.setAffectedContractTransactions(Stream.of(affected1, affected2).collect(Collectors.toSet()));
stagingEntityDAO.save(stagingTransaction);
assertThat(stagingEntityDAO.retrieveByHash(txHash)).isPresent();
final StagingTransaction retrieved = stagingEntityDAO.retrieveByHash(txHash).get();
assertThat(retrieved).isEqualTo(stagingTransaction);
assertThat(retrieved.getValidationStage()).isNull();
assertThat(retrieved.getPrivacyMode()).isEqualTo(PrivacyMode.STANDARD_PRIVATE);
assertThat(retrieved.getAffectedContractTransactions()).containsExactlyInAnyOrder(affected1, affected2);
retrieved.getAffectedContractTransactions().forEach(a -> assertThat(a.getId()).isNotNull());
}
use of com.quorum.tessera.data.staging.StagingTransaction in project tessera by ConsenSys.
the class StagingEntityDAOTest method updateStageForBatch.
@Test
public void updateStageForBatch() {
final long validationStage = new Random().nextLong();
final int batchSize = 1;
int results = stagingEntityDAO.updateStageForBatch(batchSize, validationStage);
assertThat(results).isEqualTo(batchSize);
EntityManager entityManager = entityManagerFactory.createEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<Long> criteriaQuery = criteriaBuilder.createQuery(Long.class);
Root<StagingTransaction> root = criteriaQuery.from(StagingTransaction.class);
criteriaQuery.select(criteriaBuilder.count(root)).where(criteriaBuilder.equal(root.get("validationStage"), validationStage));
Long countPending = entityManager.createQuery(criteriaQuery).setParameter("stage", validationStage).getSingleResult();
assertThat(countPending).isEqualTo((long) batchSize);
}
use of com.quorum.tessera.data.staging.StagingTransaction in project tessera by ConsenSys.
the class StagingEntityDAOImpl method retrieveByHash.
@Override
public Optional<StagingTransaction> retrieveByHash(final String hash) {
return entityManagerTemplate.execute(entityManager -> {
LOGGER.debug("Retrieving payload with hash {}", hash);
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<StagingTransaction> query = criteriaBuilder.createQuery(StagingTransaction.class);
Root<StagingTransaction> root = query.from(StagingTransaction.class);
query.select(root).where(criteriaBuilder.equal(root.get("hash"), hash));
return Optional.ofNullable(entityManager.createQuery(query).getSingleResult());
});
}
Aggregations