Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Commit 28c1eb0

Browse files
authored
Merge pull request #1236 from pervazea/junit
Junit updates
2 parents 3b64df8 + 1b14834 commit 28c1eb0

File tree

6 files changed

+246
-42
lines changed

6 files changed

+246
-42
lines changed

script/testing/junit/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
!Makefile

script/testing/junit/InsertPSTest.java

Lines changed: 65 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -62,37 +62,6 @@ public void Teardown() throws SQLException {
6262
stmt.execute(SQL_DROP_TABLE);
6363
}
6464

65-
/**
66-
* Set column values.
67-
*
68-
* @param pstmt prepared statement to receive values
69-
* @param values array of values
70-
*/
71-
public void setValues(PreparedStatement pstmt,
72-
int [] values) throws SQLException {
73-
int col = 1;
74-
for (int i=0; i<values.length; i++) {
75-
pstmt.setInt(col++, (int) values[i]);
76-
}
77-
}
78-
79-
/**
80-
* Check a single row of queried values against expected values
81-
*
82-
* @param rs resultset, with cursor at the desired row
83-
* @param columns column names
84-
* @param expected_values expected values of columns
85-
*/
86-
87-
public void checkRow(ResultSet rs,
88-
String [] columns,
89-
int [] expected_values) throws SQLException {
90-
assertEquals(columns.length, expected_values.length);
91-
for (int i=0; i<columns.length; i++) {
92-
assertEquals(rs.getInt(columns[i]), expected_values[i]);
93-
}
94-
}
95-
9665
/**
9766
* Prepared statement, 1 tuple insert, with no column specification.
9867
*/
@@ -144,7 +113,7 @@ public void testPS_1Tuple_CS_1() throws SQLException {
144113
*/
145114

146115
// Currently fails. See #1197
147-
//@Test
116+
@Test
148117
public void testPS_1Tuple_CS_2() throws SQLException {
149118

150119
String sql = "INSERT INTO tbl (c3, c1, c2) VALUES (?, ?, ?);";
@@ -168,7 +137,7 @@ public void testPS_1Tuple_CS_2() throws SQLException {
168137
*/
169138

170139
// Currently fails. See #1197
171-
// @Test
140+
@Test
172141
public void testPS_1Tuple_CS_3() throws SQLException {
173142

174143
String sql = "INSERT INTO tbl (c3, c1, c2) VALUES (?, 1, ?);";
@@ -232,7 +201,33 @@ public void testPS_1Tuple_CS_5() throws SQLException {
232201
new int [] {1, 2, 3});
233202
assertNoMoreRows(rs);
234203
}
204+
205+
/**
206+
* Prepared statement, 1 tuple insert, all constants
207+
*/
208+
// Works, due to use of insert rather than push back
235209

210+
@Test
211+
public void testPS_1Tuple_CS_6() throws SQLException {
212+
213+
String sql = "INSERT INTO tbl (c1, c2, c3) VALUES (1, 2, 3);";
214+
PreparedStatement pstmt = conn.prepareStatement(sql);
215+
216+
// setValues(pstmt, new int [] {});
217+
// Todo: determine if this is 100% correct. addBatch call required
218+
// as, internally, SetParameterValues is where the constants
219+
// are inserted.
220+
pstmt.addBatch();
221+
pstmt.executeBatch();
222+
223+
getResultsPS();
224+
rs.next();
225+
checkRow(rs,
226+
new String [] {"c1", "c2", "c3"},
227+
new int [] {1, 2, 3});
228+
assertNoMoreRows(rs);
229+
}
230+
236231
/* --------------------------------------------
237232
* 2 tuple insertions
238233
* ---------------------------------------------
@@ -301,13 +296,13 @@ public void testPS_2Tuple_CS_1() throws SQLException {
301296
* in different order from schema.
302297
*/
303298
// Currently fails. See #1197
304-
//@Test
299+
@Test
305300
public void testPS_2Tuple_CS_2() throws SQLException {
306301

307302
String sql = "INSERT INTO tbl (c3, c1, c2) VALUES (?, ?, ?);";
308303
PreparedStatement pstmt = conn.prepareStatement(sql);
309304

310-
setValues(pstmt, new int [] {3, 2, 1});
305+
setValues(pstmt, new int [] {3, 1, 2});
311306
pstmt.addBatch();
312307

313308
setValues(pstmt, new int [] {13, 11, 12});
@@ -331,12 +326,42 @@ public void testPS_2Tuple_CS_2() throws SQLException {
331326
* in different order from schema, with one constant column.
332327
*/
333328
// Currently fails. See #1197
334-
//@Test
329+
@Test
335330
public void testPS_2Tuple_CS_3() throws SQLException {
336331

337-
String sql = "INSERT INTO tbl (c3, c1, c2) VALUES (?, 1, ?);";
332+
String sql = "INSERT INTO tbl (c3, c1, c2) VALUES (3, ?, ?);";
338333
PreparedStatement pstmt = conn.prepareStatement(sql);
339-
setValues(pstmt, new int [] {3, 2});
334+
setValues(pstmt, new int [] {1, 2});
335+
pstmt.addBatch();
336+
337+
setValues(pstmt, new int [] {11, 12});
338+
pstmt.addBatch();
339+
pstmt.executeBatch();
340+
341+
getResultsPS();
342+
rs.next();
343+
checkRow(rs,
344+
new String [] {"c1", "c2", "c3"},
345+
new int [] {1, 2, 3});
346+
rs.next();
347+
checkRow(rs,
348+
new String [] {"c1", "c2", "c3"},
349+
new int [] {11, 12, 3});
350+
assertNoMoreRows(rs);
351+
}
352+
353+
/**
354+
* Prepared statement, 2 tuple insert, with columns inserted
355+
* in different order from schema, with one constant column.
356+
* Variant of above, with constant column last.
357+
*/
358+
// Currently fails. See #1197
359+
@Test
360+
public void testPS_2Tuple_CS_3a() throws SQLException {
361+
362+
String sql = "INSERT INTO tbl (c3, c1, c2) VALUES (?, ?, 2);";
363+
PreparedStatement pstmt = conn.prepareStatement(sql);
364+
setValues(pstmt, new int [] {3, 1});
340365
pstmt.addBatch();
341366

342367
setValues(pstmt, new int [] {13, 12});
@@ -351,7 +376,7 @@ public void testPS_2Tuple_CS_3() throws SQLException {
351376
rs.next();
352377
checkRow(rs,
353378
new String [] {"c1", "c2", "c3"},
354-
new int [] {1, 12, 13});
379+
new int [] {12, 2, 13});
355380
assertNoMoreRows(rs);
356381
}
357382

@@ -360,7 +385,7 @@ public void testPS_2Tuple_CS_3() throws SQLException {
360385
* in schema order, with 2nd column missing.
361386
*/
362387
// Currently failing. See comments in #1197
363-
// @Test
388+
@Test
364389
public void testPS_2Tuple_CS_4() throws SQLException {
365390

366391
String sql = "INSERT INTO tbl (c1, c3) VALUES (?, ?);";

script/testing/junit/Makefile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
3+
4+
.SUFFIXES: .java .class
5+
6+
CP = .:lib/junit-4.12.jar:lib/hamcrest-core-1.3.jar:lib/postgresql-9.4.1209.jre6.jar
7+
JC = javac
8+
JFLAGS = -g
9+
JUNIT = org.junit.runner.JUnitCore
10+
RM = rm
11+
12+
.java.class:
13+
$(JC) $(JFLAGS) -cp $(CP) $*.java
14+
15+
CLASSES = \
16+
PLTestBase.java \
17+
InsertTPCCTest.java \
18+
InsertPSTest.java \
19+
UpdateTest.java
20+
21+
default: classes
22+
23+
classes: $(CLASSES:.java=.class)
24+
25+
clean:
26+
$(RM) *.class
27+
28+
test: $(CLASSES)
29+
java -jar lib/junit-platform-console-standalone-1.1.0.jar \
30+
--class-path $(CP) \
31+
-c InsertPSTest
32+
# -c UpdateTest
33+
# -c InsertPSTest -c InsertTPCCTest
34+
35+
36+

script/testing/junit/PLTestBase.java

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,36 @@ public static Connection makeConnection(String host,
3434
return conn;
3535
}
3636

37+
/**
38+
* Assert that we have consumed all the rows.
39+
*
40+
* @param rs resultset
41+
*/
3742
public static void assertNoMoreRows(ResultSet rs) throws SQLException {
3843
int extra_rows = 0;
3944
while(rs.next()) {
4045
extra_rows++;
4146
}
4247
assertEquals(extra_rows, 0);
4348
}
49+
50+
/**
51+
* Check a single row of queried values against expected values
52+
*
53+
* @param rs resultset, with cursor at the desired row
54+
* @param columns column names
55+
* @param expected_values expected values of columns
56+
*/
57+
58+
public void checkRow(ResultSet rs,
59+
String [] columns,
60+
int [] expected_values) throws SQLException {
61+
assertEquals(columns.length, expected_values.length);
62+
for (int i=0; i<columns.length; i++) {
63+
assertEquals(expected_values[i], rs.getInt(columns[i]));
64+
}
65+
}
66+
4467

4568
public static void DumpSQLException(SQLException ex) {
4669
System.err.println("Failed to execute test. Got " +
@@ -49,5 +72,18 @@ public static void DumpSQLException(SQLException ex) {
4972
System.err.println(" + Error Code: " + ex.getErrorCode());
5073
System.err.println(" + SQL State: " + ex.getSQLState());
5174
}
52-
75+
76+
/**
77+
* Set column values.
78+
*
79+
* @param pstmt prepared statement to receive values
80+
* @param values array of values
81+
*/
82+
public void setValues(PreparedStatement pstmt,
83+
int [] values) throws SQLException {
84+
int col = 1;
85+
for (int i=0; i<values.length; i++) {
86+
pstmt.setInt(col++, (int) values[i]);
87+
}
88+
}
5389
}

script/testing/junit/UpdateTest.java

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Peloton
4+
//
5+
// UpdateTest.java
6+
//
7+
// Identification: script/testing/junit/UpdateTest.java
8+
//
9+
// Copyright (c) 2015-2018, Carnegie Mellon University Database Group
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
/**
14+
* 1 and 2 tuple, prepared insert statement tests.
15+
*/
16+
17+
import java.sql.*;
18+
import org.junit.*;
19+
import static org.junit.Assert.assertEquals;
20+
21+
public class UpdateTest extends PLTestBase {
22+
private Connection conn;
23+
private String s_sql = "SELECT * FROM tbl;";
24+
25+
private static final String SQL_DROP_TABLE =
26+
"DROP TABLE IF EXISTS tbl;";
27+
28+
private static final String SQL_CREATE_TABLE =
29+
"CREATE TABLE tbl (" +
30+
"id integer, " +
31+
"year integer);";
32+
33+
/**
34+
* Initialize the database and table for testing
35+
*/
36+
private void InitDatabase() throws SQLException {
37+
Statement stmt = conn.createStatement();
38+
stmt.execute(SQL_DROP_TABLE);
39+
stmt.execute(SQL_CREATE_TABLE);
40+
}
41+
42+
@Before
43+
public void Setup() throws SQLException {
44+
conn = makeDefaultConnection();
45+
conn.setAutoCommit(true);
46+
InitDatabase();
47+
}
48+
49+
@After
50+
public void Teardown() throws SQLException {
51+
Statement stmt = conn.createStatement();
52+
stmt.execute(SQL_DROP_TABLE);
53+
}
54+
55+
/**
56+
* Set column values.
57+
*
58+
* @param pstmt prepared statement to receive values
59+
* @param values array of values
60+
*/
61+
public void setValues(PreparedStatement pstmt,
62+
int [] values) throws SQLException {
63+
int col = 1;
64+
for (int i=0; i<values.length; i++) {
65+
pstmt.setInt(col++, (int) values[i]);
66+
}
67+
}
68+
69+
/**
70+
* xxx
71+
*/
72+
@Test
73+
public void test_Update_1() throws SQLException {
74+
75+
String sql_1 = "INSERT INTO tbl VALUES (5, 400);";
76+
conn.createStatement().execute(sql_1);
77+
78+
ResultSet rs_1 = conn.createStatement().executeQuery(s_sql);
79+
rs_1.next();
80+
checkRow(rs_1,
81+
new String [] {"id", "year"},
82+
new int [] {5, 400});
83+
assertNoMoreRows(rs_1);
84+
85+
String sql_2 = "UPDATE tbl set year=year*2, id=id*2";
86+
conn.createStatement().execute(sql_2);
87+
ResultSet rs_2 = conn.createStatement().executeQuery(s_sql);
88+
89+
rs_2.next();
90+
checkRow(rs_2,
91+
new String [] {"id", "year"},
92+
new int [] {10, 800});
93+
assertNoMoreRows(rs_2);
94+
95+
String sql_3 = "UPDATE tbl set year=year*2, id=id*2";
96+
conn.createStatement().execute(sql_3);
97+
ResultSet rs_3 = conn.createStatement().executeQuery(s_sql);
98+
99+
rs_3.next();
100+
checkRow(rs_3,
101+
new String [] {"id", "year"},
102+
new int [] {20, 1600});
103+
assertNoMoreRows(rs_3);
104+
}
105+
}

src/settings/settings_manager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ const std::string SettingsManager::GetInfo() const {
114114
info.append(
115115
StringUtil::Format("%28s: %-28s\n", "Code-generation",
116116
GetBool(SettingId::codegen) ? "enabled" : "disabled"));
117-
info.append(StringUtil::Format("%28s: %-28s\n", "Optimization Timeout",
117+
info.append(StringUtil::Format("%28s: %-28i\n", "Optimization Timeout",
118118
GetInt(SettingId::task_execution_timeout)));
119119
return StringBoxUtil::Box(info);
120120
}

0 commit comments

Comments
 (0)