use of com.google.cloud.teleport.v2.templates.spanner.ddl.Ddl in project DataflowTemplates by GoogleCloudPlatform.
the class SpannerStreamingWriteIntegrationTest method readDdl.
private Ddl readDdl(String db) {
DatabaseClient dbClient = spannerServer.getDbClient(db);
Ddl ddl;
try (ReadOnlyTransaction ctx = dbClient.readOnlyTransaction()) {
ddl = new InformationSchemaScanner(ctx).scan();
}
return ddl;
}
use of com.google.cloud.teleport.v2.templates.spanner.ddl.Ddl in project DataflowTemplates by GoogleCloudPlatform.
the class ChangeEventConvertorTest method cannotConvertChangeEventWithInvalidTimestampToPrimaryKey.
@Test(expected = ChangeEventConvertorException.class)
public void cannotConvertChangeEventWithInvalidTimestampToPrimaryKey() throws Exception {
Ddl ddl = getTestDdl();
JSONObject changeEvent = getTestChangeEvent("Users2");
changeEvent.put("timestamp_field", "2020-12-asdf");
JsonNode ce = parseChangeEvent(changeEvent.toString());
Key key = ChangeEventConvertor.changeEventToPrimaryKey(ddl, ce);
// Expect an exception since the event has invalid timestamp
}
use of com.google.cloud.teleport.v2.templates.spanner.ddl.Ddl in project DataflowTemplates by GoogleCloudPlatform.
the class ChangeEventConvertorTest method cannotConvertChangeEventWithInvalidFloat64ToShadowMutation.
@Test(expected = ChangeEventConvertorException.class)
public void cannotConvertChangeEventWithInvalidFloat64ToShadowMutation() throws Exception {
Ddl ddl = getTestDdl();
JSONObject changeEvent = getTestChangeEvent("Users2");
changeEvent.put("float64_field", "asdfas");
JsonNode ce = parseChangeEvent(changeEvent.toString());
Mutation mutation = ChangeEventConvertor.changeEventToShadowTableMutationBuilder(ddl, ce, "shadow_").build();
// Expect an Exception to be thrown with Invalid Float64
}
use of com.google.cloud.teleport.v2.templates.spanner.ddl.Ddl in project DataflowTemplates by GoogleCloudPlatform.
the class ChangeEventConvertorTest method canConvertValidDeleteChangeEventToMutation.
@Test
public void canConvertValidDeleteChangeEventToMutation() throws Exception {
Ddl ddl = getTestDdl();
JSONObject changeEvent = getTestChangeEvent("Users2");
changeEvent.put(DatastreamConstants.EVENT_CHANGE_TYPE_KEY, "DELETE");
JsonNode ce = parseChangeEvent(changeEvent.toString());
Mutation mutation = ChangeEventConvertor.changeEventToMutation(ddl, ce);
Map<String, Value> expected = getExpectedMapForTestChangeEvent();
assertEquals(mutation.getTable(), "Users2");
assertEquals(mutation.getOperation(), Mutation.Op.DELETE);
}
use of com.google.cloud.teleport.v2.templates.spanner.ddl.Ddl in project DataflowTemplates by GoogleCloudPlatform.
the class ChangeEventConvertorTest method cannotConvertChangeEventWithInvalidInt64ToPrimaryKey.
@Test(expected = ChangeEventConvertorException.class)
public void cannotConvertChangeEventWithInvalidInt64ToPrimaryKey() throws Exception {
Ddl ddl = getTestDdl();
JSONObject changeEvent = getTestChangeEvent("Users2");
changeEvent.put("int64_field", "asdfas");
JsonNode ce = parseChangeEvent(changeEvent.toString());
Key key = ChangeEventConvertor.changeEventToPrimaryKey(ddl, ce);
// Expect an exception since the event has invalid timestamp
}
Aggregations