Github user roshannaik commented on a diff in the pull request:

    https://github.com/apache/storm/pull/2241#discussion_r158942500
  
    --- Diff: 
storm-client/test/jvm/org/apache/storm/utils/JCQueueBackpressureTest.java ---
    @@ -0,0 +1,94 @@
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + * http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.storm.utils;
    +
    +import org.apache.storm.policy.WaitStrategyPark;
    +import org.apache.storm.utils.JCQueue.Consumer;
    +import org.junit.Assert;
    +import org.junit.Test;
    +import junit.framework.TestCase;
    +
    +
    +public class JCQueueBackpressureTest extends TestCase {
    +
    +    @Test
    +    public void testNoReOrderingUnderBackPressure() throws Exception {
    +        final int MESSAGES = 100;
    +        final int CAPACITY = 64;
    +
    +        final JCQueue queue = createQueue("testBackPressure", CAPACITY);
    +
    +        for (int i = 0; i < MESSAGES; i++) {
    +            if (!queue.tryPublish(i)) {
    +                Assert.assertTrue(queue.tryPublishToOverflow(i));
    +            }
    +        }
    +
    +        TestConsumer consumer = new TestConsumer();
    +        queue.consume(consumer);
    +        Assert.assertEquals(MESSAGES, consumer.lastMsg);
    +
    +    }
    +
    +    private static JCQueue createQueue(String name, int queueSize) {
    +        return new JCQueue(name, queueSize, 0, 1, new WaitStrategyPark(0));
    +    }
    +
    +    private static class TestConsumer implements Consumer {
    +        int lastMsg = 0;
    +
    +        @Override
    +        public void accept(Object o) {
    +            Integer i = (Integer) o;
    +            Assert.assertEquals(lastMsg++, i.intValue());
    +            System.err.println(i);
    +        }
    +
    +        @Override
    +        public void flush() throws InterruptedException
    +        { }
    +    }
    +
    +
    +    // check that tryPublish() & tryOverflowPublish() work as expected
    --- End diff --
    
    thanks. will fix.


---

Reply via email to