Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
package io.carbynestack.castor.common.entities;

import io.carbynestack.castor.common.exceptions.CastorClientException;

import java.io.ByteArrayOutputStream;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused import?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If not update Copyright Header

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
Expand Down
4 changes: 2 additions & 2 deletions castor-java-client/3RD-PARTY-LICENSES/sbom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
<name>Carbyne Stack Java HTTP Client</name>
<groupId>io.carbynestack</groupId>
<artifactId>java-http-client</artifactId>
<version>0.1-SNAPSHOT-4075044562-9-8ffab9c</version>
<version>0.1.2</version>
<licenses>
<license>
<name>Apache-2.0</name>
Expand All @@ -132,7 +132,7 @@
<name>castor-common</name>
<groupId>io.carbynestack</groupId>
<artifactId>castor-common</artifactId>
<version>0.1-SNAPSHOT-4321261594-23-40a9faa</version>
<version>0.1.1</version>
<licenses>
<license>
<name>Apache-2.0</name>
Expand Down
1 change: 1 addition & 0 deletions castor-java-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<dependency>
<groupId>io.carbynestack</groupId>
<artifactId>java-http-client</artifactId>
<version>0.1.2</version>
</dependency>

<dependency>
Expand Down
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update Copyright header

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
import io.carbynestack.httpclient.CsHttpClientException;
import io.vavr.control.Option;
import io.vavr.control.Try;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.UUID;
import lombok.Value;
Expand Down Expand Up @@ -91,19 +95,26 @@ private DefaultCastorIntraVcpClient(Builder builder) {
@Override
public TupleList downloadTupleShares(UUID requestId, TupleType tupleType, long count) {
try {
return csHttpClient
.getForEntity(
serviceUri.getIntraVcpRequestTuplesUri(requestId, tupleType, count),
getHeaders(serviceUri),
TupleList.class)
.get();
byte[] shares = csHttpClient
.getForEntity(
serviceUri.getIntraVcpRequestTuplesUri(requestId, tupleType, count),
getHeaders(serviceUri),
byte[].class)
.get();
long length = tupleType.getTupleSize() * count;
return TupleList.fromStream(tupleType.getTupleCls(),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As Tuples as mostly consumed within a stream, it may make sense to keep tuples as a stream (potentially still wrapped as a TupleList and lazily converted later if required).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe TupleList became obsolete

tupleType.getField(),
new ByteArrayInputStream(shares),
length);
} catch (CsHttpClientException chce) {
throw new CastorClientException(
String.format(
FAILED_DOWNLOADING_TUPLES_EXCEPTION_MSG,
serviceUri.getRestServiceUri(),
chce.getMessage()),
chce);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.*;

import io.carbynestack.castor.common.BearerTokenProvider;
import io.carbynestack.castor.common.CastorServiceUri;
Expand All @@ -25,7 +24,9 @@
import io.carbynestack.httpclient.CsHttpClient;
import io.carbynestack.httpclient.CsHttpClientException;
import io.carbynestack.httpclient.CsResponseEntity;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.nio.file.Files;
import java.util.ArrayList;
Expand Down Expand Up @@ -99,23 +100,35 @@ void givenSslConfiguration_whenBuildClient_thenInitializeCsHttpClientAccordingly

@SneakyThrows
@Test
void givenSuccessfulRequest_whenDownloadTripleShares_thenReturnExpectedContent() {
void givenSuccessfulRequest_whenDownloadTripleSharesAsBytes_thenReturnExpectedContent() {
UUID requestId = UUID.fromString("3dc08ff2-5eed-49a9-979e-3a3ac0e4a2cf");
int expectedCount = 2;
TupleList<MultiplicationTriple<Field.Gfp>, Field.Gfp> expectedTripleList =
new TupleList(MultiplicationTriple.class, GFP);

expectedTripleList.add(new MultiplicationTriple(GFP, testShare, testShare, testShare));
expectedTripleList.add(new MultiplicationTriple(GFP, testShare, testShare, testShare));
CsResponseEntity<String, TupleList> givenResponseEntity =
CsResponseEntity.success(HttpStatus.SC_OK, expectedTripleList);
ByteArrayOutputStream tripeListAsBytes = new ByteArrayOutputStream();
expectedTripleList.forEach(
tuple -> {
try {
tuple.writeTo(tripeListAsBytes);
} catch (IOException e) {
throw new RuntimeException(e);
}
});
CsResponseEntity<String, byte[]> givenResponseEntity =
CsResponseEntity.success(HttpStatus.SC_OK, tripeListAsBytes.toByteArray());

CastorServiceUri serviceUri = new CastorServiceUri(serviceAddress);

when(csHttpClientMock.getForEntity(
doReturn(givenResponseEntity)
.when(csHttpClientMock)
.getForEntity(
serviceUri.getIntraVcpRequestTuplesUri(
requestId, TupleType.MULTIPLICATION_TRIPLE_GFP, expectedCount),
Collections.emptyList(),
TupleList.class))
.thenReturn(givenResponseEntity);
byte[].class);
TupleList actualTripleList =
castorIntraVcpClient.downloadTupleShares(
requestId, TupleType.MULTIPLICATION_TRIPLE_GFP, expectedCount);
Expand All @@ -129,7 +142,7 @@ void givenRequestEmitsError_whenDownloadTripleShares_thenThrowCastorClientExcept
UUID requestId = UUID.fromString("3dc08ff2-5eed-49a9-979e-3a3ac0e4a2cf");
CsHttpClientException expectedCause = new CsHttpClientException("totally expected");
URI expectedUri = new CastorServiceUri(serviceAddress).getRestServiceUri();
when(csHttpClientMock.getForEntity(any(), eq(Collections.emptyList()), eq(TupleList.class)))
when(csHttpClientMock.getForEntity(any(), eq(Collections.emptyList()), eq(byte[].class)))
.thenThrow(expectedCause);
CastorClientException actualCce =
assertThrows(
Expand Down
Loading