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,12 +9,11 @@ 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(){
|
||||||
@KtorExperimentalAPI
|
private val gson = GsonBuilder().setPrettyPrinting().create()
|
||||||
suspend fun uploadData(currIteration: Int, gson: Gson, inputSound: ByteArray) {
|
private val inputSound = File("/app/wave.wav").readBytes()
|
||||||
HttpClient(Apache).use { client ->
|
|
||||||
|
|
||||||
val parts: List<PartData> = formData {
|
val parts: List<PartData> = formData {
|
||||||
val headersBuilder = HeadersBuilder()
|
val headersBuilder = HeadersBuilder()
|
||||||
headersBuilder[HttpHeaders.ContentType] = "audio/wave"
|
headersBuilder[HttpHeaders.ContentType] = "audio/wave"
|
||||||
@ -23,7 +23,7 @@ class Uploader(){
|
|||||||
inputSound,
|
inputSound,
|
||||||
headersBuilder.build()
|
headersBuilder.build()
|
||||||
)
|
)
|
||||||
val inputSvcApi = InputSvcApi("2020-02-02T02:02:02", currIteration)
|
val inputSvcApi = InputSvcApi("2020-02-02T02:02:02", 1)
|
||||||
val jsonHeadersBuilder = HeadersBuilder()
|
val jsonHeadersBuilder = HeadersBuilder()
|
||||||
jsonHeadersBuilder[HttpHeaders.ContentType] = "application/json"
|
jsonHeadersBuilder[HttpHeaders.ContentType] = "application/json"
|
||||||
this.append(
|
this.append(
|
||||||
@ -32,6 +32,9 @@ class Uploader(){
|
|||||||
jsonHeadersBuilder.build()
|
jsonHeadersBuilder.build()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@KtorExperimentalAPI
|
||||||
|
suspend fun uploadData(currIteration: Int) {
|
||||||
|
HttpClient(Apache).use { client ->
|
||||||
|
|
||||||
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