public function testOthers() { $this->assertNull($this->object->project); $this->object->setProject('demo'); $this->assertEquals('demo', $this->object->getProject()); $this->object->setTimeout(0); $this->assertFalse($this->object->hasRespond()); $this->object->sendCommand(CMD_OK); $this->assertFalse($this->object->hasRespond()); $this->object->sendCommand(CMD_SEARCH_GET_DB); usleep(50000); $this->assertTrue($this->object->hasRespond()); $res = $this->object->respond; $this->assertEquals(CMD_OK_DB_INFO, $res->arg); $this->assertEquals('Database()', $res->buf); // read timeout try { stream_set_timeout($this->object->socket, 2); $this->object->getRespond(); } catch (XSException $e) { } $this->assertInstanceOf('XSException', $e); $this->assertRegExp('/timeout/', $e->getMessage()); // send cmd $this->object->reopen(); $this->object->project = 'demo'; $cmd = new XSCommand(array('cmd' => CMD_QUERY_GET_STRING, 'buf' => 'hello')); $res = $this->object->execCommand($cmd); $this->assertEquals(CMD_OK_QUERY_STRING, $res->arg); $this->assertEquals('Xapian::Query(Zhello:(pos=1))', $res->buf); // test unimp cmd try { $e = null; $this->object->execCommand(array('cmd' => CMD_INDEX_SUBMIT)); } catch (XSException $e) { } $this->assertInstanceOf('XSException', $e); $this->assertEquals('Command not implemented', $e->getMessage()); // test io closed try { $e = null; $err = error_reporting(0); fclose($this->object->socket); $this->object->sendCommand(CMD_INDEX_SUBMIT); } catch (XSException $e) { } $this->assertInstanceOf('XSException', $e); $this->assertRegExp('/unknown/', $e->getMessage()); error_reporting($err); }
/** * 命令函数: 重连或新建服务端连接 * @param string $args */ function cmd_open($args) { global $server; if (empty($args)) { if (!$server instanceof XSServer) { echo " 请问要打开什么服务端? (索引默认端口:8383, 搜索默认端口:8384)\n"; echo " 用法: open <port>|<host:port>|<path>|<search|index>\n"; return; } $res = $server->reopen(); echo " 重新打开服务端连接\n"; } else { $args == 'index' && ($args = '8383'); $args == 'search' && ($args = '8384'); $server = new XSServer($args); echo " 已打开服务端连接: {$args}\n"; } $server->setTimeout(0); }