[
https://issues.apache.org/jira/browse/PHOENIX-1295?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Gabriel Reid updated PHOENIX-1295:
----------------------------------
Attachment: PHOENIX-1295-WIP1.patch
Here's an initial WIP patch that implements the QueryTestUtil as explained in
the description, and rewrites a couple of tests to demonstrate it.
As an example of the query output checking (but not the table population), a
test in HashJoinIT gets changed from this
{code}
@Test
public void testDefaultJoin() throws Exception {
String query = "SELECT item.\"item_id\", item.name,
supp.\"supplier_id\", supp.name FROM " + JOIN_ITEM_TABLE_FULL_NAME + " item
JOIN " + JOIN_SUPPLIER_TABLE_FULL_NAME + " supp ON item.\"supplier_id\" =
supp.\"supplier_id\"";
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
Connection conn = DriverManager.getConnection(getUrl(), props);
try {
PreparedStatement statement = conn.prepareStatement(query);
ResultSet rs = statement.executeQuery();
assertTrue (rs.next());
assertEquals(rs.getString(1), "0000000001");
assertEquals(rs.getString(2), "T1");
assertEquals(rs.getString(3), "0000000001");
assertEquals(rs.getString(4), "S1");
assertTrue (rs.next());
assertEquals(rs.getString(1), "0000000002");
assertEquals(rs.getString(2), "T2");
assertEquals(rs.getString(3), "0000000001");
assertEquals(rs.getString(4), "S1");
assertTrue (rs.next());
assertEquals(rs.getString(1), "0000000003");
assertEquals(rs.getString(2), "T3");
assertEquals(rs.getString(3), "0000000002");
assertEquals(rs.getString(4), "S2");
assertTrue (rs.next());
assertEquals(rs.getString(1), "0000000004");
assertEquals(rs.getString(2), "T4");
assertEquals(rs.getString(3), "0000000002");
assertEquals(rs.getString(4), "S2");
assertTrue (rs.next());
assertEquals(rs.getString(1), "0000000005");
assertEquals(rs.getString(2), "T5");
assertEquals(rs.getString(3), "0000000005");
assertEquals(rs.getString(4), "S5");
assertTrue (rs.next());
assertEquals(rs.getString(1), "0000000006");
assertEquals(rs.getString(2), "T6");
assertEquals(rs.getString(3), "0000000006");
assertEquals(rs.getString(4), "S6");
assertFalse(rs.next());
} finally {
conn.close();
}
}
{code}
to this
{code}
@Test
public void testDefaultJoin() throws Exception {
String query =
"SELECT item.\"item_id\", item.name, supp.\"supplier_id\",
supp.name " +
"FROM " + JOIN_ITEM_TABLE_FULL_NAME + " item " +
"JOIN " + JOIN_SUPPLIER_TABLE_FULL_NAME + " supp " +
"ON item.\"supplier_id\" = supp.\"supplier_id\"";
QueryTestUtil.on(getUrl())
.verifyQueryResultsOrdered(query,
"0000000001", "T1", "0000000001", "S1",
"0000000002", "T2", "0000000001", "S1",
"0000000003", "T3", "0000000002", "S2",
"0000000004", "T4", "0000000002", "S2",
"0000000005", "T5", "0000000005", "S5",
"0000000006", "T6", "0000000006", "S6");
}
{code}
> Add testing utility for table creation, population, and checking query results
> ------------------------------------------------------------------------------
>
> Key: PHOENIX-1295
> URL: https://issues.apache.org/jira/browse/PHOENIX-1295
> Project: Phoenix
> Issue Type: Improvement
> Reporter: Gabriel Reid
> Attachments: PHOENIX-1295-WIP1.patch
>
>
> Mostly due to the way the JDBC is structured in general, it's relatively
> painful to create a simple test case that just creates a simple table,
> populates it with a couple of rows, and checks the output of a query.
> Adding to this is the fact that there isn't really a single "right way" to
> write simple unit tests in Phoenix. Some tests try to cleanly close
> statements, ResultsSets, and Connections, while others don't. New tests of
> this sort are often created by first copying an existing test.
> The end results is that a couple of simple test cases to test a new built-in
> function often end up being mostly wresting with JDBC, with the actual test
> case getting largely hidden in the noise.
> The purpose of this ticket is to propose a utility to simplify creating
> tables, populating them, and verifying the output.
> The general API I have in mind is would look like this:
> {code}
> QueryTestUtil.on(jdbcUrl)
> .createTable("testtable",
> "id integer not null primary key",
> "name varchar")
> .withRows(
> 1, "name1",
> 2, "name2",
> 3, "othername")
> .verifyQueryResults(
> "select id, name from testtable where name like 'name%'",
> 1, "name1",
> 2, "name2");
> {code}
> The intention is to make it much less painful to write tests, and also to
> replace as enough existing test code to use this pattern so that new tests
> being created based on existing code will also follow this pattern.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)