Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

test case: for NewsPool to check the id modificator (for unique id) and observe the distribution order .. hands on. + add test/DATA to gitignor

reger585d2a644146
diff --git a/.gitignore b/.gitignore
index fdc434760..788ae08e6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -16,4 +16,5 @@ RELEASE/
/winDATA.bkp/
/DATA.cloud/
yacy.log
-/target/
\ No newline at end of file
+/target/
+/test/DATA/
\ No newline at end of file
diff --git a/source/net/yacy/peers/NewsPool.java b/source/net/yacy/peers/NewsPool.java
index a16a8bcce..9fdfdb8cc 100644
--- a/source/net/yacy/peers/NewsPool.java
+++ b/source/net/yacy/peers/NewsPool.java
@@ -333,6 +333,16 @@ public class NewsPool {
}
}
+ /**
+ * Gets the last news in the outgoing queue, increases the distribution
+ * counter of the message and put's it back into the outgoingNews queue or
+ * if distribution count is above maxDistribution (default = 30) into the
+ * publishedNews queue.
+ *
+ * @return current news Record or null if outgoingNews queue is empty
+ * @throws IOException
+ * @throws SpaceExceededException
+ */
public NewsDB.Record myPublication() throws IOException, SpaceExceededException {
// generate a record for next peer-ping
if (this.outgoingNews.isEmpty()) return null;
diff --git a/test/java/net/yacy/peers/NewsPoolTest.java b/test/java/net/yacy/peers/NewsPoolTest.java
new file mode 100644
index 000000000..3fa45ef22
--- /dev/null
+++ b/test/java/net/yacy/peers/NewsPoolTest.java
@@ -0,0 +1,80 @@
+package net.yacy.peers;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.LinkedHashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import net.yacy.cora.document.encoding.ASCII;
+import net.yacy.kelondro.data.word.Word;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+public class NewsPoolTest {
+
+ static NewsPool newsPool;
+
+ public NewsPoolTest() {
+
+ }
+
+ @BeforeClass
+ public static void setUpClass() {
+ String networkpath = "test/DATA/INDEX/webportal/NETWORK";
+ newsPool = new NewsPool(new File(networkpath), false, true);
+ }
+
+ @AfterClass
+ public static void tearDownClass() {
+ newsPool.close();
+ }
+
+ /**
+ * Test of myPublication method, of class NewsPool.
+ */
+ @Test
+ public void testMyPublication() throws Exception {
+
+ // create a test seed as sender
+ ConcurrentMap<String, String> dna = new ConcurrentHashMap<String, String>();
+ byte[] hash = Word.word2hash("myseed"); // just generate any hash for testing
+ Seed myseed = new Seed(ASCII.String(hash), dna);
+
+ // generate 3 test messages and simulate publish (put in outgoing queuq
+ Map<String, String> msgattr = new HashMap();
+ for (int i = 1; i <= 3; i++) {
+ msgattr.put("text", "message " + Integer.toString(i));
+ msgattr.put("#", Integer.toString(i)); // use id modificator attribute (to generate unique id for same creation second, used in id)
+ newsPool.publishMyNews(myseed, "TestCat", msgattr); // add msg to outgoing queue
+ }
+
+ // test the distribution process
+ Set<String> resultmemory = new LinkedHashSet();
+ NewsDB.Record rec = newsPool.myPublication();
+ int cnt = 3 * 30 + 5; // end condition (3 msg * 30 distribution) for loop (+5 > as expected count)
+ while (rec != null && cnt > 0) {
+ // System.out.println(rec.toString());
+ assertTrue(rec.distributed() > 0);
+ resultmemory.add(rec.id());
+
+ cnt--;
+ rec = newsPool.myPublication();
+ }
+ assertTrue(cnt == 5); // test total counter
+
+ // test news record in published queue
+ cnt = 1;
+ for (String msgid : resultmemory) {
+ NewsDB.Record msg = newsPool.getByID(NewsPool.PUBLISHED_DB, msgid);
+ System.out.println(cnt + ". news published: \"" + msg.attribute("text", "***missing***") + "\" distributed=" + msg.distributed());
+ assertEquals("default distributin count", 30, msg.distributed()); // test expected distribution count
+ cnt++;
+ }
+
+ }
+
+}