Skip to content

Commit

Permalink
spike: marks computed config fields as transient.
Browse files Browse the repository at this point in the history
  • Loading branch information
outofcoffee committed Jul 8, 2024
1 parent 41e7279 commit 6a6f93f
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ class ImposterLauncher(args: Array<String>) {

@JvmStatic
fun main(args: Array<String>) {
println("Ready")
readln()
LogUtil.configureLoggingFromEnvironment()
LogUtil.configureVertxLogging()
ImposterLauncher(args)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ open class CaptureConfig(
@field:JsonProperty("jsonPath")
private val jsonPath: String? = null

val requestBody: BodyCaptureConfig by lazy { BodyCaptureConfig.parse(_requestBody, jsonPath) }
@delegate:Transient
open val requestBody: BodyCaptureConfig by lazy { BodyCaptureConfig.parse(_requestBody, jsonPath) }

override fun toString(): String {
return "CaptureConfig(pathParam=$pathParam, queryParam=$queryParam, formParam=$formParam, requestHeader=$requestHeader, jsonPath=$jsonPath, expression=$expression, constValue=$constValue)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ class ItemCaptureConfig(
expression,
constValue,
) {
@delegate:Transient
val key: CaptureConfig? by lazyParse(_key, CaptureConfig)

@delegate:Transient
val store: CaptureConfig? by lazyParse(_store, CaptureConfig)

override val requestBody
get() = super.requestBody
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,14 @@ import com.fasterxml.jackson.annotation.JsonProperty
import io.gatehill.imposter.http.HttpMethod
import io.gatehill.imposter.plugin.config.resource.conditional.ConditionalNameValuePair
import io.gatehill.imposter.plugin.config.resource.conditional.MatchOperator
import io.gatehill.imposter.plugin.config.resource.request.*
import io.gatehill.imposter.plugin.config.resource.request.FormParamsResourceConfig
import io.gatehill.imposter.plugin.config.resource.request.LegacyQueryParamsResourceConfig
import io.gatehill.imposter.plugin.config.resource.request.MethodResourceConfig
import io.gatehill.imposter.plugin.config.resource.request.PathParamsResourceConfig
import io.gatehill.imposter.plugin.config.resource.request.QueryParamsResourceConfig
import io.gatehill.imposter.plugin.config.resource.request.RequestBodyConfig
import io.gatehill.imposter.plugin.config.resource.request.RequestBodyResourceConfig
import io.gatehill.imposter.plugin.config.resource.request.RequestHeadersResourceConfig
import io.gatehill.imposter.plugin.config.steps.StepConfig
import io.gatehill.imposter.plugin.config.steps.StepsConfigHolder

Expand Down Expand Up @@ -88,18 +95,22 @@ open class RestResourceConfig(
@field:JsonProperty("method")
override var method: HttpMethod? = null

@delegate:Transient
override val pathParams: Map<String, ConditionalNameValuePair> by lazy {
rawPathParams?.let { ConditionalNameValuePair.parse(it) } ?: emptyMap()
}

@delegate:Transient
override val queryParams: Map<String, ConditionalNameValuePair> by lazy {
rawQueryParams?.let { ConditionalNameValuePair.parse(it) } ?: emptyMap()
}

@delegate:Transient
override val requestHeaders: Map<String, ConditionalNameValuePair> by lazy {
rawRequestHeaders?.let { ConditionalNameValuePair.parse(it) } ?: emptyMap()
}

@delegate:Transient
override val formParams: Map<String, ConditionalNameValuePair> by lazy {
rawFormParams?.let { ConditionalNameValuePair.parse(it) } ?: emptyMap()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,15 @@ class SecurityCondition(
@field:JsonProperty("requestHeaders")
private val rawRequestHeaders: Map<String, Any>? = null,
): QueryParamsResourceConfig, RequestHeadersResourceConfig, FormParamsResourceConfig {
@delegate:Transient
override val queryParams: Map<String, ConditionalNameValuePair> by lazy {
rawQueryParams?.let { ConditionalNameValuePair.parse(it) } ?: emptyMap()
}
@delegate:Transient
override val formParams: Map<String, ConditionalNameValuePair> by lazy {
rawFormParams?.let { ConditionalNameValuePair.parse(it) } ?: emptyMap()
}
@delegate:Transient
override val requestHeaders: Map<String, ConditionalNameValuePair> by lazy {
rawRequestHeaders?.let { ConditionalNameValuePair.parse(it) } ?: emptyMap()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ enum class StepType {
Remote,
}

class StepConfig(
class StepConfig: HashMap<String, Any>() {
val type: StepType
) : HashMap<String, Any>()
get() = when(val stepType = this["type"]) {
"script" -> StepType.Script
"remote" -> StepType.Remote
else -> throw IllegalStateException("Unsupported step type: $stepType")
}
}
3 changes: 3 additions & 0 deletions core/config/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ dependencies {

implementation "com.esotericsoftware:kryo:5.6.0"

// implementation "de.ruedigermoeller:fst:2.56"
implementation "de.ruedigermoeller:fst:3.0.1"

// test
testImplementation "junit:junit:$version_junit"
testImplementation group: 'org.hamcrest', name: 'hamcrest', version: version_hamcrest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,47 @@ package io.gatehill.imposter.config.util
import com.esotericsoftware.kryo.Kryo
import com.esotericsoftware.kryo.io.Input
import com.esotericsoftware.kryo.io.Output
import org.nustaq.serialization.FSTConfiguration
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.File
import java.io.ObjectInputStream
import java.io.ObjectOutputStream

object BinarySerialisationUtil {
val kryo = Kryo().apply {
private val kryo = Kryo().apply {
isRegistrationRequired = false
references = true
}

private val conf: FSTConfiguration by lazy { FSTConfiguration.createDefaultConfiguration() }

fun serialise(obj: Any, filePath: String) = serialiseKryo(obj, filePath)
fun <T> deserialise(filePath: String) = deserialiseKryo<T>(filePath)

/**
* Serialises an object to a file using FST.
*/
fun serialiseFst(obj: Any, filePath: String) {
File(filePath).outputStream().use {
val output = conf.asByteArray(obj)
it.write(output)
}
}

/**
* Deserialises an object from a file using FST.
*/
fun <T> deserialiseFst(filePath: String): T {
return File(filePath).inputStream().use {
conf.asObject(it.readAllBytes()) as T
}
}

/**
* Serialises an object to a file using Kryo.
*/
fun serialise(obj: Any, filePath: String) {
fun serialiseKryo(obj: Any, filePath: String) {
File(filePath).outputStream().use {
val output = Output(it)
kryo.writeClassAndObject(output, obj)
Expand All @@ -29,7 +54,7 @@ object BinarySerialisationUtil {
/**
* Deserialises an object from a file using Kryo.
*/
fun <T> deserialise(filePath: String): T {
fun <T> deserialiseKryo(filePath: String): T {
return File(filePath).inputStream().use {
val input = Input(it)
val obj = kryo.readClassAndObject(input) as T
Expand Down

0 comments on commit 6a6f93f

Please sign in to comment.