Skip to content
This repository was archived by the owner on Dec 28, 2025. It is now read-only.
Merged
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 @@ -29,7 +29,7 @@ public class LsnOffset extends Offset {

private static final long serialVersionUID = 1L;

public static final LsnOffset INITIAL_OFFSET = valueOf(Lsn.valueOf(new byte[] {0}).toString());
public static final LsnOffset INITIAL_OFFSET = new LsnOffset(null, null, null);
public static final LsnOffset NO_STOPPING_OFFSET =
valueOf(Lsn.valueOf(new byte[] {Byte.MAX_VALUE}).toString());

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.seatunnel.connectors.seatunnel.cdc.sqlserver.source.offset;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import io.debezium.connector.sqlserver.Lsn;

class LsnOffsetTest {

@Test
void testInitialOffsetRepresentsNoLsn() {
LsnOffset initial = LsnOffset.INITIAL_OFFSET;

// no LSN keys should be present in the offset map
Assertions.assertTrue(initial.getOffset().isEmpty());

// commit LSN resolved from the empty map should be Debezium's NULL LSN
Lsn commitLsn = initial.getCommitLsn();
Assertions.assertFalse(commitLsn.isAvailable());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,47 @@ public void testCDCWithCustomPrimaryKey(TestContainer container) {
});
}

@TestTemplate
@DisabledOnContainer(
value = {},
type = {EngineType.SPARK, EngineType.FLINK},
disabledReason =
"This case checks SqlServer CDC earliest startup mode only on Zeta engine.")
public void testEarliestStartupMode(TestContainer container) throws InterruptedException {
initializeSqlServerTable("column_type_test");

Long jobId = JobIdGenerator.newJobId();
CompletableFuture.runAsync(
() -> {
try {
container.executeJob(
"/sqlservercdc_earliest_to_sqlserver.conf", String.valueOf(jobId));
} catch (Exception e) {
log.error("Execute earliest job exception: {}", e.getMessage());
throw new RuntimeException(e);
}
});

// give the job some time to start
TimeUnit.SECONDS.sleep(10);

// verify job stays running (i.e. no fatal exception like ArrayIndexOutOfBounds from
// Debezium)
await().atMost(2, TimeUnit.MINUTES)
.untilAsserted(
() -> {
String jobStatus = container.getJobStatus(String.valueOf(jobId));
Assertions.assertEquals("RUNNING", jobStatus);
});

try {
Container.ExecResult cancelJobResult = container.cancelJob(String.valueOf(jobId));
Assertions.assertEquals(0, cancelJobResult.getExitCode(), cancelJobResult.getStderr());
} catch (IOException | InterruptedException e) {
throw new RuntimeException(e);
}
}

@TestTemplate
@DisabledOnContainer(
value = {},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
######
###### This config file is a demonstration of streaming processing in seatunnel config
######

env {
# You can set engine configuration here
parallelism = 1
job.mode = "STREAMING"
checkpoint.interval = 5000
}

source {
# This is an example source plugin **only for test and demonstrate the feature source plugin**
SqlServer-CDC {
plugin_output = "customers"
username = "sa"
password = "Password!"
database-names = ["column_type_test"]
table-names = ["column_type_test.dbo.full_types"]
url = "jdbc:sqlserver://sqlserver-host:1433;databaseName=column_type_test"
# start from the earliest available CDC LSN
startup.mode = "earliest"
}
}

transform {
}

sink {
Jdbc {
plugin_input = "customers"
driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver"
url = "jdbc:sqlserver://sqlserver-host:1433;encrypt=false"
user = "sa"
password = "Password!"
generate_sink_sql = true
database = "column_type_test"
table = "dbo.full_types_sink"
batch_size = 1
primary_keys = ["id"]
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ public void notifyCheckpointComplete(long checkpointId) throws Exception {
}
aggregatedCommitInfo.addAll(value);
checkpointCommitInfoMap.remove(key);
commitInfoCache.remove(key);
checkpointBarrierCounter.remove(key);
});
List<AggregatedCommitInfoT> commit = aggregatedCommitter.commit(aggregatedCommitInfo);
tryClose(checkpointId);
Expand All @@ -323,6 +325,8 @@ public void notifyCheckpointComplete(long checkpointId) throws Exception {
public void notifyCheckpointAborted(long checkpointId) throws Exception {
aggregatedCommitter.abort(checkpointCommitInfoMap.get(checkpointId));
checkpointCommitInfoMap.remove(checkpointId);
commitInfoCache.remove(checkpointId);
checkpointBarrierCounter.remove(checkpointId);
tryClose(checkpointId);
}
}
Loading
Loading