Skip to content

Commit b65943e

Browse files
ahitrinbpkroth
andauthored
Convert unit tests into JUnit4 format (#306)
* Convert tests into JUnit4 format * remove unused import --------- Co-authored-by: Brian Kroth <[email protected]>
1 parent 207bf9e commit b65943e

27 files changed

+250
-65
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717

1818
package com.oltpbenchmark.api;
1919

20+
import static org.junit.Assert.assertEquals;
21+
import static org.junit.Assert.assertFalse;
22+
import static org.junit.Assert.assertNotNull;
23+
import static org.junit.Assert.assertTrue;
24+
2025
import com.oltpbenchmark.catalog.AbstractCatalog;
2126
import com.oltpbenchmark.catalog.Table;
2227
import com.oltpbenchmark.types.DatabaseType;
@@ -29,6 +34,7 @@
2934
import java.util.List;
3035
import java.util.Set;
3136
import java.util.stream.Collectors;
37+
import org.junit.Test;
3238

3339
public abstract class AbstractTestBenchmarkModule<T extends BenchmarkModule> extends AbstractTestCase<T> {
3440

@@ -45,6 +51,7 @@ public List<String> ignorableTables() {
4551
/**
4652
* testGetDatabaseDDLPath
4753
*/
54+
@Test
4855
public void testGetDatabaseDDLPath() throws Exception {
4956
String ddlPath = this.benchmark.getDatabaseDDLPath(this.workConf.getDatabaseType());
5057
assertNotNull(ddlPath);
@@ -56,6 +63,7 @@ public void testGetDatabaseDDLPath() throws Exception {
5663
/**
5764
* testCreateDatabase
5865
*/
66+
@Test
5967
public void testCreateDatabase() throws Exception {
6068
this.benchmark.createDatabase();
6169

@@ -74,6 +82,7 @@ public void testCreateDatabase() throws Exception {
7482
/**
7583
* testGetTransactionType
7684
*/
85+
@Test
7786
public void testGetTransactionType() {
7887
int id = 1;
7988
for (Class<? extends Procedure> procClass : procedures()) {
@@ -89,6 +98,7 @@ public void testGetTransactionType() {
8998
/**
9099
* testGetSQLDialectPath
91100
*/
101+
@Test
92102
public void testGetSQLDialectPath() throws Exception {
93103
for (DatabaseType dbType : DatabaseType.values()) {
94104
String xmlFilePath = this.benchmark.getStatementDialects().getSQLDialectPath(dbType);
@@ -104,6 +114,7 @@ public void testGetSQLDialectPath() throws Exception {
104114
/**
105115
* testLoadSQLDialect
106116
*/
117+
@Test
107118
public void testLoadSQLDialect() throws Exception {
108119
for (DatabaseType dbType : DatabaseType.values()) {
109120
this.workConf.setDatabaseType(dbType);
@@ -128,6 +139,7 @@ public void testLoadSQLDialect() throws Exception {
128139
/**
129140
* testDumpSQLDialect
130141
*/
142+
@Test
131143
public void testDumpSQLDialect() throws Exception {
132144
for (DatabaseType dbType : DatabaseType.values()) {
133145
this.workConf.setDatabaseType(dbType);
@@ -157,6 +169,7 @@ public void testDumpSQLDialect() throws Exception {
157169
/**
158170
* testSetSQLDialect
159171
*/
172+
@Test
160173
public void testSetSQLDialect() throws Exception {
161174
for (DatabaseType dbType : DatabaseType.values()) {
162175
this.workConf.setDatabaseType(dbType);

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,21 @@
1616

1717
package com.oltpbenchmark.api;
1818

19+
import static org.junit.Assert.assertNotNull;
20+
import static org.junit.Assert.fail;
21+
1922
import com.oltpbenchmark.WorkloadConfiguration;
2023
import com.oltpbenchmark.catalog.AbstractCatalog;
2124
import com.oltpbenchmark.types.DatabaseType;
2225
import com.oltpbenchmark.util.ClassUtil;
23-
import junit.framework.TestCase;
2426
import org.hsqldb.Database;
2527
import org.hsqldb.persist.HsqlProperties;
2628
import org.hsqldb.server.Server;
2729
import org.hsqldb.server.ServerConstants;
30+
import org.junit.After;
31+
import org.junit.Before;
32+
import org.junit.Rule;
33+
import org.junit.rules.TestName;
2834
import org.slf4j.Logger;
2935
import org.slf4j.LoggerFactory;
3036

@@ -34,7 +40,7 @@
3440
import java.util.List;
3541
import java.util.concurrent.atomic.AtomicInteger;
3642

37-
public abstract class AbstractTestCase<T extends BenchmarkModule> extends TestCase {
43+
public abstract class AbstractTestCase<T extends BenchmarkModule> {
3844

3945
protected final Logger LOG = LoggerFactory.getLogger(getClass());
4046

@@ -83,14 +89,17 @@ public AbstractTestCase(boolean createDatabase, boolean loadDatabase, String ddl
8389

8490
public abstract List<String> ignorableTables();
8591

86-
@Override
87-
protected final void setUp() throws Exception {
92+
@Rule
93+
public TestName name = new TestName();
94+
95+
@Before
96+
public final void setUp() throws Exception {
8897
HsqlProperties props = new HsqlProperties();
8998
//props.setProperty("server.remote_open", true);
9099

91100
int port = portCounter.incrementAndGet();
92101

93-
LOG.info("starting HSQLDB server for test [{}] on port [{}]", this.getName(), port);
102+
LOG.info("starting HSQLDB server for test [{}] on port [{}]", name.getMethodName(), port);
94103

95104
server = new Server();
96105
server.setProperties(props);
@@ -174,8 +183,8 @@ protected void postCreateDatabaseSetup() throws IOException {
174183
}
175184

176185

177-
@Override
178-
protected final void tearDown() throws Exception {
186+
@After
187+
public final void tearDown() throws Exception {
179188

180189
if (this.conn != null) {
181190
this.conn.close();

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,14 @@
1717

1818
package com.oltpbenchmark.api;
1919

20+
import static org.junit.Assert.assertFalse;
21+
import static org.junit.Assert.assertNotNull;
22+
import static org.junit.Assert.assertTrue;
23+
2024
import com.oltpbenchmark.catalog.Table;
2125
import com.oltpbenchmark.util.Histogram;
2226
import com.oltpbenchmark.util.SQLUtil;
27+
import org.junit.Test;
2328
import org.slf4j.Logger;
2429
import org.slf4j.LoggerFactory;
2530

@@ -44,6 +49,7 @@ public List<String> ignorableTables() {
4449
/**
4550
* testLoad
4651
*/
52+
@Test
4753
public void testLoad() throws Exception {
4854

4955
this.benchmark.loadDatabase();

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,17 @@
1717

1818
package com.oltpbenchmark.api;
1919

20+
import static org.junit.Assert.assertEquals;
21+
import static org.junit.Assert.assertFalse;
22+
import static org.junit.Assert.assertNotNull;
23+
2024
import com.oltpbenchmark.api.Procedure.UserAbortException;
2125
import org.apache.commons.lang3.time.StopWatch;
2226

2327
import java.io.IOException;
2428
import java.util.List;
2529
import java.util.concurrent.TimeUnit;
30+
import org.junit.Test;
2631

2732
public abstract class AbstractTestWorker<T extends BenchmarkModule> extends AbstractTestCase<T> {
2833

@@ -49,6 +54,7 @@ protected void postCreateDatabaseSetup() throws IOException {
4954
/**
5055
* testGetProcedure
5156
*/
57+
@Test
5258
public void testGetProcedure() {
5359
// Make sure that we can get a Procedure handle for each TransactionType
5460
Worker<?> w = workers.get(0);
@@ -64,6 +70,7 @@ public void testGetProcedure() {
6470
/**
6571
* testExecuteWork
6672
*/
73+
@Test
6774
public void testExecuteWork() throws Exception {
6875

6976
Worker<?> w = workers.get(0);

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package com.oltpbenchmark.api;
22

3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertFalse;
5+
import static org.junit.Assert.assertNotNull;
6+
import static org.junit.Assert.assertTrue;
7+
38
import com.oltpbenchmark.catalog.Table;
49
import com.oltpbenchmark.util.SQLUtil;
510

@@ -8,6 +13,7 @@
813
import java.sql.Statement;
914
import java.util.ArrayList;
1015
import java.util.List;
16+
import org.junit.Test;
1117

1218
public class TestDDLOverride extends AbstractTestCase<MockBenchmark> {
1319

@@ -30,6 +36,7 @@ public List<String> ignorableTables() {
3036
return null;
3137
}
3238

39+
@Test
3340
public void testCreateWithDdlOverride() throws Exception {
3441
this.benchmark.createDatabase();
3542

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,27 @@
1616

1717
package com.oltpbenchmark.api;
1818

19+
import static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertNotNull;
21+
1922
import com.oltpbenchmark.benchmarks.tatp.procedures.DeleteCallForwarding;
2023
import com.oltpbenchmark.types.DatabaseType;
21-
import junit.framework.TestCase;
2224

2325
import java.util.Map;
26+
import org.junit.Before;
27+
import org.junit.Test;
2428

25-
public class TestProcedure extends TestCase {
29+
public class TestProcedure {
2630

27-
@Override
28-
protected void setUp() throws Exception {
31+
@Before
32+
public void setUp() throws Exception {
2933

3034
}
3135

3236
/**
3337
* testGetProcedureName
3438
*/
39+
@Test
3540
public void testGetProcedureName() throws Exception {
3641
DeleteCallForwarding proc = new DeleteCallForwarding();
3742
assertEquals(DeleteCallForwarding.class.getSimpleName(), proc.getProcedureName());
@@ -40,6 +45,7 @@ public void testGetProcedureName() throws Exception {
4045
/**
4146
* testGetStatements
4247
*/
48+
@Test
4349
public void testGetStatements() throws Exception {
4450
Map<String, SQLStmt> stmts = Procedure.getStatements(new DeleteCallForwarding());
4551
assertNotNull(stmts);
@@ -50,6 +56,7 @@ public void testGetStatements() throws Exception {
5056
/**
5157
* testGetStatementsConstructor
5258
*/
59+
@Test
5360
public void testGetStatementsConstructor() throws Exception {
5461
Procedure proc = new DeleteCallForwarding();
5562
proc.initialize(DatabaseType.POSTGRES);

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,17 @@
1717

1818
package com.oltpbenchmark.api;
1919

20-
import junit.framework.TestCase;
20+
import static org.junit.Assert.assertEquals;
21+
import static org.junit.Assert.assertFalse;
2122

22-
public class TestSQLStmt extends TestCase {
23+
import org.junit.Test;
24+
25+
public class TestSQLStmt {
2326

2427
/**
2528
* testSubstitution
2629
*/
30+
@Test
2731
public void testSubstitution() throws Exception {
2832
int ctr = 25;
2933
SQLStmt stmt = new SQLStmt(
@@ -38,6 +42,7 @@ public void testSubstitution() throws Exception {
3842
/**
3943
* testSetSQL
4044
*/
45+
@Test
4146
public void testSetSQL() throws Exception {
4247
int expected = 99;
4348
SQLStmt stmt = new SQLStmt("SELECT * FROM tweets", expected);

src/test/java/com/oltpbenchmark/benchmarks/auctionmark/TestAuctionMarkBenchmark.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
package com.oltpbenchmark.benchmarks.auctionmark;
1919

20+
import static org.junit.Assert.assertNotNull;
21+
import static org.junit.Assert.assertTrue;
22+
2023
import com.oltpbenchmark.api.AbstractTestBenchmarkModule;
2124
import com.oltpbenchmark.api.Procedure;
2225
import com.oltpbenchmark.api.TransactionType;
@@ -26,6 +29,7 @@
2629
import java.io.IOException;
2730
import java.util.List;
2831
import java.util.Map;
32+
import org.junit.Test;
2933

3034
public class TestAuctionMarkBenchmark extends AbstractTestBenchmarkModule<AuctionMarkBenchmark> {
3135

@@ -58,6 +62,7 @@ protected void postCreateDatabaseSetup() throws IOException {
5862
/**
5963
* testCategoryParser
6064
*/
65+
@Test
6166
public void testCategoryParser() throws Exception {
6267
CategoryParser categoryParser = new CategoryParser();
6368
assertNotNull(categoryParser.getCategoryMap());
@@ -67,6 +72,7 @@ public void testCategoryParser() throws Exception {
6772
/**
6873
* testSupplementalClasses
6974
*/
75+
@Test
7076
public void testSupplementalClasses() throws Exception {
7177
// Check to make sure that we have something...
7278
Map<TransactionType, Procedure> procs = this.benchmark.getProcedures();

src/test/java/com/oltpbenchmark/benchmarks/auctionmark/TestAuctionMarkLoader.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616

1717
package com.oltpbenchmark.benchmarks.auctionmark;
1818

19+
import static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertFalse;
21+
import static org.junit.Assert.assertNotNull;
22+
import static org.junit.Assert.assertTrue;
23+
1924
import com.oltpbenchmark.api.AbstractTestLoader;
2025
import com.oltpbenchmark.api.Procedure;
2126
import com.oltpbenchmark.api.Worker;
@@ -27,6 +32,7 @@
2732
import java.util.LinkedList;
2833
import java.util.List;
2934
import java.util.Set;
35+
import org.junit.Test;
3036

3137
public class TestAuctionMarkLoader extends AbstractTestLoader<AuctionMarkBenchmark> {
3238

@@ -43,6 +49,7 @@ public Class<AuctionMarkBenchmark> benchmarkClass() {
4349
/**
4450
* testSaveLoadProfile
4551
*/
52+
@Test
4653
public void testSaveLoadProfile() throws Exception {
4754
AuctionMarkProfile.clearCachedProfile();
4855
AuctionMarkLoader loader = (AuctionMarkLoader) super.testLoadWithReturn();
@@ -58,7 +65,7 @@ public void testSaveLoadProfile() throws Exception {
5865
AuctionMarkWorker worker = (AuctionMarkWorker) workers.get(0);
5966
copy.loadProfile(worker);
6067

61-
assertEquals(orig.scale_factor, copy.scale_factor);
68+
assertEquals(orig.scale_factor, copy.scale_factor, 0.001f);
6269
assertEquals(orig.getLoaderStartTime().toString(), copy.getLoaderStartTime().toString());
6370
assertEquals(orig.getLoaderStopTime().toString(), copy.getLoaderStopTime().toString());
6471
assertEquals(orig.users_per_itemCount, copy.users_per_itemCount);
@@ -67,6 +74,7 @@ public void testSaveLoadProfile() throws Exception {
6774
/**
6875
* testLoadProfilePerClient
6976
*/
77+
@Test
7078
public void testLoadProfilePerClient() throws Exception {
7179
// We don't have to reload our cached profile here
7280
// We just want to make sure that each client's profile contains a unique

0 commit comments

Comments
 (0)