4

I am getting error message

Error invoking bsh method: eval Sourced file: inline evaluation of: ``import java.util.Arrays; import java.util.List; import java.util.concurrent.Time . . . '' : Typed variable declaration : Error in method invocation: Static method create( java.lang.String ) not found in class'com.couchbase.client.java.CouchbaseCluster'

when I execute jmeter script with Beanshell Post Processor. Any thoughts on why I am seeing this error?

Here is the sample code: import java.util.Arrays;

import java.util.List;
import java.util.concurrent.TimeUnit;

import com.couchbase.client.java.Bucket;
import com.couchbase.client.java.Cluster;
import com.couchbase.client.java.CouchbaseCluster;
import com.couchbase.client.java.document.Document;
import com.couchbase.client.java.document.JsonDocument;
import com.couchbase.client.java.document.json.JsonObject;

Cluster cluster = CouchbaseCluster.create("dev-int-couchbase1.aeg.cloud");
Bucket bucket = cluster.openBucket("source-image ",100, TimeUnit.MINUTES);
Document<JsonObject> loadedFromDoc = bucket.get("0292ofcfh4516");
if(loadedFromDoc == null)
    return "Document Not found";

bucket.remove(“0292ofcfh4516");
log.info("In bean shell processor");
System.out.println("In bean shell processor");
cluster.disconnect();
return "Document Removed";
happymacarts
  • 2,547
  • 1
  • 25
  • 33
kmn
  • 41
  • 1
  • 2

1 Answers1

1

Instead of using create(String... varargs) method, suggest using create(List<String> nodes) method.

replace the following code

Cluster cluster = CouchbaseCluster.create("dev-int-couchbase1.aeg.cloud");

With:

nodes = new ArrayList();
nodes.add("dev-int-couchbase1.aeg.cloud");
Cluster cluster = CouchbaseCluster.create(nodes);

Note: I am not sure how to fix the issue related to varargs, so suggesting another one. I tried suggested method here, but did not work for varargs.

Reference:

  1. http://docs.couchbase.com/sdk-api/couchbase-java-client-2.0.0/index.html?com/couchbase/client/java/CouchbaseCluster.html

I suggest use JSR223 Post Processor instead of BeanShell postprocessor. Just copy paste the code from BeanShell to JSR223 and select the language as Java under script language drop-down available in the JSR223 post processor.

This gives more flexibility in debugging (prints complete stack trace of the error/exception in the logs).


Coming to the error, it says that Static method create( java.lang.String ) not found in class'com.couchbase.client.java.CouchbaseCluster. I checked in the official docs here, which says there is a create method which takes String Varargs. I ma not sure whether that is causing the issue. so, try it out in JSR223 PostProcessor and debug the issue.

References:

  1. https://www.blazemeter.com/blog/beanshell-vs-jsr223-vs-java-jmeter-scripting-its-performance
Community
  • 1
  • 1
Naveen Kumar R B
  • 6,248
  • 5
  • 32
  • 65
  • @kmm, updated my answer. try with `create(List nodes)` method which is also available in the CouchbaseCluster class. this approach is working for me. – Naveen Kumar R B Dec 16 '16 at 06:17
  • Thank you naveen. I have used JSR223 Pre Processor and updated the code as per your comments. – kmn Dec 16 '16 at 22:16
  • found below error message:jmeter.modifiers.JSR223PreProcessor: Problem in JSR223 script javax.script.ScriptException: In file: inline evaluation of: ``import java.util.Arrays; import java.util.List; import java.util.concurrent.Time . . . '' Encountered "=" at line 16, column 36. in inline evaluation of: ``import java.util.Arrays; import java.util.List; import java.util.concurrent.Time . . . '' at line number 16 – kmn Dec 16 '16 at 22:18
  • nodes = new ArrayList(); nodes.add("dev-int-couchbase1.aeg.cloud"); Cluster cluster = CouchbaseCluster.create(nodes); Bucket bucket = cluster.openBucket("source-image",100, TimeUnit.MINUTES); Document loadedFromDoc = bucket.get("0292f666e15eut"); if(loadedFromDoc == null) return "Document Not found"; bucket.remove(“0292f666e15eut"); cluster.disconnect(); return "Document Removed"; – kmn Dec 16 '16 at 22:19
  • Try the code in answer with beanshell post processor itself and let me know. I checked in beanshell and I was working for me. – Naveen Kumar R B Dec 17 '16 at 01:50
  • Thanks much Naveen... Few small minor issues in my code.. I have resolved them and working fine... Thank you again – kmn Dec 21 '16 at 22:05