use of com.quorum.tessera.data.staging.StagingEntityDAO in project tessera by ConsenSys.
the class StagingEntityDAOProviderTest method provider.
@Test
public void provider() {
try (var mockedConfigFactory = mockStatic(ConfigFactory.class);
var mockedDataSourceFactory = mockStatic(DataSourceFactory.class);
var mockedPersistence = mockStatic(Persistence.class)) {
mockedPersistence.when(() -> Persistence.createEntityManagerFactory(anyString(), anyMap())).thenReturn(mock(EntityManagerFactory.class));
Config config = mock(Config.class);
JdbcConfig jdbcConfig = mock(JdbcConfig.class);
when(jdbcConfig.isAutoCreateTables()).thenReturn(autocreateTables);
when(config.getJdbcConfig()).thenReturn(jdbcConfig);
ConfigFactory configFactory = mock(ConfigFactory.class);
when(configFactory.getConfig()).thenReturn(config);
mockedConfigFactory.when(ConfigFactory::create).thenReturn(configFactory);
mockedDataSourceFactory.when(DataSourceFactory::create).thenReturn(mock(DataSourceFactory.class));
StagingEntityDAO result = StagingEntityDAOProvider.provider();
assertThat(result).isNotNull().isExactlyInstanceOf(StagingEntityDAOImpl.class);
mockedPersistence.verify(() -> Persistence.createEntityManagerFactory(anyString(), anyMap()));
mockedPersistence.verifyNoMoreInteractions();
}
}
use of com.quorum.tessera.data.staging.StagingEntityDAO in project tessera by ConsenSys.
the class StagingEntityDAOProvider method provider.
public static StagingEntityDAO provider() {
LOGGER.debug("Creating StagingEntityDAO");
Config config = ConfigFactory.create().getConfig();
final DataSource dataSource = DataSourceFactory.create().create(config.getJdbcConfig());
Map properties = new HashMap();
properties.put("jakarta.persistence.nonJtaDataSource", dataSource);
properties.put("eclipselink.logging.logger", "org.eclipse.persistence.logging.slf4j.SLF4JLogger");
properties.put("eclipselink.logging.level", "FINE");
properties.put("eclipselink.logging.parameters", "true");
properties.put("eclipselink.logging.level.sql", "FINE");
properties.put("jakarta.persistence.schema-generation.database.action", config.getJdbcConfig().isAutoCreateTables() ? "drop-and-create" : "none");
properties.put("eclipselink.session.customizer", "com.quorum.tessera.eclipselink.AtomicLongSequence");
LOGGER.debug("Creating EntityManagerFactory from {}", properties);
final EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("tessera-recover", properties);
LOGGER.debug("Created EntityManagerFactory from {}", properties);
StagingEntityDAO stagingEntityDAO = new StagingEntityDAOImpl(entityManagerFactory);
LOGGER.debug("Created StagingEntityDAO {}", stagingEntityDAO);
return stagingEntityDAO;
}
use of com.quorum.tessera.data.staging.StagingEntityDAO in project tessera by ConsenSys.
the class BatchResendManagerImplTest method testStoreResendBatchMultipleVersions.
@Test
public void testStoreResendBatchMultipleVersions() {
try (var payloadDigestMockedStatic = mockStatic(PayloadDigest.class);
var payloadEncoderMockedStatic = mockStatic(PayloadEncoder.class)) {
payloadDigestMockedStatic.when(PayloadDigest::create).thenReturn((PayloadDigest) cipherText -> cipherText);
payloadEncoderMockedStatic.when(() -> PayloadEncoder.create(any())).thenReturn(payloadEncoder);
final EncodedPayload encodedPayload = EncodedPayload.Builder.create().withSenderKey(publicKey).withCipherText("cipherText".getBytes()).withCipherTextNonce(new Nonce("nonce".getBytes())).withRecipientBoxes(singletonList("box".getBytes())).withRecipientNonce(new Nonce("recipientNonce".getBytes())).withRecipientKeys(singletonList(PublicKey.from("receiverKey".getBytes()))).withPrivacyMode(PrivacyMode.STANDARD_PRIVATE).withAffectedContractTransactions(emptyMap()).withExecHash(new byte[0]).build();
when(payloadEncoder.decode(any())).thenReturn(encodedPayload);
final byte[] raw = new PayloadEncoderImpl().encode(encodedPayload);
PushBatchRequest request = PushBatchRequest.from(List.of(raw), EncodedPayloadCodec.LEGACY);
StagingTransaction existing = new StagingTransaction();
when(stagingEntityDAO.retrieveByHash(any())).thenReturn(Optional.of(existing));
when(stagingEntityDAO.update(any(StagingTransaction.class))).thenReturn(new StagingTransaction());
manager.storeResendBatch(request);
verify(stagingEntityDAO).save(any(StagingTransaction.class));
verify(payloadEncoder).decode(any());
verify(payloadEncoder).encodedPayloadCodec();
payloadDigestMockedStatic.verify(PayloadDigest::create);
payloadDigestMockedStatic.verifyNoMoreInteractions();
}
}
use of com.quorum.tessera.data.staging.StagingEntityDAO in project tessera by ConsenSys.
the class BatchResendManagerProviderTest method provider.
@Test
public void provider() {
try (var staticEncryptedTransactionDAO = mockStatic(EncryptedTransactionDAO.class);
var staticStagingEntityDAO = mockStatic(StagingEntityDAO.class);
var staticBatchWorkflowFactory = mockStatic(BatchWorkflowFactory.class)) {
staticEncryptedTransactionDAO.when(EncryptedTransactionDAO::create).thenReturn(mock(EncryptedTransactionDAO.class));
staticStagingEntityDAO.when(StagingEntityDAO::create).thenReturn(mock(StagingEntityDAO.class));
staticBatchWorkflowFactory.when(BatchWorkflowFactory::create).thenReturn(mock(BatchWorkflowFactory.class));
BatchResendManager batchResendManager = BatchResendManagerProvider.provider();
assertThat(batchResendManager).isNotNull().isExactlyInstanceOf(BatchResendManagerImpl.class);
staticEncryptedTransactionDAO.verify(EncryptedTransactionDAO::create);
staticStagingEntityDAO.verify(StagingEntityDAO::create);
staticBatchWorkflowFactory.verify(BatchWorkflowFactory::create);
staticEncryptedTransactionDAO.verifyNoMoreInteractions();
staticStagingEntityDAO.verifyNoMoreInteractions();
staticBatchWorkflowFactory.verifyNoMoreInteractions();
assertThat(BatchResendManagerHolder.INSTANCE.getBatchResendManager()).isPresent().containsSame(batchResendManager);
assertThat(BatchResendManagerProvider.provider()).isSameAs(batchResendManager);
}
}
use of com.quorum.tessera.data.staging.StagingEntityDAO in project tessera by ConsenSys.
the class BatchResendManagerProvider method provider.
public static BatchResendManager provider() {
if (BatchResendManagerHolder.INSTANCE.getBatchResendManager().isPresent()) {
return BatchResendManagerHolder.INSTANCE.getBatchResendManager().get();
}
LOGGER.debug("Creating EncryptedTransactionDAO");
final EncryptedTransactionDAO encryptedTransactionDAO = EncryptedTransactionDAO.create();
LOGGER.debug("Created EncryptedTransactionDAO {}", encryptedTransactionDAO);
LOGGER.debug("Creating StagingEntityDAO");
final StagingEntityDAO stagingEntityDAO = StagingEntityDAO.create();
LOGGER.debug("Created StagingEntityDAO");
final int defaultMaxResults = 10000;
BatchWorkflowFactory batchWorkflowFactory = BatchWorkflowFactory.create();
BatchResendManager batchResendManager = new BatchResendManagerImpl(stagingEntityDAO, encryptedTransactionDAO, defaultMaxResults, batchWorkflowFactory);
return BatchResendManagerHolder.INSTANCE.setBatchResendManager(batchResendManager);
}
Aggregations