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();
}
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"));
}
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");
}
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");
}
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();
}
Aggregations