Skip to content

Commit

Permalink
net-sf-ucanaccess-fork: Review flaky unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
spannm committed Nov 17, 2023
1 parent 37a684f commit b1dba1f
Showing 1 changed file with 28 additions and 23 deletions.
51 changes: 28 additions & 23 deletions src/test/java/net/ucanaccess/jdbc/CounterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,52 +10,57 @@
import java.sql.Statement;

class CounterTest extends UcanaccessBaseTest {
private String tableName = "t_bbb";

@Override
protected void init(AccessVersion _accessVersion) throws SQLException {
super.init(_accessVersion);
executeStatements("CREATE TABLE " + tableName + " (z COUNTER PRIMARY KEY, B CHAR(4), c BLOB, d TEXT)");
executeStatements("CREATE TABLE t_counter (cntr COUNTER PRIMARY KEY, chr CHAR(4), blb BLOB, txt TEXT)");
}

@AfterEach
void afterEachTest() throws SQLException {
executeStatements("DROP TABLE " + tableName);
executeStatements("DROP TABLE t_counter");
}

@ParameterizedTest(name = "[{index}] {0}")
@EnumSource(value = AccessVersion.class)
void testCreateTypes(AccessVersion _accessVersion) throws SQLException {
init(_accessVersion);

try (Statement st = ucanaccess.createStatement()) {
executeStatements(st,
"DISABLE AUTOINCREMENT ON " + tableName,
"DISABLE AUTOINCREMENT ON t_counter",
// insert arbitrary AutoNumber value
"INSERT INTO " + tableName + " (z, b, c, d) VALUES (3, 'C', NULL, NULL)",
"INSERT INTO t_counter (cntr, chr, blb, txt) VALUES (3, 'C', NULL, NULL)",

"ENABLE AUTOINCREMENT ON " + tableName,
"ENABLE AUTOINCREMENT ON t_counter",

// 4 (verify AutoNumber seed updated)
"INSERT INTO " + tableName + " (b, c, d) VALUES ('D', NULL, NULL)",
// expecting cntr=4 (verify AutoNumber seed updated)
"INSERT INTO t_counter (chr, blb, txt) VALUES ('D', NULL, NULL)",

"INSERT INTO " + tableName + " (b, c, d) VALUES ('E', NULL, NULL)", // 5
"INSERT INTO " + tableName + " (b, c, d) VALUES ('F', NULL, NULL)", // 6
"INSERT INTO t_counter (chr, blb, txt) VALUES ('E', NULL, NULL)", // cntr=5
"INSERT INTO t_counter (chr, blb, txt) VALUES ('F', NULL, NULL)", // cntr=6

"DISABLE AUTOINCREMENT ON " + tableName,
"INSERT INTO " + tableName + " (z, b, c, d) VALUES (8, 'H', NULL, NULL)", // arbitrary, new seed = 9
"INSERT INTO " + tableName + " (z, b, c, d) VALUES (7, 'G', NULL, NULL)", // arbitrary smaller than
// current seed
"INSERT INTO " + tableName + " (z, b, c, d) VALUES (-1, 'A', NULL, NULL)", // arbitrary negative value
"ENABLE AUTOINCREMENT ON " + tableName,
"INSERT INTO " + tableName + " (b, c, d) VALUES ('I', NULL, NULL)"); // 9
"DISABLE AUTOINCREMENT ON t_counter",
"INSERT INTO t_counter (cntr, chr, blb, txt) VALUES (8, 'H', NULL, NULL)", // arbitrary, new seed = 9
"INSERT INTO t_counter (cntr, chr, blb, txt) VALUES (7, 'G', NULL, NULL)", // arbitrary smaller than current seed
"INSERT INTO t_counter (cntr, chr, blb, txt) VALUES (-1, 'A', NULL, NULL)", // arbitrary negative value
"ENABLE AUTOINCREMENT ON t_counter",
"INSERT INTO t_counter (chr, blb, txt) VALUES ('I', NULL, NULL)"); // cntr=9
}

dumpQueryResult("SELECT * FROM " + tableName);
Object[][] ver =
{{-1, "A", null, null}, {3, "C", null, null}, {4, "D", null, null},
{5, "E", null, null}, {6, "F", null, null}, {7, "G", null, null},
{8, "H", null, null}, {9, "I", null, null}};
checkQuery("SELECT * FROM " + tableName + " ORDER BY z", ver);
dumpQueryResult("SELECT * FROM t_counter");
Object[][] ver = {
{-1, "A", null, null},
{3, "C", null, null},
{4, "D", null, null},
{5, "E", null, null},
{6, "F", null, null},
{7, "G", null, null},
{8, "H", null, null},
{9, "I", null, null}
};
checkQuery("SELECT * FROM t_counter ORDER BY cntr", ver);

}

Expand Down

0 comments on commit b1dba1f

Please sign in to comment.