public function testRejectItems() { $time = time(); $queue = new UniqueQueue($this->redis, 'test', [Base::OPT_SLAVES_SYNC_ENABLED => true, Base::OPT_SLAVES_SYNC_REQUIRED_COUNT => 5]); $processingQueue = sprintf('test-processing-%s[%d][%d]', gethostname(), getmypid(), $time); $this->redis->lpush($processingQueue, [1, 5, 3, 6, 7]); $uTime = microtime(true); $this->redis->hset('test-timeouts', $processingQueue, $uTime); try { $queue->rejectItems([1, 3]); } catch (\PhpRQ\Exception\NotEnoughSlavesSynced $e) { } // order of the items is preserved with UniqueQueue:rejectItems only if there is a reject on all the remaining // items at once. Consecutive calls of this method causes the lost of the items order. $this->assertSame(['3', '1'], $this->redis->lrange('test', 0, 5)); $items = $this->redis->smembers('test-unique'); $this->assertCount(2, $items); $this->assertTrue(in_array('1', $items, true)); $this->assertTrue(in_array('3', $items, true)); $this->assertSame(['7', '6', '5'], $this->redis->lrange($processingQueue, 0, 5)); $this->assertSame([$processingQueue => (string) $uTime], $this->redis->hgetall('test-timeouts')); $this->assertKeys(['test', 'test-unique', $processingQueue, 'test-timeouts']); }
public function testRejectItems() { $time = time(); $queue = new UniqueQueue($this->redis, 'test'); $processingQueue = sprintf('test-processing-%s[%d][%d]', gethostname(), getmypid(), $time); $this->redis->lpush($processingQueue, [1, 5, 3, 6, 7]); $uTime = microtime(true); $this->redis->hset('test-timeouts', $processingQueue, $uTime); $queue->rejectItems([1, 3]); $queue->rejectItems([1]); $queue->rejectItems([9, 12]); // order of the items is preserved with UniqueQueue:rejectItems only if there is a reject on all the remaining // items at once. Consecutive calls of this method causes the lost of the items order. $this->assertSame(['3', '1'], $this->redis->lrange('test', 0, 5)); $items = $this->redis->smembers('test-unique'); $this->assertCount(2, $items); $this->assertTrue(in_array('1', $items, true)); $this->assertTrue(in_array('3', $items, true)); $this->assertSame(['7', '6', '5'], $this->redis->lrange($processingQueue, 0, 5)); $this->assertSame([$processingQueue => (string) $uTime], $this->redis->hgetall('test-timeouts')); $this->assertKeys(['test', 'test-unique', $processingQueue, 'test-timeouts']); $queue->rejectItems([5, 6, 7]); // order of the items is preserved with UniqueQueue:rejectItems only if there is a reject on all the remaining // items at once. Consecutive calls of this method causes the lost of the items order. $this->assertSame(['3', '1', '7', '6', '5'], $this->redis->lrange('test', 0, 10)); $items = $this->redis->smembers('test-unique'); $this->assertCount(5, $items); $this->assertTrue(in_array('1', $items, true)); $this->assertTrue(in_array('3', $items, true)); $this->assertTrue(in_array('5', $items, true)); $this->assertTrue(in_array('6', $items, true)); $this->assertTrue(in_array('7', $items, true)); $this->assertKeys(['test', 'test-unique']); $this->redis->lpush($processingQueue, 1); $uTime = microtime(true); $this->redis->hset('test-timeouts', $processingQueue, $uTime); $queue->rejectItems([1]); // order of the items is preserved with UniqueQueue:rejectItems only if there is a reject on all the remaining // items at once. Consecutive calls of this method causes the lost of the items order. $this->assertSame(['3', '1', '7', '6', '5'], $this->redis->lrange('test', 0, 10)); $items = $this->redis->smembers('test-unique'); $this->assertCount(5, $items); $this->assertTrue(in_array('1', $items, true)); $this->assertTrue(in_array('3', $items, true)); $this->assertTrue(in_array('5', $items, true)); $this->assertTrue(in_array('6', $items, true)); $this->assertTrue(in_array('7', $items, true)); $this->assertKeys(['test', 'test-unique']); }