Search in sources :

Example 6 with ConfigConverter

use of com.quorum.tessera.cli.parsers.ConfigConverter in project tessera by ConsenSys.

the class MigrationTest method doMigration.

@Test
public void doMigration() {
    MigrationCliAdapter migrationCommand = new MigrationCliAdapter();
    assertThat(migrationCommand.getType()).isEqualTo(CliType.MULTITENANCY_MIGRATION);
    final CommandLine commandLine = new CommandLine(migrationCommand);
    commandLine.registerConverter(Config.class, new ConfigConverter()).setSeparator(" ").setCaseInsensitiveEnumValuesAllowed(true);
    int exitCode = commandLine.execute(args.toArray(String[]::new));
    assertThat(exitCode).isZero();
    EntityManager secondaryEntityManager = secondaryEntityManagerFactory.createEntityManager();
    EntityManager primaryEntityManager = primaryEntityManagerFactory.createEntityManager();
    secondaryEntityManager.getTransaction().begin();
    primaryEntityManager.getTransaction().begin();
    secondaryEntityManager.createQuery("select count(e) from EncryptedTransaction e", Long.class).getResultStream().findFirst().ifPresent(count -> assertThat(count).isEqualTo(encryptedTransactionCount));
    primaryEntityManager.createQuery("select count(e) from EncryptedTransaction e", Long.class).getResultStream().findFirst().ifPresent(count -> assertThat(count).isEqualTo(encryptedTransactionCount));
    secondaryEntityManager.createQuery("select count(e) from EncryptedRawTransaction e", Long.class).getResultStream().findFirst().ifPresent(count -> assertThat(count).isEqualTo(encryptedRawTransactionCount));
    primaryEntityManager.createQuery("select count(e) from EncryptedRawTransaction e", Long.class).getResultStream().findFirst().ifPresent(count -> assertThat(count).isEqualTo(encryptedRawTransactionCount));
    secondaryEntityManager.createQuery("select e from EncryptedTransaction e", EncryptedTransaction.class).getResultStream().forEach(e -> {
        EncryptedTransaction copiedEncryptedTransaction = primaryEntityManager.find(EncryptedTransaction.class, e.getHash());
        assertThat(copiedEncryptedTransaction).isNotNull();
        assertThat(copiedEncryptedTransaction.getEncodedPayload()).isEqualTo(e.getEncodedPayload());
    });
    secondaryEntityManager.createQuery("select e from EncryptedRawTransaction e", EncryptedRawTransaction.class).getResultStream().forEach(e -> {
        EncryptedRawTransaction copiedEncryptedRawTransaction = primaryEntityManager.find(EncryptedRawTransaction.class, e.getHash());
        assertThat(copiedEncryptedRawTransaction).isNotNull();
        assertThat(copiedEncryptedRawTransaction.getEncryptedKey()).isEqualTo(e.getEncryptedKey());
        assertThat(copiedEncryptedRawTransaction.getEncryptedPayload()).isEqualTo(e.getEncryptedPayload());
        assertThat(copiedEncryptedRawTransaction.getSender()).isEqualTo(e.getSender());
        assertThat(copiedEncryptedRawTransaction.getNonce()).isEqualTo(e.getNonce());
    });
    secondaryEntityManager.getTransaction().rollback();
    primaryEntityManager.getTransaction().rollback();
    assertThat(commandLine.execute(args.toArray(String[]::new))).describedAs("Rerunning should throw no errors as there are exist checks before insert").isZero();
    primaryEntityManager.createQuery("select count(e) from EncryptedTransaction e", Long.class).getResultStream().findFirst().ifPresent(count -> assertThat(count).isEqualTo(encryptedTransactionCount));
    secondaryEntityManager.createQuery("select count(e) from EncryptedRawTransaction e", Long.class).getResultStream().findFirst().ifPresent(count -> assertThat(count).isEqualTo(encryptedRawTransactionCount));
}
Also used : ConfigConverter(com.quorum.tessera.cli.parsers.ConfigConverter) CommandLine(picocli.CommandLine) EntityManager(jakarta.persistence.EntityManager) EncryptedRawTransaction(com.quorum.tessera.data.EncryptedRawTransaction) EncryptedTransaction(com.quorum.tessera.data.EncryptedTransaction) Test(org.junit.Test)

Aggregations

ConfigConverter (com.quorum.tessera.cli.parsers.ConfigConverter)6 CommandLine (picocli.CommandLine)6 CliResult (com.quorum.tessera.cli.CliResult)4 Config (com.quorum.tessera.config.Config)2 EnclaveCliAdapter (com.quorum.tessera.enclave.server.EnclaveCliAdapter)2 Before (org.junit.Before)2 CLIExceptionCapturer (com.quorum.tessera.cli.CLIExceptionCapturer)1 ArgonOptions (com.quorum.tessera.config.ArgonOptions)1 ServerConfig (com.quorum.tessera.config.ServerConfig)1 EncryptedRawTransaction (com.quorum.tessera.data.EncryptedRawTransaction)1 EncryptedTransaction (com.quorum.tessera.data.EncryptedTransaction)1 Enclave (com.quorum.tessera.enclave.Enclave)1 TesseraServer (com.quorum.tessera.server.TesseraServer)1 TesseraServerFactory (com.quorum.tessera.server.TesseraServerFactory)1 EntityManager (jakarta.persistence.EntityManager)1 URL (java.net.URL)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 BouncyCastleProvider (org.bouncycastle.jce.provider.BouncyCastleProvider)1 Test (org.junit.Test)1