-
Notifications
You must be signed in to change notification settings - Fork 587
HDDS-3925. SCM Pipeline DB should directly use UUID bytes for key rather than rely on proto serialization for key. #1197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
caf60fd
HDDS-3925. Add first implementation that uses the approach that remov…
fapifta 9f989cb
HDDS-3925. Addressing comments from internal review and design discus…
fapifta 4fb4dc0
Add tests to the codec conversion methods, and change the conversion …
fapifta d5838fa
HDDs-3925. Added test to changes in SCMPipelineManager.
fapifta 74df1ac
HDDS-3925. Added missing license, and fixed checkstyle issues.
fapifta 78f955a
Add javadoc to newly added method on TableIterator interface.
fapifta 09c2477
Fix typo
fapifta e15f761
Trigger a new test run.
fapifta 44b9c1c
HDDS-3925. Review request. Add tests to verify RDBStoreIterator inter…
fapifta acd7ba9
Added license. Removed unused import.
fapifta da6ef72
Fix missing javadoc.
fapifta 10c6209
Trigger a new test run.
fapifta b4cba4e
empty commit to retest build
web-flow 8344923
Trigger a new test run.
fapifta 84eaec1
Merge branch 'HDDS-3925' of github.com:fapifta/hadoop-ozone into HDDS…
fapifta 94ade5b
empty commit to retest build
web-flow 4bce3d4
Trigger a new test run.
fapifta 01fcec1
Merge branch 'HDDS-3925' of github.com:fapifta/hadoop-ozone into HDDS…
fapifta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
224 changes: 224 additions & 0 deletions
224
...op-hdds/framework/src/test/java/org/apache/hadoop/hdds/utils/db/TestRDBStoreIterator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,224 @@ | ||
| /* | ||
| * 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.hadoop.hdds.utils.db; | ||
|
|
||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import org.mockito.ArgumentCaptor; | ||
| import org.mockito.InOrder; | ||
| import org.rocksdb.RocksIterator; | ||
|
|
||
| import java.util.NoSuchElementException; | ||
| import java.util.function.Consumer; | ||
|
|
||
| import static org.junit.Assert.assertArrayEquals; | ||
| import static org.junit.Assert.assertFalse; | ||
| import static org.junit.Assert.assertTrue; | ||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.Mockito.inOrder; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.never; | ||
| import static org.mockito.Mockito.times; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| /** | ||
| * This test prescribe expected behaviour from the RDBStoreIterator which wraps | ||
| * RocksDB's own iterator. Ozone internally in TypedTableIterator uses, the | ||
| * RDBStoreIterator to provide iteration over table elements in a typed manner. | ||
| * The tests are to ensure we access RocksDB via the iterator properly. | ||
| */ | ||
| public class TestRDBStoreIterator { | ||
|
|
||
| private RocksIterator rocksDBIteratorMock; | ||
| private RDBTable rocksTableMock; | ||
|
|
||
| @Before | ||
| public void setup() { | ||
| rocksDBIteratorMock = mock(RocksIterator.class); | ||
| rocksTableMock = mock(RDBTable.class); | ||
| } | ||
|
|
||
| @Test | ||
| public void testForeachRemainingCallsConsumerWithAllElements() { | ||
| when(rocksDBIteratorMock.isValid()) | ||
| .thenReturn(true, true, true, true, true, true, false); | ||
| when(rocksDBIteratorMock.key()) | ||
| .thenReturn(new byte[]{0x00}, new byte[]{0x01}, new byte[]{0x02}) | ||
| .thenThrow(new NoSuchElementException()); | ||
| when(rocksDBIteratorMock.value()) | ||
| .thenReturn(new byte[]{0x7f}, new byte[]{0x7e}, new byte[]{0x7d}) | ||
| .thenThrow(new NoSuchElementException()); | ||
|
|
||
|
|
||
| Consumer<ByteArrayKeyValue> consumerStub = mock(Consumer.class); | ||
|
|
||
| RDBStoreIterator iter = new RDBStoreIterator(rocksDBIteratorMock); | ||
| iter.forEachRemaining(consumerStub); | ||
|
|
||
| ArgumentCaptor<ByteArrayKeyValue> capture = | ||
| ArgumentCaptor.forClass(ByteArrayKeyValue.class); | ||
| verify(consumerStub, times(3)).accept(capture.capture()); | ||
| assertArrayEquals( | ||
| new byte[]{0x00}, capture.getAllValues().get(0).getKey()); | ||
| assertArrayEquals( | ||
| new byte[]{0x7f}, capture.getAllValues().get(0).getValue()); | ||
| assertArrayEquals( | ||
| new byte[]{0x01}, capture.getAllValues().get(1).getKey()); | ||
| assertArrayEquals( | ||
| new byte[]{0x7e}, capture.getAllValues().get(1).getValue()); | ||
| assertArrayEquals( | ||
| new byte[]{0x02}, capture.getAllValues().get(2).getKey()); | ||
| assertArrayEquals( | ||
| new byte[]{0x7d}, capture.getAllValues().get(2).getValue()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testHasNextDependsOnIsvalid(){ | ||
| when(rocksDBIteratorMock.isValid()).thenReturn(true, false); | ||
|
|
||
| RDBStoreIterator iter = new RDBStoreIterator(rocksDBIteratorMock); | ||
|
|
||
| assertTrue(iter.hasNext()); | ||
| assertFalse(iter.hasNext()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testNextCallsIsValidThenGetsTheValueAndStepsToNext() { | ||
| when(rocksDBIteratorMock.isValid()).thenReturn(true); | ||
| RDBStoreIterator iter = new RDBStoreIterator(rocksDBIteratorMock); | ||
|
|
||
| InOrder verifier = inOrder(rocksDBIteratorMock); | ||
|
|
||
| iter.next(); | ||
|
|
||
| verifier.verify(rocksDBIteratorMock).isValid(); | ||
| verifier.verify(rocksDBIteratorMock).key(); | ||
| verifier.verify(rocksDBIteratorMock).value(); | ||
| verifier.verify(rocksDBIteratorMock).next(); | ||
| } | ||
|
|
||
| @Test | ||
| public void testConstructorSeeksToFirstElement() { | ||
| new RDBStoreIterator(rocksDBIteratorMock); | ||
|
|
||
| verify(rocksDBIteratorMock, times(1)).seekToFirst(); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSeekToFirstSeeks() { | ||
| RDBStoreIterator iter = new RDBStoreIterator(rocksDBIteratorMock); | ||
|
|
||
| iter.seekToFirst(); | ||
|
|
||
| verify(rocksDBIteratorMock, times(2)).seekToFirst(); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSeekToLastSeeks() { | ||
| RDBStoreIterator iter = new RDBStoreIterator(rocksDBIteratorMock); | ||
|
|
||
| iter.seekToLast(); | ||
|
|
||
| verify(rocksDBIteratorMock, times(1)).seekToLast(); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSeekReturnsTheActualKey() { | ||
| when(rocksDBIteratorMock.isValid()).thenReturn(true); | ||
| when(rocksDBIteratorMock.key()).thenReturn(new byte[]{0x00}); | ||
| when(rocksDBIteratorMock.value()).thenReturn(new byte[]{0x7f}); | ||
|
|
||
| RDBStoreIterator iter = new RDBStoreIterator(rocksDBIteratorMock); | ||
| ByteArrayKeyValue val = iter.seek(new byte[]{0x55}); | ||
|
|
||
| InOrder verifier = inOrder(rocksDBIteratorMock); | ||
|
|
||
| verify(rocksDBIteratorMock, times(1)).seekToFirst(); //at construct time | ||
| verify(rocksDBIteratorMock, never()).seekToLast(); | ||
| verifier.verify(rocksDBIteratorMock, times(1)).seek(any(byte[].class)); | ||
| verifier.verify(rocksDBIteratorMock, times(1)).isValid(); | ||
| verifier.verify(rocksDBIteratorMock, times(1)).key(); | ||
| verifier.verify(rocksDBIteratorMock, times(1)).value(); | ||
| assertArrayEquals(new byte[]{0x00}, val.getKey()); | ||
| assertArrayEquals(new byte[]{0x7f}, val.getValue()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGettingTheKeyIfIteratorIsValid() { | ||
| when(rocksDBIteratorMock.isValid()).thenReturn(true); | ||
| when(rocksDBIteratorMock.key()).thenReturn(new byte[]{0x00}); | ||
|
|
||
| RDBStoreIterator iter = new RDBStoreIterator(rocksDBIteratorMock); | ||
| byte[] key = iter.key(); | ||
|
|
||
| InOrder verifier = inOrder(rocksDBIteratorMock); | ||
|
|
||
| verifier.verify(rocksDBIteratorMock, times(1)).isValid(); | ||
| verifier.verify(rocksDBIteratorMock, times(1)).key(); | ||
| assertArrayEquals(new byte[]{0x00}, key); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGettingTheValueIfIteratorIsValid() { | ||
| when(rocksDBIteratorMock.isValid()).thenReturn(true); | ||
| when(rocksDBIteratorMock.key()).thenReturn(new byte[]{0x00}); | ||
| when(rocksDBIteratorMock.value()).thenReturn(new byte[]{0x7f}); | ||
|
|
||
| RDBStoreIterator iter = new RDBStoreIterator(rocksDBIteratorMock); | ||
| ByteArrayKeyValue val = iter.value(); | ||
|
|
||
| InOrder verifier = inOrder(rocksDBIteratorMock); | ||
|
|
||
| verifier.verify(rocksDBIteratorMock, times(1)).isValid(); | ||
| verifier.verify(rocksDBIteratorMock, times(1)).key(); | ||
| assertArrayEquals(new byte[]{0x00}, val.getKey()); | ||
| assertArrayEquals(new byte[]{0x7f}, val.getValue()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testRemovingFromDBActuallyDeletesFromTable() throws Exception { | ||
| byte[] testKey = new byte[]{0x00}; | ||
| when(rocksDBIteratorMock.isValid()).thenReturn(true); | ||
| when(rocksDBIteratorMock.key()).thenReturn(testKey); | ||
|
|
||
| RDBStoreIterator iter = | ||
| new RDBStoreIterator(rocksDBIteratorMock, rocksTableMock); | ||
| iter.removeFromDB(); | ||
|
|
||
| InOrder verifier = inOrder(rocksDBIteratorMock, rocksTableMock); | ||
|
|
||
| verifier.verify(rocksDBIteratorMock, times(1)).isValid(); | ||
| verifier.verify(rocksTableMock, times(1)).delete(testKey); | ||
| } | ||
|
|
||
| @Test(expected = UnsupportedOperationException.class) | ||
| public void testRemoveFromDBWithoutDBTableSet() throws Exception { | ||
| RDBStoreIterator iter = new RDBStoreIterator(rocksDBIteratorMock); | ||
| iter.removeFromDB(); | ||
| } | ||
|
|
||
| @Test | ||
| public void testCloseCloses() throws Exception { | ||
| RDBStoreIterator iter = new RDBStoreIterator(rocksDBIteratorMock); | ||
| iter.close(); | ||
|
|
||
| verify(rocksDBIteratorMock, times(1)).close(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.