Beispiel #1
0
 /**
  * @group connected
  */
 public function testCanConnectToRedis()
 {
     $test = $this;
     $trigger = false;
     $parameters = $this->getParameters();
     $options = $this->getOptions();
     $client = new Client($parameters, $options);
     $client->connect(function ($cbkClient, $cbkConnection) use($test, $client, &$trigger) {
         $trigger = true;
         $test->assertInstanceOf('Predis\\Async\\Client', $cbkClient);
         $test->assertInstanceOf('Predis\\Async\\Connection\\ConnectionInterface', $cbkConnection);
         $test->assertSame($client, $cbkClient);
         $client->disconnect();
     });
     $loop = $client->getEventLoop();
     $loop->addTimer(0.01, function () use($test, &$trigger) {
         $test->assertTrue($trigger, 'The client was unable to connect to Redis');
     });
     $loop->run();
 }
<?php

use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
use PremiumMock\PremiumMockApp;
use Predis\Async\Client as PredisClient;
require dirname(__DIR__) . '/vendor/autoload.php';
$config = (require dirname(__DIR__) . '/config.php');
$mockApp = new PremiumMockApp($config);
$server = IoServer::factory(new HttpServer(new WsServer($mockApp)), $config['ws_port']);
$client = new PredisClient($config['redis_conn_url'], $server->loop);
$client->connect(function ($client) use($mockApp) {
    echo "Connected to Redis, now listening for incoming messages...\n";
    $client->pubSubLoop('premiummockmt', function ($event) use($mockApp) {
        echo "Received MT `{$event->payload}` from {$event->channel}.\n";
        $mockApp->processMt(json_decode($event->payload, true));
    });
});
$server->run();
Beispiel #3
0
<?php

use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
use BulkMock\BulkMockApp;
use Predis\Async\Client as PredisClient;
require dirname(__DIR__) . '/vendor/autoload.php';
$config = (require dirname(__DIR__) . '/config.php');
$mockApp = new BulkMockApp($config);
$server = IoServer::factory(new HttpServer(new WsServer($mockApp)), $config['bulk_server']['port']);
$client = new PredisClient($config['redis_conn_url'], $server->loop);
$client->connect(function ($client) use($mockApp) {
    echo "Connected to Redis, now listening for incoming messages...\n";
    $client->pubSubLoop('bulkmocksend', function ($event) use($mockApp) {
        echo "Received new Bulk Msg `{$event->payload}` from {$event->channel}.\n";
        $mockApp->processBulkMsg(json_decode($event->payload, true));
    });
});
$server->run();
 public function testHandleLogWithGoodMessageNotImplementingJobInterface()
 {
     $worker = new WorkerPresence();
     $worker->setMemory(12345);
     $frame = new Frame('MESSAGE', array('delivery_tag' => 'delivery-' . mt_rand()), $worker->toJson());
     $loop = LoopFactory::create();
     $options = array('eventloop' => $loop, 'on_error' => array($this, 'throwRedisError'));
     $redisSync = new PredisSync('tcp://127.0.0.1:6379');
     $redisSync->connect();
     $resolver = $this->getResolver();
     $resolver->expects($this->once())->method('ack');
     $done = false;
     $phpunit = $this;
     $redis = new PredisAsync('tcp://127.0.0.1:6379', $options);
     $redis->connect(function () use($resolver, $phpunit, $redis, $frame, $redisSync, &$done, $worker) {
         $component = new LogBuilderComponent();
         $component->handleLog($redis, $phpunit->getLogger(), $frame, $resolver)->then(function ($hashId) use($phpunit, $redis, $redisSync, &$done, $worker) {
             $redis->disconnect();
             $phpunit->assertEquals($worker->toJson(), $redisSync->get($hashId));
             $phpunit->assertTrue($redisSync->sismember('garbages', $hashId));
             $done = true;
         });
     });
     $loop->run();
     $this->assertTrue($done);
 }