use of com.google.cloud.ByteArray in project google-cloud-java by GoogleCloudPlatform.
the class ITWriteTest method writeBytesArray.
@Test
public void writeBytesArray() {
List<ByteArray> data = Arrays.asList(ByteArray.copyFrom("a"), ByteArray.copyFrom("b"), null);
write(baseInsert().set("BytesArrayValue").toBytesArray(data).build());
Struct row = readLastRow("BytesArrayValue");
assertThat(row.isNull(0)).isFalse();
assertThat(row.getBytesList(0)).isEqualTo(data);
}
use of com.google.cloud.ByteArray in project google-cloud-java by GoogleCloudPlatform.
the class ITWriteTest method writeBytesRandom.
@Test
public void writeBytesRandom() {
// Pseudo-random test for byte encoding. We explicitly set a random seed so that multiple
// test runs cover more data, but any failing test run can be reproduced easily.
Random rnd = new Random();
long seed = rnd.nextLong();
rnd.setSeed(seed);
Map<String, ByteArray> expected = new HashMap<>();
boolean pass = false;
try {
for (int length : new int[] { 1, 2, 5, 11 }) {
byte[] data = new byte[length];
for (int i = 0; i < 3; ++i) {
rnd.nextBytes(data);
String key = uniqueString();
ByteArray value = ByteArray.copyFrom(data);
expected.put(key, value);
write(Mutation.newInsertOrUpdateBuilder("T").set("K").to(key).set("BytesValue").to(value).build());
}
}
KeySet.Builder keys = KeySet.newBuilder();
for (String key : expected.keySet()) {
keys.addKey(Key.of(key));
}
ResultSet resultSet = client.singleUse(TimestampBound.strong()).read("T", keys.build(), Arrays.asList("K", "BytesValue"));
while (resultSet.next()) {
String key = resultSet.getString(0);
ByteArray value = resultSet.getBytes(1);
assertThat(expected).containsKey(key);
ByteArray expectedValue = expected.remove(key);
assertThat(value).isEqualTo(expectedValue);
}
assertThat(expected).isEmpty();
pass = true;
} finally {
if (!pass) {
System.out.println("To reproduce failure, use seed " + seed);
}
}
}
use of com.google.cloud.ByteArray in project google-cloud-java by GoogleCloudPlatform.
the class ITQueryTest method bindBytesArray.
@Test
public void bindBytesArray() {
ByteArray e1 = ByteArray.copyFrom("x");
ByteArray e2 = ByteArray.copyFrom("y");
ByteArray e3 = null;
Struct row = execute(Statement.newBuilder("SELECT @v").bind("v").toBytesArray(Arrays.asList(e1, e2, e3)), Type.array(Type.bytes()));
assertThat(row.isNull(0)).isFalse();
assertThat(row.getBytesList(0)).containsExactly(e1, e2, e3).inOrder();
}
use of com.google.cloud.ByteArray in project google-cloud-java by GoogleCloudPlatform.
the class ITQueryTest method bindBytesNull.
@Test
public void bindBytesNull() {
Struct row = execute(Statement.newBuilder("SELECT @v").bind("v").to((ByteArray) null), Type.bytes());
assertThat(row.isNull(0)).isTrue();
}
use of com.google.cloud.ByteArray in project spanner-jdbc by olavloite.
the class CloudSpannerConversionUtilTest method testToCloudSpannerBytes.
@Test
public void testToCloudSpannerBytes() {
byte[][] input = new byte[][] { "AA".getBytes(), "BB".getBytes() };
List<ByteArray> output = CloudSpannerConversionUtil.toCloudSpannerBytes(input);
ByteArray inp1 = ByteArray.copyFrom("AA".getBytes());
ByteArray inp2 = ByteArray.copyFrom("BB".getBytes());
assertArrayEquals(new ByteArray[] { inp1, inp2 }, output.toArray());
}
Aggregations