コード例 #1
0
 public function testRejectItem()
 {
     $queue = new UniqueQueue($this->redis, 'test', [Base::OPT_SLAVES_SYNC_ENABLED => true, Base::OPT_SLAVES_SYNC_REQUIRED_COUNT => 5], $this->getTimeMock());
     $processingQueue = sprintf('test-processing-%s[%d][%d]', gethostname(), getmypid(), self::TIME_MOCK);
     $this->redis->lpush($processingQueue, [1, 5, 3]);
     $this->redis->hset('test-timeouts', $processingQueue, self::MICRO_TIME_MOCK);
     try {
         $queue->rejectItem(1);
     } catch (\PhpRQ\Exception\NotEnoughSlavesSynced $e) {
     }
     // order of the items is lost when using UniqueQueue:rejectItem, be aware of that
     $this->assertSame(['1'], $this->redis->lrange('test', 0, 5));
     $this->assertSame(['1'], $this->redis->smembers('test-unique'));
     $this->assertSame(['3', '5'], $this->redis->lrange($processingQueue, 0, 5));
     $this->assertSame([$processingQueue => (string) self::MICRO_TIME_MOCK], $this->redis->hgetall('test-timeouts'));
     $this->assertKeys(['test', 'test-unique', $processingQueue, 'test-timeouts']);
 }
コード例 #2
0
 public function testRejectItem()
 {
     $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]);
     $uTime = microtime(true);
     $this->redis->hset('test-timeouts', $processingQueue, $uTime);
     $queue->rejectItem(1);
     $queue->rejectItem(5);
     $queue->rejectItem(1);
     $queue->rejectItem(8);
     // order of the items is lost when using UniqueQueue:rejectItem, be aware of that
     $this->assertSame(['1', '5'], $this->redis->lrange('test', 0, 5));
     $items = $this->redis->smembers('test-unique');
     $this->assertCount(2, $items);
     $this->assertTrue(in_array('5', $items, true));
     $this->assertTrue(in_array('1', $items, true));
     $this->assertSame(['3'], $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->rejectItem(3);
     // order of the items is lost when using UniqueQueue:rejectItem, be aware of that
     $this->assertSame(['1', '5', '3'], $this->redis->lrange('test', 0, 5));
     $items = $this->redis->smembers('test-unique');
     $this->assertCount(3, $items);
     $this->assertTrue(in_array('1', $items, true));
     $this->assertTrue(in_array('5', $items, true));
     $this->assertTrue(in_array('3', $items, true));
     $this->assertKeys(['test', 'test-unique']);
     $this->redis->lpush($processingQueue, 1);
     $uTime = microtime(true);
     $this->redis->hset('test-timeouts', $processingQueue, $uTime);
     $queue->rejectItem(1);
     // order of the items is lost when using UniqueQueue:rejectItem, be aware of that
     $this->assertSame(['1', '5', '3'], $this->redis->lrange('test', 0, 5));
     $items = $this->redis->smembers('test-unique');
     $this->assertCount(3, $items);
     $this->assertTrue(in_array('1', $items, true));
     $this->assertTrue(in_array('5', $items, true));
     $this->assertTrue(in_array('3', $items, true));
     $this->assertKeys(['test', 'test-unique']);
 }