-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Improve test clarity and execution time. #1743
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
Open
vbabanin
wants to merge
4
commits into
mongodb:main
Choose a base branch
from
vbabanin:JAVA-5898
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,37 +54,68 @@ class ByteBufferBsonInputTest { | |
private static final List<Integer> ALL_CODE_POINTS_EXCLUDING_SURROGATES = Stream.concat( | ||
range(1, MIN_HIGH_SURROGATE).boxed(), | ||
rangeClosed(MAX_LOW_SURROGATE + 1, MAX_CODE_POINT).boxed()) | ||
.filter(i -> i < 128 || i % 10 == 0) // only subset of code points to speed up testing | ||
.filter(i -> i < 128 || i % 30 == 0) // only subset of code points to speed up testing | ||
.collect(toList()); | ||
|
||
static Stream<BufferProvider> bufferProviders() { | ||
return Stream.of( | ||
size -> new NettyByteBuf(PooledByteBufAllocator.DEFAULT.directBuffer(size)), | ||
size -> new NettyByteBuf(PooledByteBufAllocator.DEFAULT.heapBuffer(size)), | ||
new PowerOfTwoBufferPool(), | ||
size -> new ByteBufNIO(ByteBuffer.wrap(new byte[size + 5], 2, size).slice()), //different array offsets | ||
size -> new ByteBufNIO(ByteBuffer.wrap(new byte[size + 4], 3, size).slice()), //different array offsets | ||
size -> new ByteBufNIO(ByteBuffer.allocateDirect(size)), | ||
size -> new ByteBufNIO(ByteBuffer.allocate(size)) { | ||
@Override | ||
public boolean isBackedByArray() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public byte[] array() { | ||
return Assertions.fail("array() is called, when isBackedByArray() returns false"); | ||
} | ||
|
||
@Override | ||
public int arrayOffset() { | ||
return Assertions.fail("arrayOffset() is called, when isBackedByArray() returns false"); | ||
} | ||
} | ||
createBufferProvider( | ||
"NettyByteBuf based on PooledByteBufAllocator.DEFAULT.directBuffer", | ||
size -> new NettyByteBuf(PooledByteBufAllocator.DEFAULT.directBuffer(size)) | ||
), | ||
createBufferProvider( | ||
"NettyByteBuf based on PooledByteBufAllocator.DEFAULT.heapBuffer", | ||
size -> new NettyByteBuf(PooledByteBufAllocator.DEFAULT.heapBuffer(size)) | ||
), | ||
createBufferProvider( | ||
"PowerOfTwoBufferPool", | ||
new PowerOfTwoBufferPool() | ||
), | ||
createBufferProvider( | ||
"ByteBufNIO based on ByteBuffer with arrayOffset() -> 2", | ||
size -> new ByteBufNIO(ByteBuffer.wrap(new byte[size + 5], 2, size).slice()) | ||
), | ||
createBufferProvider( | ||
"ByteBufNIO based on ByteBuffer with arrayOffset() -> 3,", | ||
size -> new ByteBufNIO(ByteBuffer.wrap(new byte[size + 4], 3, size).slice()) | ||
), | ||
createBufferProvider( | ||
"ByteBufNIO emulating direct ByteBuffer", | ||
size -> new ByteBufNIO(ByteBuffer.allocate(size)) { | ||
@Override | ||
public boolean isBackedByArray() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public byte[] array() { | ||
return Assertions.fail("array() is called, when isBackedByArray() returns false"); | ||
} | ||
|
||
@Override | ||
public int arrayOffset() { | ||
return Assertions.fail("arrayOffset() is called, when isBackedByArray() returns false"); | ||
} | ||
} | ||
) | ||
); | ||
} | ||
|
||
@ParameterizedTest | ||
private static BufferProvider createBufferProvider(final String bufferName, final BufferProvider bufferProvider) { | ||
return new BufferProvider() { | ||
@Override | ||
public ByteBuf getBuffer(final int size) { | ||
return bufferProvider.getBuffer(size); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return bufferName; | ||
} | ||
}; | ||
} | ||
|
||
@ParameterizedTest(name = "should read empty string. BufferProvider={0}") | ||
@MethodSource("bufferProviders") | ||
void shouldReadEmptyString(final BufferProvider bufferProvider) { | ||
// given | ||
|
@@ -101,7 +132,7 @@ void shouldReadEmptyString(final BufferProvider bufferProvider) { | |
} | ||
} | ||
|
||
@ParameterizedTest | ||
@ParameterizedTest(name = "should read empty CString. BufferProvider={0}") | ||
@MethodSource("bufferProviders") | ||
void shouldReadEmptyCString(final BufferProvider bufferProvider) { | ||
// given | ||
|
@@ -116,7 +147,7 @@ void shouldReadEmptyCString(final BufferProvider bufferProvider) { | |
} | ||
} | ||
|
||
@ParameterizedTest | ||
@ParameterizedTest(name = "should read invalid one byte string. BufferProvider={0}") | ||
@MethodSource("bufferProviders") | ||
void shouldReadInvalidOneByteString(final BufferProvider bufferProvider) { | ||
ByteBuf buffer = allocateAndWriteToBuffer(bufferProvider, new byte[]{2, 0, 0, 0, (byte) 0xFF, 0}); | ||
|
@@ -131,7 +162,7 @@ void shouldReadInvalidOneByteString(final BufferProvider bufferProvider) { | |
} | ||
} | ||
|
||
@ParameterizedTest | ||
@ParameterizedTest(name = "should read invalid one byte CString. BufferProvider={0}") | ||
@MethodSource("bufferProviders") | ||
void shouldReadInvalidOneByteCString(final BufferProvider bufferProvider) { | ||
ByteBuf buffer = allocateAndWriteToBuffer(bufferProvider, new byte[]{-0x01, 0}); | ||
|
@@ -147,7 +178,7 @@ void shouldReadInvalidOneByteCString(final BufferProvider bufferProvider) { | |
} | ||
|
||
|
||
@ParameterizedTest | ||
@ParameterizedTest(name = "should read string up to buffer limit. BufferProvider={0}") | ||
@MethodSource("bufferProviders") | ||
void shouldReadStringUptoBufferLimit(final BufferProvider bufferProvider) { | ||
// given | ||
|
@@ -171,7 +202,7 @@ void shouldReadStringUptoBufferLimit(final BufferProvider bufferProvider) { | |
} | ||
} | ||
|
||
@ParameterizedTest | ||
@ParameterizedTest(name = "should read string with more data in buffer. BufferProvider={0}") | ||
@MethodSource("bufferProviders") | ||
void shouldReadStringWithMoreDataInBuffer(final BufferProvider bufferProvider) throws IOException { | ||
// given | ||
|
@@ -200,7 +231,7 @@ void shouldReadStringWithMoreDataInBuffer(final BufferProvider bufferProvider) t | |
} | ||
} | ||
|
||
@ParameterizedTest | ||
@ParameterizedTest(name = "should read multiple strings within buffer. BufferProvider={0}") | ||
@MethodSource("bufferProviders") | ||
void shouldReadMultipleStringsWithinBuffer(final BufferProvider bufferProvider) throws IOException { | ||
// given | ||
|
@@ -252,7 +283,7 @@ void shouldReadMultipleStringsWithinBuffer(final BufferProvider bufferProvider) | |
} | ||
} | ||
|
||
@ParameterizedTest | ||
@ParameterizedTest(name = "should read consecutive multiple strings within buffer. BufferProvider={0}") | ||
@MethodSource("bufferProviders") | ||
void shouldReadConsecutiveMultipleStringsWithinBuffer(final BufferProvider bufferProvider) throws IOException { | ||
// given | ||
|
@@ -302,7 +333,7 @@ void shouldReadConsecutiveMultipleStringsWithinBuffer(final BufferProvider buffe | |
} | ||
} | ||
|
||
@ParameterizedTest | ||
@ParameterizedTest(name = "should read consecutive multiple CStrings within buffer. BufferProvider={0}") | ||
@MethodSource("bufferProviders") | ||
void shouldReadConsecutiveMultipleCStringsWithinBuffer(final BufferProvider bufferProvider) throws IOException { | ||
// given | ||
|
@@ -352,7 +383,7 @@ void shouldReadConsecutiveMultipleCStringsWithinBuffer(final BufferProvider buff | |
} | ||
} | ||
|
||
@ParameterizedTest | ||
@ParameterizedTest(name = "should read multiple CStrings within buffer. BufferProvider={0}") | ||
@MethodSource("bufferProviders") | ||
void shouldReadMultipleCStringsWithinBuffer(final BufferProvider bufferProvider) throws IOException { | ||
// given | ||
|
@@ -409,7 +440,7 @@ void shouldReadMultipleCStringsWithinBuffer(final BufferProvider bufferProvider) | |
} | ||
} | ||
|
||
@ParameterizedTest | ||
@ParameterizedTest(name = "should read string within buffer. BufferProvider={0}") | ||
@MethodSource("bufferProviders") | ||
void shouldReadStringWithinBuffer(final BufferProvider bufferProvider) throws IOException { | ||
// given | ||
|
@@ -441,7 +472,7 @@ void shouldReadStringWithinBuffer(final BufferProvider bufferProvider) throws IO | |
} | ||
} | ||
|
||
@ParameterizedTest | ||
@ParameterizedTest(name = "should read CString up to buffer limit. BufferProvider={0}") | ||
@MethodSource("bufferProviders") | ||
void shouldReadCStringUptoBufferLimit(final BufferProvider bufferProvider) { | ||
// given | ||
|
@@ -465,7 +496,7 @@ void shouldReadCStringUptoBufferLimit(final BufferProvider bufferProvider) { | |
} | ||
} | ||
|
||
@ParameterizedTest | ||
@ParameterizedTest(name = "should read CString with more data in buffer. BufferProvider={0}") | ||
@MethodSource("bufferProviders") | ||
void shouldReadCStringWithMoreDataInBuffer(final BufferProvider bufferProvider) throws IOException { | ||
// given | ||
|
@@ -494,7 +525,7 @@ void shouldReadCStringWithMoreDataInBuffer(final BufferProvider bufferProvider) | |
} | ||
} | ||
|
||
@ParameterizedTest | ||
@ParameterizedTest(name = "should read CString within buffer. BufferProvider={0}") | ||
@MethodSource("bufferProviders") | ||
void shouldReadCStringWithingBuffer(final BufferProvider bufferProvider) throws IOException { | ||
// given | ||
|
@@ -526,7 +557,7 @@ void shouldReadCStringWithingBuffer(final BufferProvider bufferProvider) throws | |
} | ||
} | ||
|
||
@ParameterizedTest | ||
@ParameterizedTest(name = "should throw if CString is not null terminated skip. BufferProvider={0}") | ||
@MethodSource("bufferProviders") | ||
void shouldThrowIfCStringIsNotNullTerminatedSkip(final BufferProvider bufferProvider) { | ||
// given | ||
|
@@ -553,7 +584,7 @@ public static Stream<Arguments> nonNullTerminatedStringsWithBuffers() { | |
return arguments.stream(); | ||
} | ||
|
||
@ParameterizedTest | ||
@ParameterizedTest(name = "should throw if string is not null terminated. Parameters: nonNullTerminatedString={0}, bufferProvider={1}") | ||
@MethodSource("nonNullTerminatedStringsWithBuffers") | ||
void shouldThrowIfStringIsNotNullTerminated(final byte[] nonNullTerminatedString, final BufferProvider bufferProvider) { | ||
// given | ||
|
@@ -579,7 +610,7 @@ public static Stream<Arguments> nonNullTerminatedCStringsWithBuffers() { | |
return arguments.stream(); | ||
} | ||
|
||
@ParameterizedTest | ||
@ParameterizedTest(name = "should throw if CString is not null terminated. Parameters: nonNullTerminatedCString={0}, bufferProvider={1}") | ||
@MethodSource("nonNullTerminatedCStringsWithBuffers") | ||
void shouldThrowIfCStringIsNotNullTerminated(final byte[] nonNullTerminatedCString, final BufferProvider bufferProvider) { | ||
// given | ||
|
@@ -592,7 +623,7 @@ void shouldThrowIfCStringIsNotNullTerminated(final byte[] nonNullTerminatedCStri | |
} | ||
|
||
|
||
@ParameterizedTest | ||
@ParameterizedTest(name = "should throw if one byte string is not null terminated. BufferProvider={0}") | ||
@MethodSource("bufferProviders") | ||
void shouldThrowIfOneByteStringIsNotNullTerminated(final BufferProvider bufferProvider) { | ||
// given | ||
|
@@ -604,7 +635,7 @@ void shouldThrowIfOneByteStringIsNotNullTerminated(final BufferProvider bufferPr | |
} | ||
} | ||
|
||
@ParameterizedTest | ||
@ParameterizedTest(name = "should throw if one byte CString is not null terminated. BufferProvider={0}") | ||
@MethodSource("bufferProviders") | ||
void shouldThrowIfOneByteCStringIsNotNullTerminated(final BufferProvider bufferProvider) { | ||
// given | ||
|
@@ -616,7 +647,7 @@ void shouldThrowIfOneByteCStringIsNotNullTerminated(final BufferProvider bufferP | |
} | ||
} | ||
|
||
@ParameterizedTest | ||
@ParameterizedTest(name = "should throw if length of bson string is not positive. BufferProvider={0}") | ||
@MethodSource("bufferProviders") | ||
void shouldThrowIfLengthOfBsonStringIsNotPositive(final BufferProvider bufferProvider) { | ||
// given | ||
|
@@ -644,8 +675,8 @@ public static Stream<Arguments> shouldSkipCStringWhenMultipleNullTerminationPres | |
return arguments.stream(); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource() | ||
@ParameterizedTest(name = "should skip CString when multiple null termination present. Parameters: cStringBytes={0}, bufferProvider={1}") | ||
@MethodSource | ||
void shouldSkipCStringWhenMultipleNullTerminationPresent(final byte[] cStringBytes, final BufferProvider bufferProvider) { | ||
// given | ||
ByteBuf buffer = allocateAndWriteToBuffer(bufferProvider, cStringBytes); | ||
|
@@ -660,7 +691,7 @@ void shouldSkipCStringWhenMultipleNullTerminationPresent(final byte[] cStringByt | |
} | ||
} | ||
|
||
@ParameterizedTest | ||
@ParameterizedTest(name = "should read skip CString when multiple null termination present within buffer. BufferProvider={0}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is "multiple null terminations" preferable? |
||
@MethodSource("bufferProviders") | ||
void shouldReadSkipCStringWhenMultipleNullTerminationPresentWithinBuffer(final BufferProvider bufferProvider) { | ||
// given | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure about my point. Is it true that bufferDescription is more appropriate naming? Saw it is used to overwrite toString.