Unverified 提交 43e768fc authored 作者: Noel Grandin's avatar Noel Grandin 提交者: GitHub

Merge pull request #804 from katzyn/misc

Use new ArrayList(Collection) and assertThrows()
...@@ -43,8 +43,7 @@ public class QueryStatisticsData { ...@@ -43,8 +43,7 @@ public class QueryStatisticsData {
public synchronized List<QueryEntry> getQueries() { public synchronized List<QueryEntry> getQueries() {
// return a copy of the map so we don't have to // return a copy of the map so we don't have to
// worry about external synchronization // worry about external synchronization
ArrayList<QueryEntry> list = new ArrayList<>(); ArrayList<QueryEntry> list = new ArrayList<>(map.values());
list.addAll(map.values());
// only return the newest 100 entries // only return the newest 100 entries
Collections.sort(list, QUERY_ENTRY_COMPARATOR); Collections.sort(list, QUERY_ENTRY_COMPARATOR);
return list.subList(0, Math.min(list.size(), maxQueryEntries)); return list.subList(0, Math.min(list.size(), maxQueryEntries));
...@@ -71,8 +70,7 @@ public class QueryStatisticsData { ...@@ -71,8 +70,7 @@ public class QueryStatisticsData {
// Test against 1.5 x max-size so we don't do this too often // Test against 1.5 x max-size so we don't do this too often
if (map.size() > maxQueryEntries * 1.5f) { if (map.size() > maxQueryEntries * 1.5f) {
// Sort the entries by age // Sort the entries by age
ArrayList<QueryEntry> list = new ArrayList<>(); ArrayList<QueryEntry> list = new ArrayList<>(map.values());
list.addAll(map.values());
Collections.sort(list, QUERY_ENTRY_COMPARATOR); Collections.sort(list, QUERY_ENTRY_COMPARATOR);
// Create a set of the oldest 1/3 of the entries // Create a set of the oldest 1/3 of the entries
HashSet<QueryEntry> oldestSet = HashSet<QueryEntry> oldestSet =
......
...@@ -158,12 +158,7 @@ public class TestCases extends TestBase { ...@@ -158,12 +158,7 @@ public class TestCases extends TestBase {
private void testClearSyntaxException() throws SQLException { private void testClearSyntaxException() throws SQLException {
Connection conn = getConnection("cases"); Connection conn = getConnection("cases");
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
try { assertThrows(42000, stat).execute("select t.x, t.x t.y from dual t");
stat.execute("select t.x, t.x t.y from dual t");
fail();
} catch (SQLException e) {
assertEquals("42000", e.getSQLState());
}
conn.close(); conn.close();
} }
...@@ -240,24 +235,8 @@ public class TestCases extends TestBase { ...@@ -240,24 +235,8 @@ public class TestCases extends TestBase {
Connection conn = getConnection("selfreferential"); Connection conn = getConnection("selfreferential");
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("create table sr(id integer, usecount integer as usecount + 1)"); stat.execute("create table sr(id integer, usecount integer as usecount + 1)");
check: { assertThrows(ErrorCode.NULL_NOT_ALLOWED, stat).execute("insert into sr(id) values (1)");
try { assertThrows(ErrorCode.MUST_GROUP_BY_COLUMN_1, stat).execute("select max(id), usecount from sr");
stat.execute("insert into sr(id) values (1)");
} catch (SQLException ex) {
assertEquals(ErrorCode.getState(ErrorCode.NULL_NOT_ALLOWED), ex.getSQLState());
break check;
}
fail("Exception expected");
}
check: {
try {
stat.execute("select max(id), usecount from sr");
} catch (SQLException ex) {
assertEquals(ErrorCode.getState(ErrorCode.MUST_GROUP_BY_COLUMN_1), ex.getSQLState());
break check;
}
fail("Exception expected");
}
conn.close(); conn.close();
} }
......
...@@ -1211,28 +1211,13 @@ public class TestFunctions extends TestBase implements AggregateFunction { ...@@ -1211,28 +1211,13 @@ public class TestFunctions extends TestBase implements AggregateFunction {
java.util.Date nowDate = c.getTime(); java.util.Date nowDate = c.getTime();
assertEquals(nowDate, rs.getTimestamp(2)); assertEquals(nowDate, rs.getTimestamp(2));
try { assertThrows(SQLException.class, stat).executeQuery("SELECT TRUNCATE('bad', 1) FROM dual");
rs = stat.executeQuery("SELECT TRUNCATE('bad', 1) FROM dual");
fail("expected exception");
} catch (SQLException ex) {
// expected
}
// check for passing wrong data type // check for passing wrong data type
try { rs = assertThrows(SQLException.class, stat).executeQuery("SELECT TRUNCATE('bad') FROM dual");
rs = stat.executeQuery("SELECT TRUNCATE('bad') FROM dual");
fail("expected exception");
} catch (SQLException ex) {
// expected
}
// check for too many parameters // check for too many parameters
try { rs = assertThrows(SQLException.class, stat).executeQuery("SELECT TRUNCATE(1,2,3) FROM dual");
rs = stat.executeQuery("SELECT TRUNCATE(1,2,3) FROM dual");
fail("expected exception");
} catch (SQLException ex) {
// expected
}
conn.close(); conn.close();
} }
......
...@@ -128,14 +128,8 @@ public class TestIndexHints extends TestBase { ...@@ -128,14 +128,8 @@ public class TestIndexHints extends TestBase {
private void testWithInvalidIndexName() throws SQLException { private void testWithInvalidIndexName() throws SQLException {
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
try { assertThrows(ErrorCode.INDEX_NOT_FOUND_1, stat).executeQuery("explain analyze select * " +
stat.executeQuery("explain analyze select * " + "from test use index(idx_doesnt_exist) where x=1 and y=1");
"from test use index(idx_doesnt_exist) where x=1 and y=1");
fail("Expected exception: "
+ "Index \"IDX_DOESNT_EXIST\" not found");
} catch (SQLException e) {
assertEquals(ErrorCode.INDEX_NOT_FOUND_1, e.getErrorCode());
}
} }
} }
...@@ -192,12 +192,7 @@ public class TestLob extends TestBase { ...@@ -192,12 +192,7 @@ public class TestLob extends TestBase {
Thread.sleep(100); Thread.sleep(100);
// start a new transaction, to be sure // start a new transaction, to be sure
stat.execute("delete from test"); stat.execute("delete from test");
try { assertThrows(SQLException.class, c1).getSubString(1, 3);
c1.getSubString(1, 3);
fail();
} catch (SQLException e) {
// expected
}
conn.close(); conn.close();
} }
...@@ -641,12 +636,7 @@ public class TestLob extends TestBase { ...@@ -641,12 +636,7 @@ public class TestLob extends TestBase {
Statement stat; Statement stat;
conn = getConnection("lob"); conn = getConnection("lob");
stat = conn.createStatement(); stat = conn.createStatement();
try { assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, stat).execute("create memory table test(x clob unique)");
stat.execute("create memory table test(x clob unique)");
fail();
} catch (SQLException e) {
assertEquals(ErrorCode.FEATURE_NOT_SUPPORTED_1, e.getErrorCode());
}
conn.close(); conn.close();
} }
......
...@@ -148,12 +148,7 @@ public class TestOutOfMemory extends TestBase { ...@@ -148,12 +148,7 @@ public class TestOutOfMemory extends TestBase {
stat.execute("checkpoint"); stat.execute("checkpoint");
eatMemory(80); eatMemory(80);
try { try {
try { assertThrows(ErrorCode.OUT_OF_MEMORY, prep).execute();
prep.execute();
fail();
} catch (SQLException e) {
assertEquals(ErrorCode.OUT_OF_MEMORY, e.getErrorCode());
}
assertThrows(ErrorCode.DATABASE_IS_CLOSED, conn).close(); assertThrows(ErrorCode.DATABASE_IS_CLOSED, conn).close();
freeMemory(); freeMemory();
conn = null; conn = null;
......
...@@ -165,14 +165,9 @@ public class TestTriggersConstraints extends TestBase implements Trigger { ...@@ -165,14 +165,9 @@ public class TestTriggersConstraints extends TestBase implements Trigger {
stat = conn.createStatement(); stat = conn.createStatement();
stat.execute("drop table if exists test"); stat.execute("drop table if exists test");
stat.execute("create table test(id int)"); stat.execute("create table test(id int)");
try { assertThrows(ErrorCode.TRIGGER_SELECT_AND_ROW_BASED_NOT_SUPPORTED, stat)
stat.execute("create trigger test_insert before select on test " + .execute("create trigger test_insert before select on test " +
"for each row call \"" + TestTriggerAdapter.class.getName() + "\""); "for each row call \"" + TestTriggerAdapter.class.getName() + "\"");
fail();
} catch (SQLException ex) {
assertEquals(ErrorCode.TRIGGER_SELECT_AND_ROW_BASED_NOT_SUPPORTED,
ex.getErrorCode());
}
conn.close(); conn.close();
} }
......
...@@ -79,12 +79,7 @@ public class TestMvcc3 extends TestBase { ...@@ -79,12 +79,7 @@ public class TestMvcc3 extends TestBase {
s1.execute("create unique index on test(name)"); s1.execute("create unique index on test(name)");
s1.executeUpdate("update test set name = 100 where id = 1"); s1.executeUpdate("update test set name = 100 where id = 1");
try { assertThrows(SQLException.class, s2).executeUpdate("update test set name = 100 where id = 2");
s2.executeUpdate("update test set name = 100 where id = 2");
fail();
} catch (SQLException e) {
// expected
}
ResultSet rs = s1.executeQuery("select * from test order by id"); ResultSet rs = s1.executeQuery("select * from test order by id");
assertTrue(rs.next()); assertTrue(rs.next());
...@@ -268,7 +263,3 @@ public class TestMvcc3 extends TestBase { ...@@ -268,7 +263,3 @@ public class TestMvcc3 extends TestBase {
} }
} }
...@@ -84,8 +84,7 @@ public class TestIntPerfectHash extends TestBase { ...@@ -84,8 +84,7 @@ public class TestIntPerfectHash extends TestBase {
while (set.size() < size) { while (set.size() < size) {
set.add(r.nextInt()); set.add(r.nextInt());
} }
ArrayList<Integer> list = new ArrayList<>(); ArrayList<Integer> list = new ArrayList<>(set);
list.addAll(set);
byte[] desc = IntPerfectHash.generate(list); byte[] desc = IntPerfectHash.generate(list);
int max = test(desc, set); int max = test(desc, set);
assertEquals(size - 1, max); assertEquals(size - 1, max);
......
...@@ -330,8 +330,7 @@ public class MinimalPerfectHash<K> { ...@@ -330,8 +330,7 @@ public class MinimalPerfectHash<K> {
* @return the hash function description * @return the hash function description
*/ */
public static <K> byte[] generate(Set<K> set, UniversalHash<K> hash) { public static <K> byte[] generate(Set<K> set, UniversalHash<K> hash) {
ArrayList<K> list = new ArrayList<>(); ArrayList<K> list = new ArrayList<>(set);
list.addAll(set);
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
int seed = RANDOM.nextInt(); int seed = RANDOM.nextInt();
out.write(seed >>> 24); out.write(seed >>> 24);
......
...@@ -246,8 +246,7 @@ public class ClassReader { ...@@ -246,8 +246,7 @@ public class ClassReader {
Token c = stack.pop(); Token c = stack.pop();
Stack<Token> currentStack = new Stack<>(); Stack<Token> currentStack = new Stack<>();
currentStack.addAll(stack); currentStack.addAll(stack);
ArrayList<Token> currentVariables = new ArrayList<>(); ArrayList<Token> currentVariables = new ArrayList<>(variables);
currentVariables.addAll(variables);
int branch = nextPc; int branch = nextPc;
Token a = getResult(); Token a = getResult();
stack = currentStack; stack = currentStack;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论