@Test
public void testMongoDBWebSiteUrlFifoQueue() {
try {
IDBConnection dbConnection = DBConnectionFactory.getDBConnectionInstance("mongodb", "localhost", 27017, "", "");
ISourceItemsQueue queue = QueueFactory.getSourceItemsQueueInstance("mongodb", 1, dbConnection, "testFifoQueue", "TestMongoDBWebSiteUrlFifoQueue");
if (queue!=null) {
queue.reset();
queue.start();
assertEquals(0, queue.size());
assertTrue(queue.push(getItemWeb(1, "http://a.a.a/", 0).getMap()));
assertTrue(queue.push(getItemWeb(1, "http://a.a.a/2.html", 1).getMap()));
assertTrue(queue.push(getItemWeb(1, "http://a.a.a/3.html", 2).getMap()));
assertTrue(queue.contains("http://a.a.a/"));
assertEquals(3, queue.size());
assertEquals(0, queue.getDoneQueueSize());
assertFalse(queue.isDone("http://a.a.a/"));
assertEquals("http://a.a.a/", queue.pop().get("url"));
assertEquals("http://a.a.a/2.html", queue.pop().get("url"));
assertEquals("http://a.a.a/3.html", queue.pop().get("url"));
assertEquals(3, queue.getDoneQueueSize());
assertTrue(queue.isDone("http://a.a.a/"));
assertFalse(queue.contains("http://a.a.a/"));
assertEquals(0, queue.size());
assertFalse(queue.push(getItemWeb(1, "http://a.a.a/", 0).getMap()));
assertTrue(queue.push(getItemWeb(1, "http://a.a.a/4.html", 2).getMap()));
assertTrue(queue.push(getItemWeb(1, "http://a.a.a/3.html", 1).getMap()));
assertFalse(queue.push(getItemWeb(1, "http://a.a.a/2.html", 2).getMap()));
assertEquals(2, queue.size());
assertEquals("http://a.a.a/3.html", queue.pop("depth").get("url"));
assertEquals("http://a.a.a/4.html", queue.pop("depth").get("url"));
assertEquals(0, queue.size());
}
queue = QueueFactory.getSourceItemsQueueInstance("mongodb", 1, dbConnection, "testFifoQueue", "TestMongoDBWebSiteUrlFifoQueue");
if (queue!=null) {
queue.start();
assertEquals(0, queue.size());
assertFalse(queue.push(getItemWeb(1, "http://a.a.a/", 0).getMap()));
queue.stop();
}
queue = QueueFactory.getSourceItemsQueueInstance("mongodb", 1, dbConnection, "testFifoQueue", "TestMongoDBWebSiteUrlFifoQueue");
if (queue!=null) {
queue.start();
assertEquals(0, queue.size());
assertTrue(queue.push(getItemWeb(1, "http://a.a.a/", 0).getMap()));
}
}
catch (Exception e) {
e.printStackTrace();
}