Search in sources :

Example 11 with StagingTransaction

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());
}
Also used : StagingAffectedTransaction(com.quorum.tessera.data.staging.StagingAffectedTransaction) StagingTransaction(com.quorum.tessera.data.staging.StagingTransaction) Test(org.junit.Test)

Example 12 with StagingTransaction

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);
}
Also used : CriteriaBuilder(jakarta.persistence.criteria.CriteriaBuilder) AtomicLong(java.util.concurrent.atomic.AtomicLong) StagingTransaction(com.quorum.tessera.data.staging.StagingTransaction) Test(org.junit.Test)

Example 13 with StagingTransaction

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());
    });
}
Also used : CriteriaBuilder(jakarta.persistence.criteria.CriteriaBuilder) StagingTransaction(com.quorum.tessera.data.staging.StagingTransaction)

Aggregations

StagingTransaction (com.quorum.tessera.data.staging.StagingTransaction)13 Test (org.junit.Test)10 EncodedPayload (com.quorum.tessera.enclave.EncodedPayload)7 StagingAffectedTransaction (com.quorum.tessera.data.staging.StagingAffectedTransaction)4 RecoveryResult (com.quorum.tessera.recovery.RecoveryResult)4 CriteriaBuilder (jakarta.persistence.criteria.CriteriaBuilder)4 StagingEntityDAO (com.quorum.tessera.data.staging.StagingEntityDAO)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 Collectors (java.util.stream.Collectors)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 After (org.junit.After)3 Before (org.junit.Before)3 Mockito (org.mockito.Mockito)3 TestConfig (com.quorum.tessera.data.TestConfig)2 Utils (com.quorum.tessera.data.Utils)2 EncodedPayloadCodec (com.quorum.tessera.enclave.EncodedPayloadCodec)2 PayloadEncoder (com.quorum.tessera.enclave.PayloadEncoder)2 PrivacyMode (com.quorum.tessera.enclave.PrivacyMode)2 jakarta.persistence (jakarta.persistence)2 CriteriaQuery (jakarta.persistence.criteria.CriteriaQuery)2