Skip to content

Commit 5aef216

Browse files
test: make TestOrientDBStoreWordCount deterministic
1 parent cc01c18 commit 5aef216

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

gora-orientdb/src/test/java/org/apache/gora/orientdb/GoraOrientDBTestDriver.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,14 @@ public void setUpClass() throws Exception {
6161
*/
6262
@Override
6363
public void tearDownClass() throws Exception {
64-
server.shutdown();
65-
log.info("OrientDB Embedded Server terminated successfully.");
64+
if (server != null) {
65+
try {
66+
server.shutdown();
67+
log.info("OrientDB Embedded Server terminated successfully.");
68+
} finally {
69+
server = null;
70+
}
71+
}
6672
}
6773

6874
@Override

gora-orientdb/src/test/java/org/apache/gora/orientdb/mapreduce/TestOrientDBStoreWordCount.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
import org.apache.gora.orientdb.store.OrientDBStore;
2626
import org.apache.gora.store.DataStoreFactory;
2727
import org.junit.After;
28+
import org.junit.AfterClass;
2829
import org.junit.Before;
30+
import org.junit.BeforeClass;
2931
import org.junit.Test;
3032

3133
/**
@@ -39,20 +41,29 @@ public class TestOrientDBStoreWordCount {
3941

4042
protected static GoraTestDriver testDriver = new GoraOrientDBTestDriver();
4143

44+
@BeforeClass
45+
public static void startOrientDb() throws Exception {
46+
testDriver.setUpClass();
47+
}
48+
49+
@AfterClass
50+
public static void stopOrientDb() throws Exception {
51+
testDriver.tearDownClass();
52+
}
53+
54+
@SuppressWarnings("unchecked")
4255
@Before
4356
public void setUp() throws Exception {
44-
testDriver.setUpClass();
45-
webPageStore = DataStoreFactory.getDataStore(OrientDBStore.class,
46-
String.class, WebPage.class, testDriver.getConfiguration());
47-
tokenStore = DataStoreFactory.getDataStore(OrientDBStore.class, String.class,
48-
TokenDatum.class, testDriver.getConfiguration());
57+
testDriver.setUp();
58+
webPageStore = (OrientDBStore<String, WebPage>) testDriver.createDataStore(String.class, WebPage.class);
59+
tokenStore = (OrientDBStore<String, TokenDatum>) testDriver.createDataStore(String.class, TokenDatum.class);
4960
}
5061

5162
@After
5263
public void tearDown() throws Exception {
53-
webPageStore.close();
54-
tokenStore.close();
55-
testDriver.tearDownClass();
64+
testDriver.tearDown();
65+
webPageStore = null;
66+
tokenStore = null;
5667
}
5768

5869
@Test

0 commit comments

Comments
 (0)