Skip to content

Commit

Permalink
feat: enables graal store proxy by default.
Browse files Browse the repository at this point in the history
  • Loading branch information
outofcoffee committed Jul 16, 2024
1 parent 12225c3 commit 25a4298
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ import org.apache.logging.log4j.LogManager
import org.graalvm.polyglot.Context
import org.graalvm.polyglot.Engine
import org.graalvm.polyglot.HostAccess
import javax.inject.Inject


/**
Expand All @@ -87,17 +86,29 @@ class GraalvmScriptServiceImpl : ScriptService, Plugin {
engine = Engine.newBuilder(JS_LANG_ID).build()
}

@Inject
fun onPostInject() {
if (EnvVars.getEnv(ENV_IMPOSTER_GRAAL_STORE_PROXY)?.toBoolean() == true) {
LOGGER.debug("Enabling Graal store proxy")
val storeFactory = InjectorUtil.getInstance<StoreFactory>()
storeFactory.storeInterceptors += { ObjectProxyingStore(it) }
}
private val enableStoreProxy = EnvVars.getEnv(ENV_IMPOSTER_GRAAL_STORE_PROXY)?.toBoolean() != false
private var checkedStoreProxy = false

override fun initScript(script: ScriptSource) {
checkEnableStoreProxy()
}

override fun initInlineScript(scriptId: String, scriptCode: String) {
LOGGER.trace("No op inline script init for script with ID: $scriptId")
checkEnableStoreProxy()
}

fun checkEnableStoreProxy() {
if (!checkedStoreProxy) {
checkedStoreProxy = true

if (enableStoreProxy) {
LOGGER.trace("Graal store proxy enabled")
val storeFactory = InjectorUtil.getInstance<StoreFactory>()
storeFactory.storeInterceptors += { ObjectProxyingStore(it) }
} else {
LOGGER.trace("Graal store proxy disabled")
}
}
}

override fun executeScript(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ class StoreJsonTest : AbstractBaseScriptTest() {

@Test
fun `stringify to JSON`() {
// init the store proxy
getService().checkEnableStoreProxy()

val pluginConfig = configureScript()
val resourceConfig = pluginConfig as BasicResourceConfig

Expand Down

0 comments on commit 25a4298

Please sign in to comment.