Search in sources :

Example 1 with RunnableNode

use of org.hyperledger.besu.tests.acceptance.dsl.node.RunnableNode in project besu by hyperledger.

the class Cluster method start.

public void start(final List<? extends RunnableNode> nodes) {
    if (nodes.isEmpty()) {
        throw new IllegalArgumentException("Can't start a cluster with no nodes");
    }
    this.originalNodes = nodes;
    this.nodes.clear();
    this.bootnodes.clear();
    nodes.forEach(node -> this.nodes.put(node.getName(), node));
    final Optional<? extends RunnableNode> bootnode = selectAndStartBootnode(nodes);
    nodes.parallelStream().filter(node -> {
        LOG.info("starting non-bootnode {}", node.getName());
        return bootnode.map(boot -> boot != node).orElse(true);
    }).forEach(this::startNode);
    if (clusterConfiguration.isAwaitPeerDiscovery()) {
        for (final RunnableNode node : nodes) {
            LOG.info("Awaiting peer discovery for node {}, expecting {} peers", node.getName(), nodes.size() - 1);
            node.awaitPeerDiscovery(net.awaitPeerCount(nodes.size() - 1));
        }
    }
    LOG.info("Cluster startup complete.");
}
Also used : Arrays(java.util.Arrays) Logger(org.slf4j.Logger) Collections.emptyList(java.util.Collections.emptyList) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) BesuNode(org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode) BesuNodeRunner(org.hyperledger.besu.tests.acceptance.dsl.node.BesuNodeRunner) ArrayList(java.util.ArrayList) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) RunnableNode(org.hyperledger.besu.tests.acceptance.dsl.node.RunnableNode) Map(java.util.Map) Optional(java.util.Optional) NetConditions(org.hyperledger.besu.tests.acceptance.dsl.condition.net.NetConditions) URI(java.net.URI) Node(org.hyperledger.besu.tests.acceptance.dsl.node.Node) Condition(org.hyperledger.besu.tests.acceptance.dsl.condition.Condition) RunnableNode(org.hyperledger.besu.tests.acceptance.dsl.node.RunnableNode)

Example 2 with RunnableNode

use of org.hyperledger.besu.tests.acceptance.dsl.node.RunnableNode in project besu by hyperledger.

the class Cluster method addNode.

public void addNode(final Node node) {
    assertThat(node).isInstanceOf(RunnableNode.class);
    final RunnableNode runnableNode = (RunnableNode) node;
    nodes.put(runnableNode.getName(), runnableNode);
    startNode(runnableNode);
    if (clusterConfiguration.isAwaitPeerDiscovery()) {
        runnableNode.awaitPeerDiscovery(net.awaitPeerCount(nodes.size() - 1));
    }
}
Also used : RunnableNode(org.hyperledger.besu.tests.acceptance.dsl.node.RunnableNode)

Example 3 with RunnableNode

use of org.hyperledger.besu.tests.acceptance.dsl.node.RunnableNode in project besu by hyperledger.

the class QbftValidatorContractConfigFactory method buildContractStorageConfig.

private Map<String, String> buildContractStorageConfig(final Collection<? extends RunnableNode> validators) {
    final List<String> addresses = validators.stream().map(RunnableNode::getAddress).map(Bytes::toUnprefixedHexString).map(hex -> (padZero(0) + hex).substring(hex.length())).collect(toList());
    final Map<String, String> storageValues = new LinkedHashMap<>();
    // zero location is size of array
    storageValues.put(padZero(0), padZero(addresses.size()));
    // further locations are allocation of addresses to array
    for (int i = 0; i < addresses.size(); i++) {
        final BigInteger varStorage = ARRAY_ADDR.add(BigInteger.valueOf(i));
        storageValues.put(varStorage.toString(16), addresses.get(i));
    }
    return storageValues;
}
Also used : LinkedHashMap(java.util.LinkedHashMap) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) RunnableNode(org.hyperledger.besu.tests.acceptance.dsl.node.RunnableNode) Collection(java.util.Collection) Map(java.util.Map) BigInteger(java.math.BigInteger) Bytes(org.apache.tuweni.bytes.Bytes) Bytes(org.apache.tuweni.bytes.Bytes) BigInteger(java.math.BigInteger) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with RunnableNode

use of org.hyperledger.besu.tests.acceptance.dsl.node.RunnableNode in project besu by hyperledger.

the class Cluster method close.

@Override
public void close() {
    stop();
    for (final RunnableNode node : nodes.values()) {
        node.close();
    }
    besuNodeRunner.shutdown();
}
Also used : RunnableNode(org.hyperledger.besu.tests.acceptance.dsl.node.RunnableNode)

Aggregations

RunnableNode (org.hyperledger.besu.tests.acceptance.dsl.node.RunnableNode)4 List (java.util.List)2 Map (java.util.Map)2 Collectors.toList (java.util.stream.Collectors.toList)2 BigInteger (java.math.BigInteger)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections.emptyList (java.util.Collections.emptyList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Optional (java.util.Optional)1 Bytes (org.apache.tuweni.bytes.Bytes)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Condition (org.hyperledger.besu.tests.acceptance.dsl.condition.Condition)1 NetConditions (org.hyperledger.besu.tests.acceptance.dsl.condition.net.NetConditions)1 BesuNode (org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode)1 BesuNodeRunner (org.hyperledger.besu.tests.acceptance.dsl.node.BesuNodeRunner)1 Node (org.hyperledger.besu.tests.acceptance.dsl.node.Node)1