Search in sources :

Example 1 with ByteArray

use of com.google.cloud.ByteArray in project google-cloud-java by GoogleCloudPlatform.

the class ValueTest method bytesArray.

@Test
public void bytesArray() {
    ByteArray a = newByteArray("a");
    ByteArray c = newByteArray("c");
    Value v = Value.bytesArray(Arrays.asList(a, null, c));
    assertThat(v.isNull()).isFalse();
    assertThat(v.getBytesArray()).containsExactly(a, null, c).inOrder();
    assertThat(v.toString()).isEqualTo(String.format("[%s,NULL,%s]", a, c));
}
Also used : ByteArray(com.google.cloud.ByteArray) Test(org.junit.Test)

Example 2 with ByteArray

use of com.google.cloud.ByteArray in project google-cloud-java by GoogleCloudPlatform.

the class ValueTest method bytes.

@Test
public void bytes() {
    ByteArray bytes = newByteArray("abc");
    Value v = Value.bytes(bytes);
    assertThat(v.getType()).isEqualTo(Type.bytes());
    assertThat(v.isNull()).isFalse();
    assertThat(v.getBytes()).isSameAs(bytes);
    assertThat(v.toString()).isEqualTo(bytes.toString());
}
Also used : ByteArray(com.google.cloud.ByteArray) Test(org.junit.Test)

Example 3 with ByteArray

use of com.google.cloud.ByteArray in project google-cloud-java by GoogleCloudPlatform.

the class ValueTest method bytesUnprintable.

@Test
public void bytesUnprintable() {
    ByteArray bytes = ByteArray.copyFrom(new byte[] { 'a', 0, 15, -1, 'e' });
    Value v = Value.bytes(bytes);
    assertThat(v.getBytes()).isSameAs(bytes);
    assertThat(v.toString()).isEqualTo(bytes.toString());
}
Also used : ByteArray(com.google.cloud.ByteArray) Test(org.junit.Test)

Example 4 with ByteArray

use of com.google.cloud.ByteArray in project google-cloud-java by GoogleCloudPlatform.

the class ITLargeReadTest method validate.

private void validate(ResultSet resultSet) {
    int i = 0;
    while (resultSet.next()) {
        assertThat(resultSet.getLong(0)).isEqualTo(i);
        ByteArray data = resultSet.getBytes(1);
        assertThat(data.length()).isEqualTo(resultSet.getLong(3));
        assertThat(resultSet.getLong(2)).isEqualTo(hasher.hashBytes(data.toByteArray()).asLong());
        assertThat(++i).isAtMost(numRows);
    }
    assertThat(i).isEqualTo(numRows);
}
Also used : ByteArray(com.google.cloud.ByteArray)

Example 5 with ByteArray

use of com.google.cloud.ByteArray in project google-cloud-java by GoogleCloudPlatform.

the class ITQueryTest method bindBytesArrayEmpty.

@Test
public void bindBytesArrayEmpty() {
    Struct row = execute(Statement.newBuilder("SELECT @v").bind("v").toBytesArray(Arrays.<ByteArray>asList()), Type.array(Type.bytes()));
    assertThat(row.isNull(0)).isFalse();
    assertThat(row.getBytesList(0)).isEmpty();
}
Also used : ByteArray(com.google.cloud.ByteArray) Struct(com.google.cloud.spanner.Struct) IntegrationTest(com.google.cloud.spanner.IntegrationTest) Test(org.junit.Test)

Aggregations

ByteArray (com.google.cloud.ByteArray)16 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 Date (com.google.cloud.Date)1 Timestamp (com.google.cloud.Timestamp)1 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 KeyPart (org.apache.beam.sdk.io.gcp.spanner.SpannerSchema.KeyPart)1