コード例 #1
0
 /**
  * @depends testOutput
  *
  * @param $content
  */
 public function testReader($content)
 {
     file_put_contents(self::$file, $content);
     $fh = fopen(self::$file, 'r');
     $reader = new DrdStreamReader($fh, self::$fields);
     $rec = $reader->readRecord();
     $this->assertNotFalse($rec);
     $this->assertEquals('Josh', $rec['name']);
     $this->assertEquals(13, $rec['age']);
     $this->assertEquals('The o\'looka police', $rec['job']);
     $rec = $reader->readRecord();
     $this->assertNotFalse($rec);
     $this->assertEquals('Martin', $rec['name']);
     $this->assertEquals(3, $rec['age']);
     $this->assertEquals('', $rec['job']);
     $rec = $reader->readRecord();
     $this->assertNotFalse($rec);
     $this->assertEquals('O\'riel', $rec['name']);
     $this->assertEquals(21, $rec['age']);
     $this->assertEquals('pub | priv', $rec['job']);
     $rec = $reader->readRecord();
     $this->assertNotFalse($rec);
     $this->assertEquals('Nanting', $rec['name']);
     $this->assertEquals('', $rec['age']);
     $this->assertEquals("glad to\nwin", $rec['job']);
     $rec = $reader->readRecord();
     $this->assertNotFalse($rec);
     $this->assertEquals('', $rec['name']);
     $this->assertEquals(0, $rec['age']);
     $this->assertEquals("not yet born", $rec['job']);
     $rec = $reader->readRecord();
     $this->assertNotFalse($rec);
     $this->assertEquals('', $rec['name']);
     $this->assertEquals('', $rec['age']);
     $this->assertEquals("", $rec['job']);
     $rec = $reader->readRecord();
     $this->assertFalse($rec);
 }
コード例 #2
0
 public function testDataImportExportWithGzipAndParallel()
 {
     $exportPrefix = "redshift_ut_" . time();
     $this->testDataImport(true);
     $exporter = new RedshiftExporter(self::$rs, self::$localFs, self::$s3Fs, self::$s3Region, self::$sts);
     $exporter->exportToFile($exportPrefix, "SELECT * FROM php_redshift_test", true, true, true);
     $exportedCount = 0;
     $finder = self::$localFs->getFinder();
     $finder->path("#^" . preg_quote($exportPrefix, "#") . "#");
     $unloaded = [];
     foreach ($finder as $splFileInfo) {
         $relativePathname = $splFileInfo->getRelativePathname();
         $unloaded[] = $relativePathname;
         $content = self::$localFs->read($relativePathname);
         mdebug(gzdecode($content));
         $fh = fopen('php://memory', 'r+');
         fwrite($fh, gzdecode($content));
         rewind($fh);
         $reader = new DrdStreamReader($fh, self::FIELDS);
         while ($reader->readRecord()) {
             $exportedCount++;
         }
         fclose($fh);
     }
     self::assertEquals(5, $exportedCount);
     // test import of parallel data
     $importer = new RedshiftImporter(self::$rs, self::$localFs, self::$s3Fs, self::$s3Region, self::$sts);
     $importer->importFromFile($exportPrefix, 'php_redshift_test', self::FIELDS, true, true);
     $stmt = self::$rs->prepare("SELECT COUNT(*) FROM php_redshift_test");
     $stmt->execute();
     $result = $stmt->fetchColumn();
     self::assertEquals(10, $result);
     foreach ($unloaded as $relativePathname) {
         self::$localFs->delete($relativePathname);
     }
 }