From 7080d43ccb86116bf93a3df2590841ef576eaa68 Mon Sep 17 00:00:00 2001 From: "slav.babanin" Date: Tue, 17 Jun 2025 15:52:05 -0700 Subject: [PATCH 1/5] Improve test clarity and performance. JAVA-5898 --- .../connection/ByteBufferBsonOutputTest.java | 179 +++++++++++------- 1 file changed, 113 insertions(+), 66 deletions(-) diff --git a/driver-core/src/test/unit/com/mongodb/internal/connection/ByteBufferBsonOutputTest.java b/driver-core/src/test/unit/com/mongodb/internal/connection/ByteBufferBsonOutputTest.java index 4ab076dd5dd..330a430c96a 100644 --- a/driver-core/src/test/unit/com/mongodb/internal/connection/ByteBufferBsonOutputTest.java +++ b/driver-core/src/test/unit/com/mongodb/internal/connection/ByteBufferBsonOutputTest.java @@ -70,38 +70,76 @@ final class ByteBufferBsonOutputTest { private static final List ALL_CODE_POINTS_EXCLUDING_SURROGATES = Stream.concat( range(1, MIN_HIGH_SURROGATE).boxed(), rangeClosed(MAX_LOW_SURROGATE + 1, MAX_CODE_POINT).boxed()) + .filter(codePoint -> codePoint < 128 || codePoint % 30 == 0) // only subset of code points to speed up testing .collect(toList()); + private static final List ALL_SURROGATE_CODE_POINTS = Stream.concat( range(MIN_LOW_SURROGATE, MAX_LOW_SURROGATE).boxed(), - range(MIN_HIGH_SURROGATE, MAX_HIGH_SURROGATE).boxed()).collect(toList()); + range(MIN_HIGH_SURROGATE, MAX_HIGH_SURROGATE).boxed()) + .filter(codePoint -> codePoint < 128 || codePoint % 30 == 0) // only subset of code points to speed up testing + .collect(toList()); + public static final List ALL_UTF_16_CODE_POINTS_FORMED_BY_SURROGATE_PAIRS = rangeClosed(0x10000, MAX_CODE_POINT) .boxed() + .filter(codePoint -> codePoint < 128 || codePoint % 30 == 0) // only subset of code points to speed up testing .collect(toList()); static Stream 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.allocate(size)) { - @Override - public boolean isBackedByArray() { - return 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"); + } + } + ) + ); + } - @Override - public byte[] array() { - return Assertions.fail("array() is called, when isBackedByArray() returns false"); - } + private static BufferProvider createBufferProvider(final String bufferName, BufferProvider bufferProvider) { + return new BufferProvider() { + @Override + public ByteBuf getBuffer(final int size) { + return bufferProvider.getBuffer(size); + } - @Override - public int arrayOffset() { - return Assertions.fail("arrayOffset() is called, when isBackedByArray() returns false"); - } - } - ); + @Override + public String toString() { + return bufferName; + } + }; } public static Stream bufferProvidersWithBranches() { @@ -127,7 +165,7 @@ void constructorShouldThrowIfBufferProviderIsNull() { } @DisplayName("position and size should be 0 after constructor") - @ParameterizedTest + @ParameterizedTest(name = "position and size should be 0 after constructor. Parameters: useBranch={0}") @ValueSource(strings = {"none", "empty", "truncated"}) void positionAndSizeShouldBe0AfterConstructor(final String branchState) { try (ByteBufferBsonOutput out = new ByteBufferBsonOutput(new SimpleBufferProvider())) { @@ -161,7 +199,7 @@ void positionAndSizeShouldBe0AfterConstructor(final String branchState) { } @DisplayName("should write a byte") - @ParameterizedTest + @ParameterizedTest(name = "should write a byte. Parameters: useBranch={0}, bufferProvider={1}") @MethodSource("bufferProvidersWithBranches") void shouldWriteByte(final boolean useBranch, final BufferProvider bufferProvider) { try (ByteBufferBsonOutput out = new ByteBufferBsonOutput(bufferProvider)) { @@ -180,7 +218,7 @@ void shouldWriteByte(final boolean useBranch, final BufferProvider bufferProvide } @DisplayName("should write byte at position") - @ParameterizedTest + @ParameterizedTest(name = "should write byte at position. Parameters: useBranch={0}") @ValueSource(booleans = {false, true}) void shouldWriteByteAtPosition(final boolean useBranch) { for (int offset = 0; offset < 5; offset++) { @@ -206,7 +244,7 @@ void shouldWriteByteAtPosition(final boolean useBranch) { } @DisplayName("should throw exception when writing byte at invalid position") - @ParameterizedTest + @ParameterizedTest(name = "should throw exception when writing byte at invalid position. Parameters: useBranch={0}") @ValueSource(booleans = {false, true}) void shouldThrowExceptionWhenWriteByteAtInvalidPosition(final boolean useBranch) { try (ByteBufferBsonOutput out = new ByteBufferBsonOutput(new SimpleBufferProvider())) { @@ -225,7 +263,7 @@ void shouldThrowExceptionWhenWriteByteAtInvalidPosition(final boolean useBranch) } @DisplayName("should write a bytes") - @ParameterizedTest + @ParameterizedTest(name = "should write a bytes. Parameters: useBranch={0}, bufferProvider={1}") @MethodSource("bufferProvidersWithBranches") void shouldWriteBytes(final boolean useBranch, final BufferProvider bufferProvider) { try (ByteBufferBsonOutput out = new ByteBufferBsonOutput(bufferProvider)) { @@ -244,7 +282,7 @@ void shouldWriteBytes(final boolean useBranch, final BufferProvider bufferProvid } @DisplayName("should write bytes from offset until length") - @ParameterizedTest + @ParameterizedTest(name = "should write bytes from offset until length. Parameters: useBranch={0}, bufferProvider={1}") @MethodSource("bufferProvidersWithBranches") void shouldWriteBytesFromOffsetUntilLength(final boolean useBranch, final BufferProvider bufferProvider) { try (ByteBufferBsonOutput out = new ByteBufferBsonOutput(bufferProvider)) { @@ -263,7 +301,7 @@ void shouldWriteBytesFromOffsetUntilLength(final boolean useBranch, final Buffer } @DisplayName("should write a little endian Int32") - @ParameterizedTest + @ParameterizedTest(name = "should write a little endian Int32. Parameters: useBranch={0}, bufferProvider={1}") @MethodSource("bufferProvidersWithBranches") void shouldWriteLittleEndianInt32(final boolean useBranch, final BufferProvider bufferProvider) { try (ByteBufferBsonOutput out = new ByteBufferBsonOutput(bufferProvider)) { @@ -282,7 +320,7 @@ void shouldWriteLittleEndianInt32(final boolean useBranch, final BufferProvider } @DisplayName("should write a little endian Int64") - @ParameterizedTest + @ParameterizedTest(name = "should write a little endian Int64. Parameters: useBranch={0}, bufferProvider={1}") @MethodSource("bufferProvidersWithBranches") void shouldWriteLittleEndianInt64(final boolean useBranch, final BufferProvider bufferProvider) { try (ByteBufferBsonOutput out = new ByteBufferBsonOutput(bufferProvider)) { @@ -301,7 +339,7 @@ void shouldWriteLittleEndianInt64(final boolean useBranch, final BufferProvider } @DisplayName("should write a double") - @ParameterizedTest + @ParameterizedTest(name = "should write a double. Parameters: useBranch={0}, bufferProvider={1}") @MethodSource("bufferProvidersWithBranches") void shouldWriteDouble(final boolean useBranch, final BufferProvider bufferProvider) { try (ByteBufferBsonOutput out = new ByteBufferBsonOutput(bufferProvider)) { @@ -320,7 +358,7 @@ void shouldWriteDouble(final boolean useBranch, final BufferProvider bufferProvi } @DisplayName("should write an ObjectId") - @ParameterizedTest + @ParameterizedTest(name = "should write an ObjectId. Parameters: useBranch={0}, bufferProvider={1}") @MethodSource("bufferProvidersWithBranches") void shouldWriteObjectId(final boolean useBranch, final BufferProvider bufferProvider) { try (ByteBufferBsonOutput out = new ByteBufferBsonOutput(bufferProvider)) { @@ -340,7 +378,7 @@ void shouldWriteObjectId(final boolean useBranch, final BufferProvider bufferPro } @DisplayName("should write an empty string") - @ParameterizedTest + @ParameterizedTest(name = "should write an empty string. Parameters: useBranch={0}, bufferProvider={1}") @MethodSource("bufferProvidersWithBranches") void shouldWriteEmptyString(final boolean useBranch, final BufferProvider bufferProvider) { try (ByteBufferBsonOutput out = new ByteBufferBsonOutput(bufferProvider)) { @@ -359,7 +397,7 @@ void shouldWriteEmptyString(final boolean useBranch, final BufferProvider buffer } @DisplayName("should write an ASCII string") - @ParameterizedTest + @ParameterizedTest(name = "should write an ASCII string. Parameters: useBranch={0}, bufferProvider={1}") @MethodSource("bufferProvidersWithBranches") void shouldWriteAsciiString(final boolean useBranch, final BufferProvider bufferProvider) { try (ByteBufferBsonOutput out = new ByteBufferBsonOutput(bufferProvider)) { @@ -378,7 +416,7 @@ void shouldWriteAsciiString(final boolean useBranch, final BufferProvider buffer } @DisplayName("should write a UTF-8 string") - @ParameterizedTest + @ParameterizedTest(name = "should write a UTF-8 string. Parameters: useBranch={0}, bufferProvider={1}") @MethodSource("bufferProvidersWithBranches") void shouldWriteUtf8String(final boolean useBranch, final BufferProvider bufferProvider) { try (ByteBufferBsonOutput out = new ByteBufferBsonOutput(bufferProvider)) { @@ -397,7 +435,7 @@ void shouldWriteUtf8String(final boolean useBranch, final BufferProvider bufferP } @DisplayName("should write an empty CString") - @ParameterizedTest + @ParameterizedTest(name = "should write an empty CString. Parameters: useBranch={0}, bufferProvider={1}") @MethodSource("bufferProvidersWithBranches") void shouldWriteEmptyCString(final boolean useBranch, final BufferProvider bufferProvider) { try (ByteBufferBsonOutput out = new ByteBufferBsonOutput(bufferProvider)) { @@ -416,7 +454,7 @@ void shouldWriteEmptyCString(final boolean useBranch, final BufferProvider buffe } @DisplayName("should write an ASCII CString") - @ParameterizedTest + @ParameterizedTest(name = "should write an ASCII CString. Parameters: useBranch={0}, bufferProvider={1}") @MethodSource("bufferProvidersWithBranches") void shouldWriteAsciiCString(final boolean useBranch, final BufferProvider bufferProvider) { try (ByteBufferBsonOutput out = new ByteBufferBsonOutput(bufferProvider)) { @@ -435,7 +473,7 @@ void shouldWriteAsciiCString(final boolean useBranch, final BufferProvider buffe } @DisplayName("should write a UTF-8 CString") - @ParameterizedTest + @ParameterizedTest(name = "should write a UTF-8 CString. Parameters: useBranch={0}, bufferProvider={1}") @MethodSource("bufferProvidersWithBranches") void shouldWriteUtf8CString(final boolean useBranch, final BufferProvider bufferProvider) { try (ByteBufferBsonOutput out = new ByteBufferBsonOutput(bufferProvider)) { @@ -454,7 +492,7 @@ void shouldWriteUtf8CString(final boolean useBranch, final BufferProvider buffer } @DisplayName("should get byte buffers as little endian") - @ParameterizedTest + @ParameterizedTest(name = "should get byte buffers as little endian. Parameters: useBranch={0}, bufferProvider={1}") @MethodSource("bufferProvidersWithBranches") void shouldGetByteBuffersAsLittleEndian(final boolean useBranch, final BufferProvider bufferProvider) { try (ByteBufferBsonOutput out = new ByteBufferBsonOutput(bufferProvider)) { @@ -471,7 +509,7 @@ void shouldGetByteBuffersAsLittleEndian(final boolean useBranch, final BufferPro } @DisplayName("null character in CString should throw SerializationException") - @ParameterizedTest + @ParameterizedTest(name = "null character in CString should throw SerializationException. Parameters: useBranch={0}, bufferProvider={1}") @MethodSource("bufferProvidersWithBranches") void nullCharacterInCStringShouldThrowSerializationException(final boolean useBranch, final BufferProvider bufferProvider) { try (ByteBufferBsonOutput out = new ByteBufferBsonOutput(bufferProvider)) { @@ -487,7 +525,7 @@ void nullCharacterInCStringShouldThrowSerializationException(final boolean useBr } @DisplayName("null character in String should not throw SerializationException") - @ParameterizedTest + @ParameterizedTest(name = "null character in String should not throw SerializationException. Parameters: useBranch={0}, bufferProvider={1}") @MethodSource("bufferProvidersWithBranches") void nullCharacterInStringShouldNotThrowSerializationException(final boolean useBranch, final BufferProvider bufferProvider) { try (ByteBufferBsonOutput out = new ByteBufferBsonOutput(bufferProvider)) { @@ -517,7 +555,8 @@ public static Stream writeInt32AtPositionShouldThrowWithInvalidPositi } @DisplayName("write Int32 at position should throw with invalid position") - @ParameterizedTest + @ParameterizedTest(name = "write Int32 at position should throw with invalid position. " + + "Parameters: useBranch={0}, position={1}, bufferProvider={2}") @MethodSource void writeInt32AtPositionShouldThrowWithInvalidPosition(final boolean useBranch, final int position, final BufferProvider bufferProvider) { @@ -537,7 +576,7 @@ void writeInt32AtPositionShouldThrowWithInvalidPosition(final boolean useBranch, } @DisplayName("should write Int32 at position") - @ParameterizedTest + @ParameterizedTest(name = "should write Int32 at position. Parameters: useBranch={0}, bufferProvider={1}") @MethodSource("bufferProvidersWithBranches") void shouldWriteInt32AtPosition(final boolean useBranch, final BufferProvider bufferProvider) { try (ByteBufferBsonOutput out = new ByteBufferBsonOutput(bufferProvider)) { @@ -585,7 +624,8 @@ public static Stream truncateShouldThrowWithInvalidPosition() { } @DisplayName("truncate should throw with invalid position") - @ParameterizedTest + @ParameterizedTest(name = "truncate should throw with invalid position. " + + "Parameters: useBranch={0}, position={1}") @MethodSource void truncateShouldThrowWithInvalidPosition(final boolean useBranch, final int position) { try (ByteBufferBsonOutput out = new ByteBufferBsonOutput(new SimpleBufferProvider())) { @@ -603,7 +643,7 @@ void truncateShouldThrowWithInvalidPosition(final boolean useBranch, final int p } @DisplayName("should truncate to position") - @ParameterizedTest + @ParameterizedTest(name = "should truncate to position. Parameters: useBranch={0}, bufferProvider={1}") @MethodSource("bufferProvidersWithBranches") void shouldTruncateToPosition(final boolean useBranch, final BufferProvider bufferProvider) { try (ByteBufferBsonOutput out = new ByteBufferBsonOutput(bufferProvider)) { @@ -627,7 +667,7 @@ void shouldTruncateToPosition(final boolean useBranch, final BufferProvider buff } @DisplayName("should grow to maximum allowed size of byte buffer") - @ParameterizedTest + @ParameterizedTest(name = "should grow to maximum allowed size of byte buffer. Parameters: useBranch={0}, bufferProvider={1}") @MethodSource("bufferProvidersWithBranches") void shouldGrowToMaximumAllowedSizeOfByteBuffer(final boolean useBranch, final BufferProvider bufferProvider) { try (ByteBufferBsonOutput out = new ByteBufferBsonOutput(bufferProvider)) { @@ -669,7 +709,7 @@ void shouldGrowToMaximumAllowedSizeOfByteBuffer(final boolean useBranch, final B } @DisplayName("should pipe") - @ParameterizedTest + @ParameterizedTest(name = "should pipe. Parameters: useBranch={0}, bufferProvider={1}") @MethodSource("bufferProvidersWithBranches") void shouldPipe(final boolean useBranch, final BufferProvider bufferProvider) throws IOException { try (ByteBufferBsonOutput out = new ByteBufferBsonOutput(bufferProvider)) { @@ -705,7 +745,7 @@ void shouldPipe(final boolean useBranch, final BufferProvider bufferProvider) th } @DisplayName("should close") - @ParameterizedTest + @ParameterizedTest(name = "should close. Parameters: useBranch={0}, bufferProvider={1}") @MethodSource("bufferProvidersWithBranches") @SuppressWarnings("try") void shouldClose(final boolean useBranch, final BufferProvider bufferProvider) { @@ -726,7 +766,7 @@ void shouldClose(final boolean useBranch, final BufferProvider bufferProvider) { } @DisplayName("should handle mixed branching and truncating") - @ParameterizedTest + @ParameterizedTest(name = "should handle mixed branching and truncating. Reps={0}") @ValueSource(ints = {1, INITIAL_BUFFER_SIZE, INITIAL_BUFFER_SIZE * 3}) void shouldHandleMixedBranchingAndTruncating(final int reps) throws CharacterCodingException { BiConsumer write = (out, c) -> { @@ -773,8 +813,8 @@ void shouldHandleMixedBranchingAndTruncating(final int reps) throws CharacterCod } } - @ParameterizedTest @DisplayName("should throw exception when calling writeInt32 at absolute position where integer would not fit") + @ParameterizedTest(name = "should throw exception when calling writeInt32 at absolute position where integer would not fit. BufferProvider={0}") @MethodSource("bufferProviders") void shouldThrowExceptionWhenIntegerDoesNotFitWriteInt32(final BufferProvider bufferProvider) { try (ByteBufferBsonOutput output = new ByteBufferBsonOutput(bufferProvider)) { @@ -790,8 +830,8 @@ void shouldThrowExceptionWhenIntegerDoesNotFitWriteInt32(final BufferProvider bu } } - @ParameterizedTest @DisplayName("should throw exception when calling writeInt32 with negative absolute position") + @ParameterizedTest(name = "should throw exception when calling writeInt32 with negative absolute position. BufferProvider={0}") @MethodSource("bufferProviders") void shouldThrowExceptionWhenAbsolutePositionIsNegative(final BufferProvider bufferProvider) { try (ByteBufferBsonOutput output = new ByteBufferBsonOutput(bufferProvider)) { @@ -837,7 +877,8 @@ static Stream shouldWriteInt32AbsoluteValueWithinSpanningBuffers() { ))); } - @ParameterizedTest + @ParameterizedTest(name = "should write Int32 absolute value within spanning buffers. " + + "Parameters: absolutePosition={0}, intValue={1}, initialData={2}, expectedBuffers={3}, bufferProvider={4}") @MethodSource void shouldWriteInt32AbsoluteValueWithinSpanningBuffers( final int absolutePosition, @@ -964,7 +1005,9 @@ static Stream int64SpanningBuffersData() { ))); } - @ParameterizedTest + @ParameterizedTest(name = "should write Int32 within spanning buffers. " + + "Parameters: intValue={0}, initialData={1}, expectedBuffers={2}, expectedOutputPosition={3}, " + + "expectedLastBufferPosition={4}, bufferProvider={5}") @MethodSource("int32SpanningBuffersData") void shouldWriteInt32WithinSpanningBuffers( final int intValue, @@ -994,7 +1037,9 @@ void shouldWriteInt32WithinSpanningBuffers( } } - @ParameterizedTest + @ParameterizedTest(name = "should write Int64 within spanning buffers. " + + "Parameters: intValue={0}, initialData={1}, expectedBuffers={2}, expectedOutputPosition={3}, " + + "expectedLastBufferPosition={4}, bufferProvider={5}") @MethodSource("int64SpanningBuffersData") void shouldWriteInt64WithinSpanningBuffers( final long intValue, @@ -1024,7 +1069,9 @@ void shouldWriteInt64WithinSpanningBuffers( } } - @ParameterizedTest + @ParameterizedTest(name = "should write double within spanning buffers. " + + "Parameters: intValue={0}, initialData={1}, expectedBuffers={2}, expectedOutputPosition={3}, " + + "expectedLastBufferPosition={4}, bufferProvider={5}") @MethodSource("int64SpanningBuffersData") void shouldWriteDoubleWithinSpanningBuffers( final long intValue, @@ -1095,7 +1142,7 @@ private static void assertBufferContents(final List expectedBuffersConte class Utf8StringTests { @DisplayName("should write UTF-8 CString across buffers") - @ParameterizedTest + @ParameterizedTest(name = "should write UTF-8 CString across buffers. BufferProvider={0}") @MethodSource("com.mongodb.internal.connection.ByteBufferBsonOutputTest#bufferProviders") void shouldWriteCStringAcrossBuffersUTF8(final BufferProvider bufferProvider) throws IOException { for (Integer codePoint : ALL_CODE_POINTS_EXCLUDING_SURROGATES) { @@ -1107,7 +1154,7 @@ void shouldWriteCStringAcrossBuffersUTF8(final BufferProvider bufferProvider) th } @DisplayName("should write UTF-8 CString across buffers with a branch") - @ParameterizedTest + @ParameterizedTest(name = "should write UTF-8 CString across buffers with a branch. BufferProvider={0}") @MethodSource("com.mongodb.internal.connection.ByteBufferBsonOutputTest#bufferProviders") void shouldWriteCStringAcrossBuffersUTF8WithBranch(final BufferProvider bufferProvider) throws IOException { for (Integer codePoint : ALL_CODE_POINTS_EXCLUDING_SURROGATES) { @@ -1120,7 +1167,7 @@ void shouldWriteCStringAcrossBuffersUTF8WithBranch(final BufferProvider bufferPr } @DisplayName("should write UTF-8 String across buffers") - @ParameterizedTest + @ParameterizedTest(name = "should write UTF-8 String across buffers. BufferProvider={0}") @MethodSource("com.mongodb.internal.connection.ByteBufferBsonOutputTest#bufferProviders") void shouldWriteStringAcrossBuffersUTF8(final BufferProvider bufferProvider) throws IOException { for (Integer codePoint : ALL_CODE_POINTS_EXCLUDING_SURROGATES) { @@ -1138,7 +1185,7 @@ void shouldWriteStringAcrossBuffersUTF8(final BufferProvider bufferProvider) thr } @DisplayName("should write UTF-8 String across buffers with branch") - @ParameterizedTest + @ParameterizedTest(name = "should write UTF-8 String across buffers with branch. BufferProvider={0}") @MethodSource("com.mongodb.internal.connection.ByteBufferBsonOutputTest#bufferProviders") void shouldWriteStringAcrossBuffersUTF8WithBranch(final BufferProvider bufferProvider) throws IOException { for (Integer codePoint : ALL_CODE_POINTS_EXCLUDING_SURROGATES) { @@ -1161,7 +1208,7 @@ void shouldWriteStringAcrossBuffersUTF8WithBranch(final BufferProvider bufferPro Ticket: JAVA-5575 */ @DisplayName("should write malformed surrogate CString across buffers") - @ParameterizedTest + @ParameterizedTest(name = "should write malformed surrogate CString across buffers. BufferProvider={0}") @MethodSource("com.mongodb.internal.connection.ByteBufferBsonOutputTest#bufferProviders") void shouldWriteCStringWithMalformedSurrogates(final BufferProvider bufferProvider) throws IOException { for (Integer surrogateCodePoint : ALL_SURROGATE_CODE_POINTS) { @@ -1188,7 +1235,7 @@ void shouldWriteCStringWithMalformedSurrogates(final BufferProvider bufferProvid Ticket: JAVA-5575 */ @DisplayName("should write malformed surrogate CString across buffers with branch") - @ParameterizedTest + @ParameterizedTest(name = "should write malformed surrogate CString across buffers with branch. BufferProvider={0}") @MethodSource("com.mongodb.internal.connection.ByteBufferBsonOutputTest#bufferProviders") void shouldWriteCStringWithMalformedSurrogatesWithBranch(final BufferProvider bufferProvider) throws IOException { for (Integer surrogateCodePoint : ALL_SURROGATE_CODE_POINTS) { @@ -1210,7 +1257,7 @@ void shouldWriteCStringWithMalformedSurrogatesWithBranch(final BufferProvider bu } @DisplayName("should write surrogate CString across buffers") - @ParameterizedTest + @ParameterizedTest(name = "should write surrogate CString across buffers. BufferProvider={0}") @MethodSource("com.mongodb.internal.connection.ByteBufferBsonOutputTest#bufferProviders") void shouldWriteCStringWithSurrogatePairs(final BufferProvider bufferProvider) throws IOException { for (Integer surrogateCodePoint : ALL_UTF_16_CODE_POINTS_FORMED_BY_SURROGATE_PAIRS) { @@ -1228,7 +1275,7 @@ void shouldWriteCStringWithSurrogatePairs(final BufferProvider bufferProvider) t } @DisplayName("should write surrogate CString across buffers with branch") - @ParameterizedTest + @ParameterizedTest(name = "should write surrogate CString across buffers with branch. BufferProvider={0}") @MethodSource("com.mongodb.internal.connection.ByteBufferBsonOutputTest#bufferProviders") void shouldWriteCStringWithSurrogatePairsWithBranch(final BufferProvider bufferProvider) throws IOException { for (Integer surrogateCodePoint : ALL_UTF_16_CODE_POINTS_FORMED_BY_SURROGATE_PAIRS) { @@ -1246,7 +1293,7 @@ void shouldWriteCStringWithSurrogatePairsWithBranch(final BufferProvider bufferP } @DisplayName("should write surrogate String across buffers") - @ParameterizedTest + @ParameterizedTest(name = "should write surrogate String across buffers. BufferProvider={0}") @MethodSource("com.mongodb.internal.connection.ByteBufferBsonOutputTest#bufferProviders") void shouldWriteStringWithSurrogatePairs(final BufferProvider bufferProvider) throws IOException { for (Integer surrogateCodePoint : ALL_UTF_16_CODE_POINTS_FORMED_BY_SURROGATE_PAIRS) { @@ -1264,7 +1311,7 @@ void shouldWriteStringWithSurrogatePairs(final BufferProvider bufferProvider) th } @DisplayName("should write surrogate String across buffers with branch") - @ParameterizedTest + @ParameterizedTest(name = "should write surrogate String across buffers with branch. BufferProvider={0}") @MethodSource("com.mongodb.internal.connection.ByteBufferBsonOutputTest#bufferProviders") void shouldWriteStringWithSurrogatePairsWithBranch(final BufferProvider bufferProvider) throws IOException { for (Integer surrogateCodePoint : ALL_UTF_16_CODE_POINTS_FORMED_BY_SURROGATE_PAIRS) { @@ -1287,7 +1334,7 @@ void shouldWriteStringWithSurrogatePairsWithBranch(final BufferProvider bufferPr Ticket: JAVA-5575 */ @DisplayName("should write malformed surrogate String across buffers") - @ParameterizedTest + @ParameterizedTest(name = "should write malformed surrogate String across buffers. BufferProvider={0}") @MethodSource("com.mongodb.internal.connection.ByteBufferBsonOutputTest#bufferProviders") void shouldWriteStringWithMalformedSurrogates(final BufferProvider bufferProvider) throws IOException { for (Integer surrogateCodePoint : ALL_SURROGATE_CODE_POINTS) { @@ -1314,7 +1361,7 @@ void shouldWriteStringWithMalformedSurrogates(final BufferProvider bufferProvide Ticket: JAVA-5575 */ @DisplayName("should write malformed surrogate String across buffers with branch") - @ParameterizedTest + @ParameterizedTest(name = "should write malformed surrogate String across buffers with branch. BufferProvider={0}") @MethodSource("com.mongodb.internal.connection.ByteBufferBsonOutputTest#bufferProviders") void shouldWriteStringWithMalformedSurrogatesWithBranch(final BufferProvider bufferProvider) throws IOException { for (Integer surrogateCodePoint : ALL_SURROGATE_CODE_POINTS) { From 16e12f5748804e599e9583ed07e961c1ec48f597 Mon Sep 17 00:00:00 2001 From: "slav.babanin" Date: Tue, 17 Jun 2025 15:54:19 -0700 Subject: [PATCH 2/5] Adjust code point filtering in tests. --- .../mongodb/internal/connection/ByteBufferBsonInputTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver-core/src/test/unit/com/mongodb/internal/connection/ByteBufferBsonInputTest.java b/driver-core/src/test/unit/com/mongodb/internal/connection/ByteBufferBsonInputTest.java index 0846f7a54f1..2171bc5bba3 100644 --- a/driver-core/src/test/unit/com/mongodb/internal/connection/ByteBufferBsonInputTest.java +++ b/driver-core/src/test/unit/com/mongodb/internal/connection/ByteBufferBsonInputTest.java @@ -54,7 +54,7 @@ class ByteBufferBsonInputTest { private static final List 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 bufferProviders() { From 3aa864e0b58614bcaacc6e875ddd096147e65bc3 Mon Sep 17 00:00:00 2001 From: "slav.babanin" Date: Tue, 17 Jun 2025 16:38:09 -0700 Subject: [PATCH 3/5] Refactor ByteBufferBsonInputTest to enhance test clarity. --- .../connection/ByteBufferBsonInputTest.java | 121 +++++++++++------- 1 file changed, 76 insertions(+), 45 deletions(-) diff --git a/driver-core/src/test/unit/com/mongodb/internal/connection/ByteBufferBsonInputTest.java b/driver-core/src/test/unit/com/mongodb/internal/connection/ByteBufferBsonInputTest.java index 2171bc5bba3..ccb62b5697a 100644 --- a/driver-core/src/test/unit/com/mongodb/internal/connection/ByteBufferBsonInputTest.java +++ b/driver-core/src/test/unit/com/mongodb/internal/connection/ByteBufferBsonInputTest.java @@ -59,32 +59,63 @@ class ByteBufferBsonInputTest { static Stream 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, 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 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 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 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}") @MethodSource("bufferProviders") void shouldReadSkipCStringWhenMultipleNullTerminationPresentWithinBuffer(final BufferProvider bufferProvider) { // given From ade2870e708fa08a420897679a62c4a3b9a99545 Mon Sep 17 00:00:00 2001 From: "slav.babanin" Date: Tue, 17 Jun 2025 17:06:15 -0700 Subject: [PATCH 4/5] Fix checkstyle. --- .../connection/ByteBufferBsonInputTest.java | 2 +- .../connection/ByteBufferBsonOutputTest.java | 32 +++++++++---------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/driver-core/src/test/unit/com/mongodb/internal/connection/ByteBufferBsonInputTest.java b/driver-core/src/test/unit/com/mongodb/internal/connection/ByteBufferBsonInputTest.java index ccb62b5697a..ff0de04cd41 100644 --- a/driver-core/src/test/unit/com/mongodb/internal/connection/ByteBufferBsonInputTest.java +++ b/driver-core/src/test/unit/com/mongodb/internal/connection/ByteBufferBsonInputTest.java @@ -101,7 +101,7 @@ public int arrayOffset() { ); } - private static BufferProvider createBufferProvider(final String bufferName, BufferProvider bufferProvider) { + private static BufferProvider createBufferProvider(final String bufferName, final BufferProvider bufferProvider) { return new BufferProvider() { @Override public ByteBuf getBuffer(final int size) { diff --git a/driver-core/src/test/unit/com/mongodb/internal/connection/ByteBufferBsonOutputTest.java b/driver-core/src/test/unit/com/mongodb/internal/connection/ByteBufferBsonOutputTest.java index 330a430c96a..b1a21a94275 100644 --- a/driver-core/src/test/unit/com/mongodb/internal/connection/ByteBufferBsonOutputTest.java +++ b/driver-core/src/test/unit/com/mongodb/internal/connection/ByteBufferBsonOutputTest.java @@ -128,7 +128,7 @@ public int arrayOffset() { ); } - private static BufferProvider createBufferProvider(final String bufferName, BufferProvider bufferProvider) { + private static BufferProvider createBufferProvider(final String bufferName, final BufferProvider bufferProvider) { return new BufferProvider() { @Override public ByteBuf getBuffer(final int size) { @@ -555,8 +555,8 @@ public static Stream writeInt32AtPositionShouldThrowWithInvalidPositi } @DisplayName("write Int32 at position should throw with invalid position") - @ParameterizedTest(name = "write Int32 at position should throw with invalid position. " + - "Parameters: useBranch={0}, position={1}, bufferProvider={2}") + @ParameterizedTest(name = "write Int32 at position should throw with invalid position. " + + "Parameters: useBranch={0}, position={1}, bufferProvider={2}") @MethodSource void writeInt32AtPositionShouldThrowWithInvalidPosition(final boolean useBranch, final int position, final BufferProvider bufferProvider) { @@ -624,8 +624,8 @@ public static Stream truncateShouldThrowWithInvalidPosition() { } @DisplayName("truncate should throw with invalid position") - @ParameterizedTest(name = "truncate should throw with invalid position. " + - "Parameters: useBranch={0}, position={1}") + @ParameterizedTest(name = "truncate should throw with invalid position. " + + "Parameters: useBranch={0}, position={1}") @MethodSource void truncateShouldThrowWithInvalidPosition(final boolean useBranch, final int position) { try (ByteBufferBsonOutput out = new ByteBufferBsonOutput(new SimpleBufferProvider())) { @@ -877,8 +877,8 @@ static Stream shouldWriteInt32AbsoluteValueWithinSpanningBuffers() { ))); } - @ParameterizedTest(name = "should write Int32 absolute value within spanning buffers. " + - "Parameters: absolutePosition={0}, intValue={1}, initialData={2}, expectedBuffers={3}, bufferProvider={4}") + @ParameterizedTest(name = "should write Int32 absolute value within spanning buffers. " + + "Parameters: absolutePosition={0}, intValue={1}, initialData={2}, expectedBuffers={3}, bufferProvider={4}") @MethodSource void shouldWriteInt32AbsoluteValueWithinSpanningBuffers( final int absolutePosition, @@ -1005,9 +1005,9 @@ static Stream int64SpanningBuffersData() { ))); } - @ParameterizedTest(name = "should write Int32 within spanning buffers. " + - "Parameters: intValue={0}, initialData={1}, expectedBuffers={2}, expectedOutputPosition={3}, " + - "expectedLastBufferPosition={4}, bufferProvider={5}") + @ParameterizedTest(name = "should write Int32 within spanning buffers. " + + "Parameters: intValue={0}, initialData={1}, expectedBuffers={2}, expectedOutputPosition={3}, " + + "expectedLastBufferPosition={4}, bufferProvider={5}") @MethodSource("int32SpanningBuffersData") void shouldWriteInt32WithinSpanningBuffers( final int intValue, @@ -1037,9 +1037,9 @@ void shouldWriteInt32WithinSpanningBuffers( } } - @ParameterizedTest(name = "should write Int64 within spanning buffers. " + - "Parameters: intValue={0}, initialData={1}, expectedBuffers={2}, expectedOutputPosition={3}, " + - "expectedLastBufferPosition={4}, bufferProvider={5}") + @ParameterizedTest(name = "should write Int64 within spanning buffers. " + + "Parameters: intValue={0}, initialData={1}, expectedBuffers={2}, expectedOutputPosition={3}, " + + "expectedLastBufferPosition={4}, bufferProvider={5}") @MethodSource("int64SpanningBuffersData") void shouldWriteInt64WithinSpanningBuffers( final long intValue, @@ -1069,9 +1069,9 @@ void shouldWriteInt64WithinSpanningBuffers( } } - @ParameterizedTest(name = "should write double within spanning buffers. " + - "Parameters: intValue={0}, initialData={1}, expectedBuffers={2}, expectedOutputPosition={3}, " + - "expectedLastBufferPosition={4}, bufferProvider={5}") + @ParameterizedTest(name = "should write double within spanning buffers. " + + "Parameters: intValue={0}, initialData={1}, expectedBuffers={2}, expectedOutputPosition={3}, " + + "expectedLastBufferPosition={4}, bufferProvider={5}") @MethodSource("int64SpanningBuffersData") void shouldWriteDoubleWithinSpanningBuffers( final long intValue, From b28e02bbc77fcc930e5a5d74f35ed546441e7e12 Mon Sep 17 00:00:00 2001 From: "slav.babanin" Date: Wed, 2 Jul 2025 10:05:33 -0700 Subject: [PATCH 5/5] Change parameter and test names. --- .../connection/ByteBufferBsonInputTest.java | 14 +++++++------- .../connection/ByteBufferBsonOutputTest.java | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/driver-core/src/test/unit/com/mongodb/internal/connection/ByteBufferBsonInputTest.java b/driver-core/src/test/unit/com/mongodb/internal/connection/ByteBufferBsonInputTest.java index ff0de04cd41..b988f1cde1a 100644 --- a/driver-core/src/test/unit/com/mongodb/internal/connection/ByteBufferBsonInputTest.java +++ b/driver-core/src/test/unit/com/mongodb/internal/connection/ByteBufferBsonInputTest.java @@ -101,7 +101,7 @@ public int arrayOffset() { ); } - private static BufferProvider createBufferProvider(final String bufferName, final BufferProvider bufferProvider) { + private static BufferProvider createBufferProvider(final String bufferDescription, final BufferProvider bufferProvider) { return new BufferProvider() { @Override public ByteBuf getBuffer(final int size) { @@ -110,7 +110,7 @@ public ByteBuf getBuffer(final int size) { @Override public String toString() { - return bufferName; + return bufferDescription; } }; } @@ -659,7 +659,7 @@ void shouldThrowIfLengthOfBsonStringIsNotPositive(final BufferProvider bufferPro } } - public static Stream shouldSkipCStringWhenMultipleNullTerminationPresent() { + public static Stream shouldSkipCStringWhenMultipleNullTerminatorsPresent() { List arguments = new ArrayList<>(); List collect = bufferProviders().collect(toList()); for (BufferProvider bufferProvider : collect) { @@ -675,9 +675,9 @@ public static Stream shouldSkipCStringWhenMultipleNullTerminationPres return arguments.stream(); } - @ParameterizedTest(name = "should skip CString when multiple null termination present. Parameters: cStringBytes={0}, bufferProvider={1}") + @ParameterizedTest(name = "should skip CString when multiple null terminatiors present. Parameters: cStringBytes={0}, bufferProvider={1}") @MethodSource - void shouldSkipCStringWhenMultipleNullTerminationPresent(final byte[] cStringBytes, final BufferProvider bufferProvider) { + void shouldSkipCStringWhenMultipleNullTerminatorsPresent(final byte[] cStringBytes, final BufferProvider bufferProvider) { // given ByteBuf buffer = allocateAndWriteToBuffer(bufferProvider, cStringBytes); try (ByteBufferBsonInput bufferInput = new ByteBufferBsonInput(buffer)) { @@ -691,9 +691,9 @@ void shouldSkipCStringWhenMultipleNullTerminationPresent(final byte[] cStringByt } } - @ParameterizedTest(name = "should read skip CString when multiple null termination present within buffer. BufferProvider={0}") + @ParameterizedTest(name = "should read skip CString when multiple null terminators present within buffer. BufferProvider={0}") @MethodSource("bufferProviders") - void shouldReadSkipCStringWhenMultipleNullTerminationPresentWithinBuffer(final BufferProvider bufferProvider) { + void shouldReadSkipCStringWhenMultipleNullTerminatorPresentWithinBuffer(final BufferProvider bufferProvider) { // given byte[] input = {4, 0, 0, 0, 0x4a, 0x61, 0x76, 0x61, 0, 8, 0, 0, 0}; ByteBuf buffer = allocateAndWriteToBuffer(bufferProvider, input); diff --git a/driver-core/src/test/unit/com/mongodb/internal/connection/ByteBufferBsonOutputTest.java b/driver-core/src/test/unit/com/mongodb/internal/connection/ByteBufferBsonOutputTest.java index b1a21a94275..c54332b0f19 100644 --- a/driver-core/src/test/unit/com/mongodb/internal/connection/ByteBufferBsonOutputTest.java +++ b/driver-core/src/test/unit/com/mongodb/internal/connection/ByteBufferBsonOutputTest.java @@ -128,7 +128,7 @@ public int arrayOffset() { ); } - private static BufferProvider createBufferProvider(final String bufferName, final BufferProvider bufferProvider) { + private static BufferProvider createBufferProvider(final String bufferDescription, final BufferProvider bufferProvider) { return new BufferProvider() { @Override public ByteBuf getBuffer(final int size) { @@ -137,7 +137,7 @@ public ByteBuf getBuffer(final int size) { @Override public String toString() { - return bufferName; + return bufferDescription; } }; }