This commit is contained in:
parent
b285769cfd
commit
701412d7c2
@ -15,8 +15,6 @@ fun main(args: Array<String>): Unit = io.ktor.server.tomcat.EngineMain.main(args
|
|||||||
@kotlin.jvm.JvmOverloads
|
@kotlin.jvm.JvmOverloads
|
||||||
fun Application.module(testing: Boolean = false) {
|
fun Application.module(testing: Boolean = false) {
|
||||||
runBlocking {
|
runBlocking {
|
||||||
val cachedFile = File("/app/wave.wav").readBytes()
|
|
||||||
val gson = GsonBuilder().setPrettyPrinting().create()
|
|
||||||
var startTime : Instant
|
var startTime : Instant
|
||||||
var elapsed = Duration.ofSeconds(0)
|
var elapsed = Duration.ofSeconds(0)
|
||||||
val targetTime = Duration.ofSeconds(System.getenv("WAITTIME").toLong())
|
val targetTime = Duration.ofSeconds(System.getenv("WAITTIME").toLong())
|
||||||
@ -30,7 +28,7 @@ fun Application.module(testing: Boolean = false) {
|
|||||||
println("Starting benchmark")
|
println("Starting benchmark")
|
||||||
startTime = Instant.now()
|
startTime = Instant.now()
|
||||||
while(elapsed < targetTime){
|
while(elapsed < targetTime){
|
||||||
uploader.uploadData(currIter, gson, cachedFile)
|
uploader.uploadData(currIter)
|
||||||
currIter+=1
|
currIter+=1
|
||||||
currTimeStamp = Instant.now()
|
currTimeStamp = Instant.now()
|
||||||
timestamps[currIter] = currTimeStamp
|
timestamps[currIter] = currTimeStamp
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.kmlabz.k8s
|
package com.kmlabz.k8s
|
||||||
|
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
|
import com.google.gson.GsonBuilder
|
||||||
import io.ktor.client.*
|
import io.ktor.client.*
|
||||||
import io.ktor.client.engine.apache.*
|
import io.ktor.client.engine.apache.*
|
||||||
import io.ktor.client.request.*
|
import io.ktor.client.request.*
|
||||||
@ -8,31 +9,33 @@ import io.ktor.client.request.forms.*
|
|||||||
import io.ktor.http.*
|
import io.ktor.http.*
|
||||||
import io.ktor.http.content.*
|
import io.ktor.http.content.*
|
||||||
import io.ktor.util.*
|
import io.ktor.util.*
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
class Uploader(){
|
class Uploader(){
|
||||||
|
private val gson = GsonBuilder().setPrettyPrinting().create()
|
||||||
|
private val inputSound = File("/app/wave.wav").readBytes()
|
||||||
|
val parts: List<PartData> = formData {
|
||||||
|
val headersBuilder = HeadersBuilder()
|
||||||
|
headersBuilder[HttpHeaders.ContentType] = "audio/wave"
|
||||||
|
headersBuilder[HttpHeaders.ContentDisposition] = "filename=csirip.wav"
|
||||||
|
this.append(
|
||||||
|
"file",
|
||||||
|
inputSound,
|
||||||
|
headersBuilder.build()
|
||||||
|
)
|
||||||
|
val inputSvcApi = InputSvcApi("2020-02-02T02:02:02", 1)
|
||||||
|
val jsonHeadersBuilder = HeadersBuilder()
|
||||||
|
jsonHeadersBuilder[HttpHeaders.ContentType] = "application/json"
|
||||||
|
this.append(
|
||||||
|
"description",
|
||||||
|
gson.toJson(inputSvcApi),
|
||||||
|
jsonHeadersBuilder.build()
|
||||||
|
)
|
||||||
|
}
|
||||||
@KtorExperimentalAPI
|
@KtorExperimentalAPI
|
||||||
suspend fun uploadData(currIteration: Int, gson: Gson, inputSound: ByteArray) {
|
suspend fun uploadData(currIteration: Int) {
|
||||||
HttpClient(Apache).use { client ->
|
HttpClient(Apache).use { client ->
|
||||||
|
|
||||||
val parts: List<PartData> = formData {
|
|
||||||
val headersBuilder = HeadersBuilder()
|
|
||||||
headersBuilder[HttpHeaders.ContentType] = "audio/wave"
|
|
||||||
headersBuilder[HttpHeaders.ContentDisposition] = "filename=csirip.wav"
|
|
||||||
this.append(
|
|
||||||
"file",
|
|
||||||
inputSound,
|
|
||||||
headersBuilder.build()
|
|
||||||
)
|
|
||||||
val inputSvcApi = InputSvcApi("2020-02-02T02:02:02", currIteration)
|
|
||||||
val jsonHeadersBuilder = HeadersBuilder()
|
|
||||||
jsonHeadersBuilder[HttpHeaders.ContentType] = "application/json"
|
|
||||||
this.append(
|
|
||||||
"description",
|
|
||||||
gson.toJson(inputSvcApi),
|
|
||||||
jsonHeadersBuilder.build()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
client.submitFormWithBinaryData<Unit>(formData = parts) {
|
client.submitFormWithBinaryData<Unit>(formData = parts) {
|
||||||
url(System.getenv("URL") ?: "https://birb.k8s.kmlabz.com/benchmark")
|
url(System.getenv("URL") ?: "https://birb.k8s.kmlabz.com/benchmark")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user