-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DBZ-7305 Add tests for Always, When Needed and Custom snapshot mode f…
…or DB2 connector
- Loading branch information
Showing
6 changed files
with
285 additions
and
1 deletion.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
src/test/java/io/debezium/connector/db2/CustomTestSnapshot.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright Debezium Authors. | ||
* | ||
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package io.debezium.connector.db2; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
import io.debezium.bean.StandardBeanNames; | ||
import io.debezium.bean.spi.BeanRegistry; | ||
import io.debezium.bean.spi.BeanRegistryAware; | ||
import io.debezium.connector.db2.snapshot.query.SelectAllSnapshotQuery; | ||
import io.debezium.pipeline.spi.Offsets; | ||
import io.debezium.spi.snapshot.Snapshotter; | ||
|
||
/** | ||
* This is a small class used in PostgresConnectorIT to test a custom snapshot | ||
* | ||
* It is tightly coupled to the test there, but needs to be placed here in order | ||
* to allow for class loading to work | ||
*/ | ||
public class CustomTestSnapshot extends SelectAllSnapshotQuery implements Snapshotter, BeanRegistryAware { | ||
|
||
private boolean hasState; | ||
|
||
@Override | ||
public String name() { | ||
return CustomTestSnapshot.class.getName(); | ||
} | ||
|
||
@Override | ||
public void injectBeanRegistry(BeanRegistry beanRegistry) { | ||
|
||
Offsets<Db2Partition, Db2OffsetContext> db2OffsetContextOffsets = beanRegistry.lookupByName(StandardBeanNames.OFFSETS, Offsets.class); | ||
for (Db2OffsetContext offset : db2OffsetContextOffsets.getOffsets().values()) { | ||
hasState = offset != null; | ||
} | ||
} | ||
|
||
@Override | ||
public boolean shouldSnapshotData(boolean offsetExists, boolean snapshotInProgress) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean shouldStream() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean shouldSnapshotSchema(boolean offsetExists, boolean snapshotInProgress) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean shouldSnapshotOnSchemaError() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean shouldSnapshotOnDataError() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public Optional<String> snapshotQuery(String tableId, List<String> snapshotSelectColumns) { | ||
|
||
if (!hasState && tableId.contains("TABLEB")) { | ||
return Optional.empty(); | ||
} | ||
else { | ||
String query = snapshotSelectColumns.stream() | ||
.collect(Collectors.joining(", ", "SELECT ", " FROM " + tableId)); | ||
|
||
return Optional.of(query); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/test/resources/META-INF/services/io.debezium.snapshot.spi.SnapshotQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
io.debezium.connector.db2.CustomTestSnapshot |
1 change: 1 addition & 0 deletions
1
src/test/resources/META-INF/services/io.debezium.spi.snapshot.Snapshotter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
io.debezium.connector.db2.CustomTestSnapshot |