Search in sources :

Example 1 with CommitTimestamps

use of org.springframework.cloud.gcp.data.spanner.test.domain.CommitTimestamps in project spring-cloud-gcp by spring-cloud.

the class CommitTimestampIntegrationTests method testCommitTimestamp.

@Test
public void testCommitTimestamp() {
    final CommitTimestamps entity = new CommitTimestamps();
    final String id = UUID.randomUUID().toString();
    entity.id = id;
    doWithFields(CommitTimestamps.class, f -> setField(f, entity, CommitTimestamp.of(f.getType())), ff -> !ff.isSynthetic() && Objects.isNull(ff.getAnnotation(PrimaryKey.class)));
    final Timestamp committedAt = databaseClient.write(mutationFactory.insert(entity));
    final CommitTimestamps fetched = spannerOperations.read(CommitTimestamps.class, Key.of(id));
    doWithFields(CommitTimestamps.class, f -> assertThat(getField(f, fetched)).describedAs("Test of the field %s has tailed", f).isEqualTo(getConverter(f).convert(committedAt)), ff -> !ff.isSynthetic() && isNull(ff.getAnnotation(PrimaryKey.class)));
}
Also used : CommitTimestamps(org.springframework.cloud.gcp.data.spanner.test.domain.CommitTimestamps) PrimaryKey(org.springframework.cloud.gcp.data.spanner.core.mapping.PrimaryKey) Timestamp(com.google.cloud.Timestamp) CommitTimestamp(org.springframework.cloud.gcp.data.spanner.core.convert.CommitTimestamp) Test(org.junit.Test) AbstractSpannerIntegrationTest(org.springframework.cloud.gcp.data.spanner.test.AbstractSpannerIntegrationTest)

Example 2 with CommitTimestamps

use of org.springframework.cloud.gcp.data.spanner.test.domain.CommitTimestamps in project spring-cloud-gcp by spring-cloud.

the class ConverterAwareMappingSpannerEntityWriterTests method testCommitTimestampsType.

@Test
public void testCommitTimestampsType() {
    CommitTimestamps entity = new CommitTimestamps();
    doWithFields(CommitTimestamps.class, f -> setField(f, entity, CommitTimestamp.of(f.getType())), ff -> !ff.isSynthetic() && Objects.isNull(ff.getAnnotation(PrimaryKey.class)));
    WriteBuilder writeBuilder = Mutation.newInsertBuilder("commit_timestamps_table");
    this.spannerEntityWriter.write(entity, writeBuilder::set);
    Mutation mutation = writeBuilder.build();
    assertThat(mutation.asMap().entrySet().stream().filter(e -> !"id".equals(e.getKey())).map(Map.Entry::getValue).collect(Collectors.toList())).allMatch(Value::isCommitTimestamp);
}
Also used : CommitTimestamps(org.springframework.cloud.gcp.data.spanner.test.domain.CommitTimestamps) WriteBuilder(com.google.cloud.spanner.Mutation.WriteBuilder) Value(com.google.cloud.spanner.Value) PrimaryKey(org.springframework.cloud.gcp.data.spanner.core.mapping.PrimaryKey) Mutation(com.google.cloud.spanner.Mutation) Map(java.util.Map) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 PrimaryKey (org.springframework.cloud.gcp.data.spanner.core.mapping.PrimaryKey)2 CommitTimestamps (org.springframework.cloud.gcp.data.spanner.test.domain.CommitTimestamps)2 Timestamp (com.google.cloud.Timestamp)1 Mutation (com.google.cloud.spanner.Mutation)1 WriteBuilder (com.google.cloud.spanner.Mutation.WriteBuilder)1 Value (com.google.cloud.spanner.Value)1 Map (java.util.Map)1 CommitTimestamp (org.springframework.cloud.gcp.data.spanner.core.convert.CommitTimestamp)1 AbstractSpannerIntegrationTest (org.springframework.cloud.gcp.data.spanner.test.AbstractSpannerIntegrationTest)1