vamossagar12 commented on a change in pull request #9717: URL: https://github.com/apache/kafka/pull/9717#discussion_r553484121
########## File path: streams/src/test/java/org/apache/kafka/streams/state/internals/RocksDBRangeIteratorTest.java ########## @@ -0,0 +1,295 @@ +/* + * 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.kafka.streams.state.internals; + +import org.apache.kafka.common.utils.Bytes; +import org.apache.kafka.streams.KeyValue; +import org.junit.Test; + +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.partialMockBuilder; +import static org.easymock.EasyMock.replay; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.nullValue; +import static org.hamcrest.core.Is.is; + +public class RocksDBRangeIteratorTest { + + private RocksDBRangeIterator mockRocksDBRangeIterator() { + return partialMockBuilder(RocksDBRangeIterator.class) + .addMockedMethod("getNext") + .addMockedMethod("getRawLastKey") + .addMockedMethod("isForward") + .addMockedMethod("getComparator") + .createMock(); + } + + @Test + public void shouldReturnAllKeysInTheRangeInForwardDirection() { + final RocksDBRangeIterator rocksDBRangeIterator = mockRocksDBRangeIterator(); + + final String key1 = "a"; + final String key2 = "b"; + final String key3 = "c"; + final String key4 = "d"; + final String value = "value"; + + final Bytes key1Bytes = Bytes.wrap(key1.getBytes()); + final Bytes key2Bytes = Bytes.wrap(key2.getBytes()); + final Bytes key3Bytes = Bytes.wrap(key3.getBytes()); + final Bytes key4Bytes = Bytes.wrap(key4.getBytes()); + final byte[] valueBytes = value.getBytes(); + + expect(rocksDBRangeIterator.getNext()) + .andReturn(KeyValue.pair(key1Bytes, valueBytes)) + .andReturn(KeyValue.pair(key2Bytes, valueBytes)) + .andReturn(KeyValue.pair(key3Bytes, valueBytes)) + .andReturn(KeyValue.pair(key4Bytes, valueBytes)); + + expect(rocksDBRangeIterator.getRawLastKey()) + .andReturn(key3Bytes.get()) + .anyTimes(); + + expect(rocksDBRangeIterator.isForward()) + .andReturn(true) + .anyTimes(); + + expect(rocksDBRangeIterator.getComparator()) + .andReturn(Bytes.BYTES_LEXICO_COMPARATOR) + .anyTimes(); + + + replay(rocksDBRangeIterator); + assertThat(rocksDBRangeIterator.makeNext().key, is(key1Bytes)); + assertThat(rocksDBRangeIterator.makeNext().key, is(key2Bytes)); + assertThat(rocksDBRangeIterator.makeNext().key, is(key3Bytes)); + assertThat(rocksDBRangeIterator.makeNext(), is(nullValue())); Review comment: @cadonna , did you get a chance to review these changes? ---------------------------------------------------------------- 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: us...@infra.apache.org