Skip to content

Commit b425478

Browse files
author
Paolo Viotti
committed
add test for bytestring valuecoder
1 parent 0b5683f commit b425478

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

src/test/java/eu/antidotedb/client/test/AbstractAntidoteTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ public class AbstractAntidoteTest {
2222
final AntidoteClient antidoteClient;
2323
final Bucket bucket;
2424
final String bucketKey;
25+
final SecureRandom random;
2526

2627
public AbstractAntidoteTest() {
28+
random = new SecureRandom();
29+
2730
List<TransformerFactory> transformers = new ArrayList<>();
2831
transformers.add(messageCounter = new CountingTransformer());
2932
if (debugLog) {
@@ -41,7 +44,6 @@ public AbstractAntidoteTest() {
4144
}
4245

4346
public String nextSessionId() {
44-
SecureRandom random = new SecureRandom();
4547
return new BigInteger(130, random).toString(32);
4648
}
4749
}

src/test/java/eu/antidotedb/client/test/ValueCoderTest.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
package eu.antidotedb.client.test;
22

3-
import com.google.protobuf.ByteString;
43
import eu.antidotedb.client.*;
54
import org.junit.Test;
65

6+
import com.google.protobuf.ByteString;
7+
78
import java.util.Arrays;
89
import java.util.List;
910
import java.util.Objects;
1011

11-
import static org.junit.Assert.assertEquals;
12+
import static org.junit.Assert.*;
1213

1314
/**
1415
*
1516
*/
1617
public class ValueCoderTest extends AbstractAntidoteTest {
1718

1819
@Test
19-
public void staticReadWrite() {
20+
public void customValueCoder() {
2021

2122
NoTransaction tx = antidoteClient.noTransaction();
2223

@@ -35,7 +36,20 @@ public void staticReadWrite() {
3536

3637

3738
}
38-
39+
40+
@Test
41+
public void byteStringValueCoder() {
42+
43+
byte[] testArray = new byte[20];
44+
random.nextBytes(testArray);
45+
46+
ValueCoder<ByteString> vc = ValueCoder.bytestringEncoder;
47+
bucket.update(antidoteClient.noTransaction(),
48+
Key.register("test", vc).assign(ByteString.copyFrom(testArray)));
49+
ByteString bs = bucket.read(antidoteClient.noTransaction(), Key.register("test", vc));
50+
51+
assertArrayEquals(testArray, bs.toByteArray());
52+
}
3953
}
4054

4155
class UserId {

0 commit comments

Comments
 (0)