use of com.google.cloud.teleport.v2.templates.datastream.ChangeEventContext in project DataflowTemplates by GoogleCloudPlatform.
the class OracleChangeEventContextTest method canGenerateShadowTableMutationForBackfillEvent.
@Test
public void canGenerateShadowTableMutationForBackfillEvent() throws Exception {
// Test Ddl
Ddl ddl = ChangeEventConvertorTest.getTestDdl();
// Test Change Event
JSONObject changeEvent = ChangeEventConvertorTest.getTestChangeEvent("Users2");
changeEvent.put(DatastreamConstants.ORACLE_TIMESTAMP_KEY, eventTimestamp);
changeEvent.put(DatastreamConstants.ORACLE_SCN_KEY, JSONObject.NULL);
changeEvent.put(DatastreamConstants.EVENT_SOURCE_TYPE_KEY, DatastreamConstants.ORACLE_SOURCE_TYPE);
ChangeEventContext changeEventContext = ChangeEventContextFactory.createChangeEventContext(getJsonNode(changeEvent.toString()), ddl, "shadow_", DatastreamConstants.ORACLE_SOURCE_TYPE);
Mutation shadowMutation = changeEventContext.getShadowTableMutation();
Map<String, Value> actual = shadowMutation.asMap();
// Expected result
Map<String, Value> expected = ChangeEventConvertorTest.getExpectedMapForTestChangeEvent();
expected.put(DatastreamConstants.ORACLE_TIMESTAMP_SHADOW_INFO.getLeft(), Value.int64(eventTimestamp));
expected.put(DatastreamConstants.ORACLE_SCN_SHADOW_INFO.getLeft(), Value.int64(-1));
// Verify if OracleChangeEventContext was actually created.
assertThat(changeEventContext, instanceOf(OracleChangeEventContext.class));
// Verify shadow mutation
assertThat(actual, is(expected));
assertEquals(shadowMutation.getTable(), "shadow_Users2");
assertEquals(shadowMutation.getOperation(), Mutation.Op.INSERT_OR_UPDATE);
}
use of com.google.cloud.teleport.v2.templates.datastream.ChangeEventContext in project DataflowTemplates by GoogleCloudPlatform.
the class OracleChangeEventContextTest method canGenerateShadowTableMutationForBackfillEventWithMissingKeys.
@Test
public void canGenerateShadowTableMutationForBackfillEventWithMissingKeys() throws Exception {
// Test Ddl
Ddl ddl = ChangeEventConvertorTest.getTestDdl();
// Test Change Event
JSONObject changeEvent = ChangeEventConvertorTest.getTestChangeEvent("Users2");
changeEvent.put(DatastreamConstants.ORACLE_TIMESTAMP_KEY, eventTimestamp);
changeEvent.put(DatastreamConstants.EVENT_SOURCE_TYPE_KEY, DatastreamConstants.ORACLE_SOURCE_TYPE);
ChangeEventContext changeEventContext = ChangeEventContextFactory.createChangeEventContext(getJsonNode(changeEvent.toString()), ddl, "shadow_", DatastreamConstants.ORACLE_SOURCE_TYPE);
Mutation shadowMutation = changeEventContext.getShadowTableMutation();
Map<String, Value> actual = shadowMutation.asMap();
// Expected result
Map<String, Value> expected = ChangeEventConvertorTest.getExpectedMapForTestChangeEvent();
expected.put(DatastreamConstants.ORACLE_TIMESTAMP_SHADOW_INFO.getLeft(), Value.int64(eventTimestamp));
expected.put(DatastreamConstants.ORACLE_SCN_SHADOW_INFO.getLeft(), Value.int64(-1));
// Verify if OracleChangeEventContext was actually created.
assertThat(changeEventContext, instanceOf(OracleChangeEventContext.class));
// Verify shadow mutation
assertThat(actual, is(expected));
assertEquals(shadowMutation.getTable(), "shadow_Users2");
assertEquals(shadowMutation.getOperation(), Mutation.Op.INSERT_OR_UPDATE);
}
Aggregations