Example #1
0
 def test_simple_producer_ctor(self):
     client = mock.Mock()
     ack = SimpleAIOProducer.ACK_AFTER_LOCAL_WRITE
     producer = SimpleAIOProducer(client, req_acks=ack)
     name = producer.__class__.__name__
     self.assertTrue(name in producer.__repr__())
     self.assertEqual(producer._req_acks, ack)
Example #2
0
 def test_simple_producer_ctor(self):
     client = mock.Mock()
     ack = SimpleAIOProducer.ACK_AFTER_LOCAL_WRITE
     producer = SimpleAIOProducer(client, req_acks=ack)
     name = producer.__class__.__name__
     self.assertTrue(name in producer.__repr__())
     self.assertEqual(producer._req_acks, ack)
Example #3
0
    def test_simple_producer(self):
        start_offset0 = yield from self.current_offset(self.topic, 0)
        start_offset1 = yield from self.current_offset(self.topic, 1)
        producer = SimpleAIOProducer(self.client)

        # Goes to first partition, randomly.
        resp = yield from producer.send(self.topic, self.msg("one"),
                                        self.msg("two"))
        self.assert_produce_response(resp, start_offset0)

        # Goes to the next partition, randomly.
        resp = yield from producer.send(self.topic, self.msg("three"))
        self.assert_produce_response(resp, start_offset1)

        yield from self.assert_fetch_offset(0, start_offset0,
                                            [self.msg("one"), self.msg("two")])
        yield from self.assert_fetch_offset(1, start_offset1,
                                            [self.msg("three")])

        # Goes back to the first partition because there's only two partitions
        resp = yield from producer.send(self.topic, self.msg("four"),
                                        self.msg("five"))
        self.assert_produce_response(resp, start_offset0 + 2)
        yield from self.assert_fetch_offset(0, start_offset0,
                                            [self.msg("one"), self.msg("two"),
                                             self.msg("four"),
                                             self.msg("five")])
Example #4
0
    def test_simple_producer(self):
        start_offset0 = yield from self.current_offset(self.topic, 0)
        start_offset1 = yield from self.current_offset(self.topic, 1)
        producer = SimpleAIOProducer(self.client)

        # Goes to first partition, randomly.
        resp = yield from producer.send(self.topic, self.msg("one"),
                                        self.msg("two"))
        self.assert_produce_response(resp, start_offset0)

        # Goes to the next partition, randomly.
        resp = yield from producer.send(self.topic, self.msg("three"))
        self.assert_produce_response(resp, start_offset1)

        yield from self.assert_fetch_offset(
            0, start_offset0,
            [self.msg("one"), self.msg("two")])
        yield from self.assert_fetch_offset(1, start_offset1,
                                            [self.msg("three")])

        # Goes back to the first partition because there's only two partitions
        resp = yield from producer.send(self.topic, self.msg("four"),
                                        self.msg("five"))
        self.assert_produce_response(resp, start_offset0 + 2)
        yield from self.assert_fetch_offset(0, start_offset0, [
            self.msg("one"),
            self.msg("two"),
            self.msg("four"),
            self.msg("five")
        ])
Example #5
0
 def test_codec_gzip(self):
     start_offset0 = yield from self.current_offset(self.topic, 0)
     producer = SimpleAIOProducer(self.client, codec=CODEC_GZIP)
     resp = yield from producer.send(self.topic, self.msg("one"))
     self.assert_produce_response(resp, start_offset0)
     yield from self.assert_fetch_offset(0, start_offset0,
                                         [self.msg("one")])
Example #6
0
 def test_codec_gzip(self):
     start_offset0 = yield from self.current_offset(self.topic, 0)
     producer = SimpleAIOProducer(
         self.client, codec=CODEC_GZIP)
     resp = yield from producer.send(self.topic, self.msg("one"))
     self.assert_produce_response(resp, start_offset0)
     yield from self.assert_fetch_offset(0, start_offset0,
                                         [self.msg("one")])
Example #7
0
    def test_acks_none(self):
        start_offset0 = yield from self.current_offset(self.topic, 0)

        producer = SimpleAIOProducer(
            self.client, req_acks=SimpleAIOProducer.ACK_NOT_REQUIRED)
        resp = yield from producer.send(self.topic, self.msg("one"))
        self.assertEquals(len(resp), 0)
        yield from self.assert_fetch_offset(0, start_offset0,
                                            [self.msg("one")])
Example #8
0
    def test_produce__new_topic_fails_with_reasonable_error(self):
        new_topic = 'new_topic_{guid}'.format(guid=str(uuid.uuid4())).encode(
            'utf-8')
        producer = SimpleAIOProducer(self.client)

        # At first it doesn't exist
        with self.assertRaises((UnknownTopicOrPartitionError,
                                LeaderNotAvailableError)):
            yield from producer.send(new_topic, self.msg("one"))
Example #9
0
    def test_produce__new_topic_fails_with_reasonable_error(self):
        new_topic = 'new_topic_{guid}'.format(
            guid=str(uuid.uuid4())).encode('utf-8')
        producer = SimpleAIOProducer(self.client)

        # At first it doesn't exist
        with self.assertRaises(
            (UnknownTopicOrPartitionError, LeaderNotAvailableError)):
            yield from producer.send(new_topic, self.msg("one"))
Example #10
0
    def test_acks_none(self):
        start_offset0 = yield from self.current_offset(self.topic, 0)

        producer = SimpleAIOProducer(
            self.client, req_acks=SimpleAIOProducer.ACK_NOT_REQUIRED)
        resp = yield from producer.send(self.topic, self.msg("one"))
        self.assertEquals(len(resp), 0)
        yield from self.assert_fetch_offset(0, start_offset0,
                                            [self.msg("one")])
Example #11
0
    def test_producer_random_order(self):
        producer = SimpleAIOProducer(self.client, random_start=True)
        resp1 = yield from producer.send(self.topic, self.msg("one"),
                                         self.msg("two"))
        resp2 = yield from producer.send(self.topic, self.msg("three"))
        resp3 = yield from producer.send(self.topic, self.msg("four"),
                                         self.msg("five"))

        self.assertEqual(resp1[0].partition, resp3[0].partition)
        self.assertNotEqual(resp1[0].partition, resp2[0].partition)
Example #12
0
    def test_send_non_byteish(self):
        client = mock.Mock()
        sproducer = SimpleAIOProducer(client)
        with self.assertRaises(TypeError):
            self.loop.run_until_complete(sproducer.send(b"topic", "text"))

        kproducer = KeyedAIOProducer(client)
        with self.assertRaises(TypeError):
            self.loop.run_until_complete(kproducer.send(b"topic", "text",
                                                        key=b'key'))
Example #13
0
    def test_acks_local_write(self):
        start_offset0 = yield from self.current_offset(self.topic, 0)

        producer = SimpleAIOProducer(
            self.client, req_acks=SimpleAIOProducer.ACK_AFTER_LOCAL_WRITE)
        resp = yield from producer.send(self.topic, self.msg("one"))

        self.assert_produce_response(resp, start_offset0)
        yield from self.assert_fetch_offset(0, start_offset0,
                                            [self.msg("one")])
Example #14
0
    def test_send_non_byteish(self):
        client = mock.Mock()
        sproducer = SimpleAIOProducer(client)
        with self.assertRaises(TypeError):
            self.loop.run_until_complete(sproducer.send(b"topic", "text"))

        kproducer = KeyedAIOProducer(client)
        with self.assertRaises(TypeError):
            self.loop.run_until_complete(
                kproducer.send(b"topic", "text", key=b'key'))
Example #15
0
    def test_acks_cluster_commit(self):
        start_offset0 = yield from self.current_offset(self.topic, 0)

        producer = SimpleAIOProducer(
            self.client, req_acks=SimpleAIOProducer.ACK_AFTER_CLUSTER_COMMIT)

        resp = yield from producer.send(self.topic, self.msg("one"))
        self.assert_produce_response(resp, start_offset0)
        yield from self.assert_fetch_offset(0, start_offset0,
                                            [self.msg("one")])
Example #16
0
    def test_acks_local_write(self):
        start_offset0 = yield from self.current_offset(self.topic, 0)

        producer = SimpleAIOProducer(
            self.client, req_acks=SimpleAIOProducer.ACK_AFTER_LOCAL_WRITE)
        resp = yield from producer.send(self.topic, self.msg("one"))

        self.assert_produce_response(resp, start_offset0)
        yield from self.assert_fetch_offset(0, start_offset0,
                                            [self.msg("one")])
Example #17
0
    def test_acks_cluster_commit(self):
        start_offset0 = yield from self.current_offset(self.topic, 0)

        producer = SimpleAIOProducer(
            self.client,
            req_acks=SimpleAIOProducer.ACK_AFTER_CLUSTER_COMMIT)

        resp = yield from producer.send(self.topic, self.msg("one"))
        self.assert_produce_response(resp, start_offset0)
        yield from self.assert_fetch_offset(0, start_offset0,
                                            [self.msg("one")])
Example #18
0
    def test_producer_random_order(self):
        producer = SimpleAIOProducer(self.client, random_start=True)
        resp1 = yield from producer.send(self.topic, self.msg("one"),
                                         self.msg("two"))
        resp2 = yield from producer.send(self.topic,
                                         self.msg("three"))
        resp3 = yield from producer.send(self.topic, self.msg("four"),
                                         self.msg("five"))

        self.assertEqual(resp1[0].partition, resp3[0].partition)
        self.assertNotEqual(resp1[0].partition, resp2[0].partition)
Example #19
0
 def test_invalid_codec(self):
     client = mock.Mock()
     with self.assertRaises(UnsupportedCodecError):
         SimpleAIOProducer(client, codec=123)