fix import, more tests

This commit is contained in:
Zlatin Balevsky
2018-07-11 17:49:16 +01:00
parent c6b32b81df
commit 04afbb6158
3 changed files with 74 additions and 0 deletions

View File

@ -1,5 +1,7 @@
package com.muwire.hostcache
import java.util.stream.Collectors
import net.i2p.data.Destination
class Crawler {

View File

@ -18,7 +18,10 @@ class CrawlerTest {
def crawler
Destinations destinations = new Destinations()
final Host host = new Host(destination: new Destination())
final Host host1 = new Host(destination: destinations.dest1)
final Host host2 = new Host(destination: destinations.dest2)
final int parallel = 5
@ -72,4 +75,64 @@ class CrawlerTest {
crawler.startCrawl()
crawler.startCrawl()
}
@Test
void testVerifiesAnswered() {
def currentUUID
hostPoolMock.demand.getUnverified { n -> [host1] }
hostPoolMock.demand.verify { h -> assert h == host1 }
pingerMock.demand.ping { h, uuid -> currentUUID = uuid }
initCrawler()
crawler.startCrawl()
def pong = [uuid : currentUUID.toString(), leafSlots : "false", peerSlots: "false", peers: [] ]
crawler.handleCrawlerPong(pong, host1.destination)
}
@Test
void testWrongSourceIgnored() {
def currentUUID
hostPoolMock.demand.getUnverified { n -> [host1] }
pingerMock.demand.ping { h, uuid -> currentUUID = uuid }
initCrawler()
crawler.startCrawl()
def pong = [uuid : currentUUID.toString(), leafSlots : "false", peerSlots: "false", peers: [] ]
crawler.handleCrawlerPong(pong, host2.destination)
}
@Test
void testHost1CarriesHost2() {
def currentUUID
hostPoolMock.demand.getUnverified { n -> [host1] }
hostPoolMock.demand.addUnverified { h -> assert h == host2 }
hostPoolMock.demand.verify { h -> assert h == host1 }
pingerMock.demand.ping { h, uuid -> currentUUID = uuid }
initCrawler()
crawler.startCrawl()
def pong = [uuid : currentUUID.toString(), leafSlots : "false", peerSlots: "false", peers: [destinations.dest2.toBase64()] ]
crawler.handleCrawlerPong(pong, host1.destination)
}
@Test
void testWrongUUID() {
def currentUUID
hostPoolMock.demand.getUnverified { n -> [host1] }
hostPoolMock.demand.fail { h -> assert h == host1 }
pingerMock.demand.ping { h, uuid -> currentUUID = uuid }
initCrawler()
crawler.startCrawl()
def pong = [uuid : UUID.randomUUID().toString(), leafSlots : "false", peerSlots: "false", peers: [] ]
crawler.handleCrawlerPong(pong, host1.destination)
}
}

View File

@ -0,0 +1,9 @@
package com.muwire.hostcache
import net.i2p.data.Destination
class Destinations {
Destination dest1 = new Destination("KvwWPKMSAtzf7Yruj8TQaHi2jaQpSNsXJskbpmSBTxkcYlDB2GllH~QBu-cs4FSYdaRmKDUUx7793jjnYJgTMbrjqeIL5-BTORZ09n6PUfhSejDpJjdkUxaV1OHRatfYs70RNBv7rvdj1-nXUow5tMfOJtoWVocUoKefUGFQFbJLDDkBqjm1kFyKFZv6m6S6YqXxBgVB1qYicooy67cNQF5HLUFtP15pk5fMDNGz5eNCjPfC~2Gp8FF~OpSy92HT0XN7uAMJykPcbdnWfcvVwqD7eS0K4XEnsqnMPLEiMAhqsugEFiFqtB3Wmm7UHVc03lcAfRhr1e2uZBNFTtM2Uol4MD5sCCKRZVHGcH-WGPSEz0BM5YO~Xi~dQ~N3NVud32PVzhh8xoGcAlhTqMqAbRJndCv-H6NflX90pYmbirCTIDOaR9758mThrqX0d4CwCn4jFXer52l8Qe8CErGoLuB-4LL~Gwrn7R1k7ZQc2PthkqeW8MfigyiN7hZVkul9AAAA")
Destination dest2 = new Destination("KvwWPKMSAtzf7Yruj8TQaHi2jaQpSNsXJskbpmSBTxkcYlDB2GllH~QBu-cs4FSYdaRmKDUUx7793jjnYJgTMbrjqeIL5-BTORZ09n6PUfhSejDpJjdkUxaV1OHRatfYs70RNBv7rvdj1-nXUow5tMfOJtoWVocUoKefUGFQFbJLDDkBqjm1kFyKFZv6m6S6YqXxBgVB1qYicooy67cNQF5HLUFtP15pk5fMDNGz5eNCjPfC~2Gp8FF~OpSy92HT0XN7uAMJykPcbdnWfcvVwqD7eS0K4XEnsqnMPLEiMAhqsugEFiFqtB3Wmm7UHVc03lcAfRhr1e2uZBNFTtM2Uol4MD5sCCKRZVHGcH-WGPSEz0BM5YO~Xi~dQ~N3NVud32PVzhh8xoGcAlhTqMqAbRJndCv-H6NflX90pYmbirCTIDOaR9758mThrqX0d4CwCn4jFXer52l8Qe8CErGoLuB-4LL~Gwrn7R1k7ZQc2PthkqeW8MfigyiN7hZVkul8AAAA")
}