diff options
| author | luccioman <luccioman@users.noreply.github.com> | 2017-11-08 09:33:30 +0100 |
|---|---|---|
| committer | luccioman <luccioman@users.noreply.github.com> | 2017-11-08 09:33:30 +0100 |
| commit | fcd57e2d0f19955bfa58329fda9075cd4405d902 (patch) | |
| tree | 8a386118181e14217d0c9250a8f108a20d8c2574 /test | |
| parent | e0eda84c246c59b28fd4d4d2e40209d4e53dbacd (diff) | |
Improved some JUnit tests isolation and resources release
The modified tests were successfull when run manually from an IDE such
as Eclipse, but failed occasionnally when run with maven as part of the
overall test suite.
Diffstat (limited to 'test')
| -rw-r--r-- | test/java/net/yacy/kelondro/io/RecordsTest.java | 37 | ||||
| -rw-r--r-- | test/java/net/yacy/search/index/SegmentTest.java | 23 |
2 files changed, 38 insertions, 22 deletions
diff --git a/test/java/net/yacy/kelondro/io/RecordsTest.java b/test/java/net/yacy/kelondro/io/RecordsTest.java index 6b49e5a47..26a65d1c2 100644 --- a/test/java/net/yacy/kelondro/io/RecordsTest.java +++ b/test/java/net/yacy/kelondro/io/RecordsTest.java @@ -9,26 +9,26 @@ import org.junit.Test; public class RecordsTest {
- final String tesDir = "test/DATA/INDEX/QUEUE";
-
/**
* Test of cleanLast method, of class Records.
*/
@Test
public void testCleanLast_byteArr_int() throws Exception {
- File tablefile = new File(tesDir, "test.stack");
-
+ File tablefile = new File(System.getProperty("java.io.tmpdir"), "test1.stack");
byte[] b = ASCII.getBytes("testDataString");
Records rec = new Records(tablefile, b.length);
-
- rec.add(b, 0); // add some data
-
- for (int i = 0; i < 5; i++) { // multiple cleanlast
- rec.cleanLast(b, 0);
+
+ try {
+ rec.add(b, 0); // add some data
+
+ for (int i = 0; i < 5; i++) { // multiple cleanlast
+ rec.cleanLast(b, 0);
+ }
+ assertEquals(0,rec.size());
+ } finally {
+ rec.close();
}
- assertEquals(0,rec.size());
- rec.close();
}
/**
@@ -37,16 +37,19 @@ public class RecordsTest { @Test
public void testCleanLast() throws Exception {
- File tablefile = new File (tesDir,"test.stack");
+ File tablefile = new File (System.getProperty("java.io.tmpdir"),"test2.stack");
byte[] b = ASCII.getBytes("testdata");
Records rec = new Records(tablefile, b.length);
- rec.add(b, 0); // add data
- for (int i = 0; i < 5; i++) { // multiple cleanLast
- rec.cleanLast();
+ try {
+ rec.add(b, 0); // add data
+ for (int i = 0; i < 5; i++) { // multiple cleanLast
+ rec.cleanLast();
+ }
+ assertEquals(0,rec.size());
+ } finally {
+ rec.close();
}
- assertEquals(0,rec.size());
- rec.close();
}
}
diff --git a/test/java/net/yacy/search/index/SegmentTest.java b/test/java/net/yacy/search/index/SegmentTest.java index 3614879fa..c75a54e14 100644 --- a/test/java/net/yacy/search/index/SegmentTest.java +++ b/test/java/net/yacy/search/index/SegmentTest.java @@ -23,23 +23,26 @@ import net.yacy.kelondro.rwi.ReferenceFactory; import net.yacy.kelondro.rwi.TermSearch;
import net.yacy.kelondro.util.Bitfield;
import net.yacy.search.query.QueryGoal;
+
+import org.junit.After;
import org.junit.AfterClass;
+import org.junit.Before;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import org.junit.BeforeClass;
import org.junit.Test;
public class SegmentTest {
- static Segment index;
+ Segment index;
/**
* Setup RWI index
*
* @throws IOException
*/
- @BeforeClass
- public static void setUpClass() throws IOException {
+ @Before
+ public void setUp() throws IOException {
// setup a index segment
index = new Segment(new ConcurrentLog("SegmentTest"),
new File("test/DATA/INDEX/webportal/SEGMENTS"),
@@ -50,9 +53,19 @@ public class SegmentTest { index.connectRWI(10, 1024);
}
+ @After
+ public void tearDown() {
+ if(index != null) {
+ try {
+ index.clear();
+ } finally {
+ index.close();
+ }
+ }
+ }
+
@AfterClass
public static void tearDownClass() {
- index.close();
ConcurrentLog.shutdown();
}
|
