Skip to content

Instantly share code, notes, and snippets.

@posulliv
Created September 29, 2011 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save posulliv/1252049 to your computer and use it in GitHub Desktop.
Save posulliv/1252049 to your computer and use it in GitHub Desktop.
Akiban Simple Simple OLB Tests
#!/usr/bin/env php
<?php
/**
* Basic tests for Akiban database.
* @author posulliva@akiban.com
* @package test/akiban
*/
require_once dirname(__FILE__)."/../bootstrap/unit.php";
require_once(SF_ROOT_DIR. '/lib/net/manhunt/search/SearchFactory.php');
/*
* get the first X characters of a valid username
* from the member_info table
*/
function getUsernamePrefix($num_of_chars) {
$shardManager = ShardManager::getInstance();
$dbh = $shardManager->getConnection(0, "main", Shard::MASTER);
$username = NULL;
while (! $username) {
$profile_id = rand(100, 100000000);
$sql = "select username from member_info where profileID = " . $profile_id;
$stmt = $dbh->prepare($sql);
$stmt->execute();
$res = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$username = $res['username'];
}
return substr($username, 0, $num_of_chars);
}
/*
* This is not really useful at the moment
* placeholder for something more extensive
*/
function genAdminInput($gen_like, $gen_ft_search) {
$attrArray = array();
$attrArray['ageMin'] = rand(18, 35);
$attrArray['ageMax'] = rand(36, 65);
$username = getUsernamePrefix(rand(1, 10));
if ($username) {
$attrArray['username'] = $username;
$attrArray['usernameExact'] = 1;
}
if ($gen_like) {
// akiban does not support LIKE
// setting usernameExact to NULL causes SQL with LIKE
// to be generated
$attrArray['usernameExact'] = NULL;
}
if ($gen_ft_search) {
// this causes a full text search to be issued
$attrArray['text'] = 'something';
}
return $attrArray;
}
$t = new mh_test(16);
// enable akiban (it is not enabled by default)
sfConfig::set("app_useakiban", true);
$func_input = genAdminInput(false, false);
// first explicitly control whether to use akiban or not
$akiban_results = SearchFactory::executeAdminSearch($func_input, 250, true);
$mysql_results = SearchFactory::executeAdminSearch($func_input, 250, false);
// compare results
$t->ok($akiban_results == $mysql_results, "Akiban & MySQL Results match");
$func_input = genAdminInput(false, false);
// now do not explicitly control whether to use akiban or not
$akiban_results = SearchFactory::executeAdminSearch($func_input, 250);
$mysql_results = SearchFactory::executeAdminSearch($func_input, 250);
// compare results
$t->ok($akiban_results == $mysql_results, "Akiban & MySQL Results match");
$func_input = genAdminInput(false, false);
// now disable akiban at global level and make sure only mysql is used
// this should mean results are still valid
sfConfig::set("app_useakiban", false);
$akiban_results = SearchFactory::executeAdminSearch($func_input, 250);
$mysql_results = SearchFactory::executeAdminSearch($func_input, 250);
// compare results
$t->ok($akiban_results == $mysql_results, "Akiban & MySQL Results match");
// re-enable akiban
sfConfig::set("app_useakiban", true);
// try a few generated inputs and sure everything is hunky dory
$iterations = 10;
for ($i = 0; $i < $iterations; $i++) {
$func_input = genAdminInput(false, false);
$akiban_results = SearchFactory::executeAdminSearch($func_input, 10, true);
$mysql_results = SearchFactory::executeAdminSearch($func_input, 10, false);
$t->ok($akiban_results == $mysql_results, "Akiban & MySQL Results match");
}
// now generate some input that will generate a query akiban can not handle
// make sure admin module still services the query by going to mysql
$func_input = genAdminInput(true, false);
// akiban is not used for this
$mysql_results = SearchFactory::executeAdminSearch($func_input, 250, false);
// make results are valid
$t->is_not_null($mysql_results, "MySQL Results are valid");
// now try full text search query
$func_input = genAdminInput(false, true);
// akiban is not used for this
$mysql_results = SearchFactory::executeAdminSearch($func_input, 250, false);
// make sure this data is valid
$t->is_not_null($mysql_results, "MySQL Results are valid");
// send off a query to akiban with the largest limit allowed
// by the admin module at the moment
$func_input = genAdminInput(false, false);
$akiban_results = SearchFactory::executeAdminSearch($func_input, sfConfig::get("uidlistmax"), true);
$mysql_results = SearchFactory::executeAdminSearch($func_input, sfConfig::get("uidlistmax"), false);
// compare results
$t->ok($akiban_results == $mysql_results, "Akiban & MySQL Results match");
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment