Ejemplo n.º 1
0
 public function testShowJobAPI()
 {
     $api = new TreasureData_API();
     $stub = $this->getMockForAbstractClass('TreasureData_API_Driver');
     $fixture = file_get_contents(TD_API_FIXTURE_PATH . join(DIRECTORY_SEPARATOR, array("api", "kill.json")));
     $stub->expects($this->any())->method('request')->will($this->returnValue(new TreasureData_API_Response(new TreasureData_API_Request(), new TreasureData_API_Stream_InputStream($fixture))));
     $api->setDriver($stub);
     $result = $api->killJob("12345");
     $this->assertInstanceof('TreasureData_API_Result', $result);
     $message = $result->getResult();
     /** @var TreasureData_API_Message_Kill $message */
     $this->assertInstanceof('TreasureData_API_Message_Kill', $message);
     $this->assertEquals("12345", $message->getJobId());
     $this->assertEquals("running", $message->getFormerStatus());
 }
 public function testGetDatabaseListAPI()
 {
     $api = new TreasureData_API();
     $stub = $this->getMockForAbstractClass('TreasureData_API_Driver');
     $fixture = file_get_contents(TD_API_FIXTURE_PATH . join(DIRECTORY_SEPARATOR, array("api", "databases.json")));
     $stub->expects($this->any())->method('request')->will($this->returnValue(new TreasureData_API_Response(new TreasureData_API_Request(), new TreasureData_API_Stream_InputStream($fixture))));
     $api->setDriver($stub);
     $result = $api->getDatabaseList();
     $this->assertInstanceof('TreasureData_API_Result', $result);
     $message = $result->getResult();
     $this->assertInstanceof('TreasureData_API_Message_Databases', $message);
     $databases = $message->getDatabases();
     $this->assertEquals("db0", $databases[0]->getName());
     $this->assertEquals("db1", $databases[1]->getName());
 }
 public function testIssueHiveJobAPI()
 {
     $api = new TreasureData_API();
     $stub = $this->getMockForAbstractClass('TreasureData_API_Driver');
     $fixture = file_get_contents(TD_API_FIXTURE_PATH . join(DIRECTORY_SEPARATOR, array("api", "issue_hive_job.json")));
     $stub->expects($this->any())->method('request')->will($this->returnValue(new TreasureData_API_Response(new TreasureData_API_Request(), new TreasureData_API_Stream_InputStream($fixture))));
     $api->setDriver($stub);
     $result = $api->issueHiveQuery("www_access", "select v['code'] as code, count(1) as cnt from www_access group by v['code']");
     $this->assertInstanceof('TreasureData_API_Result', $result);
     $message = $result->getResult();
     /** @var TreasureData_API_Message_IssueJob $message */
     $this->assertInstanceof('TreasureData_API_Message_IssueJob', $message);
     $this->assertEquals("www_access", $message->getDatabase());
     $this->assertEquals("hive", $message->getType());
     $this->assertEquals("http://console.treasure-data.com/will-be-ready", $message->getUrl());
 }
 public function testGetJobStatusAPI()
 {
     $api = new TreasureData_API();
     $stub = $this->getMockForAbstractClass('TreasureData_API_Driver');
     $fixture = file_get_contents(TD_API_FIXTURE_PATH . join(DIRECTORY_SEPARATOR, array("api", "job_status.json")));
     $stub->expects($this->any())->method('request')->will($this->returnValue(new TreasureData_API_Response(new TreasureData_API_Request(), new TreasureData_API_Stream_InputStream($fixture))));
     $api->setDriver($stub);
     $result = $api->getJobStatus(860329);
     $this->assertInstanceof('TreasureData_API_Result', $result);
     $message = $result->getResult();
     /** @var TreasureData_API_Message_JobStatus $message */
     $this->assertInstanceof('TreasureData_API_Message_JobStatus', $message);
     $this->assertEquals("860329", $message->getJobId());
     $this->assertEquals("success", $message->getStatus());
     $this->assertInstanceof("DateTime", $message->getCreatedAt());
     $this->assertInstanceof("DateTime", $message->getStartAt());
     $this->assertInstanceof("DateTime", $message->getEndAt());
 }
 public function testGetTableListAPI()
 {
     $api = new TreasureData_API();
     $fixture = file_get_contents(TD_API_FIXTURE_PATH . join(DIRECTORY_SEPARATOR, array("api", "table_list.json")));
     $stub = $this->getMockForAbstractClass('TreasureData_API_Driver');
     $stub->expects($this->any())->method('request')->will($this->returnValue(new TreasureData_API_Response(new TreasureData_API_Request(), new TreasureData_API_Stream_InputStream($fixture))));
     $api->setDriver($stub);
     $result = $api->getTableList("db0");
     $this->assertInstanceof('TreasureData_API_Result', $result);
     $message = $result->getResult();
     $this->assertInstanceof('TreasureData_API_Message_TableList', $message);
     /** @var TreasureData_API_Message_TableList $message */
     $this->assertEquals("db0", $message->getDatabase());
     $i = 0;
     $expected = json_decode($fixture, true);
     foreach ($message->getTables() as $table) {
         /** @var TreasureData_API_Message_Table $table */
         $this->assertInstanceof("TreasureData_API_Message_Table", $table);
         $this->assertEquals($expected['tables'][$i]['count'], $table->getCount());
         $this->assertEquals($expected['tables'][$i]['name'], $table->getName());
         $i++;
     }
 }
Ejemplo n.º 6
0
 public function testShowJobAPI()
 {
     $api = new TreasureData_API();
     $stub = $this->getMockForAbstractClass('TreasureData_API_Driver');
     $fixture = file_get_contents(TD_API_FIXTURE_PATH . join(DIRECTORY_SEPARATOR, array("api", "show_job.json")));
     $stub->expects($this->any())->method('request')->will($this->returnValue(new TreasureData_API_Response(new TreasureData_API_Request(), new TreasureData_API_Stream_InputStream($fixture))));
     $api->setDriver($stub);
     $result = $api->showJob("12345");
     $this->assertInstanceof('TreasureData_API_Result', $result);
     $message = $result->getResult();
     /** @var TreasureData_API_Message_JobInformation $message */
     $this->assertInstanceof('TreasureData_API_Message_JobInformation', $message);
     $this->assertEquals("12345", $message->getJobId());
     $this->assertEquals("SELECT * FROM ACCESS", $message->getQuery());
     $this->assertEquals("hive", $message->getType());
     $this->assertEquals("http://console.treasure-data.com/jobs/12345", $message->getUrl());
     $this->assertInstanceof("DateTime", $message->getCreatedAt());
     $this->assertInstanceof("DateTime", $message->getUpdatedAt());
     $debug = $message->getDebug();
     /** @var TreasureData_API_Message_JobInformationDebug $debug */
     $this->assertInstanceof('TreasureData_API_Message_JobInformationDebug', $debug);
     $this->assertEquals("...", $debug->getCmdout());
     $this->assertEquals("...", $debug->getStderr());
 }