Package com.taobao.metamorphosis.consumer

Examples of com.taobao.metamorphosis.consumer.MessageIterator


    private void assertMessages(final MessageStore store) throws IOException, InvalidMessageException {
        final FileMessageSet msgSet = (FileMessageSet) store.slice(0, 1024);
        final ByteBuffer buf = ByteBuffer.allocate((int) msgSet.getSizeInBytes());
        msgSet.read(buf, 0);
        final MessageIterator it = new MessageIterator("topic1", buf.array());
        int count = 0;
        while (it.hasNext()) {
            final Message msg = it.next();
            assertTrue(new String(msg.getData()).startsWith("msg"));
            count++;
        }
        assertEquals(2, count);
    }
View Full Code Here


    @Test
    public void testIteratorInSamePartition() throws Exception {
        EasyMock
        .expect(
            this.consumer.get(this.topic, new Partition("0-0"), 0L, this.maxSize, this.timeoutInMills,
                TimeUnit.MILLISECONDS)).andReturn(new MessageIterator(this.topic, this.createMessageBuffer()))
                .once();
        EasyMock
        .expect(
            this.consumer.get(this.topic, new Partition("0-0"), 25L, this.maxSize, this.timeoutInMills,
                TimeUnit.MILLISECONDS)).andReturn(new MessageIterator(this.topic, this.createMessageBuffer()))
                .once();
        this.control.replay();
        Iterator<Message> it = this.browser.iterator();
        if (it.hasNext()) {
            this.assertMsg(it.next());
View Full Code Here

    @Test
    public void testIteratorMoveOnPartition() throws Exception {
        EasyMock
        .expect(
            this.consumer.get(this.topic, new Partition("0-0"), 0L, this.maxSize, this.timeoutInMills,
                TimeUnit.MILLISECONDS)).andReturn(new MessageIterator(this.topic, this.createMessageBuffer()))
                .once();
        EasyMock.expect(
            this.consumer.get(this.topic, new Partition("0-0"), 25L, this.maxSize, this.timeoutInMills,
                TimeUnit.MILLISECONDS)).andReturn(null);
        EasyMock
        .expect(
            this.consumer.get(this.topic, new Partition("0-1"), 0L, this.maxSize, this.timeoutInMills,
                TimeUnit.MILLISECONDS)).andReturn(new MessageIterator(this.topic, this.createMessageBuffer()))
                .once();
        this.control.replay();
        Iterator<Message> it = this.browser.iterator();
        if (it.hasNext()) {
            this.assertMsg(it.next());
View Full Code Here

    @Test
    public void testIteratorToEnd() throws Exception {
        EasyMock
        .expect(
            this.consumer.get(this.topic, new Partition("0-0"), 0L, this.maxSize, this.timeoutInMills,
                TimeUnit.MILLISECONDS)).andReturn(new MessageIterator(this.topic, this.createMessageBuffer()))
                .once();
        EasyMock.expect(
            this.consumer.get(this.topic, new Partition("0-0"), 25L, this.maxSize, this.timeoutInMills,
                TimeUnit.MILLISECONDS)).andReturn(null);
        EasyMock
        .expect(
            this.consumer.get(this.topic, new Partition("0-1"), 0L, this.maxSize, this.timeoutInMills,
                TimeUnit.MILLISECONDS)).andReturn(new MessageIterator(this.topic, this.createMessageBuffer()))
                .once();
        EasyMock
        .expect(
            this.consumer.get(this.topic, new Partition("0-1"), 25L, this.maxSize, this.timeoutInMills,
                TimeUnit.MILLISECONDS)).andReturn(null).once();
        EasyMock
        .expect(
            this.consumer.get(this.topic, new Partition("0-2"), 0L, this.maxSize, this.timeoutInMills,
                TimeUnit.MILLISECONDS)).andReturn(new MessageIterator(this.topic, this.createMessageBuffer()))
                .once();
        EasyMock
        .expect(
            this.consumer.get(this.topic, new Partition("0-2"), 25L, this.maxSize, this.timeoutInMills,
                TimeUnit.MILLISECONDS)).andReturn(null).once();
View Full Code Here

        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) {
View Full Code Here

        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) {
View Full Code Here

        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) {
View Full Code Here

        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) {
View Full Code Here

        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();
View Full Code Here

                    new PutCommand(topic, partition.getPartition(), "hello".getBytes(), null, 0, 0)).array();
        final FetchRequest request =
                new FetchRequest(broker, 0, new TopicPartitionRegInfo(topic, partition, offset), maxSize);
        request.incrementRetriesAndGet();
        assertEquals(1, request.getRetries());
        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();
View Full Code Here

TOP

Related Classes of com.taobao.metamorphosis.consumer.MessageIterator

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.