Package org.apache.kafka.clients.producer.internals

Examples of org.apache.kafka.clients.producer.internals.ProduceRequestResult


    @Override
    public synchronized Future<RecordMetadata> send(ProducerRecord record, Callback callback) {
        int partition = 0;
        if (this.cluster.partitionsForTopic(record.topic()) != null)
            partition = partitioner.partition(record, this.cluster);
        ProduceRequestResult result = new ProduceRequestResult();
        FutureRecordMetadata future = new FutureRecordMetadata(result, 0);
        TopicPartition topicPartition = new TopicPartition(record.topic(), partition);
        long offset = nextOffset(topicPartition);
        Completion completion = new Completion(topicPartition, offset, new RecordMetadata(topicPartition, 0, offset), result, callback);
        this.sent.add(record);
View Full Code Here


    /**
     * Test that waiting on a request that never completes times out
     */
    @Test
    public void testTimeout() throws Exception {
        ProduceRequestResult request = new ProduceRequestResult();
        FutureRecordMetadata future = new FutureRecordMetadata(request, relOffset);
        assertFalse("Request is not completed", future.isDone());
        try {
            future.get(5, TimeUnit.MILLISECONDS);
            fail("Should have thrown exception.");
        } catch (TimeoutException e) { /* this is good */
        }

        request.done(topicPartition, baseOffset, null);
        assertTrue(future.isDone());
        assertEquals(baseOffset + relOffset, future.get().offset());
    }
View Full Code Here

        assertEquals(baseOffset + relOffset, future.get().offset());
    }

    /* create a new request result that will be completed after the given timeout */
    public ProduceRequestResult asyncRequest(final long baseOffset, final RuntimeException error, final long timeout) {
        final ProduceRequestResult request = new ProduceRequestResult();
        new Thread() {
            public void run() {
                try {
                    sleep(timeout);
                    request.done(topicPartition, baseOffset, error);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }.start();
View Full Code Here

TOP

Related Classes of org.apache.kafka.clients.producer.internals.ProduceRequestResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.