/** * NOTE: to run these tests, use the ENV/CLI flag WITH_REDIS=1, ie: * * WITH_REDIS=1 php tests/this_test.php */ public function testWithRedis() { if (getenv('WITH_REDIS') !== false) { if ($this->DEBUG) { print "NOTE: Running redis test againt a local redis server\n"; } $queue = new StreamMessageQueueRedis(); $queue->enqueueStatus("this is a mock status 1"); $queue->enqueueStatus("this is a mock status 2"); $data1 = $queue->processStreamData(); $this->assertEqual($data1, "this is a mock status 1"); $data2 = $queue->processStreamData(); $this->assertEqual($data2, "this is a mock status 2"); $this->assertNull($queue->processStreamData()); } else { if ($this->DEBUG) { print "NOTE: Skipping local redis server tests...\n"; } } }
public function testEnqueueStatusRedis() { //dont run redis test for php less than 5.3 $version = explode('.', PHP_VERSION); if (!($version[0] >= 5 && $version[1] >= 3)) { //error_log("PHP version less than 5.3, Skipping Redis Tests..."); return; } if (getenv('WITH_REDIS') !== false) { if ($this->DEBUG) { print "NOTE: Running redis test againt a local redis server\n"; } $stream_data = $this->setUpData('true'); $twitter_data = $this->setUpTwitterData(); $consumer_user_stream = new ConsumerUserStream('username', 'password'); $consumer_user_stream->setKey('*****@*****.**', 1); $procs_data = FixtureBuilder::build('stream_procs', array('process_id' => getmypid(), 'email' => '*****@*****.**', 'instance_id' => 1)); $consumer_user_stream->enqueueStatus("string1"); $consumer_user_stream->enqueueStatus("string2"); $queue = new StreamMessageQueueRedis(); $this->assertEqual($queue->processStreamData(), 'string1'); $this->assertEqual($queue->processStreamData(), 'string2'); $this->assertNull($queue->processStreamData()); // stream proc data set $sql = "select process_id, email, instance_id, unix_timestamp(last_report) as last_report from " . $this->table_prefix . "stream_procs"; $stmt = PluginOptionMysqlDAO::$PDO->query($sql); $data = $stmt->fetchAll(); $process_id = getmypid(); $this->assertIdentical($data[0]['process_id'], $process_id . ''); $recent_time = time() - 50; $this->assertTrue($data[0]['last_report'] > $recent_time); } }
public function testProcessStreamDataRedis() { $version = explode('.', PHP_VERSION); if (!($version[0] >= 5 && $version[1] >= 3)) { //error_log("PHP version less than 5.3, Skipping Redis Tests..."); return; } if (getenv('WITH_REDIS') !== false) { if ($this->DEBUG) { print "NOTE: Running redis test againt a local redis server\n"; } $this->setUpTwitterData(); $this->setUpData('true'); $stream_process = new ConsumerStreamProcess(); $stream_process->STIME = 0; // no data in the queue $queue = new StreamMessageQueueRedis(); // items in the queue $retweet_test_data = file_get_contents($this->test_dir . "retweet1.json"); $queue->enqueueStatus($retweet_test_data); $stream_process->process($queue); // now test that both users have been added $user = $this->user_dao->getDetails(19202541, 'twitter'); $this->assertEqual($user->user_id, 19202541); $user = $this->user_dao->getDetails(17567533, 'twitter'); $this->assertEqual($user->user_id, 17567533); // check post RT count $post = $this->post_dao->getPost(3.647968240468787E+16, 'twitter'); $this->assertEqual($post->retweet_count_cache, 1); } }