Jmeter Getting Connection Error with MongoDb - groovy

I want to perform load test on my mongodb database.So I added mongodb driver to bin/ext folder and restarted jmeter. I selected JSR223 Sampler and selected groovy as my language and added connection code as below
import com.mongodb.*
import com.mongodb.client.MongoClients;
import com.mongodb.client.MongoClient;
import com.mongodb.MongoClientSettings;
import com.mongodb.ServerAddress;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import org.bson.Document;
import java.util.Arrays;
try {
MongoClientSettings settings = MongoClientSettings.builder()
.applyToClusterSettings {builder ->
builder.hosts(Arrays.asList(new ServerAddress(vars.get("mongoHost"),vars.get("mongoPort").toInteger())))}
.build();
MongoClient mongoClient = MongoClients.create(settings);
MongoDatabase database = mongoClient.getDatabase(vars.get("databaseName"));
MongoCollection<Document> collection = database.getCollection(vars.get("collectionName"));
vars.putObject("collection", collection);
return "Connected to " + vars.get("collectionName");
}
catch (Exception e) {
SampleResult.setSuccessful(false);
SampleResult.setResponseCode("500");
SampleResult.setResponseMessage("Exception: " + e);
}
mongoHost,mongoPort,databaseName,collectionName are configured in user defined variables(Test Plan).
When I run sampler getting error
Thread Name:myThread Group 1-1
Sample Start:2020-01-27 15:57:35 IST
Load time:39
Connect Time:0
Latency:0
Size in bytes:0
Sent bytes:0
Headers size in bytes:0
Body size in bytes:0
Sample Count:1
Error Count:1
Data type ("text"|"bin"|""):text
Response code:500
Response message:javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script3.groovy: 6: unable to resolve class com.mongodb.ServerAddress
# line 6, column 1.
import com.mongodb.ServerAddress;
^
Script3.groovy: 5: unable to resolve class com.mongodb.MongoClientSettings
# line 5, column 1.
import com.mongodb.MongoClientSettings;
^
Script3.groovy: 10: unable to resolve class org.bson.Document
# line 10, column 1.
import org.bson.Document;
^
3 errors
SampleResult fields:
ContentType:
DataEncoding: null

You need to add the following libraries to JMeter Classpath:
mongo-java-driver
bson
The libraries version must match (or at least be compatible) with your MongoDB version, it can be obtained by running db.version() query in the MongoDB shell
JMeter restart will be required to pick up the libraries
More information: MongoDB Performance Testing with JMeter

Related

mlflow dowload artifact too many 500 error responses

i want to download artifact from remote server i used for mlflow tracking with below code :
from mlflow.tracking import MlflowClient
import pandas as pd
import mlflow
uri="http://some_url"
ex_id = '1'
mlflow.set_tracking_uri(uri)
experiments = mlflow.list_experiments()
runs = mlflow.search_runs(ex_id)
runs=runs[runs['tags.dataset'] == 'my_dataset']
client = MlflowClient()
client.download_artifacts("c21d2c4e75c047608003235f213e5bb5", "myarts/arts.csv", dst_path="./local_arts/")
but after a minute it give me below error :
The following failures occurred while downloading one or more artifacts from http://some_url/api/2.0/mlflow-artifacts/artifacts/1/c21d2c4e75c047608003235f213e5bb5/artifacts: {'myarts/': 'MlflowException("API request to http://some_url/api/2.0/mlflow-artifacts/artifacts/1/c21d2c4e75c047608003235f213e5bb5/artifacts/myarts/ failed with exception HTTPConnectionPool(host='some_url', port=80): Max retries exceeded with url: /api/2.0/mlflow-artifacts/artifacts/1/c21d2c4e75c047608003235f213e5bb5/artifacts/myarts/ (Caused by ResponseError('too many 500 error responses'))")'}
what is wrong with it ?
i upgraded mlflow but nothing changed

Failed to translate JSON in request error in Watson discovery query call

Using the ibm-watson Python SDK version 5.3.0 with the following code example:
from ibm_watson import DiscoveryV2, ApiException
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
import json
url = 'https://api.eu-de.discovery.watson.cloud.ibm.com'
version = '2020-08-30'
apikey = '...'
project = '...'
collection = '...'
authenticator = IAMAuthenticator(apikey)
discovery = DiscoveryV2(version=version, authenticator=authenticator)
discovery.set_service_url(url)
try:
result = discovery.query(
project_id=project,
collection_ids=collection,
query='text:searchterm',
table_results=True
).get_result()
print(json.dumps(result, indent=2))
except ApiException as ex:
print(f'Failed. Status code {ex.code}: {ex.message}')
Returns the following error from the server.
Failed. Status code 400: Failed to translate JSON in request: Cannot
deserialize value of type
`scala.collection.immutable.List<java.lang.String>` from String value
(token `JsonToken.VALUE_STRING`)
The error only occurs if collections_ids or table_results is specified.
The server is telling you that the JSON sent to it doesn't match what it expects to process.
The collections_ids and table_results are incorrectly formatted for the API request.
As per the API documentation.
collections_ids must be a list. So change to collections_ids=[collections]
table_results expects an object. To correct use table_results={ 'enabled': True }

received error: tornado.ioloop.TimeoutError: Operation timed out after 5 seconds.what to do?

Hy. I try to write test for webHander:
import pytest
import tornado
from tornado.testing import AsyncTestCase
from tornado.httpclient import AsyncHTTPClient
from tornado.web import Application, RequestHandler
import urllib.parse
class TestRESTAuthHandler(AsyncTestCase):
#tornado.testing.gen_test
def test_http_fetch_login(self):
data = urllib.parse.urlencode(dict(username='admin', password='123456'))
client = AsyncHTTPClient(self.io_loop)
response = yield client.fetch("http://localhost:8080//#/login", method="POST", body=data)
# Test contents of response
self.assertIn("Automation web console", response.body)
Received error when running test:
raise TimeoutError('Operation timed out after %s seconds' % timeout)
tornado.ioloop.TimeoutError: Operation timed out after 5 seconds
Set ASYNC_TEST_TIMEOUT environment variable.
Runs the IOLoop until stop is called or timeout has passed.
In the event of a timeout, an exception will be thrown. The default timeout is 5 seconds; it may be overridden with a timeout keyword argument or globally with the ASYNC_TEST_TIMEOUT environment variable. -- from http://www.tornadoweb.org/en/stable/testing.html#tornado.testing.AsyncTestCase.wait
You need to use AsyncHTTPTestCase, not just AsyncTestCase. A nice example is in Tornado's self-tests:
https://github.com/tornadoweb/tornado/blob/d7d9c467cda38f4c9352172ba7411edc29a85196/tornado/test/httpclient_test.py#L130-L130
You need to implement get_app to return an application with the RequestHandler you've written. Then, do something like:
class TestRESTAuthHandler(AsyncHTTPTestCase):
def get_app(self):
# implement this
pass
def test_http_fetch_login(self):
data = urllib.parse.urlencode(dict(username='admin', password='123456'))
response = self.fetch("http://localhost:8080//#/login", method="POST", body=data)
# Test contents of response
self.assertIn("Automation web console", response.body)
AsyncHTTPTestCase provides convenient features so you don't need to write coroutines with "gen.coroutine" and "yield".
Also, I notice you're fetching a url with a fragment after "#", please note that in real life web browsers do not include the fragment when they send the URL to the server. So your server would see the URL only as "//", not "//#/login".

Pentaho data source access from Groovy

In Pentaho Report Designer (PRD), I want to connect to my Data source using a Groovy script (or EMCAScript script) by referring to JNDI created in default.properties file. So, I will create a mult-value list parameter containing JNDI names and connect to the data source based on the JNDI selected in the parameter.
Script:
import groovy.sql.Sql
import javax.naming.InitialContext
import javax.sql.DataSource
class SqlClient {
InitialContext context = new InitialContext()
DataSource dataSource = context.lookup("OLTP") as DataSource
def sql = new Sql(dataSource)
sql.execute("SELECT * FROM Person.User_JNDI")
TypedTableModel model = new TypedTableModel();
while(sql.next())
model.addRow(new Object [] {rs.getString(1)});
c.close();
return model;
}
I am getting the following error:
Caused by: org.apache.bsf.BSFException: exception from Groovy: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
expression: 11: unexpected token: sql # line 11, column 5.
sql.execute("SELECT * FROM Person.User_JNDI")
Also, PRD expects the script to return a model, probably something to do with TypedtableModel class.
Can anyone give me an example of Groovy script?
Assuming that you have filled the default.properties as it says here, you should be able to access the data source with something like:
import groovy.sql.Sql
import javax.naming.InitialContext
import javax.sql.DataSource
class SqlClient {
InitialContext context = new InitialContext()
DataSource dataSource = context.lookup("SampleData") as DataSource
def sql = new Sql(dataSource)
sql.execute '''
select * from ... '''
...
}
Using a Sql instance.

ALL time groovy compilation error

All time am getting below error message in groovy...
Could not understand whats causing this " Unexpected token error" ????
I used to think only PERL give bad compilation error,now groovy outperforming it..
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
D:\Playground\groovy\release-b-work\cmd_line_soapui\trial.groovy: 12:
unexpected token: myrunner # line 12, column 1.
myrunner.setProjectFile("D:\soapui-release-B\try.xml");
^
1 error
Code taken from comment;
import com.eviware.soapui.SoapUIProTestCaseRunner;
import com.eviware.soapui.support.*;
import com.eviware.soapui.model.*;
import com.eviware.soapui.impl.wsdl.*;
import com.eviware.soapui.*;
class trial {
def myrunner = new com.eviware.soapui.SoapUIProTestCaseRunner();
myrunner.setProjectFile("D:\soapui-release-B\try.xml");
myrunner.setTestSuite("MediaAssetServiceTestSuite");
myrunner.setTestCase("createMediaAsset TestCase");
myrunner.run();
}
You need to put your code in a method
You can't just add code into a class at class level
Try:
import com.eviware.soapui.SoapUIProTestCaseRunner;
import com.eviware.soapui.support.*;
import com.eviware.soapui.model.*;
import com.eviware.soapui.impl.wsdl.*;
import com.eviware.soapui.*;
class trial {
def someMethod() {
def myrunner = new com.eviware.soapui.SoapUIProTestCaseRunner();
myrunner.setProjectFile("D:\soapui-release-B\try.xml");
myrunner.setTestSuite("MediaAssetServiceTestSuite");
myrunner.setTestCase("createMediaAsset TestCase");
myrunner.run();
}
}

Resources