From b1dba1f2fa0e764e18a018caf2ba389f79d126c7 Mon Sep 17 00:00:00 2001 From: Markus Spann Date: Fri, 17 Nov 2023 14:02:38 +0100 Subject: [PATCH] net-sf-ucanaccess-fork: Review flaky unit test --- .../java/net/ucanaccess/jdbc/CounterTest.java | 51 ++++++++++--------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/src/test/java/net/ucanaccess/jdbc/CounterTest.java b/src/test/java/net/ucanaccess/jdbc/CounterTest.java index 7289c1f8..eaecff5c 100644 --- a/src/test/java/net/ucanaccess/jdbc/CounterTest.java +++ b/src/test/java/net/ucanaccess/jdbc/CounterTest.java @@ -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); }