http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/27e5b2c8/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/plugin/dsl/credential/CredentialGraphTokens.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/plugin/dsl/credential/CredentialGraphTokens.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/plugin/dsl/credential/CredentialGraphTokens.java deleted file mode 100644 index 1f0d8cf..0000000 --- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/plugin/dsl/credential/CredentialGraphTokens.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.tinkerpop.gremlin.groovy.plugin.dsl.credential; - -/** - * @author Stephen Mallette (http://stephen.genoprime.com) - * @deprecated As of release 3.2.4, replaced by {@link org.apache.tinkerpop.gremlin.groovy.jsr223.dsl.credential.CredentialGraphTokens}. - */ -@Deprecated -public final class CredentialGraphTokens { - public static final String PROPERTY_USERNAME = "username"; - public static final String PROPERTY_PASSWORD = "password"; - - public static final String VERTEX_LABEL_USER = "user"; - - private CredentialGraphTokens() {} -}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/27e5b2c8/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/DefaultDefaultImportCustomizerProviderTest.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/DefaultDefaultImportCustomizerProviderTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/DefaultDefaultImportCustomizerProviderTest.java deleted file mode 100644 index 9a3785f..0000000 --- a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/DefaultDefaultImportCustomizerProviderTest.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.tinkerpop.gremlin.groovy; - -import org.apache.tinkerpop.gremlin.groovy.loaders.SugarLoader; -import org.junit.Test; - -import java.util.HashSet; -import java.util.Set; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -/** - * @author Stephen Mallette (http://stephen.genoprime.com) - */ -public class DefaultDefaultImportCustomizerProviderTest { - static { - SugarLoader.load(); - } - - @Test - public void shouldReturnDefaultImports() { - final DefaultImportCustomizerProvider provider = new DefaultImportCustomizerProvider(); - assertImportsInProvider(provider); - } - - @Test - public void shouldReturnWithExtraStaticImports() { - final Set<String> statics = new HashSet<>(); - statics.add("com.test.This.*"); - statics.add("com.test.That.OTHER"); - final DefaultImportCustomizerProvider provider = new DefaultImportCustomizerProvider(new HashSet<>(), statics); - assertImportsInProvider(provider); - } - - @Test - public void shouldReturnWithExtraImports() { - final Set<String> imports = new HashSet<>(); - imports.add("com.test.that.*"); - imports.add("com.test.that.That"); - final DefaultImportCustomizerProvider provider = new DefaultImportCustomizerProvider(imports, new HashSet<>()); - assertImportsInProvider(provider); - } - - @Test - public void shouldReturnWithBothImportTypes() { - final Set<String> imports = new HashSet<>(); - imports.add("com.test.that.*"); - imports.add("com.test.that.That"); - - final Set<String> statics = new HashSet<>(); - statics.add("com.test.This.*"); - statics.add("com.test.That.OTHER"); - - final DefaultImportCustomizerProvider provider = new DefaultImportCustomizerProvider(imports, statics); - assertImportsInProvider(provider); - } - - private static void assertImportsInProvider(DefaultImportCustomizerProvider provider) { - final Set<String> allImports = provider.getAllImports(); - - final Set<String> imports = provider.getImports(); - final Set<String> staticImports = provider.getStaticImports(); - final Set<String> extraImports = provider.getExtraImports(); - final Set<String> extraStaticImports = provider.getExtraStaticImports(); - - assertEquals(imports.size() + staticImports.size() + extraImports.size() + extraStaticImports.size(), allImports.size()); - assertTrue(allImports.containsAll(imports)); - assertTrue(allImports.containsAll(staticImports)); - assertTrue(allImports.containsAll(extraImports)); - assertTrue(allImports.containsAll(extraStaticImports)); - } -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/27e5b2c8/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorTest.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorTest.java index a56f805..9aef783 100644 --- a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorTest.java +++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorTest.java @@ -20,9 +20,9 @@ package org.apache.tinkerpop.gremlin.groovy.engine; import org.apache.commons.lang3.concurrent.BasicThreadFactory; import org.apache.tinkerpop.gremlin.TestHelper; -import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.ThreadInterruptCustomizerProvider; -import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.TimedInterruptCustomizerProvider; -import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.TimedInterruptTimeoutException; +import org.apache.tinkerpop.gremlin.groovy.jsr223.GroovyCompilerGremlinPlugin; +import org.apache.tinkerpop.gremlin.groovy.jsr223.TimedInterruptTimeoutException; +import org.apache.tinkerpop.gremlin.jsr223.ScriptFileGremlinPlugin; import org.javatuples.Pair; import org.junit.Test; @@ -30,13 +30,10 @@ import javax.script.Bindings; import javax.script.CompiledScript; import javax.script.SimpleBindings; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CountDownLatch; import java.util.concurrent.CyclicBarrier; @@ -166,8 +163,7 @@ public class GremlinExecutorTest { @Test public void shouldEvalScriptWithMapBindingsAndLanguage() throws Exception { - final GremlinExecutor gremlinExecutor = GremlinExecutor.build() - .addEngineSettings("gremlin-groovy", Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyMap()).create(); + final GremlinExecutor gremlinExecutor = GremlinExecutor.build().create(); final Map<String,Object> b = new HashMap<>(); b.put("x", 1); assertEquals(2, gremlinExecutor.eval("1+x", "gremlin-groovy", b).get()); @@ -176,8 +172,7 @@ public class GremlinExecutorTest { @Test public void shouldEvalScriptWithMapBindingsAndLanguageThenTransform() throws Exception { - final GremlinExecutor gremlinExecutor = GremlinExecutor.build() - .addEngineSettings("gremlin-groovy", Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyMap()).create(); + final GremlinExecutor gremlinExecutor = GremlinExecutor.build().create(); final Map<String,Object> b = new HashMap<>(); b.put("x", 1); assertEquals(4, gremlinExecutor.eval("1+x", "gremlin-groovy", b, r -> (int) r * 2).get()); @@ -186,8 +181,7 @@ public class GremlinExecutorTest { @Test public void shouldEvalScriptWithMapBindingsAndLanguageThenConsume() throws Exception { - final GremlinExecutor gremlinExecutor = GremlinExecutor.build() - .addEngineSettings("gremlin-groovy", Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyMap()).create(); + final GremlinExecutor gremlinExecutor = GremlinExecutor.build().create(); final Map<String,Object> b = new HashMap<>(); b.put("x", 1); @@ -453,54 +447,14 @@ public class GremlinExecutorTest { } @Test - public void shouldFailUntilImportExecutes() throws Exception { - final GremlinExecutor gremlinExecutor = GremlinExecutor.build().create(); - - final Set<String> imports = new HashSet<String>() {{ - add("import java.awt.Color"); - }}; - - final AtomicInteger successes = new AtomicInteger(0); - final AtomicInteger failures = new AtomicInteger(0); - - // issue 1000 scripts in one thread using a class that isn't imported. this will result in failure. - // while that thread is running start a new thread that issues an addImports to include that class. - // this should block further evals in the first thread until the import is complete at which point - // evals in the first thread will resume and start to succeed - final Thread t1 = new Thread(() -> - IntStream.range(0, 1000).mapToObj(i -> gremlinExecutor.eval("Color.BLACK")) - .forEach(f -> { - f.exceptionally(t -> failures.incrementAndGet()).join(); - if (!f.isCompletedExceptionally()) - successes.incrementAndGet(); - }) - ); - - final Thread t2 = new Thread(() -> { - while (failures.get() < 500) { } - gremlinExecutor.getScriptEngines().addImports(imports); - }); - - t1.start(); - t2.start(); - - t1.join(); - t2.join(); - - assertTrue(successes.intValue() > 0); - assertTrue(failures.intValue() >= 500); - - gremlinExecutor.close(); - } - - @Test public void shouldInitializeWithScript() throws Exception { + final Map<String, Map<String,Object>> config = new HashMap<>(); + final Map<String, Object> scriptPluginConfig = new HashMap<>(); + scriptPluginConfig.put("files", Collections.singletonList(PATHS.get("GremlinExecutorInit.groovy"))); + config.put(ScriptFileGremlinPlugin.class.getName(), scriptPluginConfig); + final GremlinExecutor gremlinExecutor = GremlinExecutor.build() - .addEngineSettings("gremlin-groovy", - Collections.emptyList(), - Collections.emptyList(), - Arrays.asList(PATHS.get("GremlinExecutorInit.groovy")), - Collections.emptyMap()) + .addPlugins("gremlin-groovy", config) .create(); assertEquals(2, gremlinExecutor.eval("add(1,1)").get()); @@ -510,12 +464,13 @@ public class GremlinExecutorTest { @Test public void shouldInitializeWithScriptAndMakeGlobalBinding() throws Exception { + final Map<String, Map<String,Object>> config = new HashMap<>(); + final Map<String, Object> scriptPluginConfig = new HashMap<>(); + scriptPluginConfig.put("files", Collections.singletonList(PATHS.get("GremlinExecutorInit.groovy"))); + config.put(ScriptFileGremlinPlugin.class.getName(), scriptPluginConfig); + final GremlinExecutor gremlinExecutor = GremlinExecutor.build() - .addEngineSettings("gremlin-groovy", - Collections.emptyList(), - Collections.emptyList(), - Arrays.asList(PATHS.get("GremlinExecutorInit.groovy")), - Collections.emptyMap()) + .addPlugins("gremlin-groovy", config) .create(); assertEquals(2, gremlinExecutor.eval("add(1,1)").get()); @@ -529,20 +484,17 @@ public class GremlinExecutorTest { @Test public void shouldContinueToEvalScriptsEvenWithTimedInterrupt() throws Exception { - final Map<String,List<Object>> compilerCustomizerConfig = new HashMap<>(); - final List<Object> args = new ArrayList<>(); - args.add(250); - compilerCustomizerConfig.put(TimedInterruptCustomizerProvider.class.getName(), args); + final Map<String, Map<String,Object>> config = new HashMap<>(); + final Map<String, Object> scriptPluginConfig = new HashMap<>(); + scriptPluginConfig.put("files", Collections.singletonList(PATHS.get("GremlinExecutorInit.groovy"))); + config.put(ScriptFileGremlinPlugin.class.getName(), scriptPluginConfig); - final Map<String, Object> config = new HashMap<>(); - config.put("compilerCustomizerProviders", compilerCustomizerConfig); + final Map<String, Object> groovyPluginConfig = new HashMap<>(); + groovyPluginConfig.put("timedInterrupt", 250); + config.put(GroovyCompilerGremlinPlugin.class.getName(), groovyPluginConfig); final GremlinExecutor gremlinExecutor = GremlinExecutor.build() - .addEngineSettings("gremlin-groovy", - Collections.emptyList(), - Collections.emptyList(), - Arrays.asList(PATHS.get("GremlinExecutorInit.groovy")), - config) + .addPlugins("gremlin-groovy", config) .create(); for (int ix = 0; ix < 5; ix++) { @@ -563,18 +515,17 @@ public class GremlinExecutorTest { @Test public void shouldInterruptWhile() throws Exception { - final Map<String,List<Object>> compilerCustomizerConfig = new HashMap<>(); - compilerCustomizerConfig.put(ThreadInterruptCustomizerProvider.class.getName(), new ArrayList<>()); + final Map<String, Map<String,Object>> config = new HashMap<>(); + final Map<String, Object> scriptPluginConfig = new HashMap<>(); + scriptPluginConfig.put("files", Collections.singletonList(PATHS.get("GremlinExecutorInit.groovy"))); + config.put(ScriptFileGremlinPlugin.class.getName(), scriptPluginConfig); - final Map<String, Object> config = new HashMap<>(); - config.put("compilerCustomizerProviders", compilerCustomizerConfig); + final Map<String, Object> groovyPluginConfig = new HashMap<>(); + groovyPluginConfig.put("enableThreadInterrupt", true); + config.put(GroovyCompilerGremlinPlugin.class.getName(), groovyPluginConfig); final GremlinExecutor gremlinExecutor = GremlinExecutor.build() - .addEngineSettings("gremlin-groovy", - Collections.emptyList(), - Collections.emptyList(), - Arrays.asList(PATHS.get("GremlinExecutorInit.groovy")), - config) + .addPlugins("gremlin-groovy", config) .create(); final AtomicBoolean asserted = new AtomicBoolean(false); @@ -595,25 +546,6 @@ public class GremlinExecutorTest { } @Test - public void shouldInitializeWithScriptAndWorkAfterReset() throws Exception { - final GremlinExecutor gremlinExecutor = GremlinExecutor.build() - .addEngineSettings("gremlin-groovy", - Collections.emptyList(), - Collections.emptyList(), - Arrays.asList(PATHS.get("GremlinExecutorInit.groovy")), - Collections.emptyMap()) - .create(); - - assertEquals(2, gremlinExecutor.eval("add(1,1)").get()); - - gremlinExecutor.getScriptEngines().reset(); - - assertEquals(2, gremlinExecutor.eval("add(1,1)").get()); - - gremlinExecutor.close(); - } - - @Test public void shouldNotShutdownExecutorServicesSuppliedToGremlinExecutor() throws Exception { final ScheduledExecutorService service = Executors.newScheduledThreadPool(4, testingThreadFactory); final GremlinExecutor gremlinExecutor = GremlinExecutor.build() http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/27e5b2c8/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEnginesTest.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEnginesTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEnginesTest.java deleted file mode 100644 index 3a4b233..0000000 --- a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEnginesTest.java +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.tinkerpop.gremlin.groovy.engine; - -import groovy.lang.MissingPropertyException; -import org.apache.commons.lang.exception.ExceptionUtils; -import org.apache.tinkerpop.gremlin.groovy.plugin.GremlinPlugin; -import org.apache.tinkerpop.gremlin.groovy.plugin.IllegalEnvironmentException; -import org.apache.tinkerpop.gremlin.groovy.plugin.PluginAcceptor; -import org.apache.tinkerpop.gremlin.groovy.plugin.PluginInitializationException; -import org.junit.Test; - -import javax.script.Bindings; -import javax.script.SimpleBindings; -import java.awt.*; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.stream.IntStream; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.IsInstanceOf.instanceOf; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -/** - * @author Stephen Mallette (http://stephen.genoprime.com) - */ -public class ScriptEnginesTest { - @Test - public void shouldNotPreserveInstantiatedVariablesBetweenEvals() throws Exception { - final ScriptEngines engines = new ScriptEngines(se -> {}); - engines.reload("gremlin-groovy", Collections.<String>emptySet(), - Collections.<String>emptySet(), Collections.emptyMap()); - - final Bindings localBindingsFirstRequest = new SimpleBindings(); - localBindingsFirstRequest.put("x", "there"); - assertEquals("herethere", engines.eval("z = 'here' + x", localBindingsFirstRequest, "gremlin-groovy")); - - try { - final Bindings localBindingsSecondRequest = new SimpleBindings(); - engines.eval("z", localBindingsSecondRequest, "gremlin-groovy"); - fail("Should not have knowledge of z"); - } catch (Exception ex) { - final Throwable root = ExceptionUtils.getRootCause(ex); - assertThat(root, instanceOf(MissingPropertyException.class)); - } - } - - @Test - public void shouldMergeBindingsFromLocalAndGlobal() throws Exception { - final ScriptEngines engines = new ScriptEngines(se -> {}); - engines.reload("gremlin-groovy", Collections.<String>emptySet(), - Collections.<String>emptySet(), Collections.emptyMap()); - - engines.loadPlugins(Arrays.asList(new GremlinPlugin() { - @Override - public String getName() { - return "mock"; - } - - @Override - public void pluginTo(final PluginAcceptor pluginAcceptor) throws IllegalEnvironmentException, PluginInitializationException { - pluginAcceptor.addBinding("y", "here"); - } - })); - - final Bindings localBindings = new SimpleBindings(); - localBindings.put("x", "there"); - - assertEquals("herethere", engines.eval("y+x", localBindings, "gremlin-groovy")); - } - - @Test - public void shouldMergeBindingsFromLocalAndGlobalWithMultiplePlugins() throws Exception { - final ScriptEngines engines = new ScriptEngines(se -> {}); - engines.reload("gremlin-groovy", Collections.<String>emptySet(), - Collections.<String>emptySet(), Collections.emptyMap()); - - engines.loadPlugins(Arrays.asList(new GremlinPlugin() { - @Override - public String getName() { - return "mock1"; - } - - @Override - public void pluginTo(final PluginAcceptor pluginAcceptor) throws IllegalEnvironmentException, PluginInitializationException { - pluginAcceptor.addBinding("y", "here"); - } - })); - - final Bindings localBindings = new SimpleBindings(); - localBindings.put("x", "there"); - - assertEquals("herethere", engines.eval("y+x", localBindings, "gremlin-groovy")); - - engines.loadPlugins(Arrays.asList(new GremlinPlugin() { - @Override - public String getName() { - return "mock2"; - } - - @Override - public void pluginTo(final PluginAcceptor pluginAcceptor) throws IllegalEnvironmentException, PluginInitializationException { - pluginAcceptor.addBinding("z", "where"); - pluginAcceptor.addImports(new HashSet<>(Arrays.asList("import java.awt.Color"))); - } - })); - - assertEquals("heretherewhere", engines.eval("y+x+z", localBindings, "gremlin-groovy")); - assertEquals(Color.RED, engines.eval("Color.RED", localBindings, "gremlin-groovy")); - - } - - @Test - public void shouldMergeBindingsWhereLocalOverridesGlobal() throws Exception { - final ScriptEngines engines = new ScriptEngines(se -> {}); - engines.reload("gremlin-groovy", Collections.<String>emptySet(), - Collections.<String>emptySet(), Collections.emptyMap()); - - engines.loadPlugins(Arrays.asList(new GremlinPlugin() { - @Override - public String getName() { - return "mock"; - } - - @Override - public void pluginTo(final PluginAcceptor pluginAcceptor) throws IllegalEnvironmentException, PluginInitializationException { - pluginAcceptor.addBinding("y", "here"); - } - })); - - // the "y" below should override the global variable setting. - final Bindings localBindings = new SimpleBindings(); - localBindings.put("y", "there"); - localBindings.put("z", "where"); - - assertEquals("therewhere", engines.eval("y+z", localBindings, "gremlin-groovy")); - } - - @Test - public void shouldFailUntilImportExecutes() throws Exception { - final ScriptEngines engines = new ScriptEngines(se -> {}); - engines.reload("gremlin-groovy", Collections.<String>emptySet(), - Collections.<String>emptySet(), Collections.emptyMap()); - - final Set<String> imports = new HashSet<String>() {{ - add("import java.awt.Color"); - }}; - - final AtomicInteger successes = new AtomicInteger(0); - final AtomicInteger failures = new AtomicInteger(0); - final CountDownLatch latch = new CountDownLatch(1); - - final Thread threadImport = new Thread(() -> { - engines.addImports(imports); - latch.countDown(); - }); - - // issue 1000 scripts in one thread using a class that isn't imported. this will result in failure. - // while that thread is running start a new thread that issues an addImports to include that class. - // this should block further evals in the first thread until the import is complete at which point - // evals in the first thread will resume and start to succeed - final Thread threadEvalAndTriggerImport = new Thread(() -> - IntStream.range(0, 1000).forEach(i -> { - try { - - engines.eval("Color.BLACK", new SimpleBindings(), "gremlin-groovy"); - successes.incrementAndGet(); - } catch (Exception ex) { - // stop the failures halfway and allow the import thread to start - if (failures.incrementAndGet() == 500) { - threadImport.start(); - - // block until the import occurs - try { - latch.await(30000, TimeUnit.MILLISECONDS); - } catch (Exception inner) { - // this test should fail given that the nubmer of asserts for successes will not implement - // appropriately if this RuntimeException is thrown. - throw new RuntimeException(inner); - } - } - } - }) - ); - - threadEvalAndTriggerImport.start(); - - threadEvalAndTriggerImport.join(); - - assertTrue("Success: " + successes.intValue() + " - Success: " + failures.intValue(), successes.intValue() == 500); - assertTrue("Failures: " + successes.intValue() + " - Failures: " + failures.intValue(), failures.intValue() == 500); - - engines.close(); - } -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/27e5b2c8/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/ConfigurationCustomizerProviderTest.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/ConfigurationCustomizerProviderTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/ConfigurationCustomizerProviderTest.java new file mode 100644 index 0000000..1a06455 --- /dev/null +++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/ConfigurationCustomizerProviderTest.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.tinkerpop.gremlin.groovy.jsr223; + +import org.codehaus.groovy.control.CompilerConfiguration; +import org.junit.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.IsInstanceOf.instanceOf; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +/** + * @author Stephen Mallette (http://stephen.genoprime.com) + */ +public class ConfigurationCustomizerProviderTest { + @Test(expected = IllegalArgumentException.class) + public void shouldThrowExceptionForNoSettings() { + new ConfigurationGroovyCustomizer(); + } + + @Test(expected = IllegalArgumentException.class) + public void shouldThrowExceptionForInvalidSettings() { + new ConfigurationGroovyCustomizer("only-one-arg"); + } + + @Test + public void shouldThrowExceptionForNotFoundSetting() { + final CompilerConfiguration configuration = new CompilerConfiguration(); + try { + final ConfigurationGroovyCustomizer provider = new ConfigurationGroovyCustomizer( + "Tolerance", 3, + "NotRealSettingThatWouldEverOccur2", new java.util.Date()); + + provider.applyCustomization(configuration); + } catch (Exception ex) { + assertThat(ex, instanceOf(IllegalStateException.class)); + assertEquals("Invalid setting [NotRealSettingThatWouldEverOccur2] for CompilerConfiguration", ex.getMessage()); + } + } + + @Test + public void shouldApplyConfigurationChanges() { + final CompilerConfiguration configuration = new CompilerConfiguration(); + + assertEquals(10, configuration.getTolerance()); + assertNull(configuration.getScriptBaseClass()); + assertEquals(false, configuration.getDebug()); + + final ConfigurationGroovyCustomizer provider = new ConfigurationGroovyCustomizer( + "Tolerance", 3, + "ScriptBaseClass", "Something", + "Debug", true); + + provider.applyCustomization(configuration); + + assertEquals(3, configuration.getTolerance()); + assertEquals("Something", configuration.getScriptBaseClass()); + assertEquals(true, configuration.getDebug()); + } +} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/27e5b2c8/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineCompileStaticTest.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineCompileStaticTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineCompileStaticTest.java index 6f3383e..b47c9c4 100644 --- a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineCompileStaticTest.java +++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineCompileStaticTest.java @@ -19,7 +19,6 @@ package org.apache.tinkerpop.gremlin.groovy.jsr223; import org.apache.commons.lang.exception.ExceptionUtils; -import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.CompileStaticCustomizerProvider; import org.codehaus.groovy.control.MultipleCompilationErrorsException; import org.junit.Test; @@ -34,23 +33,6 @@ import static org.junit.Assert.fail; * @author Stephen Mallette (http://stephen.genoprime.com) */ public class GremlinGroovyScriptEngineCompileStaticTest { - @Test - public void shouldCompileStaticDeprecated() throws Exception { - // with no type checking this should pass - try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine()) { - assertEquals(255, scriptEngine.eval("((Object) new java.awt.Color(255, 255, 255)).getRed()")); - } - - final CompileStaticCustomizerProvider provider = new CompileStaticCustomizerProvider(); - try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(provider)) { - scriptEngine.eval("((Object) new java.awt.Color(255, 255, 255)).getRed()"); - fail("Should have failed type checking"); - } catch (ScriptException se) { - final Throwable root = ExceptionUtils.getRootCause(se); - assertEquals(MultipleCompilationErrorsException.class, root.getClass()); - assertThat(se.getMessage(), containsString("[Static type checking] - Cannot find matching method java.lang.Object#getRed(). Please check if the declared type is right and if the method exists.")); - } - } @Test public void shouldCompileStatic() throws Exception { @@ -71,25 +53,6 @@ public class GremlinGroovyScriptEngineCompileStaticTest { } @Test - public void shouldCompileStaticWithExtensionDeprecated() throws Exception { - // with no type checking extension this should pass - final CompileStaticCustomizerProvider providerNoExtension = new CompileStaticCustomizerProvider(); - try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(providerNoExtension)) { - assertEquals(255, scriptEngine.eval("def c = new java.awt.Color(255, 255, 255); c.red")); - } - - final CompileStaticCustomizerProvider providerWithExtension = new CompileStaticCustomizerProvider( - PrecompiledExtensions.PreventColorUsageExtension.class.getName()); - try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(providerWithExtension)) { - scriptEngine.eval("def c = new java.awt.Color(255, 255, 255); c.red"); - fail("Should have failed type checking"); - } catch (ScriptException se) { - assertEquals(MultipleCompilationErrorsException.class, se.getCause().getClass()); - assertThat(se.getMessage(), containsString("Method call is not allowed!")); - } - } - - @Test public void shouldCompileStaticWithExtension() throws Exception { // with no type checking extension this should pass final CompileStaticGroovyCustomizer providerNoExtension = new CompileStaticGroovyCustomizer(); @@ -109,35 +72,6 @@ public class GremlinGroovyScriptEngineCompileStaticTest { } @Test - public void shouldCompileStaticWithMultipleExtensionDeprecated() throws Exception { - // with no type checking extension this should pass - final CompileStaticCustomizerProvider providerNoExtension = new CompileStaticCustomizerProvider(); - try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(providerNoExtension)) { - assertEquals(255, scriptEngine.eval("def c = new java.awt.Color(255, 255, 255); c.red")); - assertEquals(1l, scriptEngine.eval("def c = new java.util.concurrent.CountDownLatch(1); c.count")); - } - - final CompileStaticCustomizerProvider providerWithExtension = new CompileStaticCustomizerProvider( - PrecompiledExtensions.PreventColorUsageExtension.class.getName() + - "," + PrecompiledExtensions.PreventCountDownLatchUsageExtension.class.getName()); - try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(providerWithExtension)) { - scriptEngine.eval("def c = new java.awt.Color(255, 255, 255); c.red"); - fail("Should have failed type checking"); - } catch (ScriptException se) { - assertEquals(MultipleCompilationErrorsException.class, se.getCause().getClass()); - assertThat(se.getMessage(), containsString("Method call is not allowed!")); - } - - try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(providerWithExtension)) { - scriptEngine.eval("def c = new java.util.concurrent.CountDownLatch(1); c.count"); - fail("Should have failed type checking"); - } catch (ScriptException se) { - assertEquals(MultipleCompilationErrorsException.class, se.getCause().getClass()); - assertThat(se.getMessage(), containsString("Method call is not allowed!")); - } - } - - @Test public void shouldCompileStaticWithMultipleExtension() throws Exception { // with no type checking extension this should pass final CompileStaticGroovyCustomizer providerNoExtension = new CompileStaticGroovyCustomizer(); http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/27e5b2c8/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineConfigTest.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineConfigTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineConfigTest.java index 289b2ca..8414274 100644 --- a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineConfigTest.java +++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineConfigTest.java @@ -18,8 +18,6 @@ */ package org.apache.tinkerpop.gremlin.groovy.jsr223; -import org.apache.tinkerpop.gremlin.groovy.DefaultImportCustomizerProvider; -import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.ConfigurationCustomizerProvider; import org.junit.Test; import javax.script.ScriptEngine; @@ -30,14 +28,6 @@ import static org.junit.Assert.assertEquals; * @author Stephen Mallette (http://stephen.genoprime.com) */ public class GremlinGroovyScriptEngineConfigTest { - @Test - public void shouldAddBaseScriptClassDeprecated() throws Exception { - final ScriptEngine engine = new GremlinGroovyScriptEngine( - new ConfigurationCustomizerProvider("ScriptBaseClass", BaseScriptForTesting.class.getName()), - new DefaultImportCustomizerProvider()); - - assertEquals("hello, stephen", engine.eval("hello('stephen')")); - } @Test public void shouldAddBaseScriptClass() throws Exception { http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/27e5b2c8/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineFileSandboxTest.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineFileSandboxTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineFileSandboxTest.java index 6018a48..2b27dd0 100644 --- a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineFileSandboxTest.java +++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineFileSandboxTest.java @@ -20,8 +20,6 @@ package org.apache.tinkerpop.gremlin.groovy.jsr223; import org.apache.tinkerpop.gremlin.LoadGraphWith; import org.apache.tinkerpop.gremlin.TestHelper; -import org.apache.tinkerpop.gremlin.groovy.CompilerCustomizerProvider; -import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.CompileStaticCustomizerProvider; import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.FileSandboxExtension; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; import org.apache.tinkerpop.gremlin.structure.Graph; @@ -69,7 +67,7 @@ public class GremlinGroovyScriptEngineFileSandboxTest { @Test public void shouldEvalAsTheMethodIsWhiteListed() throws Exception { - final CompilerCustomizerProvider standardSandbox = new CompileStaticCustomizerProvider(FileSandboxExtension.class.getName()); + final CompileStaticGroovyCustomizer standardSandbox = new CompileStaticGroovyCustomizer(FileSandboxExtension.class.getName()); try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(standardSandbox)) { assertEquals(123, engine.eval("java.lang.Math.abs(-123)")); assertThat(engine.eval("new Boolean(true)"), is(true)); @@ -79,7 +77,7 @@ public class GremlinGroovyScriptEngineFileSandboxTest { @Test public void shouldEvalAsGroovyPropertiesWhenWhiteListed() throws Exception { - final CompilerCustomizerProvider standardSandbox = new CompileStaticCustomizerProvider(FileSandboxExtension.class.getName()); + final CompileStaticGroovyCustomizer standardSandbox = new CompileStaticGroovyCustomizer(FileSandboxExtension.class.getName()); try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(standardSandbox)) { assertThat(Arrays.equals("test".getBytes(), (byte[]) engine.eval("'test'.bytes")), is(true)); } @@ -87,10 +85,10 @@ public class GremlinGroovyScriptEngineFileSandboxTest { @Test public void shouldPreventMaliciousStuffWithSystemButAllowSomeMethodsOnSystem() throws Exception { - final CompilerCustomizerProvider standardSandbox = new CompileStaticCustomizerProvider(FileSandboxExtension.class.getName()); + final CompileStaticGroovyCustomizer standardSandbox = new CompileStaticGroovyCustomizer(FileSandboxExtension.class.getName()); try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(standardSandbox)) { - assertThat((long) engine.eval("System.currentTimeMillis()"), greaterThan(0l)); - assertThat((long) engine.eval("System.nanoTime()"), greaterThan(0l)); + assertThat((long) engine.eval("System.currentTimeMillis()"), greaterThan(0L)); + assertThat((long) engine.eval("System.nanoTime()"), greaterThan(0L)); engine.eval("System.exit(0)"); fail("Should have a compile error because class/method is not white listed"); @@ -102,7 +100,7 @@ public class GremlinGroovyScriptEngineFileSandboxTest { @Test public void shouldPreventMaliciousStuffWithFile() throws Exception { - final CompilerCustomizerProvider standardSandbox = new CompileStaticCustomizerProvider(FileSandboxExtension.class.getName()); + final CompileStaticGroovyCustomizer standardSandbox = new CompileStaticGroovyCustomizer(FileSandboxExtension.class.getName()); try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(standardSandbox)) { engine.eval("java.nio.file.FileSystems.getDefault()"); fail("Should have a compile error because class/method is not white listed"); @@ -115,7 +113,7 @@ public class GremlinGroovyScriptEngineFileSandboxTest { @Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldEvalOnGAsTheMethodIsWhiteListed() throws Exception { - final CompilerCustomizerProvider standardSandbox = new CompileStaticCustomizerProvider(FileSandboxExtension.class.getName()); + final CompileStaticGroovyCustomizer standardSandbox = new CompileStaticGroovyCustomizer(FileSandboxExtension.class.getName()); try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(standardSandbox)) { final Bindings bindings = engine.createBindings(); bindings.put("g", g); http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/27e5b2c8/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineOverGraphTest.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineOverGraphTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineOverGraphTest.java index 84542e1..4b52a5e 100644 --- a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineOverGraphTest.java +++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineOverGraphTest.java @@ -20,10 +20,6 @@ package org.apache.tinkerpop.gremlin.groovy.jsr223; import groovy.lang.MissingPropertyException; import org.apache.commons.lang.exception.ExceptionUtils; -import org.apache.tinkerpop.gremlin.groovy.CompilerCustomizerProvider; -import org.apache.tinkerpop.gremlin.groovy.DefaultImportCustomizerProvider; -import org.apache.tinkerpop.gremlin.groovy.NoImportCustomizerProvider; -import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine; import org.apache.tinkerpop.gremlin.process.traversal.Traversal; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; import org.apache.tinkerpop.gremlin.structure.Direction; @@ -32,7 +28,6 @@ import org.apache.tinkerpop.gremlin.structure.Graph; import org.apache.tinkerpop.gremlin.structure.Vertex; import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory; import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph; -import org.apache.tinkerpop.gremlin.util.config.YamlConfiguration; import org.junit.Assert; import org.junit.Test; @@ -42,7 +37,6 @@ import javax.script.ScriptEngine; import javax.script.ScriptException; import java.util.ArrayList; import java.util.Arrays; -import java.util.HashSet; import java.util.List; import java.util.Random; import java.util.concurrent.CountDownLatch; @@ -78,15 +72,7 @@ public class GremlinGroovyScriptEngineOverGraphTest { public void shouldLoadImports() throws Exception { final Graph graph = TinkerFactory.createModern(); final GraphTraversalSource g = graph.traversal(); - final ScriptEngine engineNoImports = new GremlinGroovyScriptEngine((CompilerCustomizerProvider) NoImportCustomizerProvider.INSTANCE); - try { - engineNoImports.eval("Vertex.class.getName()"); - fail("Should have thrown an exception because no imports were supplied"); - } catch (Exception se) { - assertTrue(se instanceof ScriptException); - } - - final ScriptEngine engineWithImports = new GremlinGroovyScriptEngine((CompilerCustomizerProvider) new DefaultImportCustomizerProvider()); + final ScriptEngine engineWithImports = new GremlinGroovyScriptEngine(); engineWithImports.put("g", g); assertEquals(Vertex.class.getName(), engineWithImports.eval("Vertex.class.getName()")); assertEquals(2l, engineWithImports.eval("g.V().has('age',gt(30)).count().next()")); @@ -95,36 +81,6 @@ public class GremlinGroovyScriptEngineOverGraphTest { assertEquals(Direction.BOTH, engineWithImports.eval("Direction.BOTH")); } - - @Test - public void shouldLoadStandardImportsAndThenAddToThem() throws Exception { - final Graph graph = TinkerFactory.createModern(); - final GraphTraversalSource g = graph.traversal(); - final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine((CompilerCustomizerProvider) new DefaultImportCustomizerProvider()); - engine.put("g", g); - assertEquals(Vertex.class.getName(), engine.eval("Vertex.class.getName()")); - assertEquals(2l, engine.eval("g.V().has('age',gt(30)).count().next()")); - assertEquals(Direction.IN, engine.eval("Direction.IN")); - assertEquals(Direction.OUT, engine.eval("Direction.OUT")); - assertEquals(Direction.BOTH, engine.eval("Direction.BOTH")); - - try { - engine.eval("YamlConfiguration.class.getName()"); - fail("Should have thrown an exception because no imports were supplied"); - } catch (Exception se) { - assertTrue(se instanceof ScriptException); - } - - engine.addImports(new HashSet<>(Arrays.asList("import " + YamlConfiguration.class.getCanonicalName()))); - engine.put("g", g); - assertEquals(YamlConfiguration.class.getName(), engine.eval("YamlConfiguration.class.getName()")); - assertEquals(Vertex.class.getName(), engine.eval("Vertex.class.getName()")); - assertEquals(2l, engine.eval("g.V().has('age',gt(30)).count().next()")); - assertEquals(Direction.IN, engine.eval("Direction.IN")); - assertEquals(Direction.OUT, engine.eval("Direction.OUT")); - assertEquals(Direction.BOTH, engine.eval("Direction.BOTH")); - } - @Test public void shouldProperlyHandleBindings() throws Exception { final Graph graph = TinkerFactory.createClassic(); http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/27e5b2c8/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineSandboxedStandardTest.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineSandboxedStandardTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineSandboxedStandardTest.java index 349fcd5..c3bac74 100644 --- a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineSandboxedStandardTest.java +++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineSandboxedStandardTest.java @@ -18,11 +18,7 @@ */ package org.apache.tinkerpop.gremlin.groovy.jsr223; -import org.apache.tinkerpop.gremlin.groovy.CompilerCustomizerProvider; -import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine; -import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.CompileStaticCustomizerProvider; import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.SimpleSandboxExtension; -import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.TypeCheckedCustomizerProvider; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; import org.apache.tinkerpop.gremlin.structure.Graph; import org.apache.tinkerpop.gremlin.structure.Vertex; @@ -48,18 +44,18 @@ public class GremlinGroovyScriptEngineSandboxedStandardTest { @Parameterized.Parameters(name = "{0}") public static Iterable<Object[]> data() { return Arrays.asList(new Object[][]{ - {TypeCheckedCustomizerProvider.class.getSimpleName(), new TypeCheckedCustomizerProvider(), new TypeCheckedCustomizerProvider(SimpleSandboxExtension.class.getName())}, - {CompileStaticCustomizerProvider.class.getSimpleName(), new CompileStaticCustomizerProvider(), new CompileStaticCustomizerProvider(SimpleSandboxExtension.class.getName())}}); + {TypeCheckedGroovyCustomizer.class.getSimpleName(), new TypeCheckedGroovyCustomizer(), new TypeCheckedGroovyCustomizer(SimpleSandboxExtension.class.getName())}, + {CompileStaticGroovyCustomizer.class.getSimpleName(), new CompileStaticGroovyCustomizer(), new CompileStaticGroovyCustomizer(SimpleSandboxExtension.class.getName())}}); } @Parameterized.Parameter(value = 0) public String name; @Parameterized.Parameter(value = 1) - public CompilerCustomizerProvider notSandboxed; + public GroovyCustomizer notSandboxed; @Parameterized.Parameter(value = 2) - public CompilerCustomizerProvider sandboxed; + public GroovyCustomizer sandboxed; @Test public void shouldEvalGraphTraversalSource() throws Exception { http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/27e5b2c8/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java index eb0a44b..f21b4c4 100644 --- a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java +++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTest.java @@ -22,11 +22,6 @@ import groovy.lang.Closure; import groovy.lang.MissingPropertyException; import org.apache.commons.lang.exception.ExceptionUtils; import org.apache.commons.lang3.concurrent.BasicThreadFactory; -import org.apache.tinkerpop.gremlin.groovy.CompilerCustomizerProvider; -import org.apache.tinkerpop.gremlin.groovy.NoImportCustomizerProvider; -import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.InterpreterModeCustomizerProvider; -import org.apache.tinkerpop.gremlin.structure.Vertex; -import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; import org.javatuples.Pair; import org.junit.Test; import org.slf4j.Logger; @@ -37,27 +32,19 @@ import javax.script.ScriptContext; import javax.script.ScriptEngine; import javax.script.ScriptException; import javax.script.SimpleBindings; -import java.awt.*; import java.io.StringWriter; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; -import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicReference; import java.util.stream.IntStream; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.junit.Assert.assertEquals; @@ -99,28 +86,6 @@ public class GremlinGroovyScriptEngineTest { } @Test - public void shouldPromoteDefinedVarsInInterpreterModeWithNoBindingsDeprecated() throws Exception { - final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(new InterpreterModeCustomizerProvider()); - engine.eval("def addItUp = { x, y -> x + y }"); - assertEquals(3, engine.eval("int xxx = 1 + 2")); - assertEquals(4, engine.eval("yyy = xxx + 1")); - assertEquals(7, engine.eval("def zzz = yyy + xxx")); - assertEquals(4, engine.eval("zzz - xxx")); - assertEquals("accessible-globally", engine.eval("if (yyy > 0) { def inner = 'should-stay-local'; outer = 'accessible-globally' }\n outer")); - assertEquals("accessible-globally", engine.eval("outer")); - - try { - engine.eval("inner"); - fail("Should not have been able to access 'inner'"); - } catch (Exception ex) { - final Throwable root = ExceptionUtils.getRootCause(ex); - assertThat(root, instanceOf(MissingPropertyException.class)); - } - - assertEquals(10, engine.eval("addItUp(zzz,xxx)")); - } - - @Test public void shouldPromoteDefinedVarsInInterpreterModeWithNoBindings() throws Exception { final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(new InterpreterModeGroovyCustomizer()); engine.eval("def addItUp = { x, y -> x + y }"); @@ -143,30 +108,6 @@ public class GremlinGroovyScriptEngineTest { } @Test - public void shouldPromoteDefinedVarsInInterpreterModeWithBindingsDeprecated() throws Exception { - final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(new InterpreterModeCustomizerProvider()); - final Bindings b = new SimpleBindings(); - b.put("x", 2); - engine.eval("def addItUp = { x, y -> x + y }", b); - assertEquals(3, engine.eval("int xxx = 1 + x", b)); - assertEquals(4, engine.eval("yyy = xxx + 1", b)); - assertEquals(7, engine.eval("def zzz = yyy + xxx", b)); - assertEquals(4, engine.eval("zzz - xxx", b)); - assertEquals("accessible-globally", engine.eval("if (yyy > 0) { def inner = 'should-stay-local'; outer = 'accessible-globally' }\n outer", b)); - assertEquals("accessible-globally", engine.eval("outer", b)); - - try { - engine.eval("inner", b); - fail("Should not have been able to access 'inner'"); - } catch (Exception ex) { - final Throwable root = ExceptionUtils.getRootCause(ex); - assertThat(root, instanceOf(MissingPropertyException.class)); - } - - assertEquals(10, engine.eval("addItUp(zzz,xxx)", b)); - } - - @Test public void shouldPromoteDefinedVarsInInterpreterModeWithBindings() throws Exception { final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(new InterpreterModeGroovyCustomizer()); final Bindings b = new SimpleBindings(); @@ -218,106 +159,6 @@ public class GremlinGroovyScriptEngineTest { engine.eval("assert 1==0"); } - @Test - public void shouldLoadImportsViaDependencyManagerInterface() throws Exception { - final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine((CompilerCustomizerProvider) NoImportCustomizerProvider.INSTANCE); - try { - engine.eval("Vertex.class.getName()"); - fail("Should have thrown an exception because no imports were supplied"); - } catch (Exception se) { - assertTrue(se instanceof ScriptException); - } - - engine.addImports(new HashSet<>(Arrays.asList("import org.apache.tinkerpop.gremlin.structure.Vertex"))); - assertEquals(Vertex.class.getName(), engine.eval("Vertex.class.getName()")); - } - - @Test - public void shouldLoadImportsViaDependencyManagerInterfaceAdditively() throws Exception { - final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine((CompilerCustomizerProvider) NoImportCustomizerProvider.INSTANCE); - try { - engine.eval("Vertex.class.getName()"); - fail("Should have thrown an exception because no imports were supplied"); - } catch (Exception se) { - assertTrue(se instanceof ScriptException); - } - - try { - engine.eval("StreamFactory.class.getName()"); - fail("Should have thrown an exception because no imports were supplied"); - } catch (Exception se) { - assertTrue(se instanceof ScriptException); - } - - engine.addImports(new HashSet<>(Arrays.asList("import " + Vertex.class.getCanonicalName()))); - assertEquals(Vertex.class.getName(), engine.eval("Vertex.class.getName()")); - - try { - engine.eval("IteratorUtils.class.getName()"); - fail("Should have thrown an exception because no imports were supplied"); - } catch (Exception se) { - assertTrue(se instanceof ScriptException); - } - - engine.addImports(new HashSet<>(Arrays.asList("import " + IteratorUtils.class.getCanonicalName()))); - assertEquals(Vertex.class.getName(), engine.eval("Vertex.class.getName()")); - assertEquals(IteratorUtils.class.getName(), engine.eval("IteratorUtils.class.getName()")); - } - - @Test - public void shouldLoadImportsViaDependencyManagerFromDependencyGatheredByUse() throws Exception { - final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine((CompilerCustomizerProvider) NoImportCustomizerProvider.INSTANCE); - try { - engine.eval("org.apache.commons.math3.util.FastMath.abs(-1235)"); - fail("Should have thrown an exception because no imports were supplied"); - } catch (Exception se) { - assertTrue(se instanceof ScriptException); - } - - engine.addImports(new HashSet<>(Arrays.asList("import org.apache.commons.math3.util.FastMath"))); - engine.use("org.apache.commons", "commons-math3", "3.2"); - assertEquals(1235, engine.eval("org.apache.commons.math3.util.FastMath.abs(-1235)")); - } - - @Test - public void shouldAllowsUseToBeExecutedAfterImport() throws Exception { - final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine((CompilerCustomizerProvider) NoImportCustomizerProvider.INSTANCE); - try { - engine.eval("org.apache.commons.math3.util.FastMath.abs(-1235)"); - fail("Should have thrown an exception because no imports were supplied"); - } catch (Exception se) { - assertTrue(se instanceof ScriptException); - } - - engine.use("org.apache.commons", "commons-math3", "3.2"); - engine.addImports(new HashSet<>(Arrays.asList("import org.apache.commons.math3.util.FastMath"))); - assertEquals(1235, engine.eval("org.apache.commons.math3.util.FastMath.abs(-1235)")); - } - - @Test - public void shouldAllowsMultipleImports() throws Exception { - final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine((CompilerCustomizerProvider) NoImportCustomizerProvider.INSTANCE); - try { - engine.eval("Color.RED"); - fail("Should have thrown an exception because no imports were supplied"); - } catch (Exception se) { - assertTrue(se instanceof ScriptException); - } - - try { - engine.eval("SystemColor.ACTIVE_CAPTION"); - fail("Should have thrown an exception because no imports were supplied"); - } catch (Exception se) { - assertTrue(se instanceof ScriptException); - } - - engine.addImports(new HashSet<>(Arrays.asList("import java.awt.Color"))); - assertEquals(Color.RED, engine.eval("Color.RED")); - - engine.addImports(new HashSet<>(Arrays.asList("import java.awt.SystemColor"))); - assertEquals(Color.RED, engine.eval("Color.RED")); - assertEquals(SystemColor.ACTIVE_CAPTION, engine.eval("SystemColor.ACTIVE_CAPTION")); - } @Test public void shouldClearEngineScopeOnReset() throws Exception { @@ -348,62 +189,6 @@ public class GremlinGroovyScriptEngineTest { } @Test - public void shouldReloadClassLoaderWhileDoingEvalInSeparateThread() throws Exception { - final AtomicBoolean fail = new AtomicBoolean(false); - final AtomicInteger counter = new AtomicInteger(0); - final CountDownLatch latch = new CountDownLatch(1); - final AtomicReference<Color> color = new AtomicReference<>(Color.RED); - - final GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(NoImportCustomizerProvider.INSTANCE); - - try { - scriptEngine.eval("Color.BLACK"); - fail("Should fail as class is not yet imported"); - } catch (ScriptException se) { - // should get here as Color.BLACK is not imported yet. - logger.info("Failed to execute Color.BLACK as expected."); - } - - final Thread evalThread = new Thread(() -> { - try { - // execute scripts until the other thread releases this latch (i.e. after import) - while (latch.getCount() == 1) { - scriptEngine.eval("1+1"); - counter.incrementAndGet(); - } - - color.set((Color) scriptEngine.eval("Color.BLACK")); - } catch (Exception se) { - fail.set(true); - } - }, "test-reload-classloader-1"); - - evalThread.start(); - - // let the first thread execute a bit. - Thread.sleep(1000); - - final Thread importThread = new Thread(() -> { - logger.info("Importing java.awt.Color..."); - final Set<String> imports = new HashSet<String>() {{ - add("import java.awt.Color"); - }}; - scriptEngine.addImports(imports); - latch.countDown(); - }, "test-reload-classloader-2"); - - importThread.start(); - - // block until both threads are done - importThread.join(); - evalThread.join(); - - assertEquals(Color.BLACK, color.get()); - assertThat(counter.get(), greaterThan(0)); - assertFalse(fail.get()); - } - - @Test public void shouldResetClassLoader() throws Exception { final GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(); try { http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/27e5b2c8/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineThreadInterruptTest.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineThreadInterruptTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineThreadInterruptTest.java index 499373f..10f8e1f 100644 --- a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineThreadInterruptTest.java +++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineThreadInterruptTest.java @@ -18,7 +18,6 @@ */ package org.apache.tinkerpop.gremlin.groovy.jsr223; -import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.ThreadInterruptCustomizerProvider; import org.junit.Test; import javax.script.ScriptEngine; @@ -32,26 +31,6 @@ import static org.junit.Assert.assertTrue; * @author Stephen Mallette (http://stephen.genoprime.com) */ public class GremlinGroovyScriptEngineThreadInterruptTest { - @Test - public void shouldInterruptWhileDeprecated() throws Exception { - final ScriptEngine engine = new GremlinGroovyScriptEngine(new ThreadInterruptCustomizerProvider()); - final AtomicBoolean asserted = new AtomicBoolean(false); - - final Thread t = new Thread(() -> { - try { - engine.eval("s = System.currentTimeMillis();\nwhile((System.currentTimeMillis() - s) < 10000) {}"); - } catch (ScriptException se) { - asserted.set(se.getCause().getCause() instanceof InterruptedException); - } - }); - - t.start(); - Thread.sleep(100); - t.interrupt(); - while(t.isAlive()) {} - - assertTrue(asserted.get()); - } @Test public void shouldInterruptWhile() throws Exception { http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/27e5b2c8/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTimedInterruptTest.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTimedInterruptTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTimedInterruptTest.java index 1745b5d..bde5e6f 100644 --- a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTimedInterruptTest.java +++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTimedInterruptTest.java @@ -18,9 +18,6 @@ */ package org.apache.tinkerpop.gremlin.groovy.jsr223; -import org.apache.tinkerpop.gremlin.groovy.DefaultImportCustomizerProvider; -import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.TimedInterruptCustomizerProvider; -import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.TimedInterruptTimeoutException; import org.junit.Test; import javax.script.ScriptEngine; @@ -35,18 +32,6 @@ import static org.junit.Assert.fail; public class GremlinGroovyScriptEngineTimedInterruptTest { @Test - public void shouldTimeoutScriptOnTimedWhileDeprecated() throws Exception { - final ScriptEngine engine = new GremlinGroovyScriptEngine( - new TimedInterruptCustomizerProvider(1000), new DefaultImportCustomizerProvider()); - try { - engine.eval("s = System.currentTimeMillis();\nwhile((System.currentTimeMillis() - s) < 10000) {}"); - fail("This should have timed out"); - } catch (ScriptException se) { - assertEquals(TimedInterruptTimeoutException.class, se.getCause().getCause().getClass()); - } - } - - @Test public void shouldTimeoutScriptOnTimedWhile() throws Exception { final ScriptEngine engine = new GremlinGroovyScriptEngine(new TimedInterruptGroovyCustomizer(1000)); try { @@ -58,22 +43,6 @@ public class GremlinGroovyScriptEngineTimedInterruptTest { } @Test - public void shouldTimeoutScriptOnTimedWhileOnceEngineHasBeenAliveForLongerThanTimeoutDeprecated() throws Exception { - final ScriptEngine engine = new GremlinGroovyScriptEngine( - new TimedInterruptCustomizerProvider(1000), new DefaultImportCustomizerProvider()); - Thread.sleep(2000); - try { - engine.eval("s = System.currentTimeMillis();\nwhile((System.currentTimeMillis() - s) < 10000) {}"); - fail("This should have timed out"); - } catch (ScriptException se) { - assertEquals(TimedInterruptTimeoutException.class, se.getCause().getCause().getClass()); - } - - assertEquals(2, engine.eval("1+1")); - } - - - @Test public void shouldTimeoutScriptOnTimedWhileOnceEngineHasBeenAliveForLongerThanTimeout() throws Exception { final ScriptEngine engine = new GremlinGroovyScriptEngine(new TimedInterruptGroovyCustomizer(1000)); Thread.sleep(2000); @@ -88,27 +57,6 @@ public class GremlinGroovyScriptEngineTimedInterruptTest { } @Test - public void shouldContinueToEvalScriptsEvenWithTimedInterruptDeprecated() throws Exception { - final ScriptEngine engine = new GremlinGroovyScriptEngine( - new TimedInterruptCustomizerProvider(1000), new DefaultImportCustomizerProvider()); - - for (int ix = 0; ix < 5; ix++) { - try { - // this script takes 1000 ms longer than the interruptionTimeout - engine.eval("s = System.currentTimeMillis();\nwhile((System.currentTimeMillis() - s) < 2000) {}"); - fail("This should have timed out"); - } catch (ScriptException se) { - assertEquals(TimedInterruptTimeoutException.class, se.getCause().getCause().getClass()); - } - - // this script takes 500 ms less than the interruptionTimeout - assertEquals("test", engine.eval("s = System.currentTimeMillis();\nwhile((System.currentTimeMillis() - s) < 500) {};'test'")); - } - - assertEquals(2, engine.eval("1+1")); - } - - @Test public void shouldContinueToEvalScriptsEvenWithTimedInterrupt() throws Exception { final ScriptEngine engine = new GremlinGroovyScriptEngine( new TimedInterruptGroovyCustomizer(1000)); @@ -130,16 +78,6 @@ public class GremlinGroovyScriptEngineTimedInterruptTest { } @Test - public void shouldNotTimeoutStandaloneFunctionDeprecated() throws Exception { - // use a super fast timeout which should not prevent the call of a cached function - final ScriptEngine engine = new GremlinGroovyScriptEngine( - new TimedInterruptCustomizerProvider(1), new DefaultImportCustomizerProvider()); - engine.eval("def addItUp(x,y) { x + y }"); - - assertEquals(3, engine.eval("addItUp(1,2)")); - } - - @Test public void shouldNotTimeoutStandaloneFunction() throws Exception { // use a super fast timeout which should not prevent the call of a cached function final ScriptEngine engine = new GremlinGroovyScriptEngine(new TimedInterruptGroovyCustomizer(1)); http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/27e5b2c8/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTinkerPopSandboxTest.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTinkerPopSandboxTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTinkerPopSandboxTest.java index 0ff2706..c2d555f 100644 --- a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTinkerPopSandboxTest.java +++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTinkerPopSandboxTest.java @@ -18,9 +18,6 @@ */ package org.apache.tinkerpop.gremlin.groovy.jsr223; -import org.apache.tinkerpop.gremlin.groovy.CompilerCustomizerProvider; -import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine; -import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.CompileStaticCustomizerProvider; import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.TinkerPopSandboxExtension; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; import org.apache.tinkerpop.gremlin.structure.Graph; @@ -42,7 +39,7 @@ import static org.junit.Assert.fail; public class GremlinGroovyScriptEngineTinkerPopSandboxTest { @Test public void shouldNotEvalAsTheMethodIsNotWhiteListed() throws Exception { - final CompilerCustomizerProvider standardSandbox = new CompileStaticCustomizerProvider(TinkerPopSandboxExtension.class.getName()); + final CompileStaticGroovyCustomizer standardSandbox = new CompileStaticGroovyCustomizer(TinkerPopSandboxExtension.class.getName()); try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(standardSandbox)) { engine.eval("java.lang.Math.abs(123)"); fail("Should have a compile error because class/method is not white listed"); @@ -56,7 +53,7 @@ public class GremlinGroovyScriptEngineTinkerPopSandboxTest { public void shouldEvalOnGAsTheMethodIsWhiteListed() throws Exception { final Graph graph = TinkerFactory.createModern(); final GraphTraversalSource g = graph.traversal(); - final CompilerCustomizerProvider standardSandbox = new CompileStaticCustomizerProvider(TinkerPopSandboxExtension.class.getName()); + final CompileStaticGroovyCustomizer standardSandbox = new CompileStaticGroovyCustomizer(TinkerPopSandboxExtension.class.getName()); try (GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(standardSandbox)) { final Bindings bindings = engine.createBindings(); bindings.put("g", g); http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/27e5b2c8/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTypeCheckedTest.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTypeCheckedTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTypeCheckedTest.java index 6c70e8e..4299f3d 100644 --- a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTypeCheckedTest.java +++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineTypeCheckedTest.java @@ -19,8 +19,6 @@ package org.apache.tinkerpop.gremlin.groovy.jsr223; import org.apache.commons.lang.exception.ExceptionUtils; -import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.CompileStaticCustomizerProvider; -import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.TypeCheckedCustomizerProvider; import org.codehaus.groovy.control.MultipleCompilationErrorsException; import org.junit.Test; @@ -35,23 +33,6 @@ import static org.junit.Assert.fail; * @author Stephen Mallette (http://stephen.genoprime.com) */ public class GremlinGroovyScriptEngineTypeCheckedTest { - @Test - public void shouldTypeCheckDeprecated() throws Exception { - // with no type checking this should pass - try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine()) { - assertEquals(255, scriptEngine.eval("((Object) new java.awt.Color(255, 255, 255)).getRed()")); - } - - final TypeCheckedCustomizerProvider provider = new TypeCheckedCustomizerProvider(); - try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(provider)) { - scriptEngine.eval("((Object) new java.awt.Color(255, 255, 255)).getRed()"); - fail("Should have failed type checking"); - } catch (ScriptException se) { - final Throwable root = ExceptionUtils.getRootCause(se); - assertEquals(MultipleCompilationErrorsException.class, root.getClass()); - assertThat(se.getMessage(), containsString("[Static type checking] - Cannot find matching method java.lang.Object#getRed(). Please check if the declared type is right and if the method exists.")); - } - } @Test public void shouldTypeCheck() throws Exception { @@ -72,25 +53,6 @@ public class GremlinGroovyScriptEngineTypeCheckedTest { } @Test - public void shouldTypeCheckWithExtensionDeprecated() throws Exception { - // with no type checking extension this should pass - final TypeCheckedCustomizerProvider providerNoExtension = new TypeCheckedCustomizerProvider(); - try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(providerNoExtension)) { - assertEquals(255, scriptEngine.eval("def c = new java.awt.Color(255, 255, 255); c.red")); - } - - final CompileStaticCustomizerProvider providerWithExtension = new CompileStaticCustomizerProvider( - PrecompiledExtensions.PreventColorUsageExtension.class.getName()); - try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(providerWithExtension)) { - scriptEngine.eval("def c = new java.awt.Color(255, 255, 255); c.red"); - fail("Should have failed type checking"); - } catch (ScriptException se) { - assertEquals(MultipleCompilationErrorsException.class, se.getCause().getClass()); - assertThat(se.getMessage(), containsString("Method call is not allowed!")); - } - } - - @Test public void shouldTypeCheckWithExtension() throws Exception { // with no type checking extension this should pass final TypeCheckedGroovyCustomizer providerNoExtension = new TypeCheckedGroovyCustomizer(); @@ -98,7 +60,7 @@ public class GremlinGroovyScriptEngineTypeCheckedTest { assertEquals(255, scriptEngine.eval("def c = new java.awt.Color(255, 255, 255); c.red")); } - final CompileStaticCustomizerProvider providerWithExtension = new CompileStaticCustomizerProvider( + final TypeCheckedGroovyCustomizer providerWithExtension = new TypeCheckedGroovyCustomizer( PrecompiledExtensions.PreventColorUsageExtension.class.getName()); try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(providerWithExtension)) { scriptEngine.eval("def c = new java.awt.Color(255, 255, 255); c.red"); @@ -110,35 +72,6 @@ public class GremlinGroovyScriptEngineTypeCheckedTest { } @Test - public void shouldTypeCheckWithMultipleExtensionDeprecated() throws Exception { - // with no type checking extension this should pass - final TypeCheckedCustomizerProvider providerNoExtension = new TypeCheckedCustomizerProvider(); - try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(providerNoExtension)) { - assertEquals(255, scriptEngine.eval("def c = new java.awt.Color(255, 255, 255); c.red")); - assertEquals(1l, scriptEngine.eval("def c = new java.util.concurrent.CountDownLatch(1); c.count")); - } - - final TypeCheckedCustomizerProvider providerWithExtension = new TypeCheckedCustomizerProvider( - PrecompiledExtensions.PreventColorUsageExtension.class.getName() + - "," + PrecompiledExtensions.PreventCountDownLatchUsageExtension.class.getName()); - try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(providerWithExtension)) { - scriptEngine.eval("def c = new java.awt.Color(255, 255, 255); c.red"); - fail("Should have failed type checking"); - } catch (ScriptException se) { - assertEquals(MultipleCompilationErrorsException.class, se.getCause().getClass()); - assertThat(se.getMessage(), containsString("Method call is not allowed!")); - } - - try (GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(providerWithExtension)) { - scriptEngine.eval("def c = new java.util.concurrent.CountDownLatch(1); c.count"); - fail("Should have failed type checking"); - } catch (ScriptException se) { - assertEquals(MultipleCompilationErrorsException.class, se.getCause().getClass()); - assertThat(se.getMessage(), containsString("Method call is not allowed!")); - } - } - - @Test public void shouldTypeCheckWithMultipleExtension() throws Exception { // with no type checking extension this should pass final TypeCheckedGroovyCustomizer providerNoExtension = new TypeCheckedGroovyCustomizer(); http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/27e5b2c8/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyCompilerGremlinPluginTest.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyCompilerGremlinPluginTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyCompilerGremlinPluginTest.java index f795fa7..4cdf158 100644 --- a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyCompilerGremlinPluginTest.java +++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyCompilerGremlinPluginTest.java @@ -18,12 +18,6 @@ */ package org.apache.tinkerpop.gremlin.groovy.jsr223; -import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.CompileStaticCustomizerProvider; -import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.ConfigurationCustomizerProvider; -import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.InterpreterModeCustomizerProvider; -import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.ThreadInterruptCustomizerProvider; -import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.TimedInterruptCustomizerProvider; -import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.TypeCheckedCustomizerProvider; import org.apache.tinkerpop.gremlin.jsr223.Customizer; import org.codehaus.groovy.control.CompilerConfiguration; import org.junit.Test; http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/27e5b2c8/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/ConfigurationCustomizerProviderTest.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/ConfigurationCustomizerProviderTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/ConfigurationCustomizerProviderTest.java deleted file mode 100644 index 54b55b1..0000000 --- a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/customizer/ConfigurationCustomizerProviderTest.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.apache.tinkerpop.gremlin.groovy.jsr223.customizer; - -import org.apache.commons.lang.exception.ExceptionUtils; -import org.codehaus.groovy.control.CompilerConfiguration; -import org.junit.Test; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.IsInstanceOf.instanceOf; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -/** - * @author Stephen Mallette (http://stephen.genoprime.com) - */ -public class ConfigurationCustomizerProviderTest { - @Test(expected = IllegalArgumentException.class) - public void shouldThrowExceptionForNoSettings() { - new ConfigurationCustomizerProvider(); - } - - @Test(expected = IllegalArgumentException.class) - public void shouldThrowExceptionForInvalidSettings() { - new ConfigurationCustomizerProvider("only-one-arg"); - } - - @Test - public void shouldThrowExceptionForNotFoundSetting() { - final CompilerConfiguration configuration = new CompilerConfiguration(); - try { - final ConfigurationCustomizerProvider provider = new ConfigurationCustomizerProvider( - "Tolerance", 3, - "NotRealSettingThatWouldEverOccur2", new java.util.Date()); - - provider.applyCustomization(configuration); - } catch (Exception ex) { - assertThat(ex, instanceOf(IllegalStateException.class)); - assertEquals("Invalid setting [NotRealSettingThatWouldEverOccur2] for CompilerConfiguration", ex.getMessage()); - } - } - - @Test - public void shouldApplyConfigurationChanges() { - final CompilerConfiguration configuration = new CompilerConfiguration(); - - assertEquals(10, configuration.getTolerance()); - assertNull(configuration.getScriptBaseClass()); - assertEquals(false, configuration.getDebug()); - - final ConfigurationCustomizerProvider provider = new ConfigurationCustomizerProvider( - "Tolerance", 3, - "ScriptBaseClass", "Something", - "Debug", true); - - provider.applyCustomization(configuration); - - assertEquals(3, configuration.getTolerance()); - assertEquals("Something", configuration.getScriptBaseClass()); - assertEquals(true, configuration.getDebug()); - } -}