Search in sources :

Example 6 with NetworkStore

use of com.quorum.tessera.discovery.NetworkStore in project tessera by ConsenSys.

the class DiscoveryHelperTest method buildAllNodeInfosFilteredOutOwn.

@Test
public void buildAllNodeInfosFilteredOutOwn() {
    when(runtimeContext.getP2pServerUri()).thenReturn(URI.create("http://node1.com"));
    final ActiveNode node1 = ActiveNode.Builder.create().withUri(NodeUri.create("http://node1.com")).withKeys(List.of(PublicKey.from("key1".getBytes()))).withSupportedVersions(List.of("v1")).build();
    final ActiveNode node2 = ActiveNode.Builder.create().withUri(NodeUri.create("http://node2.com")).withKeys(List.of(PublicKey.from("key2".getBytes()))).withSupportedVersions(List.of("v2")).build();
    when(networkStore.getActiveNodes()).thenReturn(Stream.of(node1, node2));
    final Set<NodeInfo> nodeInfos = discoveryHelper.buildRemoteNodeInfos();
    assertThat(nodeInfos).hasSize(1);
    Set<ActiveNode> activeNodes = nodeInfos.stream().map(nodeInfo -> ActiveNode.Builder.create().withUri(NodeUri.create(nodeInfo.getUrl())).withKeys(nodeInfo.getRecipients().stream().map(Recipient::getKey).collect(Collectors.toSet())).withSupportedVersions(nodeInfo.supportedApiVersions()).build()).collect(Collectors.toSet());
    assertThat(activeNodes).containsExactlyInAnyOrder(node2);
    verify(networkStore).getActiveNodes();
    verify(runtimeContext).getP2pServerUri();
    mockedRuntimeContext.verify(RuntimeContext::getInstance);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) IntStream(java.util.stream.IntStream) KeyNotFoundException(com.quorum.tessera.encryption.KeyNotFoundException) PublicKey(com.quorum.tessera.encryption.PublicKey) DiscoveryHelper(com.quorum.tessera.discovery.DiscoveryHelper) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Set(java.util.Set) Test(org.junit.Test) NodeUri(com.quorum.tessera.discovery.NodeUri) Collectors(java.util.stream.Collectors) Recipient(com.quorum.tessera.partyinfo.node.Recipient) Mockito(org.mockito.Mockito) ActiveNode(com.quorum.tessera.discovery.ActiveNode) NetworkStore(com.quorum.tessera.discovery.NetworkStore) List(java.util.List) MockedStatic(org.mockito.MockedStatic) Stream(java.util.stream.Stream) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) After(org.junit.After) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) RuntimeContext(com.quorum.tessera.context.RuntimeContext) Enclave(com.quorum.tessera.enclave.Enclave) URI(java.net.URI) Before(org.junit.Before) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) Recipient(com.quorum.tessera.partyinfo.node.Recipient) ActiveNode(com.quorum.tessera.discovery.ActiveNode) RuntimeContext(com.quorum.tessera.context.RuntimeContext) Test(org.junit.Test)

Example 7 with NetworkStore

use of com.quorum.tessera.discovery.NetworkStore in project tessera by ConsenSys.

the class DiscoveryHelperProvider method provider.

public static DiscoveryHelper provider() {
    LOGGER.debug("Creating network store");
    final NetworkStore networkStore = NetworkStore.getInstance();
    LOGGER.debug("Created network store {}", networkStore);
    LOGGER.debug("Creating enclave");
    Enclave enclave = Enclave.create();
    LOGGER.debug("Created enclave {}", enclave);
    return new DiscoveryHelperImpl(networkStore, enclave);
}
Also used : Enclave(com.quorum.tessera.enclave.Enclave) NetworkStore(com.quorum.tessera.discovery.NetworkStore)

Example 8 with NetworkStore

use of com.quorum.tessera.discovery.NetworkStore in project tessera by ConsenSys.

the class EnclaveKeySynchroniserProvider method provider.

public static EnclaveKeySynchroniser provider() {
    LOGGER.debug("Creating Enclave");
    Enclave enclave = Enclave.create();
    LOGGER.debug("Created Enclave {}", enclave);
    LOGGER.debug("Creating NetworkStore");
    NetworkStore networkStore = NetworkStore.getInstance();
    LOGGER.debug("Created NetworkStore");
    return new EnclaveKeySynchroniserImpl(enclave, networkStore);
}
Also used : Enclave(com.quorum.tessera.enclave.Enclave) NetworkStore(com.quorum.tessera.discovery.NetworkStore)

Aggregations

NetworkStore (com.quorum.tessera.discovery.NetworkStore)8 Enclave (com.quorum.tessera.enclave.Enclave)7 Test (org.junit.Test)5 RuntimeContext (com.quorum.tessera.context.RuntimeContext)4 DiscoveryHelper (com.quorum.tessera.discovery.DiscoveryHelper)4 NodeUri (com.quorum.tessera.discovery.NodeUri)4 ActiveNode (com.quorum.tessera.discovery.ActiveNode)3 KeyNotFoundException (com.quorum.tessera.encryption.KeyNotFoundException)3 PublicKey (com.quorum.tessera.encryption.PublicKey)3 NodeInfo (com.quorum.tessera.partyinfo.node.NodeInfo)3 Recipient (com.quorum.tessera.partyinfo.node.Recipient)3 URI (java.net.URI)3 List (java.util.List)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 IntStream (java.util.stream.IntStream)3 Stream (java.util.stream.Stream)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 Assertions.assertThatExceptionOfType (org.assertj.core.api.Assertions.assertThatExceptionOfType)3 After (org.junit.After)3