jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fschumac...@apache.org
Subject [jmeter] 01/12: added database and access mode parameters to BoltSampler
Date Fri, 12 Mar 2021 16:20:55 GMT
This is an automated email from the ASF dual-hosted git repository.

fschumacher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git

commit d3c89422b1910bdec85a6d6f1e672808f0a1c7dc
Author: David Pecollet <david.pecollet@gmail.com>
AuthorDate: Fri Dec 11 17:13:26 2020 +0000

    added database and access mode parameters to BoltSampler
    
    database : required to address a on-default dtabase in Neo4j 4.x
    accessMode : allow to test against a cluster w/o having all queries sent to the leader
(previous was defaulting to WRITE)
---
 .../bolt/sampler/AbstractBoltTestElement.java      | 23 ++++++++++++++++++++++
 .../jmeter/protocol/bolt/sampler/BoltSampler.java  | 12 ++++++++---
 .../sampler/BoltTestElementBeanInfoSupport.java    | 11 ++++++++++-
 .../bolt/sampler/BoltSamplerResources.properties   |  4 ++++
 .../protocol/bolt/sampler/BoltSamplerSpec.groovy   |  6 +++++-
 5 files changed, 51 insertions(+), 5 deletions(-)

diff --git a/src/protocol/bolt/src/main/java/org/apache/jmeter/protocol/bolt/sampler/AbstractBoltTestElement.java
b/src/protocol/bolt/src/main/java/org/apache/jmeter/protocol/bolt/sampler/AbstractBoltTestElement.java
index 5f77d46..bba0c83 100644
--- a/src/protocol/bolt/src/main/java/org/apache/jmeter/protocol/bolt/sampler/AbstractBoltTestElement.java
+++ b/src/protocol/bolt/src/main/java/org/apache/jmeter/protocol/bolt/sampler/AbstractBoltTestElement.java
@@ -18,13 +18,36 @@
 package org.apache.jmeter.protocol.bolt.sampler;
 
 import org.apache.jmeter.testelement.AbstractTestElement;
+import org.neo4j.driver.AccessMode;
 
 public abstract class AbstractBoltTestElement extends AbstractTestElement {
 
     private String cypher;
     private String params;
+    private String database;
+    private AccessMode accessMode;
     private boolean recordQueryResults;
 
+    public AccessMode getAccessMode() {
+        if (accessMode != null) {
+            return accessMode;
+        } else {
+            return AccessMode.WRITE;
+        }
+    }
+
+    public void setAccessMode(AccessMode accessMode) {
+        this.accessMode = accessMode;
+    }
+
+    public String getDatabase() {
+        return database;
+    }
+
+    public void setDatabase(String database) {
+        this.database = database;
+    }
+
     public String getCypher() {
         return cypher;
     }
diff --git a/src/protocol/bolt/src/main/java/org/apache/jmeter/protocol/bolt/sampler/BoltSampler.java
b/src/protocol/bolt/src/main/java/org/apache/jmeter/protocol/bolt/sampler/BoltSampler.java
index 03b2c43..dfc5d47 100644
--- a/src/protocol/bolt/src/main/java/org/apache/jmeter/protocol/bolt/sampler/BoltSampler.java
+++ b/src/protocol/bolt/src/main/java/org/apache/jmeter/protocol/bolt/sampler/BoltSampler.java
@@ -35,10 +35,12 @@ import org.apache.jmeter.samplers.SampleResult;
 import org.apache.jmeter.samplers.Sampler;
 import org.apache.jmeter.testbeans.TestBean;
 import org.apache.jmeter.testelement.TestElement;
+import org.neo4j.driver.AccessMode;
 import org.neo4j.driver.Driver;
 import org.neo4j.driver.Record;
 import org.neo4j.driver.Result;
 import org.neo4j.driver.Session;
+import org.neo4j.driver.SessionConfig;
 import org.neo4j.driver.exceptions.Neo4jException;
 import org.neo4j.driver.summary.ResultSummary;
 
@@ -82,7 +84,7 @@ public class BoltSampler extends AbstractBoltTestElement implements Sampler,
Tes
 
         try {
             res.setResponseHeaders("Cypher request: " + getCypher());
-            res.setResponseData(execute(BoltConnectionElement.getDriver(), getCypher(), params),
StandardCharsets.UTF_8.name());
+            res.setResponseData(execute(BoltConnectionElement.getDriver(), getCypher(), params,
getAccessMode(), getDatabase()), StandardCharsets.UTF_8.name());
         } catch (Exception ex) {
             res = handleException(res, ex);
         } finally {
@@ -100,8 +102,12 @@ public class BoltSampler extends AbstractBoltTestElement implements Sampler,
Tes
         return APPLICABLE_CONFIG_CLASSES.contains(guiClass);
     }
 
-    private String execute(Driver driver, String cypher, Map<String, Object> params)
{
-        try (Session session = driver.session()) {
+    private String execute(Driver driver, String cypher, Map<String, Object> params,
AccessMode accessMode, String database) {
+        SessionConfig sessionConfig = SessionConfig.builder()
+                .withDatabase(database)
+                .withDefaultAccessMode(accessMode)
+                .build();
+        try (Session session = driver.session(sessionConfig)) {
             Result statementResult = session.run(cypher, params);
             return response(statementResult);
         }
diff --git a/src/protocol/bolt/src/main/java/org/apache/jmeter/protocol/bolt/sampler/BoltTestElementBeanInfoSupport.java
b/src/protocol/bolt/src/main/java/org/apache/jmeter/protocol/bolt/sampler/BoltTestElementBeanInfoSupport.java
index 0be4e9e..1282b4b 100644
--- a/src/protocol/bolt/src/main/java/org/apache/jmeter/protocol/bolt/sampler/BoltTestElementBeanInfoSupport.java
+++ b/src/protocol/bolt/src/main/java/org/apache/jmeter/protocol/bolt/sampler/BoltTestElementBeanInfoSupport.java
@@ -22,6 +22,7 @@ import java.beans.PropertyDescriptor;
 import org.apache.jmeter.testbeans.BeanInfoSupport;
 import org.apache.jmeter.testbeans.TestBean;
 import org.apache.jmeter.testbeans.gui.TypeEditor;
+import org.neo4j.driver.AccessMode;
 
 public abstract class BoltTestElementBeanInfoSupport extends BeanInfoSupport {
     /**
@@ -32,7 +33,7 @@ public abstract class BoltTestElementBeanInfoSupport extends BeanInfoSupport
{
     protected BoltTestElementBeanInfoSupport(Class<? extends TestBean> beanClass) {
         super(beanClass);
 
-        createPropertyGroup("query", new String[] { "cypher","params","recordQueryResults"});
+        createPropertyGroup("query", new String[] { "cypher","params","recordQueryResults","accessMode","database"});
 
         PropertyDescriptor propertyDescriptor =  property("cypher", TypeEditor.TextAreaEditor);
         propertyDescriptor.setValue(NOT_UNDEFINED, Boolean.TRUE);
@@ -45,5 +46,13 @@ public abstract class BoltTestElementBeanInfoSupport extends BeanInfoSupport
{
         propertyDescriptor =  property("recordQueryResults");
         propertyDescriptor.setValue(NOT_UNDEFINED, Boolean.TRUE);
         propertyDescriptor.setValue(DEFAULT, Boolean.FALSE);
+
+        propertyDescriptor =  property("accessMode", TypeEditor.ComboStringEditor);
+        propertyDescriptor.setValue(NOT_UNDEFINED, Boolean.TRUE);
+        propertyDescriptor.setValue(NOT_EXPRESSION, Boolean.TRUE);
+        propertyDescriptor.setValue(DEFAULT, AccessMode.WRITE);
+
+        propertyDescriptor =  property("database");
+        propertyDescriptor.setValue(DEFAULT, "neo4j");
     }
 }
diff --git a/src/protocol/bolt/src/main/resources/org/apache/jmeter/protocol/bolt/sampler/BoltSamplerResources.properties
b/src/protocol/bolt/src/main/resources/org/apache/jmeter/protocol/bolt/sampler/BoltSamplerResources.properties
index 7b606b7..7ace4c2 100644
--- a/src/protocol/bolt/src/main/resources/org/apache/jmeter/protocol/bolt/sampler/BoltSamplerResources.properties
+++ b/src/protocol/bolt/src/main/resources/org/apache/jmeter/protocol/bolt/sampler/BoltSamplerResources.properties
@@ -23,3 +23,7 @@ params.displayName=Params
 params.shortDescription=Params
 recordQueryResults.displayName=Record Query Results
 recordQueryResults.shortDescription=Records the results of queries and displays in listeners
such as View Results Tree, this iterates through the entire resultset. Use to debug only.
+accessMode.displayName=Access Mode
+accessMode.shortDescription=Access Mode
+database.displayName=Database
+database.shortDescription=Database
diff --git a/src/protocol/bolt/src/test/groovy/org/apache/jmeter/protocol/bolt/sampler/BoltSamplerSpec.groovy
b/src/protocol/bolt/src/test/groovy/org/apache/jmeter/protocol/bolt/sampler/BoltSamplerSpec.groovy
index ffd3b5a..6f89702 100644
--- a/src/protocol/bolt/src/test/groovy/org/apache/jmeter/protocol/bolt/sampler/BoltSamplerSpec.groovy
+++ b/src/protocol/bolt/src/test/groovy/org/apache/jmeter/protocol/bolt/sampler/BoltSamplerSpec.groovy
@@ -24,6 +24,7 @@ import org.apache.jmeter.threads.JMeterVariables
 import org.neo4j.driver.Driver
 import org.neo4j.driver.Result
 import org.neo4j.driver.Session
+import org.neo4j.driver.SessionConfig
 import org.neo4j.driver.exceptions.ClientException
 import org.neo4j.driver.summary.ResultSummary
 import org.neo4j.driver.summary.SummaryCounters
@@ -47,12 +48,13 @@ class BoltSamplerSpec extends Specification {
         JMeterContextService.getContext().setVariables(variables)
         entry.addConfigElement(boltConfig)
         session = Mock(Session)
-        driver.session() >> session
+        driver.session(_) >> session
     }
 
     def "should execute return success on successful query"() {
         given:
             sampler.setCypher("MATCH x")
+            sampler.setDatabase("neo4j")
             session.run("MATCH x", [:]) >> getEmptyQueryResult()
         when:
             def response = sampler.sample(entry)
@@ -70,6 +72,7 @@ class BoltSamplerSpec extends Specification {
     def "should return error on failed query"() {
         given:
             sampler.setCypher("MATCH x")
+            sampler.setDatabase("neo4j")
             session.run("MATCH x", [:]) >> { throw new RuntimeException("a message")
}
         when:
             def response = sampler.sample(entry)
@@ -104,6 +107,7 @@ class BoltSamplerSpec extends Specification {
     def "should return db error code"() {
         given:
             sampler.setCypher("MATCH x")
+            sampler.setDatabase("neo4j")
             session.run("MATCH x", [:]) >> { throw new ClientException("a code", "a
message") }
         when:
             def response = sampler.sample(entry)


Mime
View raw message