Skip to content

Commit 3ed574f

Browse files
committed
fix: removed toByteArray function as it is now no longer needed
1 parent 5d05a94 commit 3ed574f

File tree

3 files changed

+39
-32
lines changed

3 files changed

+39
-32
lines changed

castor-common/src/main/java/io/carbynestack/castor/common/entities/TupleList.java

-13
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,6 @@ public static <T extends Tuple<T, F>, F extends Field> TupleList<T, F> fromStrea
7070
}
7171
}
7272

73-
public byte[] toByteArray(){
74-
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
75-
this.forEach(
76-
tuple -> {
77-
try {
78-
tuple.writeTo(outputStream);
79-
} catch (IOException exception) {
80-
rethrow(exception);
81-
}
82-
});
83-
return outputStream.toByteArray();
84-
}
85-
8673
/**
8774
* Converts a {@link TupleList} to {@link TupleChunk}
8875
*

castor-java-client/src/test/java/io/carbynestack/castor/client/download/DefaultCastorIntraVcpClientTest.java

+19-9
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
import io.carbynestack.httpclient.CsHttpClient;
2525
import io.carbynestack.httpclient.CsHttpClientException;
2626
import io.carbynestack.httpclient.CsResponseEntity;
27-
2827
import java.io.ByteArrayOutputStream;
2928
import java.io.File;
29+
import java.io.IOException;
3030
import java.net.URI;
3131
import java.nio.file.Files;
3232
import java.util.ArrayList;
@@ -100,28 +100,38 @@ void givenSslConfiguration_whenBuildClient_thenInitializeCsHttpClientAccordingly
100100

101101
@SneakyThrows
102102
@Test
103-
void givenSuccessfulRequest_whenDownloadTripleSharesAsBytes_thenReturnExpectedContent(){
103+
void givenSuccessfulRequest_whenDownloadTripleSharesAsBytes_thenReturnExpectedContent() {
104104
UUID requestId = UUID.fromString("3dc08ff2-5eed-49a9-979e-3a3ac0e4a2cf");
105105
int expectedCount = 2;
106106
TupleList<MultiplicationTriple<Field.Gfp>, Field.Gfp> expectedTripleList =
107-
new TupleList(MultiplicationTriple.class, GFP);
107+
new TupleList(MultiplicationTriple.class, GFP);
108+
108109
expectedTripleList.add(new MultiplicationTriple(GFP, testShare, testShare, testShare));
109110
expectedTripleList.add(new MultiplicationTriple(GFP, testShare, testShare, testShare));
111+
ByteArrayOutputStream tripeListAsBytes = new ByteArrayOutputStream();
112+
expectedTripleList.forEach(
113+
tuple -> {
114+
try {
115+
tuple.writeTo(tripeListAsBytes);
116+
} catch (IOException e) {
117+
throw new RuntimeException(e);
118+
}
119+
});
110120
CsResponseEntity<String, byte[]> givenResponseEntity =
111-
CsResponseEntity.success(HttpStatus.SC_OK, expectedTripleList.toByteArray());
121+
CsResponseEntity.success(HttpStatus.SC_OK, tripeListAsBytes.toByteArray());
112122

113123
CastorServiceUri serviceUri = new CastorServiceUri(serviceAddress);
114124

115125
doReturn(givenResponseEntity)
116-
.when(csHttpClientMock)
117-
.getForEntity(
126+
.when(csHttpClientMock)
127+
.getForEntity(
118128
serviceUri.getIntraVcpRequestTuplesUri(
119-
requestId, TupleType.MULTIPLICATION_TRIPLE_GFP, expectedCount),
129+
requestId, TupleType.MULTIPLICATION_TRIPLE_GFP, expectedCount),
120130
Collections.emptyList(),
121131
byte[].class);
122132
TupleList actualTripleList =
123-
castorIntraVcpClient.downloadTupleShares(
124-
requestId, TupleType.MULTIPLICATION_TRIPLE_GFP, expectedCount);
133+
castorIntraVcpClient.downloadTupleShares(
134+
requestId, TupleType.MULTIPLICATION_TRIPLE_GFP, expectedCount);
125135

126136
assertEquals(expectedTripleList, actualTripleList);
127137
}

castor-service/src/test/java/io/carbynestack/castor/service/download/DefaultTuplesDownloadServiceAsMasterIT.java

+20-10
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
import io.minio.MinioClient;
3636
import io.minio.PutObjectArgs;
3737
import java.io.ByteArrayInputStream;
38+
import java.io.ByteArrayOutputStream;
39+
import java.io.IOException;
3840
import java.io.InputStream;
3941
import java.util.Arrays;
4042
import java.util.Objects;
@@ -292,17 +294,25 @@ void givenRetrievingTuplesFails_whenGetTuples_thenKeepReservationAndReservationM
292294
tuplesDownloadService.getTupleList(
293295
tupleType.getTupleCls(), tupleType.getField(), count, requestId);
294296

295-
assertArrayEquals(
297+
TupleList actualTupleList =
296298
TupleList.fromStream(
297-
tupleType.getTupleCls(),
298-
tupleType.getField(),
299-
new ByteArrayInputStream(
300-
tupleData,
301-
(int) (fragmentStartIndex * tupleType.getTupleSize()),
302-
(int) ((fragmentStartIndex + count) * tupleType.getTupleSize())),
303-
count * tupleType.getTupleSize())
304-
.toByteArray(),
305-
tupleList);
299+
tupleType.getTupleCls(),
300+
tupleType.getField(),
301+
new ByteArrayInputStream(
302+
tupleData,
303+
(int) (fragmentStartIndex * tupleType.getTupleSize()),
304+
(int) ((fragmentStartIndex + count) * tupleType.getTupleSize())),
305+
count * tupleType.getTupleSize());
306+
ByteArrayOutputStream actualTupleData = new ByteArrayOutputStream();
307+
actualTupleList.forEach(
308+
tuple -> {
309+
try {
310+
((Tuple<?, ?>) tuple).writeTo(actualTupleData);
311+
} catch (IOException e) {
312+
throw new RuntimeException(e);
313+
}
314+
});
315+
assertArrayEquals(actualTupleData.toByteArray(), tupleList);
306316

307317
// no fragments stored -> existing fragment was reserved, consumed and then deleted
308318
assertFalse(tupleChunkFragmentRepository.findAll().iterator().hasNext());

0 commit comments

Comments
 (0)