use of com.quorum.tessera.privacygroup.exception.PrivacyGroupPublishException in project tessera by ConsenSys.
the class AsyncBatchPrivacyGroupPublisher method publishPrivacyGroup.
@Override
public void publishPrivacyGroup(byte[] data, List<PublicKey> recipientKeys) {
if (recipientKeys.size() == 0) {
return;
}
final CancellableCountDownLatch latch = countDownLatchFactory.create(recipientKeys.size());
recipientKeys.forEach(key -> executor.execute(() -> {
try {
publisher.publishPrivacyGroup(data, key);
latch.countDown();
} catch (RuntimeException e) {
LOGGER.info("Unable to publish privacy group: {}", e.getMessage());
latch.cancelWithException(e);
}
}));
try {
latch.await();
} catch (InterruptedException e) {
throw new PrivacyGroupPublishException(e.getMessage());
}
}
use of com.quorum.tessera.privacygroup.exception.PrivacyGroupPublishException in project tessera by ConsenSys.
the class RestPrivacyGroupPublisher method publishPrivacyGroup.
@Override
public void publishPrivacyGroup(byte[] data, PublicKey recipientKey) {
final NodeInfo remoteNodeInfo = discovery.getRemoteNodeInfo(recipientKey);
if (!remoteNodeInfo.supportedApiVersions().contains(PrivacyGroupVersion.API_VERSION_3)) {
throw new PrivacyGroupNotSupportedException("Transactions with privacy group is not currently supported on recipient " + recipientKey.encodeToBase64());
}
final String targetUrl = remoteNodeInfo.getUrl();
LOGGER.info("Publishing privacy group to {}", targetUrl);
try (Response response = restClient.target(targetUrl).path("/pushPrivacyGroup").request().post(Entity.entity(data, MediaType.APPLICATION_OCTET_STREAM_TYPE))) {
if (Response.Status.OK.getStatusCode() != response.getStatus()) {
throw new PrivacyGroupPublishException("Unable to push privacy group to recipient url " + targetUrl);
}
LOGGER.info("Published privacy group to {}", targetUrl);
} catch (ProcessingException ex) {
LOGGER.debug("", ex);
throw new NodeOfflineException(URI.create(targetUrl));
}
}
use of com.quorum.tessera.privacygroup.exception.PrivacyGroupPublishException in project tessera by ConsenSys.
the class AsyncBatchPrivacyGroupPublisherTest method publishReturnsError.
@Test
public void publishReturnsError() throws InterruptedException {
final Executor realExecutor = Executors.newSingleThreadExecutor();
when(mockExecutorFactory.createCachedThreadPool()).thenReturn(realExecutor);
final AsyncBatchPrivacyGroupPublisher publisher = new AsyncBatchPrivacyGroupPublisher(mockExecutorFactory, mockCountDownLatchFactory, mockPublisher);
final byte[] data = new byte[5];
doThrow(new PrivacyGroupPublishException("OUCH")).when(mockPublisher).publishPrivacyGroup(eq(data), eq(otherRecipient));
doAnswer(invocation -> {
// sleep main thread so publish threads can work
Thread.sleep(200);
return null;
}).when(mockCountDownLatch).await();
publisher.publishPrivacyGroup(data, List.of(recipient, otherRecipient));
verify(mockCountDownLatch).cancelWithException(any());
}
use of com.quorum.tessera.privacygroup.exception.PrivacyGroupPublishException in project tessera by ConsenSys.
the class RestPrivacyGroupPublisherTest method testPublishSingleError.
@Test
public void testPublishSingleError() {
String targetUrl = "https://sometargeturl.com";
PublicKey recipient = PublicKey.from("PUBLIC_KEY".getBytes());
NodeInfo nodeInfo = mock(NodeInfo.class);
when(nodeInfo.supportedApiVersions()).thenReturn(Set.of(PrivacyGroupVersion.API_VERSION_3));
when(nodeInfo.getUrl()).thenReturn(targetUrl);
when(discovery.getRemoteNodeInfo(recipient)).thenReturn(nodeInfo);
Invocation.Builder invocationBuilder = mock(Invocation.Builder.class);
when(invocationBuilder.post(any(Entity.class))).thenReturn(Response.serverError().build());
WebTarget webTarget = mock(WebTarget.class);
when(client.target(targetUrl)).thenReturn(webTarget);
when(webTarget.path(anyString())).thenReturn(webTarget);
when(webTarget.request()).thenReturn(invocationBuilder);
final byte[] data = new byte[5];
try {
publisher.publishPrivacyGroup(data, recipient);
failBecauseExceptionWasNotThrown(PrivacyGroupPublishException.class);
} catch (PrivacyGroupPublishException ex) {
verify(discovery).getRemoteNodeInfo(recipient);
verify(client).target(targetUrl);
}
}
Aggregations