|
| 1 | +<?php |
| 2 | +namespace Tests; |
| 3 | +use PHPUnit\Framework\TestCase; |
| 4 | +require_once ('griddb_php_client.php'); |
| 5 | +require_once('config.php'); |
| 6 | +require_once('utility.php'); |
| 7 | + |
| 8 | +class BS013PartitionController extends TestCase { |
| 9 | + protected static $gridstore; |
| 10 | + protected static $containerNameCol = "PC_1"; |
| 11 | + protected static $containerNameTS = "PC_2"; |
| 12 | + |
| 13 | + public static function setUpBeforeClass(): void { |
| 14 | + $modifiable = true; |
| 15 | + $factory = \StoreFactory::getInstance(); |
| 16 | + try { |
| 17 | + $storeInfo = ["host" => GRIDDB_NOTIFICATION_ADDRESS, |
| 18 | + "port" => (int)GRIDDB_NOTIFICATION_PORT, |
| 19 | + "clusterName" => GRIDDB_CLUSTER_NAME, |
| 20 | + "username" => GRIDDB_USERNAME, |
| 21 | + "password" => GRIDDB_PASSWORD]; |
| 22 | + |
| 23 | + self::$gridstore = $factory->getStore($storeInfo); |
| 24 | + /** |
| 25 | + * Container schema |
| 26 | + */ |
| 27 | + $columnInfoListCol = [["A", \Type::STRING], |
| 28 | + ["B", \Type::TIMESTAMP], |
| 29 | + ["a_9", \Type::BYTE], |
| 30 | + ["za", \Type::SHORT], |
| 31 | + ["1_a", \Type::INTEGER], |
| 32 | + ["F", \Type::BOOL], |
| 33 | + ["G", \Type::FLOAT], |
| 34 | + ["H", \Type::DOUBLE], |
| 35 | + ["I", \Type::BLOB]]; |
| 36 | + |
| 37 | + $columnInfoListTS = [["A", \Type::TIMESTAMP], |
| 38 | + ["B", \Type::STRING], |
| 39 | + ["a_9", \Type::BYTE], |
| 40 | + ["za", \Type::SHORT], |
| 41 | + ["1_a", \Type::INTEGER], |
| 42 | + ["F", \Type::BOOL], |
| 43 | + ["G", \Type::FLOAT], |
| 44 | + ["H", \Type::DOUBLE], |
| 45 | + ["I", \Type::BLOB]]; |
| 46 | + |
| 47 | + // Create a collection container |
| 48 | + $containerInfoCol = new \ContainerInfo(["name" => self::$containerNameCol, |
| 49 | + "columnInfoArray" => $columnInfoListCol, |
| 50 | + "type" => \ContainerType::COLLECTION, |
| 51 | + "rowKey" => true]); |
| 52 | + // Create a timeseries container |
| 53 | + $containerInfoTS = new \ContainerInfo(["name" => self::$containerNameTS, |
| 54 | + "columnInfoArray" => $columnInfoListTS, |
| 55 | + "type" => \ContainerType::TIME_SERIES, |
| 56 | + "rowKey" => true]); |
| 57 | + |
| 58 | + self::$gridstore->dropContainer(self::$containerNameCol); |
| 59 | + self::$gridstore->dropContainer(self::$containerNameTS); |
| 60 | + self::$gridstore->putContainer($containerInfoCol, $modifiable); |
| 61 | + self::$gridstore->putContainer($containerInfoTS, $modifiable); |
| 62 | + } catch (\GSException $e){ |
| 63 | + for ($i= 0; $i < $e->getErrorStackSize(); $i++) { |
| 64 | + echo("\n[$i]\n"); |
| 65 | + echo($e->getErrorCode($i)."\n"); |
| 66 | + echo($e->getLocation($i)."\n"); |
| 67 | + echo($e->getErrorMessage($i)."\n"); |
| 68 | + } |
| 69 | + } catch (\Exception $e1) { |
| 70 | + echo($e1."\n"); |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + /** |
| 75 | + * Provider Data |
| 76 | + */ |
| 77 | + public function providerDataTestGetContainerCount() { |
| 78 | + return getTestDataFilter("test/resource/BS-013-PartitionController.csv", 0, 3); |
| 79 | + } |
| 80 | + |
| 81 | + /** |
| 82 | + * @dataProvider providerDataTestGetContainerCount |
| 83 | + */ |
| 84 | + public function testGetContainerCount($testId, $partitionIndex, $start, |
| 85 | + $limit,$containerName, |
| 86 | + $hostname, $expectedOutput) |
| 87 | + { |
| 88 | + echo sprintf("Test case: %s \n", $testId); |
| 89 | + echo (" PartitionController::getContainerCount\n"); |
| 90 | + $expectedOutputConvert = convertData($expectedOutput); |
| 91 | + |
| 92 | + try { |
| 93 | + $partitionController = self::$gridstore->partitionController; |
| 94 | + $retCount = $partitionController->getContainerCount(convertData($partitionIndex)); |
| 95 | + |
| 96 | + } catch (\GSException $e) { |
| 97 | + echo("Throw $e\n"); |
| 98 | + for ($i= 0; $i < $e->getErrorStackSize(); $i++) { |
| 99 | + echo("\n[$i]\n"); |
| 100 | + echo($e->getErrorCode($i)."\n"); |
| 101 | + echo($e->getLocation($i)."\n"); |
| 102 | + echo($e->getErrorMessage($i)."\n"); |
| 103 | + } |
| 104 | + $retCount = -1; |
| 105 | + $this->assertLessThanOrEqual($retCount, $expectedOutputConvert); |
| 106 | + } catch (\Exception $e1) { |
| 107 | + echo($e1."\n"); |
| 108 | + $retCount = -1; |
| 109 | + $this->assertLessThanOrEqual($retCount, $expectedOutputConvert); |
| 110 | + } |
| 111 | + //Assert result |
| 112 | + $this->assertLessThanOrEqual($retCount, $expectedOutputConvert); |
| 113 | + } |
| 114 | + |
| 115 | + /** |
| 116 | + * Provider Data |
| 117 | + */ |
| 118 | + public function providerDataTestGetContainerNames() { |
| 119 | + return getTestDataFilter("test/resource/BS-013-PartitionController.csv", 3, 12); |
| 120 | + } |
| 121 | + |
| 122 | + /** |
| 123 | + * @dataProvider providerDataTestGetContainerNames |
| 124 | + */ |
| 125 | + public function testGetContainerNames($testId, $partitionIndex, $start, |
| 126 | + $limit,$containerName, |
| 127 | + $hostname, $expectedOutput) |
| 128 | + { |
| 129 | + echo sprintf("Test case: %s \n", $testId); |
| 130 | + echo (" PartitionController::getContainerNames\n"); |
| 131 | + $expectedOutputConvert = convertData($expectedOutput); |
| 132 | + |
| 133 | + try { |
| 134 | + $partitionController = self::$gridstore->partitionController; |
| 135 | + $containerNames = $partitionController->getContainerNames(convertData($partitionIndex), |
| 136 | + convertData($start), |
| 137 | + convertData($limit)); |
| 138 | + $length = sizeof($containerNames); |
| 139 | + } catch (\GSException $e) { |
| 140 | + echo("Throw $e\n"); |
| 141 | + for ($i= 0; $i < $e->getErrorStackSize(); $i++) { |
| 142 | + echo("\n[$i]\n"); |
| 143 | + echo($e->getErrorCode($i)."\n"); |
| 144 | + echo($e->getLocation($i)."\n"); |
| 145 | + echo($e->getErrorMessage($i)."\n"); |
| 146 | + } |
| 147 | + $length = -1; |
| 148 | + $this->assertLessThanOrEqual($length, $expectedOutputConvert); |
| 149 | + } catch (\Exception $e1) { |
| 150 | + echo($e1."\n"); |
| 151 | + $length = -1; |
| 152 | + $this->assertLessThanOrEqual($length, $expectedOutputConvert); |
| 153 | + } |
| 154 | + //Assert result |
| 155 | + $this->assertLessThanOrEqual($length, $expectedOutputConvert); |
| 156 | + } |
| 157 | + |
| 158 | + /** |
| 159 | + * Provider Data |
| 160 | + */ |
| 161 | + public function providerDataTestGetPartitionIndexOfContainer() { |
| 162 | + return getTestDataFilter("test/resource/BS-013-PartitionController.csv", 13, 14); |
| 163 | + } |
| 164 | + |
| 165 | + /** |
| 166 | + * @dataProvider providerDataTestGetPartitionIndexOfContainer |
| 167 | + */ |
| 168 | + public function testGetPartitionIndexOfContainer($testId, $partitionIndex, |
| 169 | + $start, $limit,$containerName, |
| 170 | + $hostname, $expectedOutput) |
| 171 | + { |
| 172 | + echo sprintf("Test case: %s \n", $testId); |
| 173 | + echo (" PartitionController::getPartitionIndexOfContainer\n"); |
| 174 | + $expectedOutputConvert = convertData($expectedOutput); |
| 175 | + |
| 176 | + try { |
| 177 | + $partitionController = self::$gridstore->partitionController; |
| 178 | + $index = $partitionController->getPartitionIndexOfContainer(convertData($containerName)); |
| 179 | + } catch (\GSException $e) { |
| 180 | + echo("Throw $e\n"); |
| 181 | + for ($i= 0; $i < $e->getErrorStackSize(); $i++) { |
| 182 | + echo("\n[$i]\n"); |
| 183 | + echo($e->getErrorCode($i)."\n"); |
| 184 | + echo($e->getLocation($i)."\n"); |
| 185 | + echo($e->getErrorMessage($i)."\n"); |
| 186 | + } |
| 187 | + $index = -1; |
| 188 | + $this->assertLessThanOrEqual($index, $expectedOutputConvert); |
| 189 | + } catch (\Exception $e1) { |
| 190 | + echo($e1."\n"); |
| 191 | + $index = -1; |
| 192 | + $this->assertLessThanOrEqual($index, $expectedOutputConvert); |
| 193 | + } |
| 194 | + //Assert result |
| 195 | + $this->assertLessThanOrEqual($index, $expectedOutputConvert); |
| 196 | + } |
| 197 | +} |
| 198 | +?> |
| 199 | + |
0 commit comments