Search in sources :

Example 11 with Timestamp

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

the class ITWriteTest method writeTimestamp.

@Test
public void writeTimestamp() {
    Timestamp timestamp = Timestamp.parseTimestamp("2016-09-15T00:00:00.111111Z");
    write(baseInsert().set("TimestampValue").to(timestamp).build());
    Struct row = readLastRow("TimestampValue");
    assertThat(row.isNull(0)).isFalse();
    assertThat(row.getTimestamp(0)).isEqualTo(timestamp);
}
Also used : Timestamp(com.google.cloud.Timestamp) Struct(com.google.cloud.spanner.Struct) IntegrationTest(com.google.cloud.spanner.IntegrationTest) Test(org.junit.Test)

Example 12 with Timestamp

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

the class ITQueryTest method bindTimestampArray.

@Test
public void bindTimestampArray() {
    Timestamp t1 = Timestamp.parseTimestamp("2016-09-18T00:00:00Z");
    Timestamp t2 = Timestamp.parseTimestamp("2016-09-19T00:00:00Z");
    Struct row = execute(Statement.newBuilder("SELECT @v").bind("v").toTimestampArray(Arrays.asList(t1, t2, null)), Type.array(Type.timestamp()));
    assertThat(row.isNull(0)).isFalse();
    assertThat(row.getTimestampList(0)).containsExactly(t1, t2, null).inOrder();
}
Also used : Timestamp(com.google.cloud.Timestamp) Struct(com.google.cloud.spanner.Struct) IntegrationTest(com.google.cloud.spanner.IntegrationTest) Test(org.junit.Test)

Example 13 with Timestamp

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

the class ITQueryTest method bindTimestampNull.

@Test
public void bindTimestampNull() {
    Struct row = execute(Statement.newBuilder("SELECT @v").bind("v").to((Timestamp) null), Type.timestamp());
    assertThat(row.isNull(0)).isTrue();
}
Also used : Timestamp(com.google.cloud.Timestamp) Struct(com.google.cloud.spanner.Struct) IntegrationTest(com.google.cloud.spanner.IntegrationTest) Test(org.junit.Test)

Example 14 with Timestamp

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

the class ITQueryTest method bindTimestamp.

@Test
public void bindTimestamp() {
    Timestamp t = Timestamp.parseTimestamp("2016-09-18T00:00:00Z");
    Struct row = execute(Statement.newBuilder("SELECT @v").bind("v").to(t), Type.timestamp());
    assertThat(row.isNull(0)).isFalse();
    assertThat(row.getTimestamp(0)).isEqualTo(t);
}
Also used : Timestamp(com.google.cloud.Timestamp) Struct(com.google.cloud.spanner.Struct) IntegrationTest(com.google.cloud.spanner.IntegrationTest) Test(org.junit.Test)

Example 15 with Timestamp

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

the class ITReadOnlyTxnTest method singleMaxStaleness.

@Test
public void singleMaxStaleness() {
    History minimum = history.get(2);
    NavigableMap<Timestamp, String> possibleValues = new TreeMap<>();
    for (History item : history.subList(2, history.size())) {
        possibleValues.put(item.timestamp, item.value);
    }
    // Pick a staleness that cannot precede the second write (which, in practice, is the staleness
    // that exceeds the minimum commit time for the subsequent write).
    long stalenessNanos = System.nanoTime() - history.get(3).minCommitNanoTime;
    TimestampBound bound = TimestampBound.ofMaxStaleness(stalenessNanos, TimeUnit.NANOSECONDS);
    ReadOnlyTransaction readContext = client.singleUseReadOnlyTransaction(bound);
    Struct row = readRow(readContext);
    assertThat(row).isNotNull();
    assertThat(readContext.getReadTimestamp()).isAtLeast(minimum.timestamp);
    assertThat(row.getString(0)).isEqualTo(possibleValues.floorEntry(readContext.getReadTimestamp()).getValue());
    row = readRow(client.singleUse(bound));
    assertThat(row).isNotNull();
    assertThat(row.getString(0)).isIn(possibleValues.values());
}
Also used : TimestampBound(com.google.cloud.spanner.TimestampBound) ReadOnlyTransaction(com.google.cloud.spanner.ReadOnlyTransaction) TreeMap(java.util.TreeMap) Timestamp(com.google.cloud.Timestamp) Struct(com.google.cloud.spanner.Struct) IntegrationTest(com.google.cloud.spanner.IntegrationTest) Test(org.junit.Test)

Aggregations

Timestamp (com.google.cloud.Timestamp)22 Test (org.junit.Test)20 Struct (com.google.cloud.spanner.Struct)9 IntegrationTest (com.google.cloud.spanner.IntegrationTest)8 LoggingEvent (ch.qos.logback.classic.spi.LoggingEvent)4 LogEntry (com.google.cloud.logging.LogEntry)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 Date (com.google.cloud.Date)2 Mutation (com.google.cloud.spanner.Mutation)2 ReadOnlyTransaction (com.google.cloud.spanner.ReadOnlyTransaction)2 TimestampBound (com.google.cloud.spanner.TimestampBound)2 EqualsTester (com.google.common.testing.EqualsTester)2 TreeMap (java.util.TreeMap)2 ThresholdFilter (ch.qos.logback.classic.filter.ThresholdFilter)1 WriteOption (com.google.cloud.logging.Logging.WriteOption)1 TransactionContext (com.google.cloud.spanner.TransactionContext)1 TransactionRunner (com.google.cloud.spanner.TransactionRunner)1 TransactionCallable (com.google.cloud.spanner.TransactionRunner.TransactionCallable)1 ByteString (com.google.protobuf.ByteString)1 CommitRequest (com.google.spanner.v1.CommitRequest)1