You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@kafka.apache.org by "Gavin Manning (JIRA)" <ji...@apache.org> on 2016/07/12 16:02:20 UTC

[jira] [Commented] (KAFKA-3956) MockProducer.send() sends a message before completeNext() or errorNext() are called

    [ https://issues.apache.org/jira/browse/KAFKA-3956?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15373134#comment-15373134 ] 

Gavin Manning commented on KAFKA-3956:
--------------------------------------

{{monospaced}}
{noformat}
    @Test
    public void testErrorNextAfterSend() {
        final MockProducer<String, byte[]> mockProducer = new MockProducer<>(false, new StringSerializer(), new ByteArraySerializer());
        byte[] bytes = new byte[10];
        final ProducerRecord<String, byte[]> record = new ProducerRecord<>("topic", "key", bytes);
        Assert.assertTrue(mockProducer.history().isEmpty());
        mockProducer.send(record);
        // History should be empty ... but isn't
        Assert.assertTrue(mockProducer.history().isEmpty());
        // Cause the next operation to fail
        Assert.assertTrue(mockProducer.errorNext(new RuntimeException("Force an error")));
        System.out.println("Mock producer contains " + mockProducer.history().size() + " message(s)");
        // We're too late ... the message has already been "sent"
        Assert.assertTrue(mockProducer.history().isEmpty());
    }
{noformat}
{{monospaced}}

> MockProducer.send() sends a message before completeNext() or errorNext() are called
> -----------------------------------------------------------------------------------
>
>                 Key: KAFKA-3956
>                 URL: https://issues.apache.org/jira/browse/KAFKA-3956
>             Project: Kafka
>          Issue Type: Bug
>          Components: producer 
>    Affects Versions: 0.10.0.0
>         Environment: JUnit test
>            Reporter: Gavin Manning
>
> I pass false for autoComplete to MockProducer's constructor.
> I then call MockProducer.send().
> MockProducer.history() now contains that message.
> I would expect completeNext() to cause the message to be added to history and errorNext() to *not* add the message to history.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)