Search in sources :

Example 21 with Timestamp

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

the class KeyTest method equalsAndHashCode.

@Test
public void equalsAndHashCode() {
    EqualsTester tester = new EqualsTester();
    tester.addEqualityGroup(Key.of(), Key.newBuilder().build());
    // All types of null are considered equal.
    tester.addEqualityGroup(Key.of((Object) null), Key.newBuilder().append((Boolean) null).build(), Key.newBuilder().append((Long) null).build(), Key.newBuilder().append((Double) null).build(), Key.newBuilder().append((String) null).build(), Key.newBuilder().append((ByteArray) null).build(), Key.newBuilder().append((Timestamp) null).build(), Key.newBuilder().append((Date) null).build(), Key.newBuilder().appendObject(null).build());
    tester.addEqualityGroup(Key.of(true), Key.newBuilder().append(true).build());
    tester.addEqualityGroup(Key.of(false), Key.newBuilder().append(false).build());
    tester.addEqualityGroup(Key.of(1), Key.of(1L), Key.newBuilder().append(1).build());
    tester.addEqualityGroup(Key.of(2), Key.of(2L), Key.newBuilder().append(2).build());
    tester.addEqualityGroup(Key.of(1, 2));
    tester.addEqualityGroup(Key.of(1.0f), Key.of(1.0d), Key.newBuilder().append(1.0).build());
    tester.addEqualityGroup(Key.of(2.0f), Key.of(2.0d), Key.newBuilder().append(2.0).build());
    tester.addEqualityGroup(Key.of("a"), Key.newBuilder().append("a").build());
    tester.addEqualityGroup(Key.of("a", "b", "c"));
    tester.addEqualityGroup(Key.of(ByteArray.copyFrom("a")), Key.newBuilder().append(ByteArray.copyFrom("a")).build());
    Timestamp t = Timestamp.parseTimestamp("2015-09-15T00:00:00Z");
    tester.addEqualityGroup(Key.of(t), Key.newBuilder().append(t).build());
    Date d = Date.parseDate("2016-09-15");
    tester.addEqualityGroup(Key.of(d), Key.newBuilder().append(d).build());
    tester.addEqualityGroup(Key.of("a", 2, null));
    tester.testEquals();
}
Also used : EqualsTester(com.google.common.testing.EqualsTester) Timestamp(com.google.cloud.Timestamp) Date(com.google.cloud.Date) Test(org.junit.Test)

Example 22 with Timestamp

use of com.google.cloud.Timestamp in project beam by apache.

the class MutationSizeEstimatorTest method dates.

@Test
public void dates() throws Exception {
    Mutation timestamp = Mutation.newInsertOrUpdateBuilder("test").set("one").to(Timestamp.now()).build();
    Mutation nullTimestamp = Mutation.newInsertOrUpdateBuilder("test").set("one").to((Timestamp) null).build();
    Mutation date = Mutation.newInsertOrUpdateBuilder("test").set("one").to(Date.fromYearMonthDay(2017, 10, 10)).build();
    Mutation nullDate = Mutation.newInsertOrUpdateBuilder("test").set("one").to((Date) null).build();
    Mutation timestampArray = Mutation.newInsertOrUpdateBuilder("test").set("one").toTimestampArray(Arrays.asList(Timestamp.now(), null)).build();
    Mutation dateArray = Mutation.newInsertOrUpdateBuilder("test").set("one").toDateArray(Arrays.asList(null, Date.fromYearMonthDay(2017, 1, 1), null, Date.fromYearMonthDay(2017, 1, 2))).build();
    assertThat(MutationSizeEstimator.sizeOf(timestamp), is(12L));
    assertThat(MutationSizeEstimator.sizeOf(date), is(12L));
    assertThat(MutationSizeEstimator.sizeOf(nullTimestamp), is(12L));
    assertThat(MutationSizeEstimator.sizeOf(nullDate), is(12L));
    assertThat(MutationSizeEstimator.sizeOf(timestampArray), is(24L));
    assertThat(MutationSizeEstimator.sizeOf(dateArray), is(48L));
}
Also used : Mutation(com.google.cloud.spanner.Mutation) Timestamp(com.google.cloud.Timestamp) Date(com.google.cloud.Date) 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