public function testPurgeQueue() { $loop = $this->loop; $PHPUnit = $this; $success = false; $client = $this->object; $queue = $this->createQueue(); $exchange = new Exchange(); $exchange->name = self::EXCHANGE_TEST_NAME; $exchange->vhost = '/'; $this->syncClient->addExchange($exchange); $binding = new Binding(); $binding->vhost = '/'; $binding->source = self::EXCHANGE_TEST_NAME; $binding->destination = self::QUEUE_TEST_NAME; $binding->routing_key = self::QUEUE_TEST_NAME; $this->syncClient->addBinding($binding); $message = json_encode(array('properties' => array(), 'routing_key' => self::QUEUE_TEST_NAME, 'payload' => 'body', 'payload_encoding' => 'string')); $n = 12; while ($n > 0) { $this->syncClientClient->post('/api/exchanges/' . urlencode('/') . '/' . self::EXCHANGE_TEST_NAME . '/publish', array('content-type' => 'application/json'), $message)->send(); $n--; } usleep(2000000); $this->syncClient->refreshQueue($queue); $this->assertEquals(12, $queue->messages_ready); $this->object->purgeQueue('/', self::QUEUE_TEST_NAME)->then(function () use($client, &$success, $PHPUnit, $queue) { usleep(4000000); $client->refreshQueue($queue); $success = true; $PHPUnit->assertEquals(0, $queue->messages_ready); $loop->stop(); }, function () use($PHPUnit) { $PHPUnit->fail('Should no fail'); }); $loop->run(); $this->assertTrue($success); }
/** * {@inheritdoc} */ public function register(GloubsterServerInterface $server) { $this->apiClient = AsyncAPIClient::factory($server['loop'], array_merge($server['configuration']['server'], $server['configuration']['server']['server-management'])); $server['loop']->addPeriodicTimer(5, Curry::bind(array($this, 'fetchMQInformations'), $server['websocket-application'], $server['configuration'], $server['monolog'])); }