Skip to content

Commit a4e1ca4

Browse files
committed
wip: adding unit tests for session setup file
1 parent 64a592f commit a4e1ca4

File tree

7 files changed

+71
-6
lines changed

7 files changed

+71
-6
lines changed

src/main/java/com/oltpbenchmark/WorkloadConfiguration.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import com.oltpbenchmark.types.DatabaseType;
2020
import com.oltpbenchmark.util.FileUtil;
2121
import com.oltpbenchmark.util.ThreadUtil;
22-
2322
import java.io.FileNotFoundException;
2423
import java.sql.Connection;
2524
import java.util.ArrayList;
@@ -141,7 +140,7 @@ private String checkPath(String path, String name) throws FileNotFoundException
141140
}
142141
}
143142

144-
public void setSessionSetupFile(String sessionSetupFile) throws FileNotFoundException{
143+
public void setSessionSetupFile(String sessionSetupFile) throws FileNotFoundException {
145144
this.sessionSetupFile = checkPath(sessionSetupFile, "sessionsetupfile");
146145
}
147146

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
DROP TABLE IF EXISTS FAKE;
22
CREATE TABLE FAKE (
33
ID INT PRIMARY KEY
4+
);
5+
CREATE TABLE FAKE2 (
6+
ID INT
47
);

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public abstract class AbstractTestCase<T extends BenchmarkModule> {
6868
protected final boolean createDatabase;
6969
protected final boolean loadDatabase;
7070
protected final String ddlOverridePath;
71+
protected final String sessionSetupFile;
7172

7273
private static final AtomicInteger portCounter = new AtomicInteger(9001);
7374
private static final int MAX_PORT_NUMBER = 65535;
@@ -77,13 +78,27 @@ public AbstractTestCase(boolean createDatabase, boolean loadDatabase) {
7778
this.createDatabase = createDatabase;
7879
this.loadDatabase = loadDatabase;
7980
this.ddlOverridePath = null;
81+
this.sessionSetupFile = null;
8082
}
8183

8284
public AbstractTestCase(boolean createDatabase, boolean loadDatabase, String ddlOverridePath) {
8385
this.benchmark = null;
8486
this.createDatabase = createDatabase;
8587
this.loadDatabase = loadDatabase;
8688
this.ddlOverridePath = ddlOverridePath;
89+
this.sessionSetupFile = ddlOverridePath;
90+
}
91+
92+
public AbstractTestCase(
93+
boolean createDatabase,
94+
boolean loadDatabase,
95+
String ddlOverridePath,
96+
String sessionSetupFile) {
97+
this.benchmark = null;
98+
this.createDatabase = createDatabase;
99+
this.loadDatabase = loadDatabase;
100+
this.ddlOverridePath = ddlOverridePath;
101+
this.sessionSetupFile = sessionSetupFile;
87102
}
88103

89104
public abstract List<Class<? extends Procedure>> procedures();
@@ -127,6 +142,7 @@ public final void setUp() throws Exception {
127142
this.workConf.setBenchmarkName(
128143
BenchmarkModule.convertBenchmarkClassToBenchmarkName(benchmarkClass()));
129144
this.workConf.setDDLPath(this.ddlOverridePath);
145+
this.workConf.setSessionSetupFile(this.sessionSetupFile);
130146

131147
customWorkloadConfiguration(this.workConf);
132148

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package com.oltpbenchmark.api;
1818

1919
import static org.junit.Assert.*;
20-
import static org.junit.Assert.fail;
2120

2221
import com.oltpbenchmark.catalog.Table;
2322
import com.oltpbenchmark.util.Histogram;
@@ -53,6 +52,8 @@ public void testLoad() throws Exception {
5352
validateLoad();
5453
}
5554

55+
// TODO: add another version of this test that uses external files (#600).
56+
5657
/** testLoad with after load script */
5758
@Test
5859
public void testLoadWithAfterLoad() throws Exception {

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,14 @@ public void testGetProcedure() {
6767
}
6868
}
6969

70-
/** testExecuteWork */
70+
/* testExecuteWork
71+
* Similar to Worker.run()
72+
*/
7173
@Test
7274
public void testExecuteWork() throws Exception {
73-
7475
Worker<?> w = workers.get(0);
7576
assertNotNull(w);
77+
w.setupSession();
7678
w.initialize();
7779
assertFalse(this.conn.isReadOnly());
7880
for (TransactionType txnType : this.workConf.getTransTypes()) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ public Class<NoOpBenchmark> benchmarkClass() {
3434

3535
@Override
3636
public List<String> ignorableTables() {
37-
return List.of("FAKE");
37+
return List.of("FAKE", "FAKE2");
3838
}
3939
}

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,21 @@
1616

1717
package com.oltpbenchmark.benchmarks.noop;
1818

19+
import static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertNotNull;
21+
import static org.junit.Assert.assertNull;
22+
import static org.junit.Assert.assertTrue;
23+
1924
import com.oltpbenchmark.api.AbstractTestWorker;
25+
import com.oltpbenchmark.api.BenchmarkModule;
2026
import com.oltpbenchmark.api.Procedure;
27+
import com.oltpbenchmark.api.Worker;
28+
import com.oltpbenchmark.catalog.Table;
29+
import com.oltpbenchmark.util.SQLUtil;
30+
import java.sql.ResultSet;
31+
import java.sql.Statement;
2132
import java.util.List;
33+
import org.junit.Test;
2234

2335
public class TestNoOpWorker extends AbstractTestWorker<NoOpBenchmark> {
2436

@@ -31,4 +43,36 @@ public List<Class<? extends Procedure>> procedures() {
3143
public Class<NoOpBenchmark> benchmarkClass() {
3244
return NoOpBenchmark.class;
3345
}
46+
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+
50+
@Test
51+
public void testNoSessionSetupFile() throws Exception {
52+
// Check that there is no session setup file assigned to the worker's config
53+
assertNull("Session setup file should be null", this.workConf.getSessionSetupFile());
54+
55+
List<Worker<? extends BenchmarkModule>> workers = this.benchmark.makeWorkers();
56+
Worker<?> worker = workers.get(0);
57+
assertNull(
58+
"Session setup file should be null",
59+
worker.getWorkloadConfiguration().getSessionSetupFile());
60+
61+
// Make sure there are no rows in the table
62+
this.testExecuteWork();
63+
64+
Table catalog_tbl = this.catalog.getTable("FAKE2");
65+
String sql = SQLUtil.getCountSQL(this.workConf.getDatabaseType(), catalog_tbl);
66+
try (Statement stmt = conn.createStatement();
67+
ResultSet result = stmt.executeQuery(sql); ) {
68+
69+
assertNotNull(result);
70+
71+
boolean adv = result.next();
72+
assertTrue(sql, adv);
73+
74+
int count = result.getInt(1);
75+
assertEquals(0, count);
76+
}
77+
}
3478
}

0 commit comments

Comments
 (0)