Skip to content

Commit 9e605a1

Browse files
committed
add test code for PartitionConrtoller API and update src
1 parent db28a90 commit 9e605a1

File tree

6 files changed

+244
-2
lines changed

6 files changed

+244
-2
lines changed

sample/ContainerNames.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
//(2)Loop by the number of partitions to get an array of container names
2020
for ($i = 0; $i < $pcCount; $i++) {
21-
$arrayContainerNames = $pc->getContainerNames($i, 0);
21+
$arrayContainerNames = $pc->getContainerNames($i, 0, -1);
2222
$nameCount = sizeof($arrayContainerNames);
2323
for ($j = 0; $j < $nameCount; $j++) {
2424
echo("$arrayContainerNames[$j]\n");

src/PartitionController.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class PartitionController {
3636
int64_t get_container_count(int32_t partition_index);
3737
void get_container_names(int32_t partition_index, int64_t start,
3838
const GSChar *const**stringList, size_t *size,
39-
int64_t limit = -1);
39+
int64_t limit);
4040
int32_t get_partition_index_of_container(const GSChar *container_name);
4141

4242
private:

src/gstype_php.i

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,3 +1276,13 @@ static bool checkTypeIsLongBool(zval* value) {
12761276
}
12771277
$1 = longVal;
12781278
}
1279+
1280+
/**
1281+
* Support to get long value
1282+
*/
1283+
%typemap(in, fragment = "checkTypeIsLongBool") int64_t {
1284+
if (!checkTypeIsLongBool(&$input)) {
1285+
SWIG_exception(E_ERROR, "Expected long value as input");
1286+
}
1287+
$1 = Z_LVAL_P(&$input);
1288+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
testID,partitionIndex,start,limit,containerName,hostname,expectedOutput
2+
BS-013-PartitionController-001,0,,,,,0
3+
BS-013-PartitionController-002,127,,,,,0
4+
BS-013-PartitionController-003,-1,,,,,-1
5+
BS-013-PartitionController-004,0,1,2147483647,,,0
6+
BS-013-PartitionController-005,-1,2147483647,1,,,-1
7+
BS-013-PartitionController-006,-2147483649,0,2147483647,,,-1
8+
BS-013-PartitionController-007,2147483648,0,NULL,,,-1
9+
BS-013-PartitionController-008,1.1,1,2147483647,,,-1
10+
BS-013-PartitionController-009,a,1,NULL,,,-1
11+
BS-013-PartitionController-010,127,-1,1,,,-1
12+
BS-013-PartitionController-011,127,a,1,,,-1
13+
BS-013-PartitionController-012,127,-2147483649,1,,,-1
14+
BS-013-PartitionController-013,,,,PC_1,,0
15+
BS-013-PartitionController-014,,,,1a_,,-1
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
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+

test/testCode/utility.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,24 @@ function getTestData($filePath) {
1212
return $data;
1313
}
1414

15+
function getTestDataFilter($filePath, $start, $finish) {
16+
$file = file_get_contents($filePath, "r");
17+
$index = 0;
18+
$numberLine = 0;
19+
$dataFilter = [];
20+
foreach (explode("\n", $file, -1) as $line) {
21+
if ($index != 0) {
22+
$numberLine++;
23+
if ($start <= $numberLine && $finish >= $numberLine) {
24+
$data[] = str_getcsv($line, ",");
25+
}
26+
} else {
27+
$index = 1;
28+
}
29+
}
30+
return $data;
31+
}
32+
1533
// Convert string to bool
1634
function convertStrToBool($str) {
1735
if ($str == 'True' || $str == 'TRUE' || $str == 'true'):

0 commit comments

Comments
 (0)