Search in sources :

Example 16 with Timestamp

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

the class ITReadOnlyTxnTest method writeNewValue.

private static void writeNewValue(DatabaseClient client, int i, @Nullable ImmutableList.Builder<History> historyBuilder) {
    String value = "v" + i;
    Mutation m = Mutation.newInsertOrUpdateBuilder(TABLE_NAME).set("StringValue").to(value).build();
    long minCommitNanoTime = System.nanoTime();
    Timestamp timestamp = client.writeAtLeastOnce(Arrays.asList(m));
    if (historyBuilder != null) {
        historyBuilder.add(new History(timestamp, value, minCommitNanoTime));
    }
}
Also used : Mutation(com.google.cloud.spanner.Mutation) Timestamp(com.google.cloud.Timestamp)

Example 17 with Timestamp

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

the class ITReadOnlyTxnTest method singleMinReadTimestamp.

@Test
public void singleMinReadTimestamp() {
    int minimumIndex = 2;
    History minimum = history.get(minimumIndex);
    NavigableMap<Timestamp, String> possibleValues = new TreeMap<>();
    for (History item : history.subList(minimumIndex, history.size())) {
        possibleValues.put(item.timestamp, item.value);
    }
    TimestampBound bound = TimestampBound.ofMinReadTimestamp(minimum.timestamp);
    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)

Example 18 with Timestamp

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

the class ITQueryTest method bindTimestampArrayEmpty.

@Test
public void bindTimestampArrayEmpty() {
    Struct row = execute(Statement.newBuilder("SELECT @v").bind("v").toTimestampArray(Arrays.<Timestamp>asList()), Type.array(Type.timestamp()));
    assertThat(row.isNull(0)).isFalse();
    assertThat(row.getTimestampList(0)).containsExactly();
}
Also used : Timestamp(com.google.cloud.Timestamp) Struct(com.google.cloud.spanner.Struct) IntegrationTest(com.google.cloud.spanner.IntegrationTest) Test(org.junit.Test)

Example 19 with Timestamp

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

the class TimestampBoundTest method equalsAndHashCode.

@Test
public void equalsAndHashCode() {
    Timestamp ts = Timestamp.ofTimeSecondsAndNanos(1444662894L, 0);
    Timestamp ts2 = Timestamp.ofTimeSecondsAndNanos(1444662895L, 0);
    int staleness = 5;
    EqualsTester tester = new EqualsTester();
    tester.addEqualityGroup(TimestampBound.strong(), TimestampBound.strong());
    tester.addEqualityGroup(TimestampBound.ofReadTimestamp(ts), TimestampBound.ofReadTimestamp(ts));
    tester.addEqualityGroup(TimestampBound.ofReadTimestamp(ts2));
    tester.addEqualityGroup(TimestampBound.ofMinReadTimestamp(ts), TimestampBound.ofMinReadTimestamp(ts));
    tester.addEqualityGroup(TimestampBound.ofMinReadTimestamp(ts2));
    tester.addEqualityGroup(TimestampBound.ofExactStaleness(staleness, TimeUnit.SECONDS), TimestampBound.ofExactStaleness(staleness, TimeUnit.SECONDS));
    tester.addEqualityGroup(TimestampBound.ofExactStaleness(staleness, TimeUnit.MILLISECONDS));
    tester.addEqualityGroup(TimestampBound.ofMaxStaleness(staleness, TimeUnit.SECONDS), TimestampBound.ofMaxStaleness(staleness, TimeUnit.SECONDS));
    tester.addEqualityGroup(TimestampBound.ofMaxStaleness(staleness, TimeUnit.MILLISECONDS));
    tester.testEquals();
}
Also used : EqualsTester(com.google.common.testing.EqualsTester) Timestamp(com.google.cloud.Timestamp) Test(org.junit.Test)

Example 20 with Timestamp

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

the class ValueTest method timestamp.

@Test
public void timestamp() {
    String timestamp = "2016-09-15T00:00:00Z";
    Timestamp t = Timestamp.parseTimestamp(timestamp);
    Value v = Value.timestamp(t);
    assertThat(v.getType()).isEqualTo(Type.timestamp());
    assertThat(v.isNull()).isFalse();
    assertThat(v.getTimestamp()).isSameAs(t);
    assertThat(v.toString()).isEqualTo(timestamp);
}
Also used : Timestamp(com.google.cloud.Timestamp) 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