Search in sources :

Example 51 with Struct

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

the class ITWriteTest method writeInt64.

@Test
public void writeInt64() {
    write(baseInsert().set("Int64Value").to(1234).build());
    Struct row = readLastRow("Int64Value");
    assertThat(row.isNull(0)).isFalse();
    assertThat(row.getLong(0)).isEqualTo(1234L);
}
Also used : Struct(com.google.cloud.spanner.Struct) IntegrationTest(com.google.cloud.spanner.IntegrationTest) Test(org.junit.Test)

Example 52 with Struct

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

the class ITWriteTest method writeFloat64.

@Test
public void writeFloat64() {
    write(baseInsert().set("Float64Value").to(2.0).build());
    Struct row = readLastRow("Float64Value");
    assertThat(row.isNull(0)).isFalse();
    assertThat(row.getDouble(0)).isWithin(0.0).of(2.0);
}
Also used : Struct(com.google.cloud.spanner.Struct) IntegrationTest(com.google.cloud.spanner.IntegrationTest) Test(org.junit.Test)

Example 53 with Struct

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

the class ITReadOnlyTxnTest method singleReadTimestamp.

@Test
public void singleReadTimestamp() {
    History expected = history.get(2);
    TimestampBound bound = TimestampBound.ofReadTimestamp(expected.timestamp);
    ReadOnlyTransaction readContext = client.singleUseReadOnlyTransaction(bound);
    Struct row = readRow(readContext);
    assertThat(row).isNotNull();
    assertThat(row.getString(0)).isEqualTo(expected.value);
    assertThat(readContext.getReadTimestamp()).isEqualTo(expected.timestamp);
    row = readRow(client.singleUse(bound));
    assertThat(row).isNotNull();
    assertThat(row.getString(0)).isEqualTo(expected.value);
}
Also used : TimestampBound(com.google.cloud.spanner.TimestampBound) ReadOnlyTransaction(com.google.cloud.spanner.ReadOnlyTransaction) Struct(com.google.cloud.spanner.Struct) IntegrationTest(com.google.cloud.spanner.IntegrationTest) Test(org.junit.Test)

Example 54 with Struct

use of com.google.cloud.spanner.Struct in project YCSB by brianfrankcooper.

the class CloudSpannerClient method read.

@Override
public Status read(String table, String key, Set<String> fields, HashMap<String, ByteIterator> result) {
    if (queriesForReads) {
        return readUsingQuery(table, key, fields, result);
    }
    Iterable<String> columns = fields == null ? STANDARD_FIELDS : fields;
    try {
        Struct row = dbClient.singleUse(timestampBound).readRow(table, Key.of(key), columns);
        decodeStruct(columns, row, result);
        return Status.OK;
    } catch (Exception e) {
        LOGGER.log(Level.INFO, "read()", e);
        return Status.ERROR;
    }
}
Also used : DBException(com.yahoo.ycsb.DBException) Struct(com.google.cloud.spanner.Struct)

Example 55 with Struct

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

the class ITReadOnlyTxnTest method multiStrong.

@Test
public void multiStrong() {
    setUpPrivateDatabase();
    History expected = history.get(history.size() - 1);
    try (ReadOnlyTransaction readContext = client.readOnlyTransaction()) {
        Struct row = readRow(readContext);
        assertThat(row).isNotNull();
        assertThat(row.getString(0)).isEqualTo(expected.value);
        assertThat(readContext.getReadTimestamp()).isAtLeast(expected.timestamp);
        insertAndReadAgain(readContext, readContext.getReadTimestamp(), expected.value);
    }
}
Also used : ReadOnlyTransaction(com.google.cloud.spanner.ReadOnlyTransaction) Struct(com.google.cloud.spanner.Struct) IntegrationTest(com.google.cloud.spanner.IntegrationTest) Test(org.junit.Test)

Aggregations

Struct (com.google.cloud.spanner.Struct)106 IntegrationTest (com.google.cloud.spanner.IntegrationTest)101 Test (org.junit.Test)101 Timestamp (com.google.cloud.Timestamp)9 ReadOnlyTransaction (com.google.cloud.spanner.ReadOnlyTransaction)9 Date (com.google.cloud.Date)6 ByteArray (com.google.cloud.ByteArray)5 TimestampBound (com.google.cloud.spanner.TimestampBound)5 TransactionContext (com.google.cloud.spanner.TransactionContext)4 Type (com.google.cloud.spanner.Type)4 SpannerException (com.google.cloud.spanner.SpannerException)3 SpannerExceptionFactory.newSpannerException (com.google.cloud.spanner.SpannerExceptionFactory.newSpannerException)3 TransactionCallable (com.google.cloud.spanner.TransactionRunner.TransactionCallable)3 AbortedException (com.google.cloud.spanner.AbortedException)2 ResultSet (com.google.cloud.spanner.ResultSet)2 ArrayList (java.util.ArrayList)2 TreeMap (java.util.TreeMap)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Ignore (org.junit.Ignore)2 TransactionRunner (com.google.cloud.spanner.TransactionRunner)1