Package com.taobao.metamorphosis.client.consumer.SimpleFetchManager

Examples of com.taobao.metamorphosis.client.consumer.SimpleFetchManager.FetchRequestRunner


                MessageUtils.makeMessageBuffer(1111,
                    new PutCommand(topic, partition.getPartition(), "hello".getBytes(), null, 0, 0)).array();
        final FetchRequest request =
                new FetchRequest(broker, 0, new TopicPartitionRegInfo(topic, partition, offset), maxSize);

        final FetchRequestRunner runner = this.fetchManager.new FetchRequestRunner();

        EasyMock.expect(this.consumer.fetch(request, -1, null)).andReturn(new MessageIterator(topic, data));
        EasyMock.expect(this.consumer.getMessageListener(topic)).andReturn(new MessageListener() {

            @Override
            public void recieveMessages(final Message message) {
                throw new RuntimeException("A stupid bug");
            }


            @Override
            public Executor getExecutor() {
                return null;
            }
        });
        this.mockFilterAndGroup(topic);

        final FetchRequest newRequest =
                new FetchRequest(broker, this.consumerConfig.getMaxDelayFetchTimeInMills() / 10,
                    new TopicPartitionRegInfo(topic, partition, offset, 1111), maxSize);
        newRequest.incrementRetriesAndGet();

        EasyMock.replay(this.consumer);
        runner.processRequest(request);
        EasyMock.verify(this.consumer);
        assertEquals(newRequest, this.fetchManager.takeFetchRequest());
    }
View Full Code Here


                MessageUtils.makeMessageBuffer(1111,
                    new PutCommand(topic, partition.getPartition(), "hello".getBytes(), null, 0, 0)).array();
        final FetchRequest request =
                new FetchRequest(broker, 0, new TopicPartitionRegInfo(topic, partition, offset), maxSize);

        final FetchRequestRunner runner = this.fetchManager.new FetchRequestRunner();

        EasyMock.expect(this.consumer.fetch(request, -1, null)).andReturn(new MessageIterator(topic, data));
        EasyMock.expect(this.consumer.getMessageListener(topic)).andReturn(new MessageListener() {

            @Override
            public void recieveMessages(final Message message) {
                System.out.println("Rollback current message");
                message.setRollbackOnly();
            }


            @Override
            public Executor getExecutor() {
                return null;
            }
        });
        this.mockFilterAndGroup(topic);

        final FetchRequest newRequest =
                new FetchRequest(broker, this.consumerConfig.getMaxDelayFetchTimeInMills() / 10,
                    new TopicPartitionRegInfo(topic, partition, offset, 1111), maxSize);
        newRequest.incrementRetriesAndGet();

        EasyMock.replay(this.consumer);
        runner.processRequest(request);
        EasyMock.verify(this.consumer);
        assertEquals(newRequest, this.fetchManager.takeFetchRequest());
    }
View Full Code Here

        final FetchRequest request =
                new FetchRequest(broker, 0, new TopicPartitionRegInfo(topic, partition, offset), maxSize);
        // ��������������0��
        request.incrementRetriesAndGet();

        final FetchRequestRunner runner = this.fetchManager.new FetchRequestRunner();
        EasyMock.expect(this.consumer.fetch(request, -1, null)).andReturn(new MessageIterator(topic, new byte[10]));
        EasyMock.expect(this.consumer.getMessageListener(topic)).andReturn(new MessageListener() {

            @Override
            public void recieveMessages(final Message message) {
                fail();
            }


            @Override
            public Executor getExecutor() {
                return null;
            }
        });
        this.mockFilterAndGroup(topic);
        final int newMaxSize = maxSize * 2;
        final FetchRequest newRequest =
                new FetchRequest(broker, this.consumerConfig.getMaxDelayFetchTimeInMills() / 10,
                    new TopicPartitionRegInfo(topic, partition, offset), newMaxSize);
        newRequest.incrementRetriesAndGet();
        newRequest.incrementRetriesAndGet();

        EasyMock.replay(this.consumer);
        runner.processRequest(request);
        EasyMock.verify(this.consumer);
        assertEquals(newRequest, this.fetchManager.takeFetchRequest());
    }
View Full Code Here

                MessageUtils.makeMessageBuffer(msgId,
                    new PutCommand(topic, partition.getPartition(), "hello".getBytes(), null, 0, 0)).array();
        final FetchRequest request =
                new FetchRequest(broker, 0, new TopicPartitionRegInfo(topic, partition, offset), maxSize);

        final FetchRequestRunner runner = this.fetchManager.new FetchRequestRunner();

        EasyMock.expect(this.consumer.fetch(request, -1, null)).andReturn(new MessageIterator(topic, data));
        final AtomicReference<Message> msg = new AtomicReference<Message>();
        EasyMock.expect(this.consumer.getMessageListener(topic)).andReturn(new MessageListener() {

            @Override
            public void recieveMessages(final Message message) {
                msg.set(message);
            }


            @Override
            public Executor getExecutor() {
                return null;
            }
        });
        this.mockFilterAndGroup(topic);

        final FetchRequest newRequest =
                new FetchRequest(broker, 0, new TopicPartitionRegInfo(topic, partition, offset + data.length, msgId),
                    maxSize);

        EasyMock.replay(this.consumer);
        runner.processRequest(request);
        EasyMock.verify(this.consumer);
        assertEquals("hello", new String(msg.get().getData()));
        assertEquals(msgId, msg.get().getId());
        assertEquals(topic, msg.get().getTopic());
        assertEquals(newRequest, this.fetchManager.takeFetchRequest());
View Full Code Here

                MessageUtils.makeMessageBuffer(msgId,
                    new PutCommand(topic, partition.getPartition(), "hello".getBytes(), null, 0, 0)).array();
        final FetchRequest request =
                new FetchRequest(broker, 0, new TopicPartitionRegInfo(topic, partition, offset), maxSize);

        final FetchRequestRunner runner = this.fetchManager.new FetchRequestRunner();

        EasyMock.expect(this.consumer.fetch(request, -1, null)).andReturn(new MessageIterator(topic, data));
        final AtomicReference<Message> msg = new AtomicReference<Message>();
        EasyMock.expect(this.consumer.getMessageListener(topic)).andReturn(new MessageListener() {

            @Override
            public void recieveMessages(final Message message) {
                msg.set(message);
            }


            @Override
            public Executor getExecutor() {
                return null;
            }
        });
        EasyMock.expect(this.consumer.getMessageFilter(topic)).andReturn(new ConsumerMessageFilter() {

            @Override
            public boolean accept(String group, Message message) {
                return true;
            }
        });
        EasyMock.expect(this.consumer.getConsumerConfig()).andReturn(new ConsumerConfig("test"));

        final FetchRequest newRequest =
                new FetchRequest(broker, 0, new TopicPartitionRegInfo(topic, partition, offset + data.length, msgId),
                    maxSize);

        EasyMock.replay(this.consumer);
        runner.processRequest(request);
        EasyMock.verify(this.consumer);
        assertEquals("hello", new String(msg.get().getData()));
        assertEquals(msgId, msg.get().getId());
        assertEquals(topic, msg.get().getTopic());
        assertEquals(newRequest, this.fetchManager.takeFetchRequest());
View Full Code Here

                MessageUtils.makeMessageBuffer(msgId,
                    new PutCommand(topic, partition.getPartition(), "hello".getBytes(), null, 0, 0)).array();
        final FetchRequest request =
                new FetchRequest(broker, 0, new TopicPartitionRegInfo(topic, partition, offset), maxSize);

        final FetchRequestRunner runner = this.fetchManager.new FetchRequestRunner();

        EasyMock.expect(this.consumer.fetch(request, -1, null)).andReturn(new MessageIterator(topic, data));
        final AtomicReference<Message> msg = new AtomicReference<Message>();
        EasyMock.expect(this.consumer.getMessageListener(topic)).andReturn(new MessageListener() {

            @Override
            public void recieveMessages(final Message message) {
                fail();
            }


            @Override
            public Executor getExecutor() {
                return null;
            }
        });
        // Don't accept all messages.
        EasyMock.expect(this.consumer.getMessageFilter(topic)).andReturn(new ConsumerMessageFilter() {

            @Override
            public boolean accept(String group, Message message) {
                // always return false.
                return false;
            }
        });
        EasyMock.expect(this.consumer.getConsumerConfig()).andReturn(new ConsumerConfig("test"));
        EasyMock.replay(this.consumer);
        runner.processRequest(request);
        EasyMock.verify(this.consumer);
        assertNull(msg.get());
    }
View Full Code Here

                MessageUtils.makeMessageBuffer(msgId,
                    new PutCommand(topic, partition.getPartition(), "hello".getBytes(), null, 0, 0)).array();
        final FetchRequest request =
                new FetchRequest(broker, 0, new TopicPartitionRegInfo(topic, partition, offset), maxSize);

        final FetchRequestRunner runner = this.fetchManager.new FetchRequestRunner();

        EasyMock.expect(this.consumer.fetch(request, -1, null)).andReturn(new MessageIterator(topic, data));
        final AtomicReference<Message> msg = new AtomicReference<Message>();
        EasyMock.expect(this.consumer.getMessageListener(topic)).andReturn(new MessageListener() {

            @Override
            public void recieveMessages(final Message message) {
                fail();
            }


            @Override
            public Executor getExecutor() {
                return null;
            }
        });
        // Don't accept all messages.
        EasyMock.expect(this.consumer.getMessageFilter(topic)).andReturn(new ConsumerMessageFilter() {

            @Override
            public boolean accept(String group, Message message) {
                throw new RuntimeException();
            }
        });
        EasyMock.expect(this.consumer.getConsumerConfig()).andReturn(new ConsumerConfig("test"));

        EasyMock.replay(this.consumer);
        runner.processRequest(request);
        EasyMock.verify(this.consumer);
        assertNull(msg.get());
    }
View Full Code Here

                makeInvalidMessageBuffer(msgId,
                    new PutCommand(topic, partition.getPartition(), "hello".getBytes(), null, 0, 0)).array();
        final FetchRequest request =
                new FetchRequest(broker, 0, new TopicPartitionRegInfo(topic, partition, offset), maxSize);

        final FetchRequestRunner runner = this.fetchManager.new FetchRequestRunner();

        EasyMock.expect(this.consumer.fetch(request, -1, null)).andReturn(new MessageIterator(topic, data));
        EasyMock.expect(this.consumer.getMessageListener(topic)).andReturn(new MessageListener() {

            @Override
            public void recieveMessages(final Message message) {
                fail();
            }


            @Override
            public Executor getExecutor() {
                return null;
            }
        });
        this.mockFilterAndGroup(topic);
        // query offset
        final long newOffset = 13;
        EasyMock.expect(this.consumer.offset(request)).andReturn(newOffset);
        // Use new offset
        final FetchRequest newRequest =
                new FetchRequest(broker, 0, new TopicPartitionRegInfo(topic, partition, newOffset, -1), maxSize);

        EasyMock.replay(this.consumer);
        runner.processRequest(request);
        EasyMock.verify(this.consumer);
        assertEquals(newRequest, this.fetchManager.takeFetchRequest());
    }
View Full Code Here

            public Executor getExecutor() {
                return null;
            }
        });
        this.mockFilterAndGroup(topic);
        final FetchRequestRunner runner = this.fetchManager.new FetchRequestRunner();
        // EasyMock.expect(this.fetchManager.isRetryTooMany(request)).andReturn(true);
        final Message message = new Message(topic, "hello".getBytes());
        MessageAccessor.setId(message, 1111);
        this.consumer.appendCouldNotProcessMessage(message);
        EasyMock.expectLastCall();

        // offset��������Ϊ������ǰ��Ϣ
        final FetchRequest newRequest =
                new FetchRequest(broker, 0, new TopicPartitionRegInfo(topic, partition, offset + data.length, 1111),
                    maxSize);

        EasyMock.replay(this.consumer);
        runner.processRequest(request);
        EasyMock.verify(this.consumer);
        // retry������
        assertEquals(0, request.getRetries());
        assertEquals(newRequest, this.fetchManager.takeFetchRequest());
    }
View Full Code Here

        final long offset = 12;
        final Broker broker = new Broker(0, "meta://localhost:0");
        final FetchRequest request =
                new FetchRequest(broker, 0, new TopicPartitionRegInfo(topic, partition, offset), maxSize);

        final FetchRequestRunner runner = this.fetchManager.new FetchRequestRunner();
        EasyMock.expect(this.consumer.fetch(request, -1, null)).andReturn(null);
        EasyMock.expect(this.consumer.getMessageListener(topic)).andReturn(new MessageListener() {

            @Override
            public void recieveMessages(final Message message) {
                fail();
            }


            @Override
            public Executor getExecutor() {
                return null;
            }
        });
        this.mockFilterAndGroup(topic);

        final FetchRequest newRequest =
                new FetchRequest(broker, this.consumerConfig.getMaxDelayFetchTimeInMills() / 10,
                    new TopicPartitionRegInfo(topic, partition, offset), maxSize);

        EasyMock.replay(this.consumer);
        runner.processRequest(request);
        EasyMock.verify(this.consumer);
        assertEquals(newRequest, this.fetchManager.takeFetchRequest());
    }
View Full Code Here

TOP

Related Classes of com.taobao.metamorphosis.client.consumer.SimpleFetchManager.FetchRequestRunner

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.