zentol commented on a change in pull request #15049: URL: https://github.com/apache/flink/pull/15049#discussion_r591475018
########## File path: flink-runtime/src/test/java/org/apache/flink/runtime/util/BoundedFIFOQueueTest.java ########## @@ -0,0 +1,100 @@ +/* + * 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.flink.runtime.util; + +import org.apache.flink.util.TestLogger; + +import org.junit.Test; + +import java.util.Arrays; + +import static org.hamcrest.collection.IsIterableContainingInOrder.contains; +import static org.hamcrest.collection.IsIterableWithSize.iterableWithSize; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; + +/** {@code BoundedFIFOTest} tests {@link BoundedFIFOQueue}. */ +public class BoundedFIFOQueueTest extends TestLogger { + + @Test(expected = IllegalArgumentException.class) + public void testConstructorFailing() { + new BoundedFIFOQueue<>(-1); + } + + @Test + public void testCollectionConstructor() { + final BoundedFIFOQueue<Integer> testInstance = new BoundedFIFOQueue<>(Arrays.asList(1, 2)); + assertThat(testInstance, contains(1, 2)); + assertThat(testInstance.size(), is(2)); + assertThat(testInstance.getElementCount(), is(2)); + } + + @Test + public void testEmptyQueue() { + final BoundedFIFOQueue<Integer> testInstance = new BoundedFIFOQueue<>(0); + assertThat(testInstance, iterableWithSize(0)); + testInstance.add(1); + assertThat(testInstance, iterableWithSize(0)); + } + + @Test + public void testQueue() { + final BoundedFIFOQueue<Integer> testInstance = new BoundedFIFOQueue<>(2); + assertThat(testInstance, iterableWithSize(0)); + + testInstance.add(1); + assertThat(testInstance, contains(1)); + + testInstance.add(2); + assertThat(testInstance, contains(1, 2)); + + testInstance.add(3); + assertThat(testInstance, contains(2, 3)); + } + + @Test + public void testElementCount() { + final BoundedFIFOQueue<Integer> testInstance = new BoundedFIFOQueue<>(0); + assertThat(testInstance.getElementCount(), is(0)); + + testInstance.add(1); + assertThat(testInstance.getElementCount(), is(1)); Review comment: Ah i see, man this elementCount thing is unintuive... ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
