Ejemplo n.º 1
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")
        ])
Ejemplo n.º 2
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")])
Ejemplo n.º 3
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)
Ejemplo n.º 4
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)
Ejemplo n.º 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")])
Ejemplo n.º 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")])
Ejemplo n.º 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")])
Ejemplo n.º 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"))
Ejemplo n.º 9
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")])
Ejemplo n.º 10
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"))
Ejemplo n.º 11
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'))
Ejemplo n.º 12
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")])
Ejemplo n.º 13
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'))
Ejemplo n.º 14
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")])
Ejemplo n.º 15
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")])
Ejemplo n.º 16
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")])