Permalink
Browse files

Bug fixed

  • Loading branch information...
oleksiyp oleksiyp
oleksiyp authored and oleksiyp committed Nov 5, 2011
1 parent c18b6ad commit 84c5cfed258454ae75c118bb9445b2da1add5f3d
Showing with 11 additions and 18 deletions.
  1. +1 −1 Crawler.groovy
  2. +3 −8 src/main/java/org/loadtest/ScriptRunner.java
  3. +7 −9 src/main/resources/org/loadtest/Classes.groovy
View
@@ -3,7 +3,7 @@
import java.util.regex.Pattern;
try {
- List urls = GLOBALS.list("urls");
+ List urls = Globals.list("urls");
String url = Variations.takeAny(urls);
if (url == null) {
return;
@@ -8,6 +8,7 @@
import java.io.File;
import java.io.IOException;
+import java.util.HashMap;
import java.util.Random;
/**
@@ -20,7 +21,7 @@
public class ScriptRunner implements Runnable {
private final LoadTestTool loadTool;
private final Stats stats = new Stats();
- private Object globals;
+ private HashMap globalValues = new HashMap();
private final Random random = new Random();
private final static ThreadLocal<GroovyShell> LOCAL_SHELL = new ThreadLocal<GroovyShell>();
@@ -66,6 +67,7 @@ public void run(GroovyShellRunner runner) {
stats.addRun();
}
Binding binding = new Binding();
+ binding.setProperty("GLOBAL_VALUES", globalValues);
binding.setVariable("STATS", stats);
GroovyShell shell = new GroovyShell(binding);
@@ -74,13 +76,6 @@ public void run(GroovyShellRunner runner) {
shell.evaluate(new GroovyCodeSource(ScriptRunner.class.getResource("Classes.groovy")));
- synchronized (this) {
- if (globals == null) {
- globals = shell.evaluate("return new Globals()");
- }
- }
- binding.setProperty("GLOBALS", globals);
-
runner.run(shell);
} catch (CompilationFailedException e) {
@@ -1,4 +1,3 @@
-import groovy.lang.Binding
import java.util.regex.Pattern
import java.util.regex.Matcher
import org.loadtest.ScriptRunner
@@ -146,7 +145,7 @@ public class Globals {
return values.get(name);
}
- private synchronized List instanceList(String name, String ...defaultValues) {
+ private synchronized List instanceList(String name, String []defaultValues) {
List list = (List) values.get(name);
if (list == null) {
list = Collections.synchronizedList(new ArrayList(Arrays.asList(defaultValues)));
@@ -166,17 +165,16 @@ public class Globals {
}
// used for alone script runs
- private static Globals LOCAL_GLOBALS;
+ private static Globals INSTANCE = new Globals();
private synchronized static Globals getGlobals() {
Binding bindings = Context.getLocalShellBindings();
- if (bindings == null || bindings.GLOBALS == null) {
- if (LOCAL_GLOBALS == null) {
- LOCAL_GLOBALS = new Globals();
- }
- return LOCAL_GLOBALS;
+ if (!(bindings == null || bindings.getProperty("GLOBAL_VALUES") == null)) {
+ INSTANCE.values = bindings.GLOBAL_VALUES;
+ } else {
+ System.err.println("Local context used - globals not working");
}
- return bindings.GLOBALS;
+ return INSTANCE;
}
// static part

0 comments on commit 84c5cfe

Please sign in to comment.