test for persistence of destinations of downloaded file

This commit is contained in:
Zlatin Balevsky
2018-07-20 21:26:51 +01:00
parent acc9355372
commit 6bb5cb5f4c
2 changed files with 43 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
package com.muwire.core
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")
}

View File

@@ -3,6 +3,8 @@ package com.muwire.core.files
import org.junit.Before
import org.junit.Test
import com.muwire.core.Destinations
import com.muwire.core.DownloadedFile
import com.muwire.core.EventBus
import com.muwire.core.InfoHash
import com.muwire.core.SharedFile
@@ -163,4 +165,36 @@ class PersisterServiceTest {
assert loadedFile2.file == sharedFile2.getCanonicalFile()
assert loadedFile2.infoHash == ih2
}
@Test
void testDownloadedFile() {
writeToSharedFile(sharedFile1, 1)
FileHasher fh = new FileHasher()
InfoHash ih1 = fh.hashFile(sharedFile1)
File persisted = initPersisted()
Destinations dests = new Destinations()
def json1 = [:]
json1.file = sharedFile1.getCanonicalFile().toString()
json1.length = 1
json1.infoHash = Base32.encode(ih1.getRoot())
json1.hashList = [Base32.encode(ih1.getHashList())]
json1.sources = [ dests.dest1.toBase64(), dests.dest2.toBase64()]
json1 = JsonOutput.toJson(json1)
persisted.write json1
PersisterService ps = new PersisterService(persisted, eventBus, 100, null)
ps.start()
Thread.sleep(2000)
assert listener.publishedFiles.size() == 1
def loadedFile1 = listener.publishedFiles[0]
assert loadedFile1 instanceof DownloadedFile
assert loadedFile1.sources.size() == 2
assert loadedFile1.sources.contains(dests.dest1)
assert loadedFile1.sources.contains(dests.dest2)
}
}