提交 5924f92b 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

add service test scripts

上级 84a29ac3
INSERT INTO tlb_table(`test0`)
VALUES ('1|1'),
('1|2|2'),
('2|3'),
('3|3|1'),
('1|1'),
('1|2|2'),
('2|3'),
('3|3|1'),
('1|1'),
('1|2|2');
Success yo start zendata http service, press CTRL+C to exist.
You may use http://10.8.0.134:8848 to retrieve the data,for example:
curl http://10.8.0.134:8848/?config=demo/default.yaml&F=field_common&lines=10.
Got GET request /?d=../../demo/default.yaml&c=../../demo/test.yaml&lines=10.
Create 10 records in 0 sec.
...@@ -90,6 +90,49 @@ class zendata ...@@ -90,6 +90,49 @@ class zendata
exec($cmdStr, $output); exec($cmdStr, $output);
} }
public function startService($port, $root)
{
$this->stopService($port);
$cmdStr = sprintf("nohup %s -p %d >log.txt 2>&1 &", $this->cmdPath, $port);
if ($root) {
$cmdStr = str_replace(" -p ", " -R " . $root . " -p ", $cmdStr);
}
print("$cmdStr\n");
pclose(popen($cmdStr, 'r'));
exec($cmdStr, $output);
exec("lsof -i :8848", $output);
$str = join($output, "\n");
print("$str\n");
}
public function stopService($port)
{
$cmdStr = sprintf("kill -9 `lsof -i :%d -t`", $port);
print("$cmdStr\n");
exec($cmdStr, $output);
}
public function httpGet($port, $default, $conf, $lines, $options = array())
{
$url = sprintf("http://127.0.0.1:%d/?d=%s/%s&c=%s/%s&lines=%d",
$port, $this->workDir, $default, $this->workDir, $conf, $lines);
if (array_key_exists("root", $options)) {
$url .= "&root=" . $options["root"];
}
print("$url\n");
$resp = file_get_contents($url);
print("$resp\n");
return $resp;
}
public function cmd($params) public function cmd($params)
{ {
$cmdStr = sprintf("%s %s", $this->cmdPath, $params); $cmdStr = sprintf("%s %s", $this->cmdPath, $params);
......
>> 10
>> int_3
\ No newline at end of file
#!/usr/bin/env php
<?php
/**
[case]
title=
cid=0
pid=0
[group]
>>
>>
[esac]
*/
include_once __DIR__ . DIRECTORY_SEPARATOR . '../lib/zd.php';
$zd = new zendata();
$port = 8848;
$zd->startService($port);
$resp = $zd->httpGet($port, "default.yaml", "test.yaml", 10);
$jsonArr = json_decode($resp,TRUE);
$count = sprintf("%d", count($jsonArr));
print(">> $count\n");
$field = $jsonArr[2]["field_common"];
print(">> $field\n");
$zd->stopService(8848);
\ No newline at end of file
>> 10
>> int_3
\ No newline at end of file
#!/usr/bin/env php
<?php
/**
[case]
title=
cid=0
pid=0
[group]
>>
>>
[esac]
*/
include_once __DIR__ . DIRECTORY_SEPARATOR . '../lib/zd.php';
$zd = new zendata();
$port = 8848;
$root = dirname(dirname(dirname(__FILE__)));
$zd->startService($port, $root);
$resp = $zd->httpGet($port, "default.yaml", "test.yaml", 10);
$jsonArr = json_decode($resp,TRUE);
$count = sprintf("%d", count($jsonArr));
print(">> $count\n");
$field = $jsonArr[2]["field_common"];
print(">> $field\n");
$zd->stopService(8848);
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册