Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ public class IntegrationTestEnv extends ExternalResource {
private DatabaseAdminClient databaseAdminClient;
private DatabaseClient databaseClient;
private boolean isPostgres;
private boolean isPlacementTableBasedChangeStream;
private boolean isMutableChangeStream;
private boolean isPlacementTable;
public boolean useSeparateMetadataDb;

@Override
Expand Down Expand Up @@ -100,13 +101,18 @@ protected void before() throws Throwable {

IntegrationTestEnv() {
this.isPostgres = false;
this.isPlacementTableBasedChangeStream = false;
this.isMutableChangeStream = false;
this.isPlacementTable = false;
}

IntegrationTestEnv(
boolean isPostgres, boolean isPlacementTableBasedChangeStream, Optional<String> host) {
boolean isPostgres,
boolean isMutableChangeStream,
boolean isPlacementTable,
Optional<String> host) {
this.isPostgres = isPostgres;
this.isPlacementTableBasedChangeStream = isPlacementTableBasedChangeStream;
this.isMutableChangeStream = isMutableChangeStream;
this.isPlacementTable = isPlacementTable;
if (host.isPresent()) {
this.host = host.get();
}
Expand Down Expand Up @@ -209,7 +215,7 @@ String createSingersTable() throws InterruptedException, ExecutionException, Tim
}

String createGSQLTableDDL(String tableName) {
if (this.isPlacementTableBasedChangeStream) {
if (this.isPlacementTable) {
// create a placement table.
return "CREATE TABLE "
+ tableName
Expand Down Expand Up @@ -240,8 +246,7 @@ String createChangeStreamFor(String tableName)
.updateDatabaseDdl(
instanceId,
databaseId,
Collections.singletonList(
"CREATE CHANGE STREAM \"" + changeStreamName + "\" FOR \"" + tableName + "\""),
Collections.singletonList(createPostgresChangeStreamDDL(changeStreamName, tableName)),
null)
.get(TIMEOUT_MINUTES, TimeUnit.MINUTES);
} else {
Expand All @@ -258,7 +263,7 @@ String createChangeStreamFor(String tableName)
}

String createGSQLChangeStreamDDL(String changeStreamName, String tableName) {
if (this.isPlacementTableBasedChangeStream) {
if (this.isMutableChangeStream) {
// Create a MUTABLE_KEY_RANGE change stream.
String statement =
"CREATE CHANGE STREAM "
Expand All @@ -271,6 +276,21 @@ String createGSQLChangeStreamDDL(String changeStreamName, String tableName) {
return "CREATE CHANGE STREAM " + changeStreamName + " FOR " + tableName;
}

String createPostgresChangeStreamDDL(String changeStreamName, String tableName) {
if (this.isMutableChangeStream) {
// Create a MUTABLE_KEY_RANGE change stream.
String statement =
"CREATE CHANGE STREAM \""
+ changeStreamName
+ "\" FOR \""
+ tableName
+ "\""
+ " WITH (partition_mode = 'MUTABLE_KEY_RANGE')";
return statement;
}
return "CREATE CHANGE STREAM \"" + changeStreamName + "\" FOR \"" + tableName + "\"";
}

void createRoleAndGrantPrivileges(String table, String changeStream)
throws InterruptedException, ExecutionException, TimeoutException {
if (this.isPostgres) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public class SpannerChangeStreamPlacementTablePostgresIT {
public static final IntegrationTestEnv ENV =
new IntegrationTestEnv(
/*isPostgres=*/ true,
/*isPlacementTableBasedChangeStream=*/ true,
/*isMutableChangeStream=*/ true,
/*isPlacementTable=*/ true,
/*host=*/ Optional.empty());

@Rule public final transient TestPipeline pipeline = TestPipeline.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public class SpannerChangeStreamPostgresIT {
public static final IntegrationTestEnv ENV =
new IntegrationTestEnv(
/*isPostgres=*/ true,
/*isPlacementTableBasedChangeStream=*/ false,
/*isMutableChangeStream=*/ false,
/*isPlacementTable=*/ false,
/*host=*/ Optional.empty());

@Rule public final transient TestPipeline pipeline = TestPipeline.create();
Expand Down
Loading