-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix flaky tests and test infra failures due to stuck tests (#232)
- Loading branch information
1 parent
7da4c4b
commit aa50e01
Showing
8 changed files
with
138 additions
and
218 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
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
93 changes: 93 additions & 0 deletions
93
src/test/java/io/debezium/connector/yugabytedb/YugabyteDBEnumValuesTest.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,93 @@ | ||
package io.debezium.connector.yugabytedb; | ||
|
||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import java.sql.SQLException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
import org.apache.kafka.connect.source.SourceRecord; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import io.debezium.config.Configuration; | ||
import io.debezium.connector.yugabytedb.common.YugabyteDBContainerTestBase; | ||
|
||
/** | ||
* Unit tests to verify the streaming of ENUM values. | ||
* | ||
* @author Vaibhav Kushwaha (vkushwaha@yugabyte.com) | ||
*/ | ||
public class YugabyteDBEnumValuesTest extends YugabyteDBContainerTestBase { | ||
|
||
@BeforeAll | ||
public static void beforeClass() throws SQLException { | ||
initializeYBContainer(); | ||
TestHelper.dropAllSchemas(); | ||
} | ||
|
||
@BeforeEach | ||
public void before() throws Exception { | ||
initializeConnectorTestFramework(); | ||
TestHelper.dropAllSchemas(); | ||
TestHelper.executeDDL("yugabyte_create_tables.ddl"); | ||
} | ||
|
||
@AfterEach | ||
public void after() throws Exception { | ||
stopConnector(); | ||
TestHelper.executeDDL("drop_tables_and_databases.ddl"); | ||
} | ||
|
||
@AfterAll | ||
public static void afterClass() { | ||
shutdownYBContainer(); | ||
} | ||
|
||
@Test | ||
public void testEnumValue() throws Exception { | ||
String dbStreamId = TestHelper.getNewDbStreamId("yugabyte", "test_enum"); | ||
Configuration.Builder configBuilder = TestHelper.getConfigBuilder("public.test_enum", dbStreamId); | ||
startEngine(configBuilder); | ||
|
||
// 3 because there are 3 enum values in the enum type | ||
final long recordsCount = 3; | ||
|
||
awaitUntilConnectorIsReady(); | ||
|
||
// 3 records will be inserted in the table test_enum | ||
insertEnumRecords(); | ||
|
||
verifyEnumValue(recordsCount); | ||
} | ||
|
||
// This function will one row each of the specified enum labels | ||
private void insertEnumRecords() throws Exception { | ||
String[] enumLabels = {"ZERO", "ONE", "TWO"}; | ||
String formatInsertString = "INSERT INTO test_enum VALUES (%d, '%s');"; | ||
for (int i = 0; i < enumLabels.length; i++) { | ||
TestHelper.execute(String.format(formatInsertString, i, enumLabels[i])); | ||
} | ||
} | ||
|
||
private void verifyEnumValue(long recordsCount) { | ||
List<SourceRecord> records = new ArrayList<>(); | ||
waitAndFailIfCannotConsume(records, recordsCount, 2 * 60 * 1000 /* 2 minutes */); | ||
|
||
String[] enum_val = {"ZERO", "ONE", "TWO"}; | ||
|
||
try { | ||
for (int i = 0; i < records.size(); ++i) { | ||
assertValueField(records.get(i), "after/id/value", i); | ||
assertValueField(records.get(i), "after/enum_col/value", enum_val[i]); | ||
} | ||
} catch (Exception e) { | ||
LOGGER.error("Exception caught while parsing records: " + e); | ||
fail(); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.