Kafka
  1. Kafka
  2. KAFKA-319

compression support added to php client does not pass unit tests

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Trivial Trivial
    • Resolution: Duplicate
    • Affects Version/s: 0.7
    • Fix Version/s: None
    • Component/s: clients
    • Labels:
      None

      Description

      The fix from #KAFKA-159 breaks unit tests. The client has changed to expect a compression algo.

        Issue Links

          Activity

          Hide
          jon added a comment -

          diff --git a/clients/php/src/lib/Kafka/Encoder.php b/clients/php/src/lib/Kafka/Encoder.php
          index 3c05cfd..edc8258 100644
          — a/clients/php/src/lib/Kafka/Encoder.php
          +++ b/clients/php/src/lib/Kafka/Encoder.php
          @@ -40,7 +40,7 @@ class Kafka_Encoder
          *

          • @return string
            */
          • static public function encode_message($msg, $compression) {
            + static public function encode_message($msg, $compression=0) {
            // <MAGIC_BYTE: 1 byte> <COMPRESSION: 1 byte> <CRC32: 4 bytes bigendian> <PAYLOAD: N bytes>
            return pack('CCN', self::CURRENT_MAGIC_VALUE, $compression, crc32($msg))
            . $msg;
            @@ -56,7 +56,7 @@ class Kafka_Encoder
            *
          • @return string
            */
          • static public function encode_produce_request($topic, $partition, array $messages, $compression) {
            + static public function encode_produce_request($topic, $partition, array $messages, $compression=0) {
            // encode messages as <LEN: int><MESSAGE_BYTES>
            $message_set = '';
            foreach ($messages as $message) {
            diff --git a/clients/php/src/tests/Kafka/BoundedByteBuffer/ReceiveTest.php b/clients/php/src/tests/Kafka/BoundedByteBuffer/ReceiveTest.php
            index a751d7e..480bd4d 100644
              • a/clients/php/src/tests/Kafka/BoundedByteBuffer/ReceiveTest.php
                +++ b/clients/php/src/tests/Kafka/BoundedByteBuffer/ReceiveTest.php
                @@ -1,3 +1,4 @@
                +<?php
                /**
          • Licensed to the Apache Software Foundation (ASF) under one or more
          • contributor license agreements. See the NOTICE file distributed with
            @@ -15,7 +16,7 @@
          • limitations under the License.
            */

          -<?php
          +
          if (!defined('PRODUCE_REQUEST_ID'))

          { define('PRODUCE_REQUEST_ID', 0); }
          diff --git a/clients/php/src/tests/Kafka/BoundedByteBuffer/SendTest.php b/clients/php/src/tests/Kafka/BoundedByteBuffer/SendTest.php
          index 72c8f30..509a4c6 100644
          — a/clients/php/src/tests/Kafka/BoundedByteBuffer/SendTest.php
          +++ b/clients/php/src/tests/Kafka/BoundedByteBuffer/SendTest.php
          @@ -1,3 +1,4 @@
          +<?php
          /**
          * Licensed to the Apache Software Foundation (ASF) under one or more
          * contributor license agreements. See the NOTICE file distributed with
          @@ -15,7 +16,6 @@
          * limitations under the License.
          */

          -<?php

          /**
          * Description of Kafka_BoundedByteBuffer_SendTest
          diff --git a/clients/php/src/tests/Kafka/EncoderTest.php b/clients/php/src/tests/Kafka/EncoderTest.php
          index 628b05f..471d31c 100644
          — a/clients/php/src/tests/Kafka/EncoderTest.php
          +++ b/clients/php/src/tests/Kafka/EncoderTest.php
          @@ -1,3 +1,4 @@
          +<?php
          /**
          * Licensed to the Apache Software Foundation (ASF) under one or more
          * contributor license agreements. See the NOTICE file distributed with
          @@ -14,8 +15,6 @@
          * See the License for the specific language governing permissions and
          * limitations under the License.
          */
          -
          -<?php
          if (!defined('PRODUCE_REQUEST_ID')) { define('PRODUCE_REQUEST_ID', 0); }

          @@ -30,7 +29,7 @@ class Kafka_EncoderTest extends PHPUnit_Framework_TestCase
          public function testEncodedMessageLength()

          { $test = 'a sample string'; $encoded = Kafka_Encoder::encode_message($test); - $this->assertEquals(5 + strlen($test), strlen($encoded)); + $this->assertEquals(6 + strlen($test), strlen($encoded)); }

          public function testByteArrayContainsString()

          { @@ -54,7 +53,7 @@ class Kafka_EncoderTest extends PHPUnit_Framework_TestCase }

          $size = 4 + 2 + 2 + strlen($topic) + 4 + 4;
          foreach ($messages as $msg)

          { - $size += 9 + strlen($msg); + $size += 10 + strlen($msg); }

          $this->assertEquals($size, strlen($encoded));
          }
          diff --git a/clients/php/src/tests/Kafka/FetchRequestTest.php b/clients/php/src/tests/Kafka/FetchRequestTest.php
          index ce3f274..408309d 100644
          — a/clients/php/src/tests/Kafka/FetchRequestTest.php
          +++ b/clients/php/src/tests/Kafka/FetchRequestTest.php
          @@ -1,3 +1,4 @@
          +<?php
          /**

          • Licensed to the Apache Software Foundation (ASF) under one or more
          • contributor license agreements. See the NOTICE file distributed with
            @@ -15,8 +16,6 @@
          • limitations under the License.
            */

          -<?php
          -
          /**

          • Description of FetchRequestTest
            *
            @@ -85,4 +84,4 @@ class Kafka_FetchRequestTest extends PHPUnit_Framework_TestCase
            $this->assertContains('offset:' . $this->offset, (string)$this->req);
            $this->assertContains('maxSize:' . $this->maxSize, (string)$this->req);
            }
            -}
            \ No newline at end of file
            +}
            diff --git a/clients/php/src/tests/Kafka/MessageTest.php b/clients/php/src/tests/Kafka/MessageTest.php
            index 38c3cc6..eed94ef 100644
              • a/clients/php/src/tests/Kafka/MessageTest.php
                +++ b/clients/php/src/tests/Kafka/MessageTest.php
                @@ -1,3 +1,4 @@
                +<?php
                /**
          • Licensed to the Apache Software Foundation (ASF) under one or more
          • contributor license agreements. See the NOTICE file distributed with
            @@ -15,7 +16,6 @@
          • limitations under the License.
            */

          -<?php

          /**

          • @author Lorenzo Alberton <l.alberton@quipo.it>
            diff --git a/clients/php/src/tests/Kafka/ProducerTest.php b/clients/php/src/tests/Kafka/ProducerTest.php
            index a6705fa..c25a96e 100644
              • a/clients/php/src/tests/Kafka/ProducerTest.php
                +++ b/clients/php/src/tests/Kafka/ProducerTest.php
                @@ -1,3 +1,4 @@
                +<?php
                /**
          • Licensed to the Apache Software Foundation (ASF) under one or more
          • contributor license agreements. See the NOTICE file distributed with
            @@ -15,7 +16,6 @@
          • limitations under the License.
            */

          -<?php

          /**

          • Override connect() method of base class
            diff --git a/clients/php/src/tests/bootstrap.php b/clients/php/src/tests/bootstrap.php
            index cbeb8cc..1681cc1 100644
              • a/clients/php/src/tests/bootstrap.php
                +++ b/clients/php/src/tests/bootstrap.php
                @@ -1,3 +1,4 @@
                +<?php
                /**
          • Licensed to the Apache Software Foundation (ASF) under one or more
          • contributor license agreements. See the NOTICE file distributed with
            @@ -15,7 +16,6 @@
          • limitations under the License.
            */

          -<?php

          function test_autoload($className)
          {
          @@ -50,4 +50,4 @@ set_include_path(
          );

          date_default_timezone_set('Europe/London');

          • \ No newline at end of file
            +


            • 1.7.4.1
          Show
          jon added a comment - diff --git a/clients/php/src/lib/Kafka/Encoder.php b/clients/php/src/lib/Kafka/Encoder.php index 3c05cfd..edc8258 100644 — a/clients/php/src/lib/Kafka/Encoder.php +++ b/clients/php/src/lib/Kafka/Encoder.php @@ -40,7 +40,7 @@ class Kafka_Encoder * @return string */ static public function encode_message($msg, $compression) { + static public function encode_message($msg, $compression=0) { // <MAGIC_BYTE: 1 byte> <COMPRESSION: 1 byte> <CRC32: 4 bytes bigendian> <PAYLOAD: N bytes> return pack('CCN', self::CURRENT_MAGIC_VALUE, $compression, crc32($msg)) . $msg; @@ -56,7 +56,7 @@ class Kafka_Encoder * @return string */ static public function encode_produce_request($topic, $partition, array $messages, $compression) { + static public function encode_produce_request($topic, $partition, array $messages, $compression=0) { // encode messages as <LEN: int><MESSAGE_BYTES> $message_set = ''; foreach ($messages as $message) { diff --git a/clients/php/src/tests/Kafka/BoundedByteBuffer/ReceiveTest.php b/clients/php/src/tests/Kafka/BoundedByteBuffer/ReceiveTest.php index a751d7e..480bd4d 100644 a/clients/php/src/tests/Kafka/BoundedByteBuffer/ReceiveTest.php +++ b/clients/php/src/tests/Kafka/BoundedByteBuffer/ReceiveTest.php @@ -1,3 +1,4 @@ +<?php /** Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +16,7 @@ limitations under the License. */ -<?php + if (!defined('PRODUCE_REQUEST_ID')) { define('PRODUCE_REQUEST_ID', 0); } diff --git a/clients/php/src/tests/Kafka/BoundedByteBuffer/SendTest.php b/clients/php/src/tests/Kafka/BoundedByteBuffer/SendTest.php index 72c8f30..509a4c6 100644 — a/clients/php/src/tests/Kafka/BoundedByteBuffer/SendTest.php +++ b/clients/php/src/tests/Kafka/BoundedByteBuffer/SendTest.php @@ -1,3 +1,4 @@ +<?php /** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -15,7 +16,6 @@ * limitations under the License. */ -<?php /** * Description of Kafka_BoundedByteBuffer_SendTest diff --git a/clients/php/src/tests/Kafka/EncoderTest.php b/clients/php/src/tests/Kafka/EncoderTest.php index 628b05f..471d31c 100644 — a/clients/php/src/tests/Kafka/EncoderTest.php +++ b/clients/php/src/tests/Kafka/EncoderTest.php @@ -1,3 +1,4 @@ +<?php /** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -14,8 +15,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -<?php if (!defined('PRODUCE_REQUEST_ID')) { define('PRODUCE_REQUEST_ID', 0); } @@ -30,7 +29,7 @@ class Kafka_EncoderTest extends PHPUnit_Framework_TestCase public function testEncodedMessageLength() { $test = 'a sample string'; $encoded = Kafka_Encoder::encode_message($test); - $this->assertEquals(5 + strlen($test), strlen($encoded)); + $this->assertEquals(6 + strlen($test), strlen($encoded)); } public function testByteArrayContainsString() { @@ -54,7 +53,7 @@ class Kafka_EncoderTest extends PHPUnit_Framework_TestCase } $size = 4 + 2 + 2 + strlen($topic) + 4 + 4; foreach ($messages as $msg) { - $size += 9 + strlen($msg); + $size += 10 + strlen($msg); } $this->assertEquals($size, strlen($encoded)); } diff --git a/clients/php/src/tests/Kafka/FetchRequestTest.php b/clients/php/src/tests/Kafka/FetchRequestTest.php index ce3f274..408309d 100644 — a/clients/php/src/tests/Kafka/FetchRequestTest.php +++ b/clients/php/src/tests/Kafka/FetchRequestTest.php @@ -1,3 +1,4 @@ +<?php /** Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,8 +16,6 @@ limitations under the License. */ -<?php - /** Description of FetchRequestTest * @@ -85,4 +84,4 @@ class Kafka_FetchRequestTest extends PHPUnit_Framework_TestCase $this->assertContains('offset:' . $this->offset, (string)$this->req); $this->assertContains('maxSize:' . $this->maxSize, (string)$this->req); } -} \ No newline at end of file +} diff --git a/clients/php/src/tests/Kafka/MessageTest.php b/clients/php/src/tests/Kafka/MessageTest.php index 38c3cc6..eed94ef 100644 a/clients/php/src/tests/Kafka/MessageTest.php +++ b/clients/php/src/tests/Kafka/MessageTest.php @@ -1,3 +1,4 @@ +<?php /** Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +16,6 @@ limitations under the License. */ -<?php /** @author Lorenzo Alberton <l.alberton@quipo.it> diff --git a/clients/php/src/tests/Kafka/ProducerTest.php b/clients/php/src/tests/Kafka/ProducerTest.php index a6705fa..c25a96e 100644 a/clients/php/src/tests/Kafka/ProducerTest.php +++ b/clients/php/src/tests/Kafka/ProducerTest.php @@ -1,3 +1,4 @@ +<?php /** Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +16,6 @@ limitations under the License. */ -<?php /** Override connect() method of base class diff --git a/clients/php/src/tests/bootstrap.php b/clients/php/src/tests/bootstrap.php index cbeb8cc..1681cc1 100644 a/clients/php/src/tests/bootstrap.php +++ b/clients/php/src/tests/bootstrap.php @@ -1,3 +1,4 @@ +<?php /** Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -15,7 +16,6 @@ limitations under the License. */ -<?php function test_autoload($className) { @@ -50,4 +50,4 @@ set_include_path( ); date_default_timezone_set('Europe/London'); \ No newline at end of file + 1.7.4.1
          Hide
          Lorenzo Alberton added a comment -

          Patch superseded by KAFKA-419

          Show
          Lorenzo Alberton added a comment - Patch superseded by KAFKA-419
          Hide
          Colin B. added a comment -

          This bug has been superceded and should be closed.

          Show
          Colin B. added a comment - This bug has been superceded and should be closed.

            People

            • Assignee:
              Unassigned
              Reporter:
              jon
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development