Using jmeter to place messages on google-cloud pubsub - jmeter

Has anyone had success in using Jmeter to load messages onto Google PubSub. I can’t find much on the web about this topic. There is a GCP pubSub plugin but it does not have a lot of instructions on how to use it.
Can JMS Publisher be used?
I don’t have much experience with any of the above.

The easiest way is following official documentation: Quickstart: Using Client Libraries
Install Maven
Create pom.xml file with the following content anywhere in your hard drive
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>untitled</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>libraries-bom</artifactId>
<version>20.2.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-pubsub</artifactId>
</dependency>
</dependencies>
</project>
Execute the copy-dependencies command in the folder where pom.xml lives:
mvn dependency:copy-dependencies
Copy everything from target/dependency folder to "lib" folder of your JMeter installation
Restart JMeter if it's running
Add JSR223 Sampler to your Test Plan
Put the following code into "Script" area:
import com.google.api.core.ApiFuture
import com.google.cloud.pubsub.v1.Publisher
import com.google.protobuf.ByteString
import com.google.pubsub.v1.PubsubMessage
import com.google.pubsub.v1.TopicName
import java.util.concurrent.TimeUnit
// TODO(developer): Replace these variables before running the sample.
String projectId = 'your-project-id'
String topicId = 'your-topic-id'
TopicName topicName = TopicName.of(projectId, topicId)
Publisher publisher = null
try {
// Create a publisher instance with default settings bound to the topic
publisher = Publisher.newBuilder(topicName).build()
String message = 'Hello World!'
ByteString data = ByteString.copyFromUtf8(message)
PubsubMessage pubsubMessage = PubsubMessage.newBuilder().setData(data).build()
// Once published, returns a server-assigned message id (unique within the topic)
ApiFuture<String> messageIdFuture = publisher.publish(pubsubMessage)
String messageId = messageIdFuture.get()
log.info('Published message ID: ' + messageId)
} finally {
if (publisher != null) {
// When finished with the publisher, shutdown to free up resources.
publisher.shutdown()
publisher.awaitTermination(1, TimeUnit.MINUTES)
}
}
Replace your-project-id and your-topic-id with your own values
Run your test - it should post Hello world message to the given project/topic
More information on Groovy scripting in JMeter: Apache Groovy - Why and How You Should Use It
Later on you can follow instructions from How to write a plugin for JMeter to make this functionality available "natively"

Related

Maven validate - Get child module pom directories

A business team outside of the development team needs some information out of a source controlled repo that we house source in. We're using Maven to perform our builds, and using Git for source control. What I want to do is get the reactor build order, and feed that into a script to automate some searching in Git to provide the business team what they need, but I need to make sure I'm telling Git to search the appropriate directories (and not just the root directory of the entire repo).
So obviously I can do something like mvn validate to provide me:
foo> mvn validate
[INFO] Reactor Build Order:
[INFO]
[INFO] foo
[INFO] sub_foo_1
[INFO] sub_foo_2
...
Except I have no way to take that and hand that off to Git for additional information because I don't know what directories any of the child modules live in.
Is there any way I can find out the path to the individual pom files that are part of the reactor build order?
I'm posting this as an answer, but it wouldn't have been my first choice; hoping somebody else will have something better. I was really hoping there was a native Maven way to do [something like] this.
Basically, I created a small plugin to print out the information.
Pom:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<groupId>foo.bar.baz.demo</groupId>
<version>1.2.3-SNAPSHOT</version>
<artifactId>test_plugin</artifactId>
<packaging>maven-plugin</packaging>
<modelVersion>4.0.0</modelVersion>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>2.2.1</version>
</dependency>
</dependencies>
</project>
Code:
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.project.MavenProject;
#Mojo(name = "print_pom_dir")
public class TestMojo extends AbstractMojo {
public void execute() throws MojoExecutionException {
MavenProject object = (MavenProject) this.getPluginContext()
.get("project");
getLog().info(
"Pom directory: " + object.getBasedir().getAbsolutePath());
}
}
Where I can put a build execution in the parent such as:
<build>
<plugins>
<plugin>
<groupId>foo.bar.baz.demo</groupId>
<version>1.2.3-SNAPSHOT</version>
<artifactId>test_plugin</artifactId>
</plugin>
</plugins>
</plugins>
So all child modules inherit it.
Then all I have to do is run mvn foo.bar.baz.demo:test_plugin:1.2.3-SNAPSHOT:print_pom_dir from the root pom, and stdout gets my data for my to regexp out.
I wonder if putting it to a file or something in the target area might be cleaner, but I'm not too clear on best practices for Maven and whether or not changing the target directory for something not related to the build is standard, or how to get the root to know about the output from all child executions of the plugin for that matter.

Spring Boot 2: Unable to start tomcat

I am new to spring boot.. Getting started by referring to the link: https://docs.spring.io/spring-boot/docs/current/reference/html/getting-started-first-application.html
After running the project its not starting the tomcat server.. Getting the error as [ERROR] error reading /home/rahul/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/8.5.31/tomcat-embed-core-8.5.31.jar; invalid LOC header (bad signature)
Not able to address this issue.. Any help would be appreciated..
Thanks a lot in advance..
My code is like below,
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.wocs</groupId>
<artifactId>REST</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>
Example.java
import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.web.bind.annotation.*;
#RestController
#EnableAutoConfiguration
public class Example {
#RequestMapping("/")
String home() {
return "Hello World!";
}
public static void main(String[] args) throws Exception {
SpringApplication.run(Example.class, args);
}
}
Seems like you have a corrupted file. Try clean your maven cache with rm -rf ~/.m2/repository and run again
Looks like you have a corrupted jar that is under your default MAVEN folder. You can delete the specific jar file that is causing this issue and trying the follow should help!
Take a Maven update by right clicking on your Project -> then select Maven and then click on 'Update Project'. You've got to wait until these dependencies are downloaded.
Run target Clean Maven (Project -> Run as -> Clean Maven)
Then finally Install Maven (Project -> Run as -> Install Maven)
These steps should resolve your invalid LOC header error.
Here is what worked for me on Windows 10:
Deleted this jar file from the shell command line
mvn spring-boot:run
After that, the jar was downloaded with no error and all is running fine.
and all is running fine

vertx 3.5.1 missing classes

I started to look into developing with VertX, and I stumbled into problems with some classes that couldnt be resolved. I am posting a simple example.
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>demo.rabbit</groupId>
<artifactId>rabbitmq-client</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
<version>3.5.1</version>
</dependency>
</dependencies>
</project>
java code
import io.vertx.core.AbstractVerticle;
import io.vertx.core.AsyncResult;
import io.vertx.core.json.JsonObject;
public class RabbitMQVerticle extends AbstractVerticle
{
#Override
public void start() throws Exception {
AsyncResult ar;
JsonObject jo;
}
}
If I leave it like this, the compiler cannot resolve the AsyncResult and JsonObject imports, and thus cannot resolve both types.
In the external libraries view, those classes appear as part of the io.vertx.core library but the icon next to them indicates that they are missing from the library.
If I replace the vertx.core version to 3.5.0 in the pom file everything works great, switch back to 3.5.1 and nothing works again.
It's also my first time using Maven, what am I missing?
Couldn't find any useful information anywhere on the web
The mentioned classes are parts of the core Vert.x library. Core blocks never get deleted in mature libraries.
Here down the AsyncResult class for example under both versions:
AsyncResult under 3.5.0 version
AsyncResult under 3.5.1 version
Indeed I think even when changing the library version, your project still compiles (using cmd line or using IntelliJ IDEA) but you are facing a UI highlight issue with you IDE.
You can try to:
Re-import all Maven modules using the Maven Projects Tool Window
Clean the system caches and restart the IDE

How do inject properties or environment variables into my Maven plugin testcase?

I've created a Maven plugin using AbstractMojo and I'm trying to test it.
I'm using the maven-plugin-testing-harness to do the testing and I'm having problems with injecting values for my plugin parameters.
I have the following pom.xml file (src/test/resources/pom.xml) for testing:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.vodori.pepper.docker.vm.unit</groupId>
<artifactId>test-pom</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Test VMStarter</name>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.vodori.common</groupId>
<artifactId>pepper-docker-vm</artifactId>
<version>1.0.1-SNAPSHOT</version>
<configuration>
<dockerSnapshotSite>pepper-demo-site</dockerSnapshotSite>
<dockerSnapshotVersion>3.6.11</dockerSnapshotVersion>
</configuration>
</plugin>
</plugins>
</build>
</project>
My Mojo looks like this (at the top):
public abstract class VMPlugin extends AbstractMojo {
/**
* Docker location
*/
#Parameter(required = true, property = "docker.path", defaultValue = "${env.DOCKER_LOCATION}")
String dockerPath;
public void setDockerPath(String dockerPath) {
this.dockerPath = dockerPath;
}
/**
* Docker VM Site name
*/
#Parameter(required = true, property = "docker.snapshot.site")
String dockerSnapshotSite;
/**
* Version of Docker snapshot
*/
#Parameter (required = true, property="docker.snapshot.version")
String dockerSnapshotVersion;
I'm using the #MojoRule approach for testing and my setup method looks like this:
#Before
public void setUp() throws Exception {
vmStarter = (VMStarter) rule.lookupMojo( "start-docker-vm", "src/test/resources/pom.xml" );
assertNotNull(vmStarter);
}
I use the setter for some of my testcases (the ones that test bad docker locations), but for my good path testing, I want to rely on the environment variable DOCKER_LOCATION for populating. However, for some reason, dockerPath is just showing up as null. It's as if the defaultValue is being ignored.
I've tried dumping System.getEnv() onto STDERR and I can see that DOCKER_LOCATION is indeed set.
What am I missing here? Why isn't my #Parameter getting populated correctly?
Where did you get the syntax defaultValue = "${env.DOCKER_LOCATION}" from?
env.* is a property and "you can use Maven properties in a pom.xml file or in any resource that is being processed by the Maven Resource plugin’s filtering features."
default-value requires an expression.
Guide to Developing Java Plugins, Introduction mentions: "(more can be found in the "Parameter Expressions" document)". But i didn't find such a document so far. Thx #khmarbaise: org.apache.maven.plugin.PluginParameterExpressionEvaluator.
help:expressions doesn't show ${env} with my Maven 3.2.1.
Though it's my experience that at least some, if not all, of the linked docs are not up-to-date and withhold latest enhancements.
Possible explanation from a program logic point of view: If a default value has to be set outside the scope of a program it can't be considered a default value. In the sense of Maven's Convention Over Configuration.
EDIT: Added link to Expressions API documentation.

How to invoke IEDriver or Chromedriver in webdriver+maven project

Can anyone please help in below situation.
I am having webdriver+maven project that's running fine with FireFox driver but to run it through Chrome or IEDriver where I need to put Chrome and IE driver exe and how to invoke it.
Where do I need to place IEDriver and ChromeDriver EXE under src/main/resources or /src/test/resources
how to specify path for these driver in code
Do I need to add something in pom.xml at present my pom.xml looks like below -
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>MavenWebDriverDemo</groupId>
<artifactId>MavenWebDriverDemo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.33.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>2.33.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.5</version>
</dependency>
</dependencies>
It is your preference to place the drivers under src/main/resources or /src/test/resources. You have to add the following code:-
System.setProperty("webdriver.ie.driver","/src/test/resources/IEDriver.exe");
driver = new InternetExplorerDriver();
or
System.setProperty("webdriver.chrome.driver","/src/test/resources/chromedriver.exe");
driver = new ChromeDriver();
There is no need to modify the pom file.
Another option is to include the (Chrome|IE)Driver location in your PATH environment variable.
https://code.google.com/p/selenium/wiki/InternetExplorerDriver#Installing
E.g. (debian):
mv chromedriver /usr/local/bin
or
echo "PATH=\$PATH:/path/to/chromedriver" > /etc/profile.d/chromedriver.sh
This is more generic than System.setProperty: if you are, or will be, using a selenium grid, then System.setProperty would be useless (as far as I understand).
Also, some say:
Store config in the environment
Just keep driver library in your project directory at whatever path you wish and set driver Property as below for initialization
For Windows -
System.setProperty("webdriver.chrome.driver",
System.getProperty("user.dir") + "/src/main/java/com/smava/util/chromedriver_2.35.exe");
For Mac -
System.setProperty("webdriver.chrome.driver",
System.getProperty("user.dir") + "/src/main/java/com/smava/util/chromedriver");

Resources