Created
July 18, 2016 10:25
-
-
Save Narigo/39f0cf576f706ff7b23a16f640e2f764 to your computer and use it in GitHub Desktop.
Test for Vertx 3 Scala support
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.vertx.lang.scala.http | |
import io.vertx.core.file.OpenOptions | |
import io.vertx.scala.core.Vertx | |
import io.vertx.scala.core.streams.Pump | |
import org.junit.runner.RunWith | |
import org.scalatest.concurrent.AsyncAssertions | |
import org.scalatest.junit.JUnitRunner | |
import org.scalatest.{FlatSpec, Matchers} | |
/** | |
* @author <a href="mailto:[email protected]">Joern Bernhardt</a> | |
*/ | |
@RunWith(classOf[JUnitRunner]) | |
class HttpDownloadTest extends FlatSpec with Matchers with AsyncAssertions { | |
"A HttpClient" should "be able to download something" in { | |
val w = new Waiter | |
val vertx = Vertx.vertx() | |
val httpServer = vertx.createHttpServer() | |
val client = vertx.createHttpClient() | |
val fs = vertx.fileSystem() | |
val testFile = fs.openBlocking("testfile.txt", new OpenOptions()) | |
val outFile = fs.openBlocking("testfile.out", new OpenOptions().setCreate(true)) | |
println("hello") | |
httpServer.requestHandler({ req => | |
println("got a request") | |
req.response().setChunked(true) | |
Pump.pump(testFile, req.response()).start() | |
println("pumping!") | |
testFile.endHandler({() => | |
println("pumped testFile into request") | |
req.response().end() | |
}) | |
}) | |
httpServer.listen(14432, { ar => | |
assert(ar.succeeded()) | |
println("server listens, sending a request") | |
client.getNow(14432, "localhost", "/testfile", { response => | |
println("client gets response") | |
Pump.pump(response, outFile).start() | |
response.endHandler({ () => | |
println("response done") | |
w.dismiss() | |
}) | |
}) | |
}) | |
w.await() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment