Permalink
Browse files

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.
  • Loading branch information...
luccioman committed Nov 8, 2017
1 parent e0eda84 commit fcd57e2d0f19955bfa58329fda9075cd4405d902
Showing with 38 additions and 22 deletions.
  1. +20 −17 test/java/net/yacy/kelondro/io/RecordsTest.java
  2. +18 −5 test/java/net/yacy/search/index/SegmentTest.java
@@ -9,26 +9,26 @@
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 void testCleanLast_byteArr_int() throws Exception {
@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();
}
}
@@ -23,23 +23,26 @@
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 static void setUpClass() throws IOException {
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();
}

0 comments on commit fcd57e2

Please sign in to comment.