Search in sources :

Example 11 with Recipient

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

the class PartyInfoServiceUtilTest method validateAttemptToChangeUrlAsInvalid.

@Test
public void validateAttemptToChangeUrlAsInvalid() {
    final String url = "http://somedomain.com";
    final PublicKey key = PublicKey.from("ONE".getBytes());
    final Set<Recipient> existingRecipients = Collections.singleton(Recipient.of(key, "http://one.com"));
    final NodeInfo existingPartyInfo = NodeInfo.Builder.create().withUrl(url).withRecipients(existingRecipients).build();
    final Set<Recipient> newRecipients = Collections.singleton(Recipient.of(key, "http://two.com"));
    final NodeInfo newPartyInfo = NodeInfo.Builder.create().withUrl(url).withRecipients(newRecipients).build();
    assertThat(PartyInfoServiceUtil.validateKeysToUrls(existingPartyInfo, newPartyInfo)).isFalse();
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) Recipient(com.quorum.tessera.partyinfo.node.Recipient) Test(org.junit.Test)

Example 12 with Recipient

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

the class EncodedPayloadPublisherTest method outstandingPayloadsPlusPublishedReachTotalExpected.

@Test
public void outstandingPayloadsPlusPublishedReachTotalExpected() {
    BatchWorkflowContext batchWorkflowContext = new BatchWorkflowContext();
    batchWorkflowContext.setBatchSize(2);
    batchWorkflowContext.setExpectedTotal(6L);
    EncodedPayload encodedPayload = mock(EncodedPayload.class);
    batchWorkflowContext.setPayloadsToPublish(Set.of(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.execute(batchWorkflowContext);
    batchWorkflowContext.setExpectedTotal(5L);
    encodedPayloadPublisher.checkOutstandingPayloads(batchWorkflowContext);
    assertThat(encodedPayloadPublisher.getPublishedCount()).isEqualTo(0);
    encodedPayloadPublisher.execute(batchWorkflowContext);
    batchWorkflowContext.setExpectedTotal(4L);
    encodedPayloadPublisher.checkOutstandingPayloads(batchWorkflowContext);
    assertThat(encodedPayloadPublisher.getPublishedCount()).isEqualTo(2);
    // Not publish yet as not yet reach batch size
    encodedPayloadPublisher.execute(batchWorkflowContext);
    assertThat(encodedPayloadPublisher.getPublishedCount()).isEqualTo(2);
    batchWorkflowContext.setExpectedTotal(3L);
    encodedPayloadPublisher.checkOutstandingPayloads(batchWorkflowContext);
    // Publish here because message count + outstanding = expected total
    assertThat(encodedPayloadPublisher.getPublishedCount()).isEqualTo(3);
    verify(resendBatchPublisher, times(2)).publishBatch(anyList(), eq("http://junit.com"));
}
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 13 with Recipient

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

the class EncodedPayloadPublisherTest method executeIfNumberOfPayloadsReachBatchSize.

@Test
public void executeIfNumberOfPayloadsReachBatchSize() {
    BatchWorkflowContext batchWorkflowContext = new BatchWorkflowContext();
    batchWorkflowContext.setBatchSize(2);
    batchWorkflowContext.setExpectedTotal(9L);
    EncodedPayload encodedPayload = mock(EncodedPayload.class);
    batchWorkflowContext.setPayloadsToPublish(Set.of(encodedPayload));
    PublicKey recipientKey = mock(PublicKey.class);
    Recipient recipient = mock(Recipient.class);
    when(recipient.getUrl()).thenReturn("http://junit.com");
    batchWorkflowContext.setRecipientKey(recipientKey);
    batchWorkflowContext.setRecipient(recipient);
    boolean result = IntStream.range(0, batchSize).allMatch(i -> encodedPayloadPublisher.execute(batchWorkflowContext));
    assertThat(result).isTrue();
    assertThat(encodedPayloadPublisher.getPublishedCount()).isEqualTo(9);
    List<EncodedPayload> sent2 = List.of(encodedPayload, encodedPayload);
    List<EncodedPayload> sent1 = List.of(encodedPayload);
    verify(resendBatchPublisher, times(4)).publishBatch(sent2, "http://junit.com");
    verify(resendBatchPublisher).publishBatch(sent1, "http://junit.com");
}
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 14 with Recipient

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

the class EncodedPayloadPublisherTest method executeIfNumberOfPayloadsReachTotal.

@Test
public void executeIfNumberOfPayloadsReachTotal() {
    BatchWorkflowContext batchWorkflowContext = new BatchWorkflowContext();
    batchWorkflowContext.setBatchSize(100);
    batchWorkflowContext.setExpectedTotal(9L);
    EncodedPayload encodedPayload = mock(EncodedPayload.class);
    batchWorkflowContext.setPayloadsToPublish(Set.of(encodedPayload));
    PublicKey recipientKey = mock(PublicKey.class);
    Recipient recipient = mock(Recipient.class);
    when(recipient.getUrl()).thenReturn("http://junit.com");
    batchWorkflowContext.setRecipientKey(recipientKey);
    batchWorkflowContext.setRecipient(recipient);
    boolean result = IntStream.range(0, batchSize).allMatch(i -> encodedPayloadPublisher.execute(batchWorkflowContext));
    assertThat(result).isTrue();
    assertThat(encodedPayloadPublisher.getPublishedCount()).isEqualTo(9);
    List<EncodedPayload> sent = Arrays.asList(new EncodedPayload[9]);
    Collections.fill(sent, encodedPayload);
    verify(resendBatchPublisher).publishBatch(sent, "http://junit.com");
}
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 15 with Recipient

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

the class FindRecipientFromPartyInfoTest method executeKeyFound.

@Test
public void executeKeyFound() {
    BatchWorkflowContext batchWorkflowContext = new BatchWorkflowContext();
    PublicKey publicKey = mock(PublicKey.class);
    batchWorkflowContext.setRecipientKey(publicKey);
    NodeInfo nodeInfo = mock(NodeInfo.class);
    Recipient recipient = mock(Recipient.class);
    when(recipient.getKey()).thenReturn(publicKey);
    when(nodeInfo.getRecipients()).thenReturn(Set.of(recipient));
    when(discovery.getCurrent()).thenReturn(nodeInfo);
    boolean result = findRecipientFromPartyInfo.execute(batchWorkflowContext);
    assertThat(result).isTrue();
    assertThat(batchWorkflowContext.getRecipient()).isSameAs(recipient);
    verify(discovery).getCurrent();
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) Recipient(com.quorum.tessera.partyinfo.node.Recipient) 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