Search in sources :

Example 1 with EnclaveExecManager

use of exec.EnclaveExecManager in project tessera by ConsenSys.

the class TestSuite method run.

@Override
public void run(RunNotifier notifier) {
    final List<ExecManager> executors = new ArrayList<>();
    try {
        final ProcessConfig annotatedConfig = Arrays.stream(getRunnerAnnotations()).filter(ProcessConfig.class::isInstance).map(ProcessConfig.class::cast).findAny().orElseThrow(() -> new AssertionError("No Test config found"));
        ExecutionContext executionContext = ExecutionContext.Builder.create().with(annotatedConfig.communicationType()).with(annotatedConfig.dbType()).with(annotatedConfig.socketType()).with(annotatedConfig.enclaveType()).withAdmin(annotatedConfig.admin()).with(annotatedConfig.encryptorType()).with(annotatedConfig.clientMode()).prefix(annotatedConfig.prefix()).createAndSetupContext();
        if (executionContext.getEnclaveType() == EnclaveType.REMOTE) {
            executionContext.getConfigs().stream().map(EnclaveExecManager::new).forEach(exec -> {
                exec.start();
                executors.add(exec);
            });
        }
        String nodeId = NodeId.generate(executionContext);
        DatabaseServer databaseServer = executionContext.getDbType().createDatabaseServer(nodeId);
        databaseServer.start();
        SetupDatabase setupDatabase = new SetupDatabase(executionContext);
        setupDatabase.setUp();
        executionContext.getConfigs().stream().map(NodeExecManager::new).forEach(exec -> {
            exec.start();
            executors.add(exec);
        });
        PartyInfoChecker partyInfoChecker = PartyInfoChecker.create(executionContext.getCommunicationType());
        CountDownLatch partyInfoSyncLatch = new CountDownLatch(1);
        ExecutorService executorService = Executors.newSingleThreadExecutor();
        executorService.submit(() -> {
            while (!partyInfoChecker.hasSynced()) {
                try {
                    Thread.sleep(1000L);
                } catch (InterruptedException ex) {
                }
            }
            partyInfoSyncLatch.countDown();
        });
        if (!partyInfoSyncLatch.await(10, TimeUnit.MINUTES)) {
            Description de = getDescription();
            notifier.fireTestFailure(new Failure(de, new IllegalStateException("Unable to sync party info nodes")));
        }
        executorService.shutdown();
        super.run(notifier);
        try {
            ExecutionContext.destroyContext();
            setupDatabase.dropAll();
        } finally {
            databaseServer.stop();
        }
    } catch (Throwable ex) {
        Description de = getDescription();
        notifier.fireTestFailure(new Failure(de, ex));
    } finally {
        executors.forEach(ExecManager::stop);
    }
}
Also used : Description(org.junit.runner.Description) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) SetupDatabase(db.SetupDatabase) ExecutorService(java.util.concurrent.ExecutorService) DatabaseServer(db.DatabaseServer) NodeExecManager(exec.NodeExecManager) EnclaveExecManager(exec.EnclaveExecManager) ExecManager(exec.ExecManager) Failure(org.junit.runner.notification.Failure)

Example 2 with EnclaveExecManager

use of exec.EnclaveExecManager in project tessera by ConsenSys.

the class SendWithRemoteEnclaveReconnectIT method beforeTest.

@Before
public void beforeTest() throws IOException {
    EncryptorConfig encryptorConfig = new EncryptorConfig() {

        {
            setType(EncryptorType.NACL);
        }
    };
    ExecutionContext.Builder.create().with(CommunicationType.REST).with(DBType.H2).with(SocketType.HTTP).with(EnclaveType.REMOTE).with(encryptorConfig.getType()).with(ClientMode.TESSERA).buildAndStoreContext();
    final PortUtil portGenerator = new PortUtil(50100);
    final String serverUriTemplate = "http://localhost:%d";
    KeyEncryptorFactory.newFactory().create(encryptorConfig);
    final Config nodeConfig = new Config();
    nodeConfig.setEncryptor(encryptorConfig);
    JdbcConfig jdbcConfig = new JdbcConfig();
    jdbcConfig.setUrl("jdbc:h2:mem:junit");
    jdbcConfig.setUsername("sa");
    jdbcConfig.setPassword("");
    jdbcConfig.setAutoCreateTables(true);
    nodeConfig.setJdbcConfig(jdbcConfig);
    ServerConfig p2pServerConfig = new ServerConfig();
    p2pServerConfig.setApp(AppType.P2P);
    p2pServerConfig.setServerAddress(String.format(serverUriTemplate, portGenerator.nextPort()));
    p2pServerConfig.setCommunicationType(CommunicationType.REST);
    final ServerConfig q2tServerConfig = new ServerConfig();
    q2tServerConfig.setApp(AppType.Q2T);
    q2tServerConfig.setServerAddress(String.format(serverUriTemplate, portGenerator.nextPort()));
    q2tServerConfig.setCommunicationType(CommunicationType.REST);
    final Config enclaveConfig = new Config();
    enclaveConfig.setEncryptor(nodeConfig.getEncryptor());
    final ServerConfig enclaveServerConfig = new ServerConfig();
    enclaveServerConfig.setApp(AppType.ENCLAVE);
    enclaveServerConfig.setServerAddress(String.format(serverUriTemplate, portGenerator.nextPort()));
    enclaveServerConfig.setCommunicationType(CommunicationType.REST);
    nodeConfig.setServerConfigs(Arrays.asList(p2pServerConfig, q2tServerConfig, enclaveServerConfig));
    KeyData keyPair = new KeyData();
    keyPair.setPublicKey("/+UuD63zItL1EbjxkKUljMgG8Z1w0AJ8pNOR4iq2yQc=");
    keyPair.setPrivateKey("yAWAJjwPqUtNVlqGjSrBmr1/iIkghuOh1803Yzx9jLM=");
    enclaveConfig.setKeys(new KeyConfiguration());
    enclaveConfig.getKeys().setKeyData(Arrays.asList(keyPair));
    nodeConfig.setPeers(Arrays.asList(new Peer(p2pServerConfig.getServerAddress())));
    enclaveConfig.setServerConfigs(Arrays.asList(enclaveServerConfig));
    Path configPath = Files.createFile(Paths.get(UUID.randomUUID().toString()));
    configPath.toFile().deleteOnExit();
    Path enclaveConfigPath = Files.createFile(Paths.get(UUID.randomUUID().toString()));
    enclaveConfigPath.toFile().deleteOnExit();
    try (OutputStream out = Files.newOutputStream(configPath)) {
        JaxbUtil.marshalWithNoValidation(nodeConfig, out);
        out.flush();
    }
    JaxbUtil.marshalWithNoValidation(enclaveConfig, System.out);
    try (OutputStream out = Files.newOutputStream(enclaveConfigPath)) {
        JaxbUtil.marshalWithNoValidation(enclaveConfig, out);
        out.flush();
    }
    ConfigDescriptor configDescriptor = new ConfigDescriptor(NodeAlias.A, configPath, nodeConfig, enclaveConfig, enclaveConfigPath);
    String key = configDescriptor.getKey().getPublicKey();
    URL file = Utils.toUrl(configDescriptor.getPath());
    String alias = configDescriptor.getAlias().name();
    this.party = new Party(key, file, alias);
    nodeExecManager = new NodeExecManager(configDescriptor);
    enclaveExecManager = new EnclaveExecManager(configDescriptor);
    enclaveExecManager.start();
    nodeExecManager.start();
    client = party.getRestClient();
}
Also used : Path(java.nio.file.Path) PortUtil(config.PortUtil) OutputStream(java.io.OutputStream) NodeExecManager(exec.NodeExecManager) EnclaveExecManager(exec.EnclaveExecManager) URL(java.net.URL) Party(com.quorum.tessera.test.Party) ConfigDescriptor(config.ConfigDescriptor) Before(org.junit.Before)

Aggregations

EnclaveExecManager (exec.EnclaveExecManager)2 NodeExecManager (exec.NodeExecManager)2 Party (com.quorum.tessera.test.Party)1 ConfigDescriptor (config.ConfigDescriptor)1 PortUtil (config.PortUtil)1 DatabaseServer (db.DatabaseServer)1 SetupDatabase (db.SetupDatabase)1 ExecManager (exec.ExecManager)1 OutputStream (java.io.OutputStream)1 URL (java.net.URL)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1 Before (org.junit.Before)1 Description (org.junit.runner.Description)1 Failure (org.junit.runner.notification.Failure)1