提交 50d1b061 authored 作者: Noel Grandin's avatar Noel Grandin

use assertContains in more places

so we get nicer error messages when things fail
上级 98b53a8c
......@@ -366,7 +366,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
ResultSet rs;
rs = stat.executeQuery("select * from information_schema.views");
rs.next();
assertTrue(rs.getString("VIEW_DEFINITION").contains("SCHEMA2.FUNC"));
assertContains(rs.getString("VIEW_DEFINITION"), "SCHEMA2.FUNC");
stat.execute("drop view test");
stat.execute("drop schema schema2");
......
......@@ -164,7 +164,7 @@ public class TestIndex extends TestBase {
int start = m.indexOf('\"'), end = m.indexOf('\"', start + 1);
String s = m.substring(start + 1, end);
for (String t : expected) {
assertTrue(t + " not in " + s, s.contains(t));
assertContains(s, t);
}
}
stat.execute("drop table test");
......
......@@ -137,7 +137,7 @@ public class TestLinkedTable extends TestBase {
"(null, 'jdbc:h2:mem:', 'sa', 'pwd', 'DUAL2')");
fail();
} catch (SQLException e) {
assertTrue(e.toString().contains("pwd"));
assertContains(e.toString(), "pwd");
}
try {
conn.createStatement().execute("create linked table test" +
......
......@@ -338,12 +338,12 @@ public class TestOptimizations extends TestBase {
rs = stat.executeQuery("explain select * from test " +
"where id > 10 order by id");
rs.next();
assertTrue(rs.getString(1).contains("IDX_ID_ASC"));
assertContains(rs.getString(1), "IDX_ID_ASC");
rs = stat.executeQuery("explain select * from test " +
"where id < 10 order by id desc");
rs.next();
assertTrue(rs.getString(1).contains("IDX_ID_DESC"));
assertContains(rs.getString(1), "IDX_ID_DESC");
rs.next();
stat.execute("drop table test");
......@@ -635,7 +635,7 @@ public class TestOptimizations extends TestBase {
rs.next();
if (!config.mvcc) {
String plan = rs.getString(1);
assertTrue(plan.indexOf("direct") > 0);
assertContains(plan, "direct");
}
rs = stat.executeQuery("select min(x), max(x) from test");
rs.next();
......@@ -667,7 +667,7 @@ public class TestOptimizations extends TestBase {
"WHERE id < 100 and type=2 AND id<100");
rs.next();
String plan = rs.getString(1);
assertTrue(plan.indexOf("TYPE_INDEX") > 0);
assertContains(plan, "TYPE_INDEX");
conn.close();
}
......
......@@ -43,19 +43,19 @@ public class TestOptimizerHints extends TestBase {
String plan;
plan = plan(s, "select * from t1, t2 where t1.id = t2.t1_id");
assertTrue(plan, plan.contains("INNER JOIN PUBLIC.T2"));
assertContains(plan, "INNER JOIN PUBLIC.T2");
plan = plan(s, "select * from t2, t1 where t1.id = t2.t1_id");
assertTrue(plan, plan.contains("INNER JOIN PUBLIC.T1"));
assertContains(plan, "INNER JOIN PUBLIC.T1");
plan = plan(s, "select * from t2, t1 where t1.id = 1");
assertTrue(plan, plan.contains("INNER JOIN PUBLIC.T1"));
assertContains(plan, "INNER JOIN PUBLIC.T1");
plan = plan(s, "select * from t2, t1 where t1.id = t2.t1_id and t2.id = 1");
assertTrue(plan, plan.contains("INNER JOIN PUBLIC.T1"));
assertContains(plan, "INNER JOIN PUBLIC.T1");
plan = plan(s, "select * from t1, t2 where t1.id = t2.t1_id and t2.id = 1");
assertTrue(plan, plan.contains("INNER JOIN PUBLIC.T2"));
assertContains(plan, "INNER JOIN PUBLIC.T2");
checkPlanComma(s, "t1", "t2", "t3", "t4");
checkPlanComma(s, "t4", "t2", "t3", "t1");
......
......@@ -393,7 +393,7 @@ public class TestSequence extends TestBase {
getNext(stat);
fail("Expected error: " + finalError);
} catch (SQLException e) {
assertTrue(e.getMessage().contains(finalError));
assertContains(e.getMessage(), finalError);
}
}
......@@ -405,7 +405,7 @@ public class TestSequence extends TestBase {
stat.execute(sql);
fail("Expected error: " + error);
} catch (SQLException e) {
assertTrue(e.getMessage(), e.getMessage().contains(error));
assertContains(e.getMessage(), error);
}
}
......
......@@ -760,7 +760,7 @@ public class TestPreparedStatement extends TestBase {
ResultSet rs = prep.executeQuery();
rs.next();
String plan = rs.getString(1);
assertTrue(plan.contains(".tableScan"));
assertContains(plan, ".tableScan");
rs = prepExe.executeQuery();
rs.next();
assertEquals("World", rs.getString(2));
......@@ -771,7 +771,7 @@ public class TestPreparedStatement extends TestBase {
rs = prep.executeQuery();
rs.next();
String plan1 = rs.getString(1);
assertTrue(plan1.contains("IDXNAME"));
assertContains(plan1, "IDXNAME");
rs = prepExe.executeQuery();
rs.next();
assertEquals("Hello", rs.getString(2));
......
......@@ -103,7 +103,7 @@ public class TestConnectionPool extends TestBase {
man.getConnection();
fail();
} catch (SQLException e) {
assertTrue(e.toString().toLowerCase().contains("timeout"));
assertContains(e.toString().toLowerCase(), "timeout");
time = System.currentTimeMillis() - time;
assertTrue("timeout after " + time + " ms", time > 1000);
} finally {
......
......@@ -142,7 +142,7 @@ public class TestWeb extends TestBase {
Server server = Server.createWebServer(
"-webPort", "8182", "-properties", "null");
server.start();
assertTrue(server.getStatus().contains("server running"));
assertContains(server.getStatus(), "server running");
Server server2 = Server.createWebServer(
"-webPort", "8182", "-properties", "null");
assertEquals("Not started", server2.getStatus());
......@@ -150,9 +150,9 @@ public class TestWeb extends TestBase {
server2.start();
fail();
} catch (Exception e) {
assertTrue(e.toString().contains("port may be in use"));
assertTrue(server2.getStatus().contains(
"could not be started"));
assertContains(e.toString(), "port may be in use");
assertContains(server2.getStatus(),
"could not be started");
}
server.stop();
}
......
......@@ -542,7 +542,7 @@ public class TestMVTableEngine extends TestBase {
rs.next();
plan = rs.getString(1);
// transaction log is larger than the table, so read the table
assertTrue(plan, plan.contains("reads:"));
assertContains(plan, "reads:");
rs = stat2.executeQuery("select count(*) from test");
rs.next();
assertEquals(10000, rs.getInt(1));
......
......@@ -285,7 +285,7 @@ public class TestNestedJoins extends TestBase {
"inner join c on c.id = b.id on b.id = a.id");
assertTrue(rs.next());
sql = rs.getString(1);
assertTrue("nested", sql.contains("("));
assertContains(sql, "(");
stat.execute("drop table a, b, c");
// see roadmap, tag: swapInnerJoinTables
......@@ -350,7 +350,7 @@ public class TestNestedJoins extends TestBase {
"left outer join (test c) on a.id = c.id");
assertTrue(rs.next());
sql = rs.getString(1);
assertTrue(sql.contains("PRIMARY_KEY"));
assertContains(sql, "PRIMARY_KEY");
stat.execute("drop table test");
/*
......
......@@ -304,7 +304,7 @@ public class TestOuterJoins extends TestBase {
"left outer join (test c) on a.id = c.id");
assertTrue(rs.next());
sql = rs.getString(1);
assertTrue(sql.contains("PRIMARY_KEY"));
assertContains(sql, "PRIMARY_KEY");
stat.execute("drop table test");
/*
......
......@@ -102,32 +102,32 @@ public class TestJmx extends TestBase {
getAttribute(name, "Version").toString().startsWith("1."));
assertEquals(14, info.getAttributes().length);
result = mbeanServer.invoke(name, "listSettings", null, null).toString();
assertTrue(result.contains("ANALYZE_AUTO"));
assertContains(result, "ANALYZE_AUTO");
conn.setAutoCommit(false);
stat.execute("create table test(id int)");
stat.execute("insert into test values(1)");
result = mbeanServer.invoke(name, "listSessions", null, null).toString();
assertTrue(result.contains("session id"));
assertContains(result, "session id");
if (config.mvcc || config.mvStore) {
assertTrue(result.contains("read lock"));
assertContains(result, "read lock");
} else {
assertTrue(result.contains("write lock"));
assertContains(result, "write lock");
}
assertEquals(2, info.getOperations().length);
assertTrue(info.getDescription().contains("database"));
assertContains(info.getDescription(), "database");
attrMap = New.hashMap();
for (MBeanAttributeInfo a : info.getAttributes()) {
attrMap.put(a.getName(), a);
}
assertTrue(attrMap.get("CacheSize").getDescription().contains("KB"));
assertContains(attrMap.get("CacheSize").getDescription(), "KB");
opMap = New.hashMap();
for (MBeanOperationInfo o : info.getOperations()) {
opMap.put(o.getName(), o);
}
assertTrue(opMap.get("listSessions").getDescription().contains("lock"));
assertContains(opMap.get("listSessions").getDescription(), "lock");
assertEquals(MBeanOperationInfo.INFO, opMap.get("listSessions").getImpact());
conn.close();
......
......@@ -138,7 +138,7 @@ public class TestPageStore extends TestBase {
InputStream in = FileUtils.newInputStream(getBaseDir() +
"/pageStoreLogLimit.trace.db");
String s = IOUtils.readStringAndClose(new InputStreamReader(in), -1);
assertTrue(s.indexOf("Transaction log could not be truncated") > 0);
assertContains(s, "Transaction log could not be truncated");
conn.commit();
ResultSet rs = stat2.executeQuery("select * from test");
assertTrue(rs.next());
......
......@@ -236,8 +236,8 @@ public class TestPgServer extends TestBase {
"select version(), pg_postmaster_start_time(), current_schema()");
rs.next();
String s = rs.getString(1);
assertTrue(s.contains("H2"));
assertTrue(s.contains("PostgreSQL"));
assertContains(s, "H2");
assertContains(s, "PostgreSQL");
s = rs.getString(2);
s = rs.getString(3);
assertEquals(s, "PUBLIC");
......
......@@ -290,7 +290,7 @@ public class TestRecovery extends TestBase {
rec.setOut(new PrintStream(buff));
rec.runTool("-dir", getBaseDir(), "-db", "recovery", "-trace");
String out = new String(buff.toByteArray());
assertTrue(out.contains("Created file"));
assertContains(out, "Created file");
Connection conn2 = getConnection("recovery2");
Statement stat2 = conn2.createStatement();
......
......@@ -536,23 +536,23 @@ public class TestTools extends TestBase {
try {
result = runServer(0, new String[]{"-?"});
assertTrue(result.contains("Starts the H2 Console"));
assertContains(result, "Starts the H2 Console");
assertTrue(result.indexOf("Unknown option") < 0);
result = runServer(1, new String[]{"-xy"});
assertTrue(result.contains("Starts the H2 Console"));
assertTrue(result.contains("Feature not supported"));
assertContains(result, "Starts the H2 Console");
assertContains(result, "Feature not supported");
result = runServer(0, new String[]{"-tcp",
"-tcpPort", "9001", "-tcpPassword", "abc"});
assertTrue(result.contains("tcp://"));
assertTrue(result.contains(":9001"));
assertTrue(result.contains("only local"));
assertContains(result, "tcp://");
assertContains(result, ":9001");
assertContains(result, "only local");
assertTrue(result.indexOf("Starts the H2 Console") < 0);
conn = getConnection("jdbc:h2:tcp://localhost:9001/mem:", "sa", "sa");
conn.close();
result = runServer(0, new String[]{"-tcpShutdown",
"tcp://localhost:9001", "-tcpPassword", "abc", "-tcpShutdownForce"});
assertTrue(result.contains("Shutting down"));
assertContains(result, "Shutting down");
} finally {
shutdownServers();
}
......@@ -565,16 +565,16 @@ public class TestTools extends TestBase {
try {
result = runServer(0, new String[]{"-tcp",
"-tcpAllowOthers", "-tcpPort", "9001", "-tcpPassword", "abcdef", "-tcpSSL"});
assertTrue(result.contains("ssl://"));
assertTrue(result.contains(":9001"));
assertTrue(result.contains("others can"));
assertContains(result, "ssl://");
assertContains(result, ":9001");
assertContains(result, "others can");
assertTrue(result.indexOf("Starts the H2 Console") < 0);
conn = getConnection("jdbc:h2:ssl://localhost:9001/mem:", "sa", "sa");
conn.close();
result = runServer(0, new String[]{"-tcpShutdown",
"ssl://localhost:9001", "-tcpPassword", "abcdef"});
assertTrue(result.contains("Shutting down"));
assertContains(result, "Shutting down");
assertThrows(ErrorCode.CONNECTION_BROKEN_1, this).
getConnection("jdbc:h2:ssl://localhost:9001/mem:", "sa", "sa");
......@@ -583,21 +583,21 @@ public class TestTools extends TestBase {
"-pg", "-pgAllowOthers", "-pgPort", "9003",
"-tcp", "-tcpAllowOthers", "-tcpPort", "9006", "-tcpPassword", "abc"});
Server stop = server;
assertTrue(result.contains("https://"));
assertTrue(result.contains(":9002"));
assertTrue(result.contains("pg://"));
assertTrue(result.contains(":9003"));
assertTrue(result.contains("others can"));
assertContains(result, "https://");
assertContains(result, ":9002");
assertContains(result, "pg://");
assertContains(result, ":9003");
assertContains(result, "others can");
assertTrue(result.indexOf("only local") < 0);
assertTrue(result.contains("tcp://"));
assertTrue(result.contains(":9006"));
assertContains(result, "tcp://");
assertContains(result, ":9006");
conn = getConnection("jdbc:h2:tcp://localhost:9006/mem:", "sa", "sa");
conn.close();
result = runServer(0, new String[]{"-tcpShutdown",
"tcp://localhost:9006", "-tcpPassword", "abc", "-tcpShutdownForce"});
assertTrue(result.contains("Shutting down"));
assertContains(result, "Shutting down");
stop.shutdown();
assertThrows(ErrorCode.CONNECTION_BROKEN_1, this).
getConnection("jdbc:h2:tcp://localhost:9006/mem:", "sa", "sa");
......@@ -926,7 +926,7 @@ public class TestTools extends TestBase {
tool.setOut(new PrintStream(buff));
tool.runTool("-url", url, "-user", user, "-password", password,
"-script", fileName + ".txt", "-showResults");
assertTrue(buff.toString().contains("Hello"));
assertContains(buff.toString(), "Hello");
// test parsing of BLOCKSIZE option
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论