g1geordie commented on a change in pull request #9906: URL: https://github.com/apache/kafka/pull/9906#discussion_r562087677
########## File path: clients/src/test/java/org/apache/kafka/common/record/MemoryRecordsBuilderTest.java ########## @@ -423,30 +455,32 @@ public void buildUsingCreateTime(Args args) { } @ParameterizedTest - @RecordBuilderSource + @ArgumentsSource(NotZstd.class) public void testAppendedChecksumConsistency(Args args) { Review comment: also test it ########## File path: clients/src/test/java/org/apache/kafka/common/record/MemoryRecordsBuilderTest.java ########## @@ -27,112 +27,81 @@ import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.ArgumentsProvider; import org.junit.jupiter.params.provider.ArgumentsSource; -import org.junit.jupiter.params.provider.EnumSource; -import org.junit.jupiter.params.support.AnnotationConsumer; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Random; -import java.util.function.BiPredicate; import java.util.function.Predicate; import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; -import static java.util.Arrays.asList; -import static org.apache.kafka.common.record.RecordBatch.CURRENT_MAGIC_VALUE; -import static org.apache.kafka.common.record.RecordBatch.MAGIC_VALUE_V0; -import static org.apache.kafka.common.record.RecordBatch.MAGIC_VALUE_V1; -import static org.apache.kafka.common.record.RecordBatch.MAGIC_VALUE_V2; import static org.apache.kafka.common.utils.Utils.utf8; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class MemoryRecordsBuilderTest { private static class Args { final int bufferOffset; - final byte magic; final CompressionType compressionType; - public Args(int bufferOffset, byte magic, CompressionType compressionType) { + public Args(int bufferOffset, CompressionType compressionType) { this.bufferOffset = bufferOffset; - this.magic = magic; this.compressionType = compressionType; } @Override public String toString() { - return "Args{" + - "bufferOffset=" + bufferOffset + - ", magic=" + magic + - ", compressionType=" + compressionType + - '}'; + return "bufferOffset=" + bufferOffset + + ", compressionType=" + compressionType; } } - private static Stream<Arguments> allArguments(BiPredicate<Byte, CompressionType> accept) { + private static Stream<Arguments> allArguments(Predicate<CompressionType> accept) { List<Arguments> values = new ArrayList<>(); for (int bufferOffset : Arrays.asList(0, 15)) - for (byte magic : asList(RecordBatch.MAGIC_VALUE_V0, RecordBatch.MAGIC_VALUE_V1, RecordBatch.MAGIC_VALUE_V2)) - for (CompressionType compressionType : CompressionType.values()) - if (accept.test(magic, compressionType)) - values.add(Arguments.of(new Args(bufferOffset, magic, compressionType))); + for (CompressionType compressionType : CompressionType.values()) + if (accept.test(compressionType)) + values.add(Arguments.of(new Args(bufferOffset, compressionType))); return values.stream(); } - private static class MemoryRecordsBuilderArgumentsProvider implements ArgumentsProvider, AnnotationConsumer<RecordBuilderSource> { - - private RecordBuilderSource recordSource; - private BiPredicate<Byte, CompressionType> validCompress = (magic, type) -> type != CompressionType.ZSTD || magic >= MAGIC_VALUE_V2; - + private static class MemoryRecordsBuilderArgumentsProvider implements ArgumentsProvider { @Override public Stream<? extends Arguments> provideArguments(ExtensionContext context) { - Predicate<Byte> predicate = magic -> recordSource.minMagic() <= magic && magic <= recordSource.maxMagic(); - return allArguments((magic, type) -> (recordSource.haveInvalidCompress() || validCompress.test(magic, type)) && predicate.test(magic)); + return allArguments(type -> true); } + } + private static class NotZstd implements ArgumentsProvider { Review comment: have added ########## File path: clients/src/test/java/org/apache/kafka/common/record/MemoryRecordsBuilderTest.java ########## @@ -72,19 +70,28 @@ public String toString() { List<Arguments> values = new ArrayList<>(); for (int bufferOffset : Arrays.asList(0, 15)) for (CompressionType compressionType : CompressionType.values()) - values.add(Arguments.of(new Args(bufferOffset, compressionType))); + if (accept(compressionType)) + values.add(Arguments.of(new Args(bufferOffset, compressionType))); return values.stream(); } + protected boolean accept(CompressionType type) { + return true; + } + } + + private static class NotZstd extends MemoryRecordsBuilderArgumentsProvider { Review comment: haha . Although I have reverted . `haveInvalidCompress= false` => (ZSTD , 2) ...other `haveInvalidCompress= true` => (ZSTD , 0) , (ZSTD , 1) ,(ZSTD , 2) ...other `NotZstd` => ...other Little diff . Never mind me. ---------------------------------------------------------------- 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