get existing tests to pass

pull/5/head
Zlatin Balevsky 2019-06-21 05:41:49 +01:00
parent b23226e8c6
commit f9777d29f4
2 changed files with 10 additions and 3 deletions

View File

@ -88,7 +88,8 @@ class DownloadSession {
os.write("X-Persona: $meB64\r\n\r\n".getBytes(StandardCharsets.US_ASCII))
os.flush()
String codeString = readTillRN(is)
codeString = codeString.substring(codeString.indexOf(' '))
int space = codeString.indexOf(' ')
codeString = codeString.substring(0, space)
int code = Integer.parseInt(codeString.trim())

View File

@ -9,6 +9,7 @@ import com.muwire.core.files.FileHasher
import static com.muwire.core.util.DataUtil.readTillRN
import net.i2p.data.Base64
import net.i2p.util.ConcurrentHashSet
class DownloadSessionTest {
@ -24,6 +25,9 @@ class DownloadSessionTest {
private InputStream fromDownloader, fromUploader
private OutputStream toDownloader, toUploader
private volatile boolean performed
private Set<Integer> available = new ConcurrentHashSet<>()
private void initSession(int size, def claimedPieces = []) {
Random r = new Random()
byte [] content = new byte[size]
@ -56,8 +60,8 @@ class DownloadSessionTest {
toUploader = new PipedOutputStream(fromDownloader)
endpoint = new Endpoint(null, fromUploader, toUploader, null)
session = new DownloadSession("",pieces, infoHash, endpoint, target, pieceSize, size)
downloadThread = new Thread( { session.request() } as Runnable)
session = new DownloadSession("",pieces, infoHash, endpoint, target, pieceSize, size, available)
downloadThread = new Thread( { performed = session.request() } as Runnable)
downloadThread.setDaemon(true)
downloadThread.start()
}
@ -87,6 +91,8 @@ class DownloadSessionTest {
assert pieces.isComplete()
assert target.bytes == source.bytes
assert performed
assert available.isEmpty()
}
@Test