Skip to content

Commit 83002e6

Browse files
committed
add test for session setup script
1 parent a4e1ca4 commit 83002e6

File tree

7 files changed

+92
-4
lines changed

7 files changed

+92
-4
lines changed

src/main/java/com/oltpbenchmark/api/Worker.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,7 @@ protected void setupSession() {
753753
try (Statement stmt = conn.createStatement()) {
754754
stmt.execute(statements);
755755
}
756+
// conn.commit();
756757
} catch (SQLException | IOException ex) {
757758
throw new RuntimeException("Failed setting up session", ex);
758759
}

src/main/resources/benchmarks/noop/ddl-generic.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ DROP TABLE IF EXISTS FAKE;
22
CREATE TABLE FAKE (
33
ID INT PRIMARY KEY
44
);
5+
DROP TABLE IF EXISTS FAKE2;
56
CREATE TABLE FAKE2 (
67
ID INT
78
);

src/test/java/com/oltpbenchmark/api/AbstractTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public AbstractTestCase(boolean createDatabase, boolean loadDatabase, String ddl
8686
this.createDatabase = createDatabase;
8787
this.loadDatabase = loadDatabase;
8888
this.ddlOverridePath = ddlOverridePath;
89-
this.sessionSetupFile = ddlOverridePath;
89+
this.sessionSetupFile = null;
9090
}
9191

9292
public AbstractTestCase(

src/test/java/com/oltpbenchmark/api/AbstractTestWorker.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ public AbstractTestWorker(String ddlOverridePath) {
4141
super(true, true, ddlOverridePath);
4242
}
4343

44+
public AbstractTestWorker(String ddlOverridePath, String sessionSetupFile) {
45+
super(true, true, ddlOverridePath, sessionSetupFile);
46+
}
47+
4448
@Override
4549
public List<String> ignorableTables() {
4650
return null;

src/test/java/com/oltpbenchmark/benchmarks/noop/TestNoOpWorker.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ public Class<NoOpBenchmark> benchmarkClass() {
4444
return NoOpBenchmark.class;
4545
}
4646

47-
// TODO: Do the same for another test, but this time with a sessionSetupFile
48-
// specified that inserts rows as a dummy operation we can check for.
49-
5047
@Test
5148
public void testNoSessionSetupFile() throws Exception {
5249
// Check that there is no session setup file assigned to the worker's config
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Copyright 2016 by OLTPBenchmark Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.oltpbenchmark.benchmarks.noop;
18+
19+
import static org.junit.Assert.assertNotNull;
20+
import static org.junit.Assert.assertTrue;
21+
22+
import com.oltpbenchmark.api.AbstractTestWorker;
23+
import com.oltpbenchmark.api.BenchmarkModule;
24+
import com.oltpbenchmark.api.Procedure;
25+
import com.oltpbenchmark.api.Worker;
26+
import com.oltpbenchmark.catalog.Table;
27+
import com.oltpbenchmark.util.SQLUtil;
28+
import java.nio.file.Paths;
29+
import java.sql.ResultSet;
30+
import java.sql.Statement;
31+
import java.util.List;
32+
import org.junit.Test;
33+
34+
public class TestNoOpWorkerWithSessionSetupFile extends AbstractTestWorker<NoOpBenchmark> {
35+
36+
public TestNoOpWorkerWithSessionSetupFile() {
37+
super(
38+
null,
39+
Paths.get("src", "test", "resources", "benchmarks", "noop", "sessionSetupFile-hsqldb.sql")
40+
.toAbsolutePath()
41+
.toString());
42+
}
43+
44+
@Override
45+
public List<Class<? extends Procedure>> procedures() {
46+
return TestNoOpBenchmark.PROCEDURE_CLASSES;
47+
}
48+
49+
@Override
50+
public Class<NoOpBenchmark> benchmarkClass() {
51+
return NoOpBenchmark.class;
52+
}
53+
54+
@Test
55+
public void testSessionSetupFile() throws Exception {
56+
// Check that there is no session setup file assigned to the worker's config
57+
assertNotNull("Session setup file should not be null", this.workConf.getSessionSetupFile());
58+
59+
List<Worker<? extends BenchmarkModule>> workers = this.benchmark.makeWorkers();
60+
Worker<?> worker = workers.get(0);
61+
assertNotNull(
62+
"Session setup file should not be null",
63+
worker.getWorkloadConfiguration().getSessionSetupFile());
64+
65+
// Make sure there are no rows in the table
66+
this.testExecuteWork();
67+
68+
Table catalog_tbl = this.catalog.getTable("FAKE2");
69+
String sql = SQLUtil.getCountSQL(this.workConf.getDatabaseType(), catalog_tbl);
70+
try (Statement stmt = conn.createStatement();
71+
ResultSet result = stmt.executeQuery(sql); ) {
72+
73+
assertNotNull(result);
74+
75+
boolean adv = result.next();
76+
assertTrue(sql, adv);
77+
78+
int count = result.getInt(1);
79+
assertTrue("FAKE2 table should have more 0 rows.", count > 0);
80+
}
81+
}
82+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-- Dummy session setup file for HSQLDB
2+
INSERT INTO FAKE2 (ID) VALUES (1);
3+
COMMIT;

0 commit comments

Comments
 (0)