Skip to content

Commit 116227c

Browse files
committed
Adding a jmeter rule
1 parent 79c5c3d commit 116227c

6 files changed

Lines changed: 168 additions & 1138 deletions

File tree

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
---
2+
description:
3+
globs:
4+
alwaysApply: false
5+
---
6+
# Run performance tests based on JMeter
7+
8+
## ⚠️ CRITICAL INSTRUCTION FOR AI ASSISTANTS ⚠️
9+
10+
**WHEN USING THE PERFORMANCE SCRIPT TEMPLATE:**
11+
- **COPY THE BASH SCRIPT EXACTLY** from `java-performance-script-template.md`
12+
- **NO MODIFICATIONS, INTERPRETATIONS, OR ENHANCEMENTS** allowed
13+
- **USE EVERY LINE VERBATIM** - do not change logic, structure, or features
14+
- **DO NOT CREATE YOUR OWN VERSION** - use the provided template only
15+
- The template script is complete, tested, and production-ready
16+
17+
---
18+
19+
## 📋 How to Copy the Performance Script Template
20+
21+
### Step 1: Create the Script File
22+
When a user requests JMeter performance testing setup:
23+
24+
1. **Copy the entire script** from `.cursor/rules/templates/java-performance-script-template.md`
25+
2. **Create the file** as `run-jmeter.sh` in the project root
26+
3. **Make it executable**: `chmod +x run-jmeter.sh`
27+
28+
### Step 2: Template Location
29+
- **Source**: `.cursor/rules/templates/java-performance-script-template.md`
30+
- **Destination**: `run-jmeter.sh` (project root)
31+
- **Copy Method**: Exact verbatim copy - no changes allowed
32+
33+
---
34+
35+
## 🚀 Script Usage Instructions
36+
37+
### Basic Usage
38+
```bash
39+
# Run with default settings (1000 loops, 1 thread, 1s ramp-up)
40+
./run-jmeter.sh
41+
42+
# Custom configuration
43+
./run-jmeter.sh -l 500 -t 10 -r 30
44+
45+
# Open JMeter GUI
46+
./run-jmeter.sh -g
47+
```
48+
49+
### Available Options
50+
- `-l, --loops LOOPS`: Number of loops per thread (default: 1000)
51+
- `-t, --threads THREADS`: Number of concurrent threads (default: 1)
52+
- `-r, --ramp-up SECONDS`: Ramp-up period in seconds (default: 1)
53+
- `-g, --gui`: Open JMeter GUI instead of running in non-GUI mode
54+
- `-h, --help`: Show detailed help message
55+
56+
### Environment Variables
57+
```bash
58+
# Override defaults using environment variables
59+
JMETER_LOOPS=500 JMETER_THREADS=5 ./run-jmeter.sh
60+
61+
# Or export them
62+
export JMETER_LOOPS=1000
63+
export JMETER_THREADS=10
64+
export JMETER_RAMP_UP=30
65+
./run-jmeter.sh
66+
```
67+
68+
### Example Scenarios
69+
```bash
70+
# Light load test
71+
./run-jmeter.sh -l 100 -t 1 -r 1
72+
73+
# Medium load test
74+
./run-jmeter.sh -l 500 -t 5 -r 10
75+
76+
# Heavy load test
77+
./run-jmeter.sh -l 1000 -t 20 -r 60
78+
79+
# Quick GUI setup
80+
./run-jmeter.sh -g
81+
```
82+
83+
---
84+
85+
## 📁 Required Project Structure
86+
87+
The script expects this structure:
88+
```
89+
project-root/
90+
├── run-jmeter.sh # The performance script
91+
├── src/test/resources/jmeter/
92+
│ └── load-test.jmx # JMeter test plan
93+
└── target/ # Generated reports (auto-created)
94+
├── jmeter-results.jtl # Raw results
95+
├── jmeter-report/ # HTML dashboard
96+
│ └── index.html # Main report
97+
└── jmeter.log # Execution log
98+
```
99+
100+
---
101+
102+
## 🔧 Prerequisites
103+
104+
1. **JMeter Installation**: Must be installed and available in PATH
105+
2. **Test Plan**: Must exist at `src/test/resources/jmeter/load-test.jmx`
106+
3. **Executable Permissions**: Script must be executable (`chmod +x run-jmeter.sh`)
107+
108+
---
109+
110+
## 📊 Output Files
111+
112+
After running the script, you'll get:
113+
114+
1. **Raw Results**: `target/jmeter-results.jtl` (JTL format)
115+
2. **HTML Dashboard**: `target/jmeter-report/index.html` (automatically opens in browser)
116+
3. **Execution Log**: `jmeter.log` (debugging information)
117+
118+
---
119+
120+
## 💡 Best Practices
121+
122+
### For Load Testing
123+
- Start with low thread counts and gradually increase
124+
- Monitor system resources during tests
125+
- Use realistic ramp-up periods (don't slam the server)
126+
127+
### For Test Plan Development
128+
- Use GUI mode (`-g`) for initial test plan creation
129+
- Test with low load first (`-l 10 -t 1`)
130+
- Validate test plan logic before heavy load testing
131+
132+
### For CI/CD Integration
133+
```bash
134+
# Example CI/CD usage
135+
./run-jmeter.sh -l 100 -t 5 -r 10
136+
# Check exit code for pass/fail status
137+
```
138+
139+
---
140+
141+
## 🚨 Important Notes
142+
143+
- The script automatically cleans previous results
144+
- HTML reports open automatically in your default browser
145+
- All configuration is parameterized - no hardcoded values
146+
- The script provides colored output for better visibility
147+
- Comprehensive error handling and validation included
148+
149+
---
150+

.cursor/rules/templates/java-checklist-template.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ Use the following process to improve the java development in some areas if requi
3636
|-------------|-------------|--------|-------|
3737
| [131-java-unit-testing](.cursor/rules/131-java-unit-testing.mdc) | Unit Testing | `Can improve the unit tests using the cursor rule @131-java-unit-testing` | Add in the context a Test Class or the package |
3838

39-
4039
### Step 5: Refactoring
4140

4241
| Cursor Rule | Description | Prompt | Notes |
@@ -45,7 +44,13 @@ Use the following process to improve the java development in some areas if requi
4544
| [142-java-functional-programming](.cursor/rules/142-java-functional-programming.mdc) | Functional Programming | `Refactor my code to use functional programming using the cursor rule @142-java-functional-programming` | |
4645
| [143-java-data-oriented-programming](.cursor/rules/143-java-data-oriented-programming.mdc) | Data Oriented Programming | `Refactor my code to use data oriented programming using the cursor rule @143-java-data-oriented-programming` | |
4746

48-
### Step 6: Profiling
47+
### Step 6: Performance (Jmeter)
48+
49+
| Activity | Description | Prompt | Notes |
50+
|----------|------|--------|-------|
51+
| [151-java-performance-jmeter](.cursor/rules/151-java-performance-jmeter.mdc) | Run a peformance test with Jmeter | `Add JMeter performance testing to this project using @151-java-performance-jmeter.mdc` | You could ask the model to create a JMeter based on a RestController/Resource |
52+
53+
### Step 7: Profiling (Async profiler)
4954

5055
| Activity | Description | Prompt | Notes |
5156
|----------|------|--------|-------|
@@ -70,6 +75,7 @@ Use the following process to improve the java development in some areas if requi
7075
| Modern Java Features | @141-java-refactoring-with-modern-features | Refactoring with modern Java (Java 8+) features |
7176
| Functional Programming | @142-java-functional-programming | Applying functional programming in Java |
7277
| Data Oriented Programming | @143-java-data-oriented-programming | Data-oriented programming style in Java |
78+
| Performance testing | @151-java-performance-jmeter | Run a Jmeter script |
7379
| Java Profiling | @161-java-profiling-detect | Generate profiling data |
7480
| Java Profiling | @162-java-profiling-analyze | Analyze profiling data |
7581
| Java Profiling | @164-java-profiling-compare | Compare results after refactoring |

examples/spring-boot-jmeter-demo/run-jmeter.sh renamed to .cursor/rules/templates/java-performance-script-template.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
```bash
12
#!/bin/bash
23

34
# JMeter Load Test Script
@@ -248,4 +249,5 @@ main() {
248249
}
249250

250251
# Execute main function
251-
main "$@"
252+
main "$@"
253+
```

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,13 @@ Using the Cursor rules is straightforward: simply `drag and drop` the cursor rul
5757
| [142-java-functional-programming](.cursor/rules/142-java-functional-programming.mdc) | Functional Programming | `Refactor my code to use functional programming using the cursor rule @142-java-functional-programming` | |
5858
| [143-java-data-oriented-programming](.cursor/rules/143-java-data-oriented-programming.mdc) | Data Oriented Programming | `Refactor my code to use data oriented programming using the cursor rule @143-java-data-oriented-programming` | |
5959

60-
### Profiling rules
60+
### Performance rule (Jmeter)
61+
62+
| Activity | Description | Prompt | Notes |
63+
|----------|------|--------|-------|
64+
| [151-java-performance-jmeter](.cursor/rules/151-java-performance-jmeter.mdc) | Run a peformance test with Jmeter | `Add JMeter performance testing to this project using @151-java-performance-jmeter.mdc` | You could ask the model to create a JMeter based on a RestController/Resource |
65+
66+
### Profiling rules (Async profiler)
6167

6268
| Activity | Description | Prompt | Notes |
6369
|----------|------|--------|-------|

0 commit comments

Comments
 (0)