2017-04-12 13 views
0

jmeter bean shell samplerで実行中に上記のようなエラーが発生しました 応答メッセージ:org.apache.jorphan.util.JMeterException:bshメソッドを呼び出すエラー:eval t null

実際にコードはEclipseでうまくいきましたが、Jmeterに実装されている間は正常に動作しませんでした。 この問題を解決するお手伝いができますか?

import com.google.gson.*; 
import com.google.gson.reflect.TypeToken; 
import java.io.FileReader; 
import java.lang.reflect.Type; 
import java.util.*; 
import java.util.Map.*; 
import java.util.Set; 
public class JsonComparator { 

public static void main(String[] args) throws Exception { 
    JsonParser parser = new JsonParser(); 

    try{ 
     Gson g = new Gson(); 
     JsonElement jsonElement1 = parser 
       .parse(new FileReader("E:\\InCites_UI\\trunk\\Tests\\Filters_ByPerson_People_PerfC.json")); 
     JsonElement jsonElement2 = parser 
       .parse(new FileReader("E:\\InCites_UI\\trunk\\Tests\\Filters_ByPerson_People_PerfA.json")); 

     System.out.println("Is the two JSON File Same: "+compareJson(jsonElement1, jsonElement2)); 
     if(!compareJson(jsonElement1, jsonElement2)){ 
      Type mapType = new TypeToken<Map<String, Object>>(){}.getType(); 
      Map<String,Object> firstMap = g.fromJson(jsonElement1, mapType); 
      Map<String, Object> secondMap = g.fromJson(jsonElement2, mapType); 
      System.out.println(JsonComparator.mapDifference(firstMap, secondMap)); 
     } 
     else{ 
      System.out.println("The Two JSON Are SAME!!!!!!!!!!!!!!!"); 
     } 

    }catch(Exception e1){ 
     e1.printStackTrace(); 
    } 

} 

public static <K, V> Map<K, V> mapDifference(Map<? extends K, ? extends V> left, Map<? extends K, ? extends V> right) { 
    Map<K, V> difference = new HashMap<K, V>(); 
    difference.putAll(left); 
    difference.putAll(right); 
    difference.entrySet().removeAll(right.entrySet()); 
    return difference; 
} 

public static boolean compareJson(JsonElement json1, JsonElement json2) { 
    boolean isEqual = true; 
    ArrayList<Object> ls1 = new ArrayList<Object>(); 
    ArrayList<Object> ls2 = new ArrayList<Object>(); 
    // Check whether both jsonElement are not null 
    if (json1 != null && json2 != null) { 

     // Check whether both jsonElement are objects 
     if (json1.isJsonObject() && json2.isJsonObject()) { 
      Set<Entry<String, JsonElement>> ens1 = ((JsonObject) json1).entrySet(); 
      Set<Entry<String, JsonElement>> ens2 = ((JsonObject) json2).entrySet(); 
      JsonObject json2obj = (JsonObject) json2; 
      if (ens1 != null && ens2 != null && (ens2.size() == ens1.size())) { 
       // Iterate JSON Elements with Key values 
       for (Entry<String, JsonElement> en : ens1) { 
        isEqual = isEqual && compareJson(en.getValue(),json2obj.get(en.getKey())); 
       } 
      } else { 
       return false; 
      } 
     } 
     // Check whether both jsonElement are arrays 
     else if (json1.isJsonArray() && json2.isJsonArray()) { 
      JsonArray jarr1 = json1.getAsJsonArray(); 
      JsonArray jarr2 = json2.getAsJsonArray(); 
      if (jarr1.size() != jarr2.size()) { 
       return false; 
      } else { 
       int i = 0; 
       // Iterate JSON Array to JSON Elements 
       for (JsonElement je : jarr1) { 
        isEqual = isEqual && compareJson(je, jarr2.get(i)); 
        i++; 
       } 
       if (isEqual) { 
        Object[] o1 = ls1.toArray(); 
        Object[] o2 = ls2.toArray(); 
        isEqual = Arrays.deepEquals(o1, o2); 
       } 
      } 

     } 

     // Check whether both jsonElement are null 
     else if (json1.isJsonNull() && json2.isJsonNull()) { 
      return true; 
     } 

     // Check whether both jsonElement are primitives 
     else if (json1.isJsonPrimitive() && json2.isJsonPrimitive()) { 
      ls1.add(json1); 
      ls2.add(json2); 
     } 
    } else if (json1 == null && json2 == null) { 
     return true; 
    } else { 
     return false; 
    } 
    return isEqual; 
} 

}

いずれかがこのコードを使用してJMeterの上で動作するようにしようとすることができるならば、我々は、この上のヘルプを探していますか? Jmeterでは実装できません。

実際にコードはEclipseでうまくいきましたが、Jmeterに実装されている間は正常に動作しませんでした。

+0

あなたのプロジェクトのスクリーンショットを投稿しないでください。代わりに自分のコードを含めてください。誰かがあなたの問題を再現したい場合に読みやすく、コピーする方が簡単です。 – cbuchart

答えて

1

2つのBeanShellスクリプトのトラブルシューティング手法があります。

  1. は、スクリプトの先頭にdebug();コマンドを追加します - あなたはstdout
  2. でテストフローに関する追加情報を取得します。この方法は、あなたのコードを入れてください内側try blockのように:

    try { 
        //your code here 
    } 
    catch (Throwable ex) { 
        log.error("Beanshell failure", ex); 
        throw ex; 
    } 
    

    lはjmeter.logファイルで一般的に

の方法より有益なスタックトレースを取得し、私はJSR223 SamplerGroovy言語に切り替えることをお勧めします。 Groovy has built-in JSON supportであり、Beanshellと比較してはるかに優れています。詳しくは、Groovy Is the New Blackの記事を参照してください。

今後、画像としてコードを投稿しないでください。これを掘り下げる熱狂家はいないと思います。

関連する問題