This directory contains SQL scripts to generate 10,000 test records in the user_report_data table for demonstrating the ShedLock Spring Boot application.
- Method: Uses temporary table with cross joins
- Performance: Good for all MySQL versions (5.7+)
- Features:
- Generates realistic data with varied timestamps
- Creates 10 different report types
- Distributes statuses: 60% PENDING, 25% COMPLETED, 10% PROCESSING, 5% FAILED
- Includes summary statistics at the end
- TESTED AND WORKING ✅
- Method: Uses stored procedure with loops
- Performance: Good for all MySQL versions
- Features:
- Most compatible approach
- Commits every 1000 records for better performance
- Works with all MySQL versions
- Method: Uses recursive CTE (Common Table Expression)
- Performance: Good for MySQL 8.0+
- Issues:
- May not work on older MySQL versions
- Syntax errors in some MySQL configurations
./run_sql_script.shResult: Successfully generated 10,000 records with proper distribution!
# Connect to MySQL
mysql -u root -p spring_shedlock_example
# Execute the script
source generate_10000_reports_simple.sql;mysql -u root -p spring_shedlock_example < generate_10000_reports_simple.sqlThe scripts generate data with the following distribution:
- PENDING: 60% (6,000 records) - Will be processed by scheduled tasks
- COMPLETED: 25% (2,500 records) - Already processed reports
- PROCESSING: 10% (1,000 records) - Currently being processed
- FAILED: 5% (500 records) - Failed processing attempts
- MONTHLY_SALES
- WEEKLY_ANALYTICS
- DAILY_METRICS
- QUARTERLY_SUMMARY
- ANNUAL_REPORT
- CUSTOMER_ANALYSIS
- PRODUCT_PERFORMANCE
- MARKETING_CAMPAIGN
- FINANCIAL_REPORT
- OPERATIONAL_METRICS
- Records span the last 90 days
- Random distribution across hours and minutes
- Processed records have appropriate
processed_attimestamps
After running the script, you can verify the data:
-- Check total count
SELECT COUNT(*) FROM user_report_data;
-- Check status distribution
SELECT status, COUNT(*) as count,
ROUND(COUNT(*) * 100.0 / (SELECT COUNT(*) FROM user_report_data), 2) as percentage
FROM user_report_data
GROUP BY status;
-- Check report type distribution
SELECT report_type, COUNT(*) as count
FROM user_report_data
GROUP BY report_type;
-- Check date range
SELECT MIN(created_at) as earliest, MAX(created_at) as latest
FROM user_report_data;- generate_10000_reports.sql: ~30-60 seconds on average hardware
- generate_10000_reports_simple.sql: ~20-40 seconds on MySQL 8.0+
- generate_10000_reports_batch.sql: ~10-30 seconds (most efficient)
-
"Table doesn't exist"
- Make sure the Spring Boot application has run at least once to create the table
- Check that
spring.jpa.hibernate.ddl-auto=updateis set
-
"Access denied"
- Verify MySQL user has INSERT privileges
- Check database name and credentials
-
"Recursive CTE not supported"
- Use
generate_10000_reports.sqlinstead of the simple version - Upgrade to MySQL 8.0+ for CTE support
- Use
-
"Out of memory"
- Use the batch version with stored procedure
- Increase MySQL buffer pool size
- MySQL 5.7+ (for basic functionality)
- MySQL 8.0+ (for recursive CTE version)
- Sufficient disk space (~50MB for 10,000 records)
- Appropriate MySQL user privileges
-
Start the Spring Boot application:
./gradlew bootRun
-
Monitor the processing:
- Watch application logs for scheduled task execution
- Check
/api/reports/statsendpoint for real-time statistics - Observe PENDING reports being processed every 30 seconds
-
Test ShedLock functionality:
- Start multiple application instances
- Verify only one instance processes scheduled tasks
- Check that reports transition from PENDING → PROCESSING → COMPLETED
To modify the data generation:
- Change record count: Modify the limit in the SQL script
- Adjust status distribution: Modify the percentage calculations
- Add new report types: Update the CASE statements
- Change time range: Modify the INTERVAL calculations
Example for 5,000 records:
-- Change this line in the script
LIMIT 5000;