/** * This method is called after the last test of this test class is run. */ public static function tearDownAfterClass() { if (self::$aerospike->isConnected()) { foreach (self::$keys as $key) { // TODO: check existence of $key in Aerospike. self::$aerospike->remove($key); } self::$aerospike->close(); } parent::tearDownAfterClass(); }
/** * Validate query string, connect to aspike * * @param array $hosts * @return array */ public function connectAero($hosts) { $config = array("hosts" => $hosts); $opts = array(Aerospike::OPT_CONNECT_TIMEOUT => 1000000, Aerospike::OPT_WRITE_TIMEOUT => 2500); $db = new Aerospike($config, true, $opts); if (!$db->isConnected()) { echo "<div class='alert alert-danger'><strong>Aerospike Error!</strong> " . $db->errorno() . " : " . $db->error() . "</div>"; exit(1); } return $db; }
} $HOST_ADDR = isset($args["h"]) ? (string) $args["h"] : (isset($args["host"]) ? (string) $args["host"] : "127.0.0.1"); $HOST_PORT = isset($args["p"]) ? (int) $args["p"] : (isset($args["port"]) ? (string) $args["port"] : 3000); if (isset($args['a']) || isset($args['annotate'])) { $annotate = true; } else { $annotate = false; } echo colorize("***** Welcome to Aerospike Developer Training *****\n", 'blue', true); echo colorize("Connecting to Aerospike cluster ≻", 'black', true); if ($annotate) { display_code(__FILE__, __LINE__, 7); } $config = array("hosts" => array(array("addr" => $HOST_ADDR, "port" => $HOST_PORT))); $client = new Aerospike($config, false); if (!$client->isConnected()) { echo standard_fail($client); echo colorize("Connection to Aerospike cluster failed! Please check the server settings and try again!\n", 'red', true); exit(2); } echo success(); $selection = show_menu(); if ($selection === 0) { $client->close(); exit(0); } $user_service = new \Aerospike\Training\UserService($client, $config, $annotate); $tweet_service = new \Aerospike\Training\TweetService($client, $config, $annotate); try { switch ($selection) { case 1:
$longopts = array("host::", "port::", "clean", "annotate", "help"); $options = getopt($shortopts, $longopts); return $options; } $args = parse_args(); if (isset($args["help"])) { echo "php standard.php [-h<HOST IP ADDRESS>|--host=<HOST IP ADDRESS> -p<HOST PORT NUMBER>|--port=<HOST PORT NUMBER> -a|--annotate -c|--clean]\n"; exit(1); } $HOST_ADDR = isset($args["h"]) ? (string) $args["h"] : (isset($args["host"]) ? (string) $args["host"] : "localhost"); $HOST_PORT = isset($args["p"]) ? (int) $args["p"] : (isset($args["port"]) ? (string) $args["port"] : 3000); echo colorize("Connecting to the host ≻", 'black', true); $start = __LINE__; $config = array("hosts" => array(array("addr" => $HOST_ADDR, "port" => $HOST_PORT))); $db = new Aerospike($config, false); if (!$db->isConnected()) { echo fail("Could not connect to host {$HOST_ADDR}:{$HOST_PORT} [{$db->errorno()}]: {$db->error()}"); exit(1); } echo success(); if (isset($args['a']) || isset($args['annotate'])) { display_code(__FILE__, $start, __LINE__); } echo colorize("Ensuring that a record is put at test.users with PK=1234 ≻", 'black', true); $start = __LINE__; $key = $db->initKey("test", "users", 1234); $put_vals = array("email" => "*****@*****.**", "name" => "Perceptron"); $status = $db->put($key, $put_vals); if ($status == Aerospike::OK) { echo success(); } else {