-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DBZ-8594 Add validations that all transactional messages are only com…
…mit or begin
- Loading branch information
Showing
4 changed files
with
52 additions
and
3 deletions.
There are no files selected for viewing
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
46 changes: 46 additions & 0 deletions
46
src/test/java/io/debezium/connector/vitess/connection/TransactionalMessageTest.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,46 @@ | ||
/* | ||
* 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.vitess.connection; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
import java.time.Instant; | ||
|
||
import org.junit.Test; | ||
|
||
import io.debezium.connector.vitess.TestHelper; | ||
|
||
/** | ||
* @author Thomas Thornton | ||
*/ | ||
public class TransactionalMessageTest { | ||
|
||
@Test | ||
public void shouldInstantiateBeginMessage() { | ||
ReplicationMessage message = new TransactionalMessage( | ||
ReplicationMessage.Operation.BEGIN, "tx_id", Instant.now(), TestHelper.TEST_UNSHARDED_KEYSPACE, TestHelper.TEST_SHARD); | ||
assertThat(message.isTransactionalMessage()).isTrue(); | ||
assertThat(message.getOperation()).isEqualTo(ReplicationMessage.Operation.BEGIN); | ||
} | ||
|
||
@Test | ||
public void shouldInstantiateCommitMessage() { | ||
ReplicationMessage message = new TransactionalMessage( | ||
ReplicationMessage.Operation.COMMIT, "tx_id", Instant.now(), TestHelper.TEST_UNSHARDED_KEYSPACE, TestHelper.TEST_SHARD); | ||
assertThat(message.isTransactionalMessage()).isTrue(); | ||
assertThat(message.getOperation()).isEqualTo(ReplicationMessage.Operation.COMMIT); | ||
} | ||
|
||
@Test | ||
public void shouldThrowExceptionForNonTransactionalOperation() { | ||
assertThatThrownBy(() -> { | ||
new TransactionalMessage( | ||
ReplicationMessage.Operation.INSERT, "tx_id", Instant.now(), TestHelper.TEST_UNSHARDED_KEYSPACE, TestHelper.TEST_SHARD); | ||
}).isInstanceOf(IllegalArgumentException.class).hasMessageContaining("TransactionalMessage can only have BEGIN or COMMIT operations"); | ||
} | ||
} |