diff --git a/host-cache/src/main/groovy/com/muwire/hostcache/Crawler.groovy b/host-cache/src/main/groovy/com/muwire/hostcache/Crawler.groovy index aa280bbb..06eeca83 100644 --- a/host-cache/src/main/groovy/com/muwire/hostcache/Crawler.groovy +++ b/host-cache/src/main/groovy/com/muwire/hostcache/Crawler.groovy @@ -1,5 +1,7 @@ package com.muwire.hostcache +import java.util.stream.Collectors + import net.i2p.data.Destination class Crawler { diff --git a/host-cache/src/test/groovy/com/muwire/hostcache/CrawlerTest.groovy b/host-cache/src/test/groovy/com/muwire/hostcache/CrawlerTest.groovy index 6b407346..05b65bcc 100644 --- a/host-cache/src/test/groovy/com/muwire/hostcache/CrawlerTest.groovy +++ b/host-cache/src/test/groovy/com/muwire/hostcache/CrawlerTest.groovy @@ -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) + } } diff --git a/host-cache/src/test/groovy/com/muwire/hostcache/Destinations.groovy b/host-cache/src/test/groovy/com/muwire/hostcache/Destinations.groovy new file mode 100644 index 00000000..d843c9e3 --- /dev/null +++ b/host-cache/src/test/groovy/com/muwire/hostcache/Destinations.groovy @@ -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") +}