Campustream 1.0
A social network MQP for WPI
|
00001 <? 00002 00003 group('debug'); 00004 00005 desc('Test sortedarray class'); 00006 task('sortedarray', function () { 00007 00008 $sarray = new sortedarray(); 00009 $sorter = function ($left, $right) { 00010 if ($left->name < $right->name) { 00011 echo "{$left->name} < {$right->name}\n"; 00012 return -1; 00013 } elseif ($left->name == $right->name) { 00014 echo "{$left->name} = {$right->name}\n"; 00015 return 0; 00016 } else { 00017 echo "{$left->name} > {$right->name}\n"; 00018 return 1; 00019 } 00020 }; 00021 00022 $user1 = new User_Model(); 00023 $user1->name = "Ryan LeFevre"; 00024 00025 $user2 = new User_Model(); 00026 $user2->name = "Bryan Crabtree"; 00027 00028 $user3 = new User_Model(); 00029 $user3->name = "Jason Donenfeld"; 00030 00031 $sarray->add($user2, $sorter); 00032 $sarray->add($user1, $sorter); 00033 $sarray->add($user3, $sorter); 00034 00035 print_r($sarray->result()); 00036 00037 }); 00038 00039 desc("Create imaginary comments for testing"); 00040 task('redistest_create', function () { 00041 $r = RedisManager::connection(); 00042 00043 echo "Starting..."; 00044 for ($i = 0; $i < 1000; $i++) { 00045 $parent_id = rand(0, 100); 00046 00047 $comment = new Commenttest_Model(); 00048 $comment->posted_by = 1; 00049 $comment->news_id = 1; 00050 $comment->parent_id = $parent_id; 00051 $comment->content = md5(rand(0, 10000)); 00052 $comment->time_posted = ActiveRecord::NOW(); 00053 00054 $comment->save(); 00055 00056 // original implementation 00057 $key = "newstest:1:comment_by_id:$parent_id"; 00058 $r->lpush($key, $comment->id); 00059 00060 // no memcache 00061 $nom_key = "newstest:1:comment:{$comment->id}"; 00062 $r->hset($nom_key, "id", $comment->id); 00063 $r->hset($nom_key, "posted_by", $comment->posted_by); 00064 $r->hset($nom_key, "news_id", $comment->news_id); 00065 $r->hset($nom_key, "parent_id", $comment->parent_id); 00066 $r->hset($nom_key, "content", $comment->content); 00067 $r->hset($nom_key, "time_posted", $comment->time_posted); 00068 $r->hset($nom_key, "deleted", 0); 00069 00070 // redis only 00071 if ($parent_id === 0) { continue; } 00072 00073 // get a unique ID 00074 $hash = uniqid(); 00075 $redh_key = "newstest:1:comment_by_hash:$hash"; 00076 $r->lpush($redh_key, $hash); 00077 00078 $red_key = "newstest:1:comment:$hash"; 00079 $r->hset($red_key, "id", $comment->id); 00080 $r->hset($red_key, "posted_by", $comment->posted_by); 00081 $r->hset($red_key, "news_id", $comment->news_id); 00082 $r->hset($red_key, "parent_id", $comment->parent_id); 00083 $r->hset($red_key, "content", $comment->content); 00084 $r->hset($red_key, "time_posted", $comment->time_posted); 00085 $r->hset($red_key, "deleted", 0); 00086 } 00087 00088 echo "Finished!"; 00089 }); 00090 00091 desc("Stress test various comment implementations"); 00092 task("redistest", function () { 00093 $r = RedisManager::connection(); 00094 00095 // Original implementation 00096 $len = $r->llen("newstest:1:comment_by_id:0"); 00097 if ($len) { 00098 $ids = $r->lrange($key, 0, $len); 00099 foreach ($ids as $id) { 00100 $comment = ActiveCache::find('Commenttest_Model', $id, 43200)->sql( 00101 "SELECT * FROM commenttests WHERE id = $id LIMIT 1" 00102 ); 00103 00104 $comment->orig_load_children(); 00105 } 00106 } 00107 00108 });