From 3b96555456037b94f142ff8eebb8be90a0873d86 Mon Sep 17 00:00:00 2001 From: Ajay Date: Wed, 3 Oct 2018 18:58:03 -0400 Subject: [PATCH 01/12] readModifyWriteRowRule model --- Bigtable/src/ReadModifyWriteRowRules.php | 91 +++++++++++++++++++ .../Unit/ReadModifyWriteRowRulesTest.php | 71 +++++++++++++++ 2 files changed, 162 insertions(+) create mode 100644 Bigtable/src/ReadModifyWriteRowRules.php create mode 100644 Bigtable/tests/Unit/ReadModifyWriteRowRulesTest.php diff --git a/Bigtable/src/ReadModifyWriteRowRules.php b/Bigtable/src/ReadModifyWriteRowRules.php new file mode 100644 index 000000000000..c7220edf79bd --- /dev/null +++ b/Bigtable/src/ReadModifyWriteRowRules.php @@ -0,0 +1,91 @@ +options = $options; + } + + /** + * Appends the value to the existing value of the cell. If targeted cell is unset, + * it will be treated as containing the empty string. + * + * @param string $familyName Family name of the row. + * @param string $qualifier Column qualifier of the row. + * @param string $value Value of the Column qualifier. + * + * @return ReadModifyWriteRowRules returns current ReadModifyWriteRowRules object. + */ + public function append($familyName, $qualifier, $value) + { + $this->rules[] = (new ReadModifyWriteRule) + ->setFamilyName($familyName) + ->setColumnQualifier($qualifier) + ->setAppendValue($value); + return $this; + } + + /** + * Adds `amount` to the existing value. If the targeted cell is unset, it will be treated + * as containing a zero. Otherwise, the targeted cell must containt an 8-byte value (interpreted + * as a 64-bit big-endian signed integer), or the entire request will fail. + * + * @param string $familyName Family name of the row. + * @param string $qualifier Column qualifier of the row. + * @param int $amount Amount to add to value of Column qualifier. + * + * @return ReadModifyWriteRowRules returns current ReadModifyWriteRowRules object. + */ + public function increment($familyName, $qualifier, $amount) + { + $this->rules[] = (new ReadModifyWriteRule) + ->setFamilyName($familyName) + ->setColumnQualifier($qualifier) + ->setIncrementAmount($amount); + return $this; + } + + /** + * Returns proto representation of ReadModifyWriteRule. + * + * @return array ReadModifyWriteRule Returns array of ReadModifyWriteRule rules. + */ + public function toProto() + { + return $this->rules; + } +} diff --git a/Bigtable/tests/Unit/ReadModifyWriteRowRulesTest.php b/Bigtable/tests/Unit/ReadModifyWriteRowRulesTest.php new file mode 100644 index 000000000000..11fc1f1bd1e0 --- /dev/null +++ b/Bigtable/tests/Unit/ReadModifyWriteRowRulesTest.php @@ -0,0 +1,71 @@ +readModifyWriteRowRules = new ReadModifyWriteRowRules; + } + + public function testAppend() + { + $return = $this->readModifyWriteRowRules->append( + self::COLUMN_FAMILY, + self::COLUMN_QUALIFIER, + 'value1' + ); + $proto = $this->readModifyWriteRowRules->toProto(); + $expectedProto[] = (new ReadModifyWriteRule) + ->setFamilyName(self::COLUMN_FAMILY) + ->setColumnQualifier(self::COLUMN_QUALIFIER) + ->setAppendValue('value1'); + $this->assertEquals($this->readModifyWriteRowRules, $return); + $this->assertEquals($expectedProto, $proto); + } + + public function testIncrement() + { + $return = $this->readModifyWriteRowRules->increment( + self::COLUMN_FAMILY, + self::COLUMN_QUALIFIER, + 5 + ); + $proto = $this->readModifyWriteRowRules->toProto(); + $expectedProto[] = (new ReadModifyWriteRule) + ->setFamilyName(self::COLUMN_FAMILY) + ->setColumnQualifier(self::COLUMN_QUALIFIER) + ->setIncrementAmount(5); + $this->assertEquals($this->readModifyWriteRowRules, $return); + $this->assertEquals($expectedProto, $proto); + } +} From b80a932638123207c94ae176bc7ba59384ec5d28 Mon Sep 17 00:00:00 2001 From: Ajay Date: Fri, 5 Oct 2018 10:38:35 -0400 Subject: [PATCH 02/12] read modify write row --- Bigtable/src/DataClient.php | 39 ++++++++++ .../DataClientReadModifyWriteRowTest.php | 75 +++++++++++++++++++ Bigtable/tests/Unit/DataClientTest.php | 38 ++++++++++ 3 files changed, 152 insertions(+) create mode 100644 Bigtable/tests/System/DataClientReadModifyWriteRowTest.php diff --git a/Bigtable/src/DataClient.php b/Bigtable/src/DataClient.php index dc33e4e2e036..43af3cf561c3 100644 --- a/Bigtable/src/DataClient.php +++ b/Bigtable/src/DataClient.php @@ -21,7 +21,9 @@ use Google\ApiCore\Serializer; use Google\Cloud\Bigtable\Exception\BigtableDataOperationException; use Google\Cloud\Bigtable\Filter\FilterInterface; +use Google\Cloud\Bigtable\ReadModifyWriteRowRules; use Google\Cloud\Bigtable\V2\BigtableClient as TableClient; +use Google\Cloud\Bigtable\V2\Row; use Google\Cloud\Bigtable\V2\RowRange; use Google\Cloud\Bigtable\V2\RowSet; use Google\Cloud\Core\ArrayTrait; @@ -322,4 +324,41 @@ public function readRow($rowKey, array $options = []) ->readAll() ->current(); } + + public function readModifyWriteRow($rowKey, ReadModifyWriteRowRules $rules, array $options = []) + { + $readModifyWriteRowResponse = $this->bigtableClient->readModifyWriteRow( + $this->tableName, + $rowKey, + $rules->toProto(), + $options + $this->options + ); + return $this->convertToArray($readModifyWriteRowResponse->getRow()); + } + + private function convertToArray(Row $row) + { + if ($row === null) { + return []; + } + $families = []; + foreach ($row->getFamilies() as $family) { + $qualifiers = []; + foreach ($family->getColumns() as $column) { + $values = []; + foreach ($column->getCells() as $cell) { + $values[] = [ + 'value' => $cell->getValue(), + 'timeStamp' => $cell->getTimestampMicros(), + 'labels' => ($cell->getLabels()->getIterator()->valid()) + ? implode(iterator_to_array($cell->getLabels()->getIterator())) + : '' + ]; + } + $qualifiers[$column->getQualifier()] = $values; + } + $families[$family->getName()] = $qualifiers; + } + return $families; + } } diff --git a/Bigtable/tests/System/DataClientReadModifyWriteRowTest.php b/Bigtable/tests/System/DataClientReadModifyWriteRowTest.php new file mode 100644 index 000000000000..91e8e77deb24 --- /dev/null +++ b/Bigtable/tests/System/DataClientReadModifyWriteRowTest.php @@ -0,0 +1,75 @@ + [ + 'cf1' => [ + 'cq1' => [ + 'value' => 'value1', + 'timeStamp' => 5000 + ] + ] + ], + 'rk2' => [ + 'cf1' => [ + 'cq2' => [ + 'value' => implode(unpack("C*", pack("J", 2))), + 'timeStamp' => 5000 + ] + ] + ], + ]; + self::$dataClient->upsert($insertRows); + } + + public function testAppend() + { + $rules = (new ReadModifyWriteRowRules) + ->append('cf1', 'cq1', 'value12'); + $row = self::$dataClient->readModifyWriteRow( + 'rk1', + $rules + ); + $this->assertEquals('value1value12', $row['cf1']['cq1'][0]['value']); + } + + public function testIncrement() + { + $rules = (new ReadModifyWriteRowRules) + ->increment('cf1', 'cq2', 3); + $row = self::$dataClient->readModifyWriteRow( + 'rk2', + $rules + ); + $intval = intval($row['cf1']['cq2'][0]['value']); + $this->assertEquals(5, $intval); + } +} diff --git a/Bigtable/tests/Unit/DataClientTest.php b/Bigtable/tests/Unit/DataClientTest.php index 4e3b2d4fd078..51bae21379a8 100644 --- a/Bigtable/tests/Unit/DataClientTest.php +++ b/Bigtable/tests/Unit/DataClientTest.php @@ -22,10 +22,17 @@ use Google\Cloud\Bigtable\ChunkFormatter; use Google\Cloud\Bigtable\DataClient; use Google\Cloud\Bigtable\Exception\BigtableDataOperationException; +use Google\Cloud\Bigtable\ReadModifyWriteRowRules; use Google\Cloud\Bigtable\RowMutation; use Google\Cloud\Bigtable\V2\BigtableClient as TableClient; +use Google\Cloud\Bigtable\V2\Cell; +use Google\Cloud\Bigtable\V2\Column; +use Google\Cloud\Bigtable\V2\Family; use Google\Cloud\Bigtable\V2\MutateRowsResponse; use Google\Cloud\Bigtable\V2\MutateRowsResponse\Entry; +use Google\Cloud\Bigtable\V2\ReadModifyWriteRowRequest; +use Google\Cloud\Bigtable\V2\ReadModifyWriteRowResponse; +use Google\Cloud\Bigtable\V2\Row; use Google\Cloud\Bigtable\V2\RowRange; use Google\Cloud\Bigtable\V2\RowSet; use Google\Cloud\Bigtable\Filter; @@ -547,6 +554,37 @@ public function testReadRowsFilterShouldThrow() $this->dataClient->readRows(['filter' => new \stdClass()]); } + /** + * @expectedException TypeError + * @expectedExceptionMessage ReadModifyWriteRowRules + */ + public function testReadModifyWriteRowNoRules() + { + $this->dataClient->readModifyWriteRow('rk1', null); + } + + public function testReadModifyWriteRowAppend() + { + $readModifyWriteRowResponse = (new ReadModifyWriteRowResponse) + ->setRow( + (new Row) + ->setName() + ->setFamilies( + [ + (new Column) + ->setQualifier() + ->setCells( + [ + (new Cell) + ->setValue() + ->setTimstampMicros() + ] + ) + ] + ) + ); + } + private function getMutateRowsResponse(array $status) { $mutateRowsResponses = []; From fe48a4c615ac50bd4b0e744c041a311729d0951c Mon Sep 17 00:00:00 2001 From: Ajay Date: Sat, 6 Oct 2018 09:38:24 -0400 Subject: [PATCH 03/12] read modify write row api --- Bigtable/src/DataClient.php | 36 +++++ Bigtable/src/DataUtil.php | 74 ++++++++++ Bigtable/tests/Snippet/DataClientTest.php | 129 ++++++++++++++++++ .../DataClientReadModifyWriteRowTest.php | 7 +- Bigtable/tests/Unit/DataClientTest.php | 95 +++++++++++-- Bigtable/tests/Unit/DataUtilTest.php | 48 +++++++ 6 files changed, 378 insertions(+), 11 deletions(-) create mode 100644 Bigtable/src/DataUtil.php create mode 100644 Bigtable/tests/Unit/DataUtilTest.php diff --git a/Bigtable/src/DataClient.php b/Bigtable/src/DataClient.php index 43af3cf561c3..f0085c34ba5d 100644 --- a/Bigtable/src/DataClient.php +++ b/Bigtable/src/DataClient.php @@ -325,6 +325,42 @@ public function readRow($rowKey, array $options = []) ->current(); } + /** + * Atomically reads and applies the rule to the row. + * + * Example: + * ``` + * use Google\Cloud\Bigtable\ReadModifyWriteRowRules; + * + * $rules = (new ReadModifyWriteRowRules)->append('cf1', 'cq1', 'value12'); + * $row = $dataClient->readModifyWriteRow('rk1', $rules); + * + * print_r($row); + * ``` + * + * //Increments value + * ``` + * use Google\Cloud\Bigtable\DataUtil; + * use Google\Cloud\Bigtable\ReadModifyWriteRowRules; + * use Google\Cloud\Bigtable\RowMutation; + * + * $rowMutation = new RowMutation('rk1'); + * $rowMutation->upsert('cf1','cq1',DataUtil::intToByteString(2),5000); + * + * $dataClient->mutateRows([$rowMutation]); + * + * $rules = (new ReadModifyWriteRowRules)->increment('cf1', 'cq1', 3); + * $row = $dataClient->readModifyWriteRow('rk1', $rules); + * + * print_r($row); + * ``` + * + * @param string $rowKey The row key to read. + * @param ReadModifyWriteRowRules $rules Rules to apply on row. + * @param array $options [optional] Configuration options. + * @return array Returns array containing all column family keyed by family name. + * @throws ApiException if the remote call fails or operation fails + */ public function readModifyWriteRow($rowKey, ReadModifyWriteRowRules $rules, array $options = []) { $readModifyWriteRowResponse = $this->bigtableClient->readModifyWriteRow( diff --git a/Bigtable/src/DataUtil.php b/Bigtable/src/DataUtil.php new file mode 100644 index 000000000000..254e5f79effe --- /dev/null +++ b/Bigtable/src/DataUtil.php @@ -0,0 +1,74 @@ +setRow( + (new Row) + ->setFamilies( + [ + (new Family) + ->setName('cf1') + ->setColumns( + [ + (new Column) + ->setQualifier('cq1') + ->setCells( + [ + (new Cell) + ->setValue('value1') + ->setTimestampMicros(5000) + ] + ) + ] + ) + ] + ) + ); + $readModifyWriteRowRules = (new ReadModifyWriteRowRules) + ->append('cf1', 'cq1', 'value12'); + $this->bigtableClient + ->readModifyWriteRow( + self::TABLE_NAME, + 'rk1', + $readModifyWriteRowRules->toProto(), + [] + ) + ->shouldBeCalled() + ->willReturn( + $readModifyWriteRowResponse + ); + $snippet = $this->snippetFromMethod(DataClient::class, 'readModifyWriteRow'); + $snippet->addLocal('dataClient', $this->dataClient); + $res = $snippet->invoke('row'); + $expectedRow = [ + 'cf1' => [ + 'cq1' => [[ + 'value' => 'value1', + 'timeStamp' => 5000, + 'labels' => '' + ]] + ] + ]; + $this->assertEquals( + print_r($expectedRow, true), + $res->output() + ); + } + + public function testReadModifyWriteRowIncrement() + { + $this->serverStream->readAll() + ->shouldBeCalled() + ->willReturn( + $this->arrayAsGenerator($this->mutateRowsResponses) + ); + $this->bigtableClient->mutateRows(self::TABLE_NAME, Argument::any(), []) + ->shouldBeCalled() + ->willReturn( + $this->serverStream->reveal() + ); + $readModifyWriteRowResponse = (new ReadModifyWriteRowResponse) + ->setRow( + (new Row) + ->setFamilies( + [ + (new Family) + ->setName('cf1') + ->setColumns( + [ + (new Column) + ->setQualifier('cq1') + ->setCells( + [ + (new Cell) + ->setValue(5) + ->setTimestampMicros(5000) + ] + ) + ] + ) + ] + ) + ); + $readModifyWriteRowRules = (new ReadModifyWriteRowRules) + ->increment('cf1', 'cq1', 3); + $this->bigtableClient + ->readModifyWriteRow( + self::TABLE_NAME, + 'rk1', + $readModifyWriteRowRules->toProto(), + [] + ) + ->shouldBeCalled() + ->willReturn( + $readModifyWriteRowResponse + ); + $snippet = $this->snippetFromMethod(DataClient::class, 'readModifyWriteRow', 1); + $snippet->addLocal('dataClient', $this->dataClient); + $res = $snippet->invoke('row'); + $expectedRow = [ + 'cf1' => [ + 'cq1' => [[ + 'value' => 5, + 'timeStamp' => 5000, + 'labels' => '' + ]] + ] + ]; + $this->assertEquals( + print_r($expectedRow, true), + $res->output() + ); + } + private function setUpReadRowsResponse() { $readRowsResponse = new ReadRowsResponse; diff --git a/Bigtable/tests/System/DataClientReadModifyWriteRowTest.php b/Bigtable/tests/System/DataClientReadModifyWriteRowTest.php index 91e8e77deb24..1dce630cbe36 100644 --- a/Bigtable/tests/System/DataClientReadModifyWriteRowTest.php +++ b/Bigtable/tests/System/DataClientReadModifyWriteRowTest.php @@ -17,8 +17,9 @@ namespace Google\Cloud\Bigtable\Tests\System; -use Google\Cloud\Bigtable\Tests\System\DataClientTest; +use Google\Cloud\Bigtable\DataUtil; use Google\Cloud\Bigtable\ReadModifyWriteRowRules; +use Google\Cloud\Bigtable\Tests\System\DataClientTest; /** * @group bigtable @@ -41,7 +42,7 @@ public static function setUpBeforeClass() 'rk2' => [ 'cf1' => [ 'cq2' => [ - 'value' => implode(unpack("C*", pack("J", 2))), + 'value' => DataUtil::intToByteString(2), 'timeStamp' => 5000 ] ] @@ -69,7 +70,7 @@ public function testIncrement() 'rk2', $rules ); - $intval = intval($row['cf1']['cq2'][0]['value']); + $intval = DataUtil::byteStringToInt($row['cf1']['cq2'][0]['value']); $this->assertEquals(5, $intval); } } diff --git a/Bigtable/tests/Unit/DataClientTest.php b/Bigtable/tests/Unit/DataClientTest.php index 51bae21379a8..844b267d8c48 100644 --- a/Bigtable/tests/Unit/DataClientTest.php +++ b/Bigtable/tests/Unit/DataClientTest.php @@ -30,7 +30,6 @@ use Google\Cloud\Bigtable\V2\Family; use Google\Cloud\Bigtable\V2\MutateRowsResponse; use Google\Cloud\Bigtable\V2\MutateRowsResponse\Entry; -use Google\Cloud\Bigtable\V2\ReadModifyWriteRowRequest; use Google\Cloud\Bigtable\V2\ReadModifyWriteRowResponse; use Google\Cloud\Bigtable\V2\Row; use Google\Cloud\Bigtable\V2\RowRange; @@ -568,21 +567,101 @@ public function testReadModifyWriteRowAppend() $readModifyWriteRowResponse = (new ReadModifyWriteRowResponse) ->setRow( (new Row) - ->setName() ->setFamilies( [ - (new Column) - ->setQualifier() - ->setCells( + (new Family) + ->setName('cf1') + ->setColumns( [ - (new Cell) - ->setValue() - ->setTimstampMicros() + (new Column) + ->setQualifier('cq1') + ->setCells( + [ + (new Cell) + ->setValue('value1') + ->setTimestampMicros(5000) + ] + ) ] ) ] ) ); + $readModifyWriteRowRules = (new ReadModifyWriteRowRules) + ->append('cf1', 'cq1', 'v1'); + $this->bigtableClient + ->readModifyWriteRow( + self::TABLE_NAME, + 'rk1', + $readModifyWriteRowRules->toProto(), + $this->options + ) + ->shouldBeCalled() + ->willReturn( + $readModifyWriteRowResponse + ); + $row = $this->dataClient->readModifyWriteRow('rk1', $readModifyWriteRowRules); + $expectedRow = [ + 'cf1' => [ + 'cq1' => [[ + 'value' => 'value1', + 'timeStamp' => 5000, + 'labels' => '' + ]] + ] + ]; + $this->assertEquals($expectedRow, $row); + } + + public function testReadModifyWriteRowIncrement() + { + $readModifyWriteRowResponse = (new ReadModifyWriteRowResponse) + ->setRow( + (new Row) + ->setFamilies( + [ + (new Family) + ->setName('cf1') + ->setColumns( + [ + (new Column) + ->setQualifier('cq1') + ->setCells( + [ + (new Cell) + ->setValue(10) + ->setTimestampMicros(5000) + ] + ) + ] + ) + ] + ) + ); + $readModifyWriteRowRules = (new ReadModifyWriteRowRules) + ->increment('cf1', 'cq1', 5); + $this->bigtableClient + ->readModifyWriteRow( + self::TABLE_NAME, + 'rk1', + $readModifyWriteRowRules->toProto(), + $this->options + ) + ->shouldBeCalled() + ->willReturn( + $readModifyWriteRowResponse + ); + $row = $this->dataClient->readModifyWriteRow('rk1', $readModifyWriteRowRules); + $expectedRow = [ + 'cf1' => [ + 'cq1' => [[ + 'value' => 10, + 'timeStamp' => 5000, + 'labels' => '' + ]] + ] + ]; + $this->assertEquals($expectedRow, $row); } private function getMutateRowsResponse(array $status) diff --git a/Bigtable/tests/Unit/DataUtilTest.php b/Bigtable/tests/Unit/DataUtilTest.php new file mode 100644 index 000000000000..adfd580a7619 --- /dev/null +++ b/Bigtable/tests/Unit/DataUtilTest.php @@ -0,0 +1,48 @@ +assertEquals("00000002", DataUtil::intToByteString(2)); + } + + public function testByteStringToInt() + { + $value = DataUtil::byteStringToInt(DataUtil::intToByteString(2)); + $this->assertEquals(2, $value); + } +} From 28a566a7033540516e49a5754d52346f9a63af77 Mon Sep 17 00:00:00 2001 From: Ajay Date: Mon, 8 Oct 2018 08:46:04 -0400 Subject: [PATCH 04/12] update comments --- Bigtable/src/DataClient.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Bigtable/src/DataClient.php b/Bigtable/src/DataClient.php index f0085c34ba5d..a9a2cefbc513 100644 --- a/Bigtable/src/DataClient.php +++ b/Bigtable/src/DataClient.php @@ -326,7 +326,11 @@ public function readRow($rowKey, array $options = []) } /** - * Atomically reads and applies the rule to the row. + * Modifies a row atomically on the server. The method reads the latest + * existing timestamp and value from the specified columns and writes a new + * entry based on pre-defined read/modify/write rules. The new value for the + * timestamp is the greater of the existing timestamp or the current server + * time. The method returns the new contents of all modified cells. * * Example: * ``` From 0c3e14c564c0b6fe2a87c4de0f450669c586ff08 Mon Sep 17 00:00:00 2001 From: Ajay Date: Mon, 8 Oct 2018 12:03:12 -0400 Subject: [PATCH 05/12] fix static initializer --- Bigtable/src/DataUtil.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Bigtable/src/DataUtil.php b/Bigtable/src/DataUtil.php index 254e5f79effe..b4251471f471 100644 --- a/Bigtable/src/DataUtil.php +++ b/Bigtable/src/DataUtil.php @@ -22,7 +22,7 @@ */ class DataUtil { - private static $isLittleEndian = false; + private static $isLittleEndian; public static function init() { @@ -31,6 +31,9 @@ public static function init() public static function isSystemLittleEndian() { + if (self::$isLittleEndian === null) { + self::init(); + } return self::$isLittleEndian; } @@ -70,5 +73,3 @@ public static function byteStringToInt($bytes) return intval($bytes); } } - -DataUtil::init(); From aca37528b04eb35e89d24b1a005c54538ac164f3 Mon Sep 17 00:00:00 2001 From: Ajay Date: Mon, 8 Oct 2018 12:28:09 -0400 Subject: [PATCH 06/12] fix exception check for php < 7 --- Bigtable/src/DataClient.php | 11 ++++++++++- Bigtable/tests/Unit/DataClientTest.php | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Bigtable/src/DataClient.php b/Bigtable/src/DataClient.php index a9a2cefbc513..6baf5cca980f 100644 --- a/Bigtable/src/DataClient.php +++ b/Bigtable/src/DataClient.php @@ -365,8 +365,17 @@ public function readRow($rowKey, array $options = []) * @return array Returns array containing all column family keyed by family name. * @throws ApiException if the remote call fails or operation fails */ - public function readModifyWriteRow($rowKey, ReadModifyWriteRowRules $rules, array $options = []) + public function readModifyWriteRow($rowKey, $rules, array $options = []) { + if (!$rules instanceof ReadModifyWriteRowRules) { + throw new \InvalidArgumentException( + sprintf( + 'Expected rules to be of type \'%s\', instead got \'%s\'.', + ReadModifyWriteRowRules::class, + gettype($filter) + ) + ); + } $readModifyWriteRowResponse = $this->bigtableClient->readModifyWriteRow( $this->tableName, $rowKey, diff --git a/Bigtable/tests/Unit/DataClientTest.php b/Bigtable/tests/Unit/DataClientTest.php index 844b267d8c48..7005b0db236f 100644 --- a/Bigtable/tests/Unit/DataClientTest.php +++ b/Bigtable/tests/Unit/DataClientTest.php @@ -554,7 +554,7 @@ public function testReadRowsFilterShouldThrow() } /** - * @expectedException TypeError + * @expectedException InvalidArgumentException * @expectedExceptionMessage ReadModifyWriteRowRules */ public function testReadModifyWriteRowNoRules() From c2e6594e299a0eccbb43b909903b1560e5547aa0 Mon Sep 17 00:00:00 2001 From: Ajay Date: Mon, 8 Oct 2018 13:01:47 -0400 Subject: [PATCH 07/12] fix test case --- Bigtable/src/DataClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Bigtable/src/DataClient.php b/Bigtable/src/DataClient.php index 6baf5cca980f..6c5774beb5bd 100644 --- a/Bigtable/src/DataClient.php +++ b/Bigtable/src/DataClient.php @@ -372,7 +372,7 @@ public function readModifyWriteRow($rowKey, $rules, array $options = []) sprintf( 'Expected rules to be of type \'%s\', instead got \'%s\'.', ReadModifyWriteRowRules::class, - gettype($filter) + gettype($rules) ) ); } From 4b6c0ebd4373419b498c6a29f6c2748eb8d88757 Mon Sep 17 00:00:00 2001 From: Ajay Date: Tue, 9 Oct 2018 21:46:19 -0400 Subject: [PATCH 08/12] update pack and unpack for php5.5 --- Bigtable/src/DataUtil.php | 26 +++++--------------------- Bigtable/tests/Unit/DataUtilTest.php | 3 ++- 2 files changed, 7 insertions(+), 22 deletions(-) diff --git a/Bigtable/src/DataUtil.php b/Bigtable/src/DataUtil.php index b4251471f471..5404deff0adf 100644 --- a/Bigtable/src/DataUtil.php +++ b/Bigtable/src/DataUtil.php @@ -22,21 +22,6 @@ */ class DataUtil { - private static $isLittleEndian; - - public static function init() - { - self::$isLittleEndian = (pack("Q", 2) === pack("P", 2)); - } - - public static function isSystemLittleEndian() - { - if (self::$isLittleEndian === null) { - self::init(); - } - return self::$isLittleEndian; - } - /** * Utility method to convert integer value in to 64 bit signed BigEndian * representation. @@ -55,11 +40,9 @@ public static function intToByteString($intValue) ) ); } - $bytes = implode(unpack("C*", pack("q", $intValue))); - if (self::isSystemLittleEndian()) { - return strrev($bytes); - } - return $bytes; + $hex = base_convert($intValue, 10, 16); + $hex = str_pad($hex, 16, '0', STR_PAD_LEFT); + return hex2bin($hex); } /** @@ -70,6 +53,7 @@ public static function intToByteString($intValue) */ public static function byteStringToInt($bytes) { - return intval($bytes); + $hex = bin2hex($bytes); + return hexdec($hex); } } diff --git a/Bigtable/tests/Unit/DataUtilTest.php b/Bigtable/tests/Unit/DataUtilTest.php index adfd580a7619..e96647a00e2f 100644 --- a/Bigtable/tests/Unit/DataUtilTest.php +++ b/Bigtable/tests/Unit/DataUtilTest.php @@ -37,7 +37,8 @@ public function testIntToByteStringWithString() public function testIntToByteString() { - $this->assertEquals("00000002", DataUtil::intToByteString(2)); + $expected = hex2bin("0000000000000002"); + $this->assertEquals($expected, DataUtil::intToByteString(2)); } public function testByteStringToInt() From 9095645830d5e4d1a52344b3a643dc843cd10d78 Mon Sep 17 00:00:00 2001 From: Ajay Date: Mon, 15 Oct 2018 19:33:48 -0400 Subject: [PATCH 09/12] address feedback --- Bigtable/src/DataClient.php | 19 ++--- Bigtable/src/DataUtil.php | 52 +++++++++--- Bigtable/src/ReadModifyWriteRowRules.php | 22 ++--- Bigtable/tests/Snippet/DataClientTest.php | 67 +++++++-------- .../DataClientReadModifyWriteRowTest.php | 3 + Bigtable/tests/Unit/DataClientTest.php | 85 +++++++------------ Bigtable/tests/Unit/DataUtilTest.php | 5 +- 7 files changed, 117 insertions(+), 136 deletions(-) diff --git a/Bigtable/src/DataClient.php b/Bigtable/src/DataClient.php index 6c5774beb5bd..0d2b6bc15760 100644 --- a/Bigtable/src/DataClient.php +++ b/Bigtable/src/DataClient.php @@ -336,7 +336,8 @@ public function readRow($rowKey, array $options = []) * ``` * use Google\Cloud\Bigtable\ReadModifyWriteRowRules; * - * $rules = (new ReadModifyWriteRowRules)->append('cf1', 'cq1', 'value12'); + * $rules = (new ReadModifyWriteRowRules) + * ->append('cf1', 'cq1', 'value12'); * $row = $dataClient->readModifyWriteRow('rk1', $rules); * * print_r($row); @@ -349,11 +350,12 @@ public function readRow($rowKey, array $options = []) * use Google\Cloud\Bigtable\RowMutation; * * $rowMutation = new RowMutation('rk1'); - * $rowMutation->upsert('cf1','cq1',DataUtil::intToByteString(2),5000); + * $rowMutation->upsert('cf1', 'cq1', DataUtil::intToByteString(2)); * * $dataClient->mutateRows([$rowMutation]); * - * $rules = (new ReadModifyWriteRowRules)->increment('cf1', 'cq1', 3); + * $rules = (new ReadModifyWriteRowRules) + * ->increment('cf1', 'cq1', 3); * $row = $dataClient->readModifyWriteRow('rk1', $rules); * * print_r($row); @@ -365,17 +367,8 @@ public function readRow($rowKey, array $options = []) * @return array Returns array containing all column family keyed by family name. * @throws ApiException if the remote call fails or operation fails */ - public function readModifyWriteRow($rowKey, $rules, array $options = []) + public function readModifyWriteRow($rowKey, ReadModifyWriteRowRules $rules, array $options = []) { - if (!$rules instanceof ReadModifyWriteRowRules) { - throw new \InvalidArgumentException( - sprintf( - 'Expected rules to be of type \'%s\', instead got \'%s\'.', - ReadModifyWriteRowRules::class, - gettype($rules) - ) - ); - } $readModifyWriteRowResponse = $this->bigtableClient->readModifyWriteRow( $this->tableName, $rowKey, diff --git a/Bigtable/src/DataUtil.php b/Bigtable/src/DataUtil.php index 5404deff0adf..cb0cde2c643b 100644 --- a/Bigtable/src/DataUtil.php +++ b/Bigtable/src/DataUtil.php @@ -19,20 +19,42 @@ /** * This class contains utility to convert integer to byte string and backward. + * This utility class is only supported on 64 bit machine with PHP version > 5.5. */ class DataUtil { + private static $isLittleEndian; + private static $isSupported; + + public static function isSystemLittleEndian() + { + if (self::$isLittleEndian === null) { + self::$isLittleEndian = (pack("P", 2) === pack("Q", 2)); + } + return self::$isLittleEndian; + } + + public static function isSupported() + { + if (self::$isSupported === null) { + self::$isSupported = PHP_VERSION_ID > 50500 && PHP_INT_SIZE >= 8; + } + return self::$isSupported; + } + /** - * Utility method to convert integer value in to 64 bit signed BigEndian - * representation. + * Utility method to convert an integer to a 64-bit big-endian signed integer byte string. * - * @param string|int $intValue Integer value to convert to. - * @return string Returns string of bytes representing 64 bit big signed BigEndian. - * @throws \InvalidArgumentException If value is not numberic. + * @param int $intValue Integer value to convert to. + * @return string Returns a string of bytes representing a 64-bit big-endian signed integer. + * @throws \InvalidArgumentException If value is not an integer. */ public static function intToByteString($intValue) { - if (!is_numeric($intValue)) { + if (!self::isSupported()) { + throw new \ErrorException('This utility is only supported on 64 bit machine with PHP version > 5.5.'); + } + if (!is_int($intValue)) { throw new \InvalidArgumentException( sprintf( 'Expected argument to be of type int, instead got \'%s\'.', @@ -40,20 +62,24 @@ public static function intToByteString($intValue) ) ); } - $hex = base_convert($intValue, 10, 16); - $hex = str_pad($hex, 16, '0', STR_PAD_LEFT); - return hex2bin($hex); + $bytes = pack("J", $intValue); + return $bytes; } /** - * Convertes string bytes of 64 bit signed BigEndian to int. + * Converts a 64-bit big-endian signed integer represented as a byte string to an integer. * - * @param string|array $bytes String of bytes to convert. + * @param string $bytes String of bytes to convert. * @return int Integer value of the string bytes. */ public static function byteStringToInt($bytes) { - $hex = bin2hex($bytes); - return hexdec($hex); + if (!self::isSupported()) { + throw new \ErrorException('This utility is only supported on 64 bit machine with PHP version > 5.5.'); + } + if (self::isSystemLittleEndian()) { + $bytes = strrev($bytes); + } + return unpack("q", $bytes)[1]; } } diff --git a/Bigtable/src/ReadModifyWriteRowRules.php b/Bigtable/src/ReadModifyWriteRowRules.php index c7220edf79bd..9657465b0e96 100644 --- a/Bigtable/src/ReadModifyWriteRowRules.php +++ b/Bigtable/src/ReadModifyWriteRowRules.php @@ -20,26 +20,18 @@ use Google\Cloud\Bigtable\V2\ReadModifyWriteRule; /** - * Represents collection of ReadModifyWriteRule to perform operation on Bigtable table. - * This is used in readModifyWriteRow operation on row in Bigtable table. + * Represents a collection of read/modify/write rules specifying how the specified row's contents + * are to be transformed into writes. Entries are applied in order, meaning that earlier rules will + * affect the results of later ones. This is intended to be used in combination with + * {@see Google\Cloud\Bigtable\DataClient::readModifyWriteRow()}. */ class ReadModifyWriteRowRules { /** - * @var array - */ - private $options; - - /** - * @var array ReadModifyWriteRule + * @var ReadModifyWriteRule[] */ private $rules = []; - public function __construct(array $options = []) - { - $this->options = $options; - } - /** * Appends the value to the existing value of the cell. If targeted cell is unset, * it will be treated as containing the empty string. @@ -82,7 +74,9 @@ public function increment($familyName, $qualifier, $amount) /** * Returns proto representation of ReadModifyWriteRule. * - * @return array ReadModifyWriteRule Returns array of ReadModifyWriteRule rules. + * @internal + * @access private + * @return ReadModifyWriteRule[] Returns array of ReadModifyWriteRule rules. */ public function toProto() { diff --git a/Bigtable/tests/Snippet/DataClientTest.php b/Bigtable/tests/Snippet/DataClientTest.php index e5cca0da0a0b..ca6f65af11c0 100644 --- a/Bigtable/tests/Snippet/DataClientTest.php +++ b/Bigtable/tests/Snippet/DataClientTest.php @@ -238,25 +238,19 @@ public function testReadModifyWriteRowAppend() $readModifyWriteRowResponse = (new ReadModifyWriteRowResponse) ->setRow( (new Row) - ->setFamilies( - [ - (new Family) - ->setName('cf1') - ->setColumns( - [ - (new Column) - ->setQualifier('cq1') - ->setCells( - [ - (new Cell) - ->setValue('value1') - ->setTimestampMicros(5000) - ] - ) - ] - ) - ] - ) + ->setFamilies([ + (new Family) + ->setName('cf1') + ->setColumns([ + (new Column) + ->setQualifier('cq1') + ->setCells([ + (new Cell) + ->setValue('value1') + ->setTimestampMicros(5000) + ]) + ]) + ]) ); $readModifyWriteRowRules = (new ReadModifyWriteRowRules) ->append('cf1', 'cq1', 'value12'); @@ -289,6 +283,9 @@ public function testReadModifyWriteRowAppend() ); } + /** + * @requires PHP 5.6.0 + */ public function testReadModifyWriteRowIncrement() { $this->serverStream->readAll() @@ -304,25 +301,19 @@ public function testReadModifyWriteRowIncrement() $readModifyWriteRowResponse = (new ReadModifyWriteRowResponse) ->setRow( (new Row) - ->setFamilies( - [ - (new Family) - ->setName('cf1') - ->setColumns( - [ - (new Column) - ->setQualifier('cq1') - ->setCells( - [ - (new Cell) - ->setValue(5) - ->setTimestampMicros(5000) - ] - ) - ] - ) - ] - ) + ->setFamilies([ + (new Family) + ->setName('cf1') + ->setColumns([ + (new Column) + ->setQualifier('cq1') + ->setCells([ + (new Cell) + ->setValue(5) + ->setTimestampMicros(5000) + ]) + ]) + ]) ); $readModifyWriteRowRules = (new ReadModifyWriteRowRules) ->increment('cf1', 'cq1', 3); diff --git a/Bigtable/tests/System/DataClientReadModifyWriteRowTest.php b/Bigtable/tests/System/DataClientReadModifyWriteRowTest.php index 1dce630cbe36..b7d09e2b6337 100644 --- a/Bigtable/tests/System/DataClientReadModifyWriteRowTest.php +++ b/Bigtable/tests/System/DataClientReadModifyWriteRowTest.php @@ -62,6 +62,9 @@ public function testAppend() $this->assertEquals('value1value12', $row['cf1']['cq1'][0]['value']); } + /** + * @requires PHP 5.6.0 + */ public function testIncrement() { $rules = (new ReadModifyWriteRowRules) diff --git a/Bigtable/tests/Unit/DataClientTest.php b/Bigtable/tests/Unit/DataClientTest.php index 7005b0db236f..82d21a17e453 100644 --- a/Bigtable/tests/Unit/DataClientTest.php +++ b/Bigtable/tests/Unit/DataClientTest.php @@ -544,48 +544,24 @@ public function testReadRowsWithFilter() $this->assertInstanceOf(ChunkFormatter::class, $iterator); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage FilterInterface - */ - public function testReadRowsFilterShouldThrow() - { - $this->dataClient->readRows(['filter' => new \stdClass()]); - } - - /** - * @expectedException InvalidArgumentException - * @expectedExceptionMessage ReadModifyWriteRowRules - */ - public function testReadModifyWriteRowNoRules() - { - $this->dataClient->readModifyWriteRow('rk1', null); - } - public function testReadModifyWriteRowAppend() { $readModifyWriteRowResponse = (new ReadModifyWriteRowResponse) ->setRow( (new Row) - ->setFamilies( - [ - (new Family) - ->setName('cf1') - ->setColumns( - [ - (new Column) - ->setQualifier('cq1') - ->setCells( - [ - (new Cell) - ->setValue('value1') - ->setTimestampMicros(5000) - ] - ) - ] - ) - ] - ) + ->setFamilies([ + (new Family) + ->setName('cf1') + ->setColumns([ + (new Column) + ->setQualifier('cq1') + ->setCells([ + (new Cell) + ->setValue('value1') + ->setTimestampMicros(5000) + ]) + ]) + ]) ); $readModifyWriteRowRules = (new ReadModifyWriteRowRules) ->append('cf1', 'cq1', 'v1'); @@ -613,30 +589,27 @@ public function testReadModifyWriteRowAppend() $this->assertEquals($expectedRow, $row); } + /** + * @requires PHP 5.6.0 + */ public function testReadModifyWriteRowIncrement() { $readModifyWriteRowResponse = (new ReadModifyWriteRowResponse) ->setRow( (new Row) - ->setFamilies( - [ - (new Family) - ->setName('cf1') - ->setColumns( - [ - (new Column) - ->setQualifier('cq1') - ->setCells( - [ - (new Cell) - ->setValue(10) - ->setTimestampMicros(5000) - ] - ) - ] - ) - ] - ) + ->setFamilies([ + (new Family) + ->setName('cf1') + ->setColumns([ + (new Column) + ->setQualifier('cq1') + ->setCells([ + (new Cell) + ->setValue(10) + ->setTimestampMicros(5000) + ]) + ]) + ]) ); $readModifyWriteRowRules = (new ReadModifyWriteRowRules) ->increment('cf1', 'cq1', 5); diff --git a/Bigtable/tests/Unit/DataUtilTest.php b/Bigtable/tests/Unit/DataUtilTest.php index e96647a00e2f..4c491ae1e08c 100644 --- a/Bigtable/tests/Unit/DataUtilTest.php +++ b/Bigtable/tests/Unit/DataUtilTest.php @@ -23,6 +23,7 @@ /** * @group bigtable * @group bigtabledata + * @requires PHP 5.6.0 */ class DataUtilTest extends TestCase { @@ -43,7 +44,7 @@ public function testIntToByteString() public function testByteStringToInt() { - $value = DataUtil::byteStringToInt(DataUtil::intToByteString(2)); - $this->assertEquals(2, $value); + $value = DataUtil::byteStringToInt(DataUtil::intToByteString(-52)); + $this->assertEquals(-52, $value); } } From dac3592abb1c9805da15fffd8d904d5392b27a46 Mon Sep 17 00:00:00 2001 From: Ajay Date: Tue, 16 Oct 2018 09:49:05 -0400 Subject: [PATCH 10/12] fix php 5.5 snippet test case --- Bigtable/tests/Snippet/DataClientTest.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Bigtable/tests/Snippet/DataClientTest.php b/Bigtable/tests/Snippet/DataClientTest.php index ca6f65af11c0..dd4f08660a93 100644 --- a/Bigtable/tests/Snippet/DataClientTest.php +++ b/Bigtable/tests/Snippet/DataClientTest.php @@ -283,11 +283,15 @@ public function testReadModifyWriteRowAppend() ); } - /** - * @requires PHP 5.6.0 - */ public function testReadModifyWriteRowIncrement() { + $snippet = $this->snippetFromMethod(DataClient::class, 'readModifyWriteRow', 1); + + if (phpversion() < '5.6.0') { + $this->markTestSkipped('This test only runs on PHP 5.6 or above.'); + return; + } + $this->serverStream->readAll() ->shouldBeCalled() ->willReturn( @@ -328,7 +332,6 @@ public function testReadModifyWriteRowIncrement() ->willReturn( $readModifyWriteRowResponse ); - $snippet = $this->snippetFromMethod(DataClient::class, 'readModifyWriteRow', 1); $snippet->addLocal('dataClient', $this->dataClient); $res = $snippet->invoke('row'); $expectedRow = [ From b3b9181846b7504c6ab2c7988741cd3d1915c4ac Mon Sep 17 00:00:00 2001 From: Ajay Date: Tue, 16 Oct 2018 10:16:34 -0400 Subject: [PATCH 11/12] update doc and check --- Bigtable/src/DataUtil.php | 2 +- Bigtable/src/ReadModifyWriteRowRules.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Bigtable/src/DataUtil.php b/Bigtable/src/DataUtil.php index cb0cde2c643b..a64526d874a3 100644 --- a/Bigtable/src/DataUtil.php +++ b/Bigtable/src/DataUtil.php @@ -37,7 +37,7 @@ public static function isSystemLittleEndian() public static function isSupported() { if (self::$isSupported === null) { - self::$isSupported = PHP_VERSION_ID > 50500 && PHP_INT_SIZE >= 8; + self::$isSupported = PHP_VERSION_ID > 50500; } return self::$isSupported; } diff --git a/Bigtable/src/ReadModifyWriteRowRules.php b/Bigtable/src/ReadModifyWriteRowRules.php index 9657465b0e96..6e2431f3c5c9 100644 --- a/Bigtable/src/ReadModifyWriteRowRules.php +++ b/Bigtable/src/ReadModifyWriteRowRules.php @@ -20,7 +20,7 @@ use Google\Cloud\Bigtable\V2\ReadModifyWriteRule; /** - * Represents a collection of read/modify/write rules specifying how the specified row's contents + * This is a builder class which builds read/modify/write rules specifying how the specified rows contents * are to be transformed into writes. Entries are applied in order, meaning that earlier rules will * affect the results of later ones. This is intended to be used in combination with * {@see Google\Cloud\Bigtable\DataClient::readModifyWriteRow()}. From 8781563023be9156502f526898e46004f69892d0 Mon Sep 17 00:00:00 2001 From: Ajay Date: Thu, 18 Oct 2018 13:47:12 -0400 Subject: [PATCH 12/12] address feedback --- Bigtable/src/DataClient.php | 2 +- Bigtable/src/DataUtil.php | 20 +++++++++++++++++--- Bigtable/src/ReadModifyWriteRowRules.php | 2 +- Bigtable/tests/Snippet/DataClientTest.php | 3 ++- Bigtable/tests/Unit/DataUtilTest.php | 2 +- 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/Bigtable/src/DataClient.php b/Bigtable/src/DataClient.php index 0d2b6bc15760..f652bd7c8294 100644 --- a/Bigtable/src/DataClient.php +++ b/Bigtable/src/DataClient.php @@ -343,8 +343,8 @@ public function readRow($rowKey, array $options = []) * print_r($row); * ``` * - * //Increments value * ``` + * // Increments value * use Google\Cloud\Bigtable\DataUtil; * use Google\Cloud\Bigtable\ReadModifyWriteRowRules; * use Google\Cloud\Bigtable\RowMutation; diff --git a/Bigtable/src/DataUtil.php b/Bigtable/src/DataUtil.php index a64526d874a3..ff967e108daa 100644 --- a/Bigtable/src/DataUtil.php +++ b/Bigtable/src/DataUtil.php @@ -26,6 +26,11 @@ class DataUtil private static $isLittleEndian; private static $isSupported; + /** + * Check if system is little-endian. + * + * @return bool + */ public static function isSystemLittleEndian() { if (self::$isLittleEndian === null) { @@ -34,10 +39,17 @@ public static function isSystemLittleEndian() return self::$isLittleEndian; } + /** + * Check if {@see Google\Cloud\Bigtable\DataUtil::intToByteString()} and + * {@see Google\Cloud\Bigtable\DataUtil::byteStringToInt()} supported on + * the current platform. + * + * @return bool + */ public static function isSupported() { if (self::$isSupported === null) { - self::$isSupported = PHP_VERSION_ID > 50500; + self::$isSupported = PHP_VERSION_ID >= 50600; } return self::$isSupported; } @@ -48,11 +60,12 @@ public static function isSupported() * @param int $intValue Integer value to convert to. * @return string Returns a string of bytes representing a 64-bit big-endian signed integer. * @throws \InvalidArgumentException If value is not an integer. + * @throws \RuntimeException If called on PHP version <= 5.5. */ public static function intToByteString($intValue) { if (!self::isSupported()) { - throw new \ErrorException('This utility is only supported on 64 bit machine with PHP version > 5.5.'); + throw new \RuntimeException('This utility is only supported on 64 bit machines with PHP version > 5.5.'); } if (!is_int($intValue)) { throw new \InvalidArgumentException( @@ -71,11 +84,12 @@ public static function intToByteString($intValue) * * @param string $bytes String of bytes to convert. * @return int Integer value of the string bytes. + * @throws \RuntimeException If called on PHP version <= 5.5. */ public static function byteStringToInt($bytes) { if (!self::isSupported()) { - throw new \ErrorException('This utility is only supported on 64 bit machine with PHP version > 5.5.'); + throw new \RuntimeException('This utility is only supported on 64 bit machines with PHP version > 5.5.'); } if (self::isSystemLittleEndian()) { $bytes = strrev($bytes); diff --git a/Bigtable/src/ReadModifyWriteRowRules.php b/Bigtable/src/ReadModifyWriteRowRules.php index 6e2431f3c5c9..352b9efbe46e 100644 --- a/Bigtable/src/ReadModifyWriteRowRules.php +++ b/Bigtable/src/ReadModifyWriteRowRules.php @@ -58,7 +58,7 @@ public function append($familyName, $qualifier, $value) * * @param string $familyName Family name of the row. * @param string $qualifier Column qualifier of the row. - * @param int $amount Amount to add to value of Column qualifier. + * @param int $amount Amount to add to value of column qualifier. * * @return ReadModifyWriteRowRules returns current ReadModifyWriteRowRules object. */ diff --git a/Bigtable/tests/Snippet/DataClientTest.php b/Bigtable/tests/Snippet/DataClientTest.php index dd4f08660a93..0ae852545a83 100644 --- a/Bigtable/tests/Snippet/DataClientTest.php +++ b/Bigtable/tests/Snippet/DataClientTest.php @@ -19,6 +19,7 @@ use Google\ApiCore\ServerStream; use Google\Cloud\Bigtable\DataClient; +use Google\Cloud\Bigtable\DataUtil; use Google\Cloud\Bigtable\ReadModifyWriteRowRules; use Google\Cloud\Bigtable\V2\BigtableClient as TableClient; use Google\Cloud\Bigtable\V2\Cell; @@ -287,7 +288,7 @@ public function testReadModifyWriteRowIncrement() { $snippet = $this->snippetFromMethod(DataClient::class, 'readModifyWriteRow', 1); - if (phpversion() < '5.6.0') { + if (!DataUtil::isSupported()) { $this->markTestSkipped('This test only runs on PHP 5.6 or above.'); return; } diff --git a/Bigtable/tests/Unit/DataUtilTest.php b/Bigtable/tests/Unit/DataUtilTest.php index 4c491ae1e08c..ade54aa49da0 100644 --- a/Bigtable/tests/Unit/DataUtilTest.php +++ b/Bigtable/tests/Unit/DataUtilTest.php @@ -31,7 +31,7 @@ class DataUtilTest extends TestCase * @expectedException \InvalidArgumentException * @expectedExceptionMessage Expected argument to be of type int, instead got */ - public function testIntToByteStringWithString() + public function testIntToByteStringThrowsExceptionWithoutInteger() { DataUtil::intToByteString('abc'); }