use of com.google.cloud.ByteArray in project google-cloud-java by GoogleCloudPlatform.
the class ITWriteTest method writeBytes.
@Test
public void writeBytes() {
ByteArray data = ByteArray.copyFrom("V1");
write(baseInsert().set("BytesValue").to(data).build());
Struct row = readLastRow("BytesValue");
assertThat(row.isNull(0)).isFalse();
assertThat(row.getBytes(0)).isEqualTo(data);
}
use of com.google.cloud.ByteArray in project spanner-jdbc by olavloite.
the class CloudSpannerConversionUtilTest method testToJavaByteArrays.
@Test
public void testToJavaByteArrays() {
ByteArray inp1 = ByteArray.copyFrom("AA".getBytes());
ByteArray inp2 = ByteArray.copyFrom("BB".getBytes());
List<byte[]> output = CloudSpannerConversionUtil.toJavaByteArrays(Arrays.asList(inp1, inp2));
List<byte[]> list = Arrays.asList("AA".getBytes(), "BB".getBytes());
assertArrayEquals(list.toArray(), output.toArray());
}
use of com.google.cloud.ByteArray in project google-cloud-java by GoogleCloudPlatform.
the class GrpcResultSetTest method multiResponseChunkingBytes.
@Test
public void multiResponseChunkingBytes() {
ByteArray expectedBytes = ByteArray.copyFrom("abcdefghijklmnopqrstuvwxyz");
String base64 = expectedBytes.toBase64();
String chunk1 = base64.substring(0, 10);
String chunk2 = base64.substring(10, 20);
String chunk3 = base64.substring(20);
consumer.onPartialResultSet(PartialResultSet.newBuilder().setMetadata(makeMetadata(Type.struct(Type.StructField.of("f", Type.bytes())))).addValues(Value.bytes(ByteArray.copyFrom("before")).toProto()).addValues(com.google.protobuf.Value.newBuilder().setStringValue(chunk1)).setChunkedValue(true).build());
consumer.onPartialResultSet(PartialResultSet.newBuilder().addValues(com.google.protobuf.Value.newBuilder().setStringValue(chunk2)).setChunkedValue(true).build());
consumer.onPartialResultSet(PartialResultSet.newBuilder().addValues(com.google.protobuf.Value.newBuilder().setStringValue(chunk3)).addValues(Value.bytes(ByteArray.copyFrom("after")).toProto()).setChunkedValue(false).build());
consumer.onCompleted();
List<ByteArray> results = new ArrayList<>();
while (resultSet.next()) {
results.add(resultSet.getBytes(0));
}
assertThat(results).containsExactly(ByteArray.copyFrom("before"), expectedBytes, ByteArray.copyFrom("after")).inOrder();
}
use of com.google.cloud.ByteArray in project google-cloud-java by GoogleCloudPlatform.
the class KeyTest method testToString.
@Test
public void testToString() {
assertThat(Key.of().toString()).isEqualTo("[]");
assertThat(Key.of(new Object[] { null }).toString()).isEqualTo("[<null>]");
assertThat(Key.of(true).toString()).isEqualTo("[true]");
assertThat(Key.of(32).toString()).isEqualTo("[32]");
assertThat(Key.of(2.0).toString()).isEqualTo("[2.0]");
assertThat(Key.of("xyz").toString()).isEqualTo("[xyz]");
ByteArray b = ByteArray.copyFrom("xyz");
assertThat(Key.of(b).toString()).isEqualTo("[" + b.toString() + "]");
String timestamp = "2015-09-15T00:00:00Z";
assertThat(Key.of(Timestamp.parseTimestamp(timestamp)).toString()).isEqualTo("[" + timestamp + "]");
String date = "2015-09-15";
assertThat(Key.of(Date.parseDate(date)).toString()).isEqualTo("[" + date + "]");
assertThat(Key.of(1, 2, 3).toString()).isEqualTo("[1,2,3]");
}
use of com.google.cloud.ByteArray in project beam by apache.
the class MutationSizeEstimatorTest method bytes.
@Test
public void bytes() throws Exception {
Mutation empty = Mutation.newInsertOrUpdateBuilder("test").set("one").to(ByteArray.fromBase64("")).build();
Mutation nullValue = Mutation.newInsertOrUpdateBuilder("test").set("one").to((ByteArray) null).build();
Mutation sample = Mutation.newInsertOrUpdateBuilder("test").set("one").to(ByteArray.fromBase64("abcdabcd")).build();
assertThat(MutationSizeEstimator.sizeOf(empty), is(0L));
assertThat(MutationSizeEstimator.sizeOf(nullValue), is(0L));
assertThat(MutationSizeEstimator.sizeOf(sample), is(6L));
}
Aggregations