????Setup??StartService???裬???????????????????????????????????????????????????????β???????????????????????????????μ????????????

????Run??sendInput??Σ???Щ???????????????????????????????http?????????????????????????????????????????????????????????????????????????????????????????????????????

????Run??execute??Σ?????????????????????????????е??????hadoop????hive????????????????????????????????????????????????????????????С?

????Run??getResult??Σ?

????Teardown??stopService??Σ???????????????????????

????Teardown??stopRefService??Σ????????????????????????????????

??????????κ???????????????????????????????????????????????????????????????????????????????????????д?????????????????á?

????????????·????????????????

????

????class underTest

????{

????function go()

????{

????$this->setup();

????$this->run();

????$this->tearDown();

????}

????function setup()

????{

????$this->cleanEvironment();

????$this->generateConfig();

????$this->generateData();

????$this->startRefServices();

????$this->startService();

????}

????function run()

????{

????$this->sendInput();

????$this->execute();

????$this->getResult();

????}

????function teardown()

????{

????$this->stopService();

????$this->stopRefServices();

????}

????function cleanEvironment()

????{

????exec('rm -rf /table_path/staff');

????}

????function generateConfig(){}

????function gnerateData()

????{

????$input = get_user_input();

????file_put_contents('/tmp/staff.table'?? $input); //???????????д?????

????}

????function startRefServices(){}

????function startService(){}

????function sendInput()

????{

????exec('hadoop fs -mkdir /table_path/staff/'); //??hadoop???????????????·??

????exec('hive -e "create external table stuff(name string?? age bigint?? salary bigint) partitioned by (dp string) location '/table_path/staff/dp=etao';"'); //????hive????????

????exec('hadoop fs -put /tmp/staff.table/table_path/staff/dp=etao/part-000'); //?????????????????hdfs??

????exec('hive -e "alter table staff add if not exists partition ( dp=etao ) location ’/table_path/staff/dp=etao"');//????alter table???????????????????????????????????(hive?????????)

????}

????function execute()

????{

????exec('underTestShell.sh'); //??б???????

????}

????function getResult()

????{

????exec('hadoop fs -cat /tmp/result.table/table_path/result/dp=etao/part-000 > /tmp/result.tmp'); //??????????????????

????$result = file_get_contents('/tmp/result.tmp'); //??????????????

????}

????function stopService(){}

????function stopRevServices(){}

????}

?????>

??????????????????????д?????????????????????????????????????

????1. ?淶??????????????κ???????????????????????????????????д?????????????????????????????????????????????

????2. ?????????С??????????????????????????????????????е?????????????η???????????????????????????????????????????£??????????test dirver?У?????????????????衣?????????????????

????3. ??????????????????????????????????????????????????飬?????????????????á?

???????????????????????????????????????Щ???????????????????????????????????кá?

???????????????£?????????????????????????

????

????//?????????????????

????$input = "zhangsan|28|8000 ";//?????????????????

????$input.= "lisi|30|10000 "; //?????????????????

????$input.= "wangwu|40|20000 "; //??????????????????

????//???????????????

????file_put_contents('/tmp/staff.table'?? $input); //???????????д?????

????exec('hadoop fs -mkdir /table_path/staff/'); //??hadoop???????????????·??

????exec('hive -e "create external table stuff(name string?? age bigint?? salary bigint) partitioned by (dp string) location '/table_path/staff/dp=etao';"'); //????hive????????

????exec('hadoop fs -put /tmp/staff.table/table_path/staff/dp=etao/part-000'); //?????????????????hdfs??