Search in sources :

Example 1 with NodeExecManager

use of exec.NodeExecManager in project tessera by ConsenSys.

the class ThirdPartyIT method partyInfoKeys.

@Test
public void partyInfoKeys() {
    Response partyinfoResponse = client.target(thirdPartyServerConfig.getServerUri()).path("partyinfo").path("keys").request().get();
    JsonObject partyinfokeysJson = partyinfoResponse.readEntity(JsonObject.class);
    assertThat(partyinfoResponse).isNotNull();
    assertThat(partyinfoResponse.getStatus()).isEqualTo(200);
    List<JsonObject> keys = Stream.of(firstNodeExecManager, secondNodeExecManager).map(NodeExecManager::getConfigDescriptor).map(ConfigDescriptor::getKey).map(ConfigKeyPair::getPublicKey).map(k -> Json.createObjectBuilder().add("key", k).build()).collect(Collectors.toUnmodifiableList());
    assertThat(partyinfokeysJson.getJsonArray("keys")).describedAs("partyInfo response that caused failure %s", partyinfokeysJson.toString()).containsAnyElementsOf(keys);
}
Also used : Response(jakarta.ws.rs.core.Response) DBType(com.quorum.tessera.test.DBType) ExecutionContext(suite.ExecutionContext) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EnclaveType(suite.EnclaveType) Response(jakarta.ws.rs.core.Response) JaxbUtil(com.quorum.tessera.config.util.JaxbUtil) JsonObject(jakarta.json.JsonObject) Path(java.nio.file.Path) OutputStream(java.io.OutputStream) NodeExecManager(exec.NodeExecManager) SocketType(suite.SocketType) ConfigKeyPair(com.quorum.tessera.config.keypairs.ConfigKeyPair) Client(jakarta.ws.rs.client.Client) Files(java.nio.file.Files) ClientFactory(com.quorum.tessera.jaxrs.client.ClientFactory) PortUtil(config.PortUtil) Collectors(java.util.stream.Collectors) Json(jakarta.json.Json) List(java.util.List) Stream(java.util.stream.Stream) com.quorum.tessera.config(com.quorum.tessera.config) Paths(java.nio.file.Paths) NodeAlias(suite.NodeAlias) org.junit(org.junit) ConfigDescriptor(config.ConfigDescriptor) ConfigKeyPair(com.quorum.tessera.config.keypairs.ConfigKeyPair) JsonObject(jakarta.json.JsonObject) NodeExecManager(exec.NodeExecManager)

Example 2 with NodeExecManager

use of exec.NodeExecManager 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 3 with NodeExecManager

use of exec.NodeExecManager 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)

Example 4 with NodeExecManager

use of exec.NodeExecManager in project tessera by ConsenSys.

the class ThirdPartyIT method init.

@BeforeClass
public static void init() throws Exception {
    ExecutionContext.Builder.create().with(CommunicationType.REST).with(DBType.H2).with(SocketType.HTTP).with(EncryptorType.NACL).with(EnclaveType.LOCAL).with(ClientMode.TESSERA).prefix(ThirdPartyIT.class.getSimpleName().toLowerCase()).buildAndStoreContext();
    Config firstNodeDesc = createNode(NodeAlias.A);
    Config secondNodeDesc = createNode(NodeAlias.B);
    firstNodeDesc.setPeers(List.of(new Peer(secondNodeDesc.getP2PServerConfig().getServerAddress())));
    secondNodeDesc.setPeers(List.of(new Peer(firstNodeDesc.getP2PServerConfig().getServerAddress())));
    firstNodeExecManager = new NodeExecManager(createConfigDescriptor(NodeAlias.A, firstNodeDesc));
    secondNodeExecManager = new NodeExecManager(createConfigDescriptor(NodeAlias.B, secondNodeDesc));
    firstNodeExecManager.start();
    secondNodeExecManager.start();
}
Also used : NodeExecManager(exec.NodeExecManager)

Aggregations

NodeExecManager (exec.NodeExecManager)4 ConfigDescriptor (config.ConfigDescriptor)2 PortUtil (config.PortUtil)2 EnclaveExecManager (exec.EnclaveExecManager)2 OutputStream (java.io.OutputStream)2 Path (java.nio.file.Path)2 com.quorum.tessera.config (com.quorum.tessera.config)1 ConfigKeyPair (com.quorum.tessera.config.keypairs.ConfigKeyPair)1 JaxbUtil (com.quorum.tessera.config.util.JaxbUtil)1 ClientFactory (com.quorum.tessera.jaxrs.client.ClientFactory)1 DBType (com.quorum.tessera.test.DBType)1 Party (com.quorum.tessera.test.Party)1 DatabaseServer (db.DatabaseServer)1 SetupDatabase (db.SetupDatabase)1 ExecManager (exec.ExecManager)1 Json (jakarta.json.Json)1 JsonObject (jakarta.json.JsonObject)1 Client (jakarta.ws.rs.client.Client)1 Response (jakarta.ws.rs.core.Response)1 URL (java.net.URL)1