Search in sources :

Example 6 with ByteArray

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);
}
Also used : ByteArray(com.google.cloud.ByteArray) Struct(com.google.cloud.spanner.Struct) IntegrationTest(com.google.cloud.spanner.IntegrationTest) Test(org.junit.Test)

Example 7 with ByteArray

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());
}
Also used : ByteArray(com.google.cloud.ByteArray) Test(org.junit.Test) UnitTest(nl.topicus.jdbc.test.category.UnitTest)

Example 8 with ByteArray

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();
}
Also used : ArrayList(java.util.ArrayList) ByteArray(com.google.cloud.ByteArray) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 9 with ByteArray

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]");
}
Also used : ByteArray(com.google.cloud.ByteArray) Test(org.junit.Test)

Example 10 with ByteArray

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));
}
Also used : ByteArray(com.google.cloud.ByteArray) Mutation(com.google.cloud.spanner.Mutation) Test(org.junit.Test)

Aggregations

ByteArray (com.google.cloud.ByteArray)15 Test (org.junit.Test)14 IntegrationTest (com.google.cloud.spanner.IntegrationTest)6 Struct (com.google.cloud.spanner.Struct)5 UnitTest (nl.topicus.jdbc.test.category.UnitTest)2 KeySet (com.google.cloud.spanner.KeySet)1 Mutation (com.google.cloud.spanner.Mutation)1 ResultSet (com.google.cloud.spanner.ResultSet)1 ByteString (com.google.protobuf.ByteString)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Random (java.util.Random)1