Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
Improved some JUnit tests isolation and resources release
lucciomanfcd57e2d0f19
diff --git a/test/java/net/yacy/kelondro/io/RecordsTest.java b/test/java/net/yacy/kelondro/io/RecordsTest.javaindex 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.*/@Testpublic 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 {@Testpublic 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.javaindex 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 segmentindex = 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();+ }+ }+ }+@AfterClasspublic static void tearDownClass() {- index.close();ConcurrentLog.shutdown();}