use of com.quorum.tessera.enclave.EncodedPayload in project tessera by ConsenSys.
the class AsyncBatchPayloadPublisherTest method publishPayloadNoRecipientsDoesNothing.
@Test
public void publishPayloadNoRecipientsDoesNothing() {
final EncodedPayload payload = mock(EncodedPayload.class);
final List<PublicKey> recipients = Collections.emptyList();
asyncPublisher.publishPayload(payload, recipients);
verify(executorFactory).createCachedThreadPool();
}
use of com.quorum.tessera.enclave.EncodedPayload in project tessera by ConsenSys.
the class RestPayloadPublisherTest method publishEnhancedTransactionsToNodesThatDoNotSupport.
@Test
public void publishEnhancedTransactionsToNodesThatDoNotSupport() {
Map<PrivacyMode, Set<String>> privacyModeAndVersions = new HashMap<>();
privacyModeAndVersions.put(PrivacyMode.PARTY_PROTECTION, Set.of("v1"));
privacyModeAndVersions.put(PrivacyMode.PRIVATE_STATE_VALIDATION, Set.of("v1"));
for (Map.Entry<PrivacyMode, Set<String>> pair : privacyModeAndVersions.entrySet()) {
String targetUrl = "http://someplace.com";
EncodedPayload encodedPayload = mock(EncodedPayload.class);
when(encodedPayload.getPrivacyMode()).thenReturn(pair.getKey());
byte[] payloadData = "Some Data".getBytes();
when(payloadEncoder.encode(encodedPayload)).thenReturn(payloadData);
PublicKey recipientKey = mock(PublicKey.class);
NodeInfo nodeInfo = mock(NodeInfo.class);
when(nodeInfo.supportedApiVersions()).thenReturn(pair.getValue());
Recipient recipient = mock(Recipient.class);
when(recipient.getKey()).thenReturn(recipientKey);
when(recipient.getUrl()).thenReturn(targetUrl);
when(nodeInfo.getRecipients()).thenReturn(Set.of(recipient));
when(discovery.getRemoteNodeInfo(recipientKey)).thenReturn(nodeInfo);
EnhancedPrivacyNotSupportedException exception = catchThrowableOfType(() -> payloadPublisher.publishPayload(encodedPayload, recipientKey), EnhancedPrivacyNotSupportedException.class);
assertThat(exception).hasMessageContaining("Transactions with enhanced privacy is not currently supported");
verify(discovery).getRemoteNodeInfo(eq(recipientKey));
}
payloadEncoderFactoryFunction.verify(times(2), () -> PayloadEncoder.create(any(EncodedPayloadCodec.class)));
}
use of com.quorum.tessera.enclave.EncodedPayload in project tessera by ConsenSys.
the class RestResendBatchPublisherTest method publishBatchRecoveryClientFails.
@Test
public void publishBatchRecoveryClientFails() {
PayloadEncoder payloadEncoder = mock(PayloadEncoder.class);
RecoveryClient recoveryClient = mock(RecoveryClient.class);
ArgumentCaptor<PushBatchRequest> requestArgumentCaptor = ArgumentCaptor.forClass(PushBatchRequest.class);
when(recoveryClient.pushBatch(anyString(), requestArgumentCaptor.capture())).thenReturn(false);
List<EncodedPayload> encodedPayloads = payloadDatList.stream().map(o -> {
EncodedPayload encodedPayload = mock(EncodedPayload.class);
when(payloadEncoder.encode(encodedPayload)).thenReturn(o);
return encodedPayload;
}).collect(Collectors.toList());
RestResendBatchPublisher restRecoveryClient = new RestResendBatchPublisher(payloadEncoder, recoveryClient);
PublishPayloadException ex = catchThrowableOfType(() -> restRecoveryClient.publishBatch(encodedPayloads, targetUrl), PublishPayloadException.class);
assertThat(ex).hasMessage(String.format("Unable to push payload batch to recipient %s", targetUrl));
verify(recoveryClient).pushBatch(targetUrl, requestArgumentCaptor.getValue());
encodedPayloads.forEach(p -> {
verify(payloadEncoder).encode(p);
});
assertThat(requestArgumentCaptor.getValue().getEncodedPayloads()).isEqualTo(payloadDatList);
verifyNoMoreInteractions(recoveryClient);
verifyNoMoreInteractions(payloadEncoder);
}
use of com.quorum.tessera.enclave.EncodedPayload in project tessera by ConsenSys.
the class RestResendBatchPublisherTest method publishBatch.
@Test
public void publishBatch() {
PayloadEncoder payloadEncoder = mock(PayloadEncoder.class);
RecoveryClient recoveryClient = mock(RecoveryClient.class);
ArgumentCaptor<PushBatchRequest> requestArgumentCaptor = ArgumentCaptor.forClass(PushBatchRequest.class);
when(recoveryClient.pushBatch(anyString(), requestArgumentCaptor.capture())).thenReturn(true);
List<EncodedPayload> encodedPayloads = payloadDatList.stream().map(o -> {
EncodedPayload encodedPayload = mock(EncodedPayload.class);
when(payloadEncoder.encode(encodedPayload)).thenReturn(o);
return encodedPayload;
}).collect(Collectors.toList());
RestResendBatchPublisher restRecoveryClient = new RestResendBatchPublisher(payloadEncoder, recoveryClient);
restRecoveryClient.publishBatch(encodedPayloads, targetUrl);
verify(recoveryClient).pushBatch(targetUrl, requestArgumentCaptor.getValue());
encodedPayloads.forEach(p -> {
verify(payloadEncoder).encode(p);
});
assertThat(requestArgumentCaptor.getValue().getEncodedPayloads()).isEqualTo(payloadDatList);
verifyNoMoreInteractions(recoveryClient);
verifyNoMoreInteractions(payloadEncoder);
}
use of com.quorum.tessera.enclave.EncodedPayload in project tessera by ConsenSys.
the class AsyncBatchPayloadPublisher method publishPayload.
/**
* Asynchronously strips (leaving data intended only for that particular recipient) and publishes
* the payload to each recipient identified by the provided keys.
*
* <p>This method blocks until all pushes return successfully; if a push fails with an exception,
* the method exits immediately and does not wait for the remaining responses.
*
* @param payload the payload object to be stripped and pushed
* @param recipientKeys list of public keys identifying the target nodes
*/
@Override
public void publishPayload(EncodedPayload payload, List<PublicKey> recipientKeys) {
if (recipientKeys.size() == 0) {
return;
}
final CancellableCountDownLatch latch = countDownLatchFactory.create(recipientKeys.size());
recipientKeys.forEach(recipient -> executor.execute(() -> {
try {
final EncodedPayload outgoing = EncodedPayload.Builder.forRecipient(payload, recipient).build();
publisher.publishPayload(outgoing, recipient);
latch.countDown();
} catch (RuntimeException e) {
LOGGER.info("unable to publish payload in batch: {}", e.getMessage());
latch.cancelWithException(e);
}
}));
try {
latch.await();
} catch (InterruptedException e) {
throw new BatchPublishPayloadException(e);
}
}
Aggregations