Search in sources :

Example 16 with Recipient

use of com.quorum.tessera.partyinfo.node.Recipient in project tessera by ConsenSys.

the class SyncPollerTest method localUrlIsExcludedFromPoll.

@Test
public void localUrlIsExcludedFromPoll() {
    final String targetUrl = "localurl.com";
    final String syncableUrl = "syncable.com";
    final com.quorum.tessera.partyinfo.node.Recipient localKey = com.quorum.tessera.partyinfo.node.Recipient.of(mock(PublicKey.class), targetUrl);
    final com.quorum.tessera.partyinfo.node.Recipient anotherKey = com.quorum.tessera.partyinfo.node.Recipient.of(mock(PublicKey.class), syncableUrl);
    final Party syncableParty = new Party(syncableUrl);
    final Set<Recipient> recipients = Set.of(localKey, anotherKey);
    NodeInfo nodeInfo = NodeInfo.Builder.create().withUrl("localurl.com").withRecipients(recipients).build();
    // partyStore.store(URI.create(syncableUrl));
    when(partyInfoService.getCurrent()).thenReturn(nodeInfo);
    doReturn(Optional.empty()).when(resendPartyStore).getNextParty();
    syncPoller.run();
    verify(resendPartyStore, times(1)).addUnseenParties(Set.of(syncableParty));
    verify(resendPartyStore, times(1)).getNextParty();
}
Also used : Party(com.quorum.tessera.partyinfo.model.Party) PublicKey(com.quorum.tessera.encryption.PublicKey) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) Recipient(com.quorum.tessera.partyinfo.node.Recipient) Recipient(com.quorum.tessera.partyinfo.node.Recipient) Test(org.junit.Test)

Example 17 with Recipient

use of com.quorum.tessera.partyinfo.node.Recipient in project tessera by ConsenSys.

the class AutoDiscoveryTest method onUpdateIgnoresKeysThatAreNotOwnedBySender.

@Test
public void onUpdateIgnoresKeysThatAreNotOwnedBySender() {
    String uri = "http://mynode.com";
    PublicKey key = mock(PublicKey.class);
    Recipient recipient = Recipient.of(key, uri);
    Recipient other = Recipient.of(mock(PublicKey.class), "http://othernode.com");
    List<Recipient> recipients = List.of(recipient, other);
    NodeInfo nodeInfo = NodeInfo.Builder.create().withUrl(uri).withRecipients(recipients).withSupportedApiVersions(List.of("Two", "Fifty")).build();
    List<ActiveNode> storedNodes = new ArrayList<>();
    doAnswer(invocation -> {
        storedNodes.add(invocation.getArgument(0));
        return null;
    }).when(networkStore).store(any(ActiveNode.class));
    discovery.onUpdate(nodeInfo);
    assertThat(storedNodes).hasSize(1);
    ActiveNode result = storedNodes.iterator().next();
    assertThat(result.getUri()).isEqualTo(NodeUri.create(uri));
    assertThat(result.getKeys()).containsExactly(key);
    assertThat(result.getSupportedVersions()).containsExactlyInAnyOrder("Two", "Fifty");
    verify(networkStore).store(any(ActiveNode.class));
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) ArrayList(java.util.ArrayList) Recipient(com.quorum.tessera.partyinfo.node.Recipient) ActiveNode(com.quorum.tessera.discovery.ActiveNode) Test(org.junit.Test)

Example 18 with Recipient

use of com.quorum.tessera.partyinfo.node.Recipient 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 19 with Recipient

use of com.quorum.tessera.partyinfo.node.Recipient in project tessera by ConsenSys.

the class EncodedPayloadPublisherTest method noOutstandingPayload.

@Test
public void noOutstandingPayload() {
    BatchWorkflowContext batchWorkflowContext = new BatchWorkflowContext();
    batchWorkflowContext.setBatchSize(100);
    batchWorkflowContext.setExpectedTotal(4L);
    EncodedPayload encodedPayload = mock(EncodedPayload.class);
    batchWorkflowContext.setEncodedPayload(encodedPayload);
    PublicKey recipientKey = mock(PublicKey.class);
    Recipient recipient = mock(Recipient.class);
    when(recipient.getUrl()).thenReturn("http://junit.com");
    batchWorkflowContext.setRecipientKey(recipientKey);
    batchWorkflowContext.setRecipient(recipient);
    encodedPayloadPublisher.checkOutstandingPayloads(batchWorkflowContext);
    assertThat(encodedPayloadPublisher.getPublishedCount()).isEqualTo(0);
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) Recipient(com.quorum.tessera.partyinfo.node.Recipient) Test(org.junit.Test)

Example 20 with Recipient

use of com.quorum.tessera.partyinfo.node.Recipient in project tessera by ConsenSys.

the class EncodedPayloadPublisherTest method flattenedPayloadsOverBatchSizeSplitsToSublists.

@Test
public void flattenedPayloadsOverBatchSizeSplitsToSublists() {
    final int numberOfMessagesToSend = 10;
    PublicKey recipientKey = mock(PublicKey.class);
    Recipient recipient = Recipient.of(recipientKey, "http://junit.com");
    EncodedPayload encodedPayloadFirst = mock(EncodedPayload.class);
    EncodedPayload encodedPayloadSecond = mock(EncodedPayload.class);
    BatchWorkflowContext batchWorkflowContext = new BatchWorkflowContext();
    batchWorkflowContext.setBatchSize(3);
    batchWorkflowContext.setExpectedTotal(10L);
    batchWorkflowContext.setPayloadsToPublish(new LinkedHashSet<>(List.of(encodedPayloadFirst, encodedPayloadSecond)));
    batchWorkflowContext.setRecipientKey(recipientKey);
    batchWorkflowContext.setRecipient(recipient);
    boolean result = IntStream.range(0, numberOfMessagesToSend).allMatch(i -> encodedPayloadPublisher.execute(batchWorkflowContext));
    assertThat(result).isTrue();
    assertThat(encodedPayloadPublisher.getPublishedCount()).isEqualTo(10);
    List<EncodedPayload> batchOne = List.of(encodedPayloadFirst, encodedPayloadSecond, encodedPayloadFirst);
    List<EncodedPayload> batchTwo = List.of(encodedPayloadSecond, encodedPayloadFirst, encodedPayloadSecond);
    List<EncodedPayload> leftovers = List.of(encodedPayloadFirst, encodedPayloadSecond);
    verify(resendBatchPublisher, times(3)).publishBatch(batchOne, "http://junit.com");
    verify(resendBatchPublisher, times(3)).publishBatch(batchTwo, "http://junit.com");
    verify(resendBatchPublisher).publishBatch(leftovers, "http://junit.com");
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) Recipient(com.quorum.tessera.partyinfo.node.Recipient) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) Test(org.junit.Test)

Aggregations

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