From b52a648f3c77a495539d64bba1e43fcbbdaa0364 Mon Sep 17 00:00:00 2001 From: Brinda Santh Date: Thu, 18 Jul 2019 19:13:00 -0400 Subject: Improve script file accessing through cache. Change-Id: If94e837975701dc7b2235c38acb46b3b883a424b Issue-ID: CCSDK-1503 Signed-off-by: Brinda Santh --- .../scripts/BluePrintScriptsServiceImplTest.kt | 67 +++++++++++++++++ .../core/scripts/BlueprintScriptingHostTest.kt | 84 ---------------------- 2 files changed, 67 insertions(+), 84 deletions(-) create mode 100644 ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintScriptsServiceImplTest.kt delete mode 100644 ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BlueprintScriptingHostTest.kt (limited to 'ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap') diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintScriptsServiceImplTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintScriptsServiceImplTest.kt new file mode 100644 index 000000000..9d4ef69bb --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintScriptsServiceImplTest.kt @@ -0,0 +1,67 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.controllerblueprints.core.scripts + + +import kotlinx.coroutines.runBlocking +import org.junit.Test +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BlueprintFunctionNode +import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName +import kotlin.script.experimental.jvm.util.classpathFromClass +import kotlin.script.experimental.jvm.util.classpathFromClassloader +import kotlin.script.experimental.jvm.util.classpathFromClasspathProperty +import kotlin.test.assertNotNull + +class BluePrintScriptsServiceImplTest { + + private fun viewClassPathInfo() { + + println(" *********** classpathFromClass *********** ") + classpathFromClass(BluePrintScriptsServiceImplTest::class.java.classLoader, + BluePrintScriptsServiceImplTest::class)!! + .forEach(::println) + + println(" *********** classpathFromClassloader *********** ") + classpathFromClassloader(BluePrintScriptsServiceImplTest::class.java.classLoader)!! + .forEach(::println) + + println(" *********** classpathFromClasspathProperty *********** ") + classpathFromClasspathProperty()!! + .forEach(::println) + } + + @Test + fun testCachedService() { + runBlocking { + + val bluePrintScriptsService = BluePrintScriptsServiceImpl() + + val basePath = normalizedPathName("src/test/resources/compile") + + val instance = bluePrintScriptsService + .scriptInstance>(basePath, + "cba.scripts.SampleBlueprintFunctionNode", true) + assertNotNull(instance, "failed to get compiled instance") + + val cachedInstance = bluePrintScriptsService + .scriptInstance>(basePath, + "cba.scripts.SampleBlueprintFunctionNode", false) + assertNotNull(cachedInstance, "failed to get cached compile instance") + } + } + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BlueprintScriptingHostTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BlueprintScriptingHostTest.kt deleted file mode 100644 index 2288d62c8..000000000 --- a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BlueprintScriptingHostTest.kt +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.cds.controllerblueprints.core.scripts - - -import org.apache.commons.io.FileUtils -import org.junit.Test -import java.io.File -import kotlin.script.experimental.jvm.util.classpathFromClass -import kotlin.script.experimental.jvm.util.classpathFromClassloader -import kotlin.script.experimental.jvm.util.classpathFromClasspathProperty -import kotlin.script.experimental.jvmhost.createJvmCompilationConfigurationFromTemplate - -class BlueprintScriptingHostTest { - - private fun viewClassPathInfo() { - - println(" *********** classpathFromClass *********** ") - classpathFromClass(BlueprintScriptingHostTest::class.java.classLoader, - BlueprintScriptingHostTest::class)!! - .forEach(::println) - - println(" *********** classpathFromClassloader *********** ") - classpathFromClassloader(BlueprintScriptingHostTest::class.java.classLoader)!! - .forEach(::println) - - println(" *********** classpathFromClasspathProperty *********** ") - classpathFromClasspathProperty()!! - .forEach(::println) - } - - @Test - fun `test same script two folders`() { - - FileUtils.forceMkdir(File("target/scripts1/")) - FileUtils.forceMkdir(File("target/scripts2/")) - - val scriptSource1 = BluePrintSourceCode() - scriptSource1.moduleName = "blueprint-test-script" - - scriptSource1.targetJarFile = File("target/scripts1/blueprint-script-generated.jar") - val sources1: MutableList = arrayListOf() - sources1.add("src/test/resources/scripts1") - scriptSource1.blueprintKotlinSources = sources1 - - val scriptClassName = "Simple_cba\$SampleComponentFunction" - - val compilationConfiguration = createJvmCompilationConfigurationFromTemplate() - - val scriptEvaluator = BluePrintScriptEvaluator(scriptClassName) - - val scriptSource2 = BluePrintSourceCode() - scriptSource2.moduleName = "blueprint-test-script" - - scriptSource2.targetJarFile = File("target/scripts2/blueprint-script-generated.jar") - val sources2: MutableList = arrayListOf() - sources2.add("src/test/resources/scripts2") - scriptSource2.blueprintKotlinSources = sources2 - - for (i in 1..2) { - val evalResponse = BlueprintScriptingHost(scriptEvaluator).eval(scriptSource1, compilationConfiguration, - null) - } - - for (i in 1..2) { - val evalResponse = BlueprintScriptingHost(scriptEvaluator).eval(scriptSource2, compilationConfiguration, - null) - } - } -} \ No newline at end of file -- cgit 1.2.3-korg