test case: for NewsPool to check the id modificator (for unique id)

and observe the distribution order .. hands on.
+ add test/DATA to gitignor
pull/77/head
reger 8 years ago
parent de5c873e38
commit 585d2a6441

3
.gitignore vendored

@ -16,4 +16,5 @@ RELEASE/
/winDATA.bkp/
/DATA.cloud/
yacy.log
/target/
/target/
/test/DATA/

@ -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;

@ -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++;
}
}
}
Loading…
Cancel
Save