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.
pull/144/head
luccioman 7 years ago
parent e0eda84c24
commit fcd57e2d0f

@ -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();
}
}

@ -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();
}

Loading…
Cancel
Save