Files
michaelschiemer/tests/debug/test-redis-queue-basic.php
Michael Schiemer fc3d7e6357 feat(Production): Complete production deployment infrastructure
- Add comprehensive health check system with multiple endpoints
- Add Prometheus metrics endpoint
- Add production logging configurations (5 strategies)
- Add complete deployment documentation suite:
  * QUICKSTART.md - 30-minute deployment guide
  * DEPLOYMENT_CHECKLIST.md - Printable verification checklist
  * DEPLOYMENT_WORKFLOW.md - Complete deployment lifecycle
  * PRODUCTION_DEPLOYMENT.md - Comprehensive technical reference
  * production-logging.md - Logging configuration guide
  * ANSIBLE_DEPLOYMENT.md - Infrastructure as Code automation
  * README.md - Navigation hub
  * DEPLOYMENT_SUMMARY.md - Executive summary
- Add deployment scripts and automation
- Add DEPLOYMENT_PLAN.md - Concrete plan for immediate deployment
- Update README with production-ready features

All production infrastructure is now complete and ready for deployment.
2025-10-25 19:18:37 +02:00

127 lines
4.5 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
declare(strict_types=1);
require_once __DIR__ . '/../bootstrap.php';
use App\Framework\Queue\InMemoryQueue;
use App\Framework\Queue\ValueObjects\JobPayload;
use App\Framework\Queue\ValueObjects\QueuePriority;
// Example Job Classes für Tests
class TestJob
{
public function __construct(
public string $id,
public string $description
) {
}
}
echo "🔴 Testing RedisQueue Priority Logic (using InMemoryQueue)\n";
echo "========================================================\n\n";
echo " Note: Testing priority logic that will be used in RedisQueue\n";
echo " InMemoryQueue implements the same priority-based sorting\n\n";
// Test 1: Basic Priority Ordering
echo "1⃣ Testing Priority Ordering...\n";
$queue = new InMemoryQueue();
$lowJob = JobPayload::create(new TestJob('low', 'Low priority task'), QueuePriority::low());
$normalJob = JobPayload::create(new TestJob('normal', 'Normal priority task'), QueuePriority::normal());
$highJob = JobPayload::create(new TestJob('high', 'High priority task'), QueuePriority::high());
$criticalJob = JobPayload::create(new TestJob('critical', 'Critical task'), QueuePriority::critical());
// Push in random order
$queue->push($normalJob);
$queue->push($lowJob);
$queue->push($criticalJob);
$queue->push($highJob);
assert($queue->size() === 4, "❌ Queue should have 4 jobs");
// Should pop in priority order: critical > high > normal > low
$first = $queue->pop();
$second = $queue->pop();
$third = $queue->pop();
$fourth = $queue->pop();
assert($first !== null && $first->job->id === 'critical', "❌ First should be critical (got: " . ($first?->job->id ?? 'null') . ")");
assert($second !== null && $second->job->id === 'high', "❌ Second should be high (got: " . ($second?->job->id ?? 'null') . ")");
assert($third !== null && $third->job->id === 'normal', "❌ Third should be normal (got: " . ($third?->job->id ?? 'null') . ")");
assert($fourth !== null && $fourth->job->id === 'low', "❌ Fourth should be low (got: " . ($fourth?->job->id ?? 'null') . ")");
echo "✅ Priority ordering works correctly\n\n";
// Test 2: Queue Operations
echo "2⃣ Testing Queue Operations...\n";
$queue->clear();
assert($queue->size() === 0, "❌ Queue should be empty after clear");
$job1 = JobPayload::create(new TestJob('job1', 'First job'));
$job2 = JobPayload::create(new TestJob('job2', 'Second job'));
$queue->push($job1);
$queue->push($job2);
// Test peek
$peeked = $queue->peek();
assert($peeked !== null, "❌ Should peek a job");
assert($peeked->job->id === 'job1', "❌ Peeked job should be first job");
assert($queue->size() === 2, "❌ Queue size should not change after peek");
// Test pop
$popped = $queue->pop();
assert($popped !== null, "❌ Should pop a job");
assert($popped->job->id === 'job1', "❌ Popped job should be first job");
assert($queue->size() === 1, "❌ Queue size should decrease after pop");
echo "✅ Queue operations work correctly\n\n";
// Test 3: Statistics
echo "3⃣ Testing Queue Statistics...\n";
$queue->clear();
$highPriorityJob = JobPayload::create(new TestJob('stats1', 'Stats test'), QueuePriority::high());
$normalPriorityJob = JobPayload::create(new TestJob('stats2', 'Stats test'), QueuePriority::normal());
$queue->push($highPriorityJob);
$queue->push($normalPriorityJob);
$stats = $queue->getStats();
assert(isset($stats['total_items']), "❌ Stats should include total_items");
assert($stats['total_items'] === 2, "❌ Stats should show 2 total items");
assert(isset($stats['priority_breakdown']), "❌ Stats should include priority breakdown");
$breakdown = $stats['priority_breakdown'];
assert(isset($breakdown['high']), "❌ Should have high priority breakdown");
assert(isset($breakdown['normal']), "❌ Should have normal priority breakdown");
assert($breakdown['high'] === 1, "❌ Should have 1 high priority job");
assert($breakdown['normal'] === 1, "❌ Should have 1 normal priority job");
echo "✅ Queue statistics work correctly\n\n";
// Test 4: Empty Queue Handling
echo "4⃣ Testing Empty Queue Handling...\n";
$queue->clear();
$nullJob = $queue->pop();
assert($nullJob === null, "❌ Pop from empty queue should return null");
$nullPeek = $queue->peek();
assert($nullPeek === null, "❌ Peek at empty queue should return null");
assert($queue->size() === 0, "❌ Empty queue size should be 0");
echo "✅ Empty queue handling works correctly\n\n";
echo "🎉 ALL REDIS QUEUE LOGIC TESTS PASSED!\n";
echo "✨ Priority-based queue logic is working correctly!\n";
echo " RedisQueue implementation uses the same priority logic with Redis sorted sets.\n";