Skip to content

Commit

Permalink
hotfix: avoid test cases that may fall into infinite loops. (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanoOo committed May 24, 2024
1 parent f0ab8e0 commit ed0ad12
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

import org.apache.commons.collections.CollectionUtils;
import org.junit.After;
import org.junit.Assert;
import org.junit.Test;

import java.math.BigDecimal;
Expand Down Expand Up @@ -359,7 +360,7 @@ public void testGis() throws Exception {
env.fromElements((RowData) rowData).sinkTo(sink);
env.execute();

waitForTableCount(tableName, 1);
waitingAndAssertTableCount(tableName, 1);
List<String> actual =
queryTable(
tableName,
Expand Down Expand Up @@ -469,19 +470,23 @@ private void validateSinkResults() throws SQLException, InterruptedException {
"108,jacket,water resistent black wind breaker,0.1000000000",
"109,spare tire,24 inch spare tire,22.2000000000");

waitForTableCount(getTestTable(), expected.size());
waitingAndAssertTableCount(getTestTable(), expected.size());

List<String> actual = queryTable(getTestTable());

assertEqualsInAnyOrder(expected, actual);
}

private void waitForTableCount(String tableName, int expectedCount)
private void waitingAndAssertTableCount(String tableName, int expectedCount)
throws InterruptedException {
while (OceanBaseJdbcUtils.getTableRowsCount(this::getConnection, tableName)
< expectedCount) {
Thread.sleep(100);
int tableRowsCount = 0;
for (int i = 0; i < 100; ++i) {
tableRowsCount = OceanBaseJdbcUtils.getTableRowsCount(this::getConnection, tableName);
if (tableRowsCount < expectedCount) {
Thread.sleep(100);
}
}
Assert.assertEquals(tableRowsCount, expectedCount);
}

public List<String> queryTable(String tableName) throws SQLException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

import org.apache.commons.collections.CollectionUtils;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
Expand Down Expand Up @@ -292,19 +293,23 @@ private void validateSinkResults() throws SQLException, InterruptedException {
"108,jacket,water resistent black wind breaker,0.1",
"109,spare tire,24 inch spare tire,22.2");

waitForTableCount(getTestTable(), expected.size());
waitingAndAssertTableCount(getTestTable(), expected.size());

List<String> actual = queryTable(getTestTable());

assertEqualsInAnyOrder(expected, actual);
}

private void waitForTableCount(String tableName, int expectedCount)
private void waitingAndAssertTableCount(String tableName, int expectedCount)
throws InterruptedException {
while (OceanBaseJdbcUtils.getTableRowsCount(this::getConnection, tableName)
< expectedCount) {
Thread.sleep(100);
int tableRowsCount = 0;
for (int i = 0; i < 100; ++i) {
tableRowsCount = OceanBaseJdbcUtils.getTableRowsCount(this::getConnection, tableName);
if (tableRowsCount < expectedCount) {
Thread.sleep(100);
}
}
Assert.assertEquals(tableRowsCount, expectedCount);
}

public List<String> queryTable(String tableName) throws SQLException {
Expand Down

0 comments on commit ed0ad12

Please sign in to comment.