|
| 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 | + |
0 commit comments