Search in sources :

Example 1 with MAGIC_VALUE_V0

use of org.apache.kafka.common.record.RecordBatch.MAGIC_VALUE_V0 in project kafka by apache.

the class MemoryRecordsTest method testUnsupportedCompress.

@Test
public void testUnsupportedCompress() {
    BiFunction<Byte, CompressionType, MemoryRecords> builderBiFunction = (magic, compressionType) -> MemoryRecords.withRecords(magic, compressionType, new SimpleRecord(10L, "key1".getBytes(), "value1".getBytes()));
    Arrays.asList(MAGIC_VALUE_V0, MAGIC_VALUE_V1).forEach(magic -> {
        Exception e = assertThrows(IllegalArgumentException.class, () -> builderBiFunction.apply(magic, CompressionType.ZSTD));
        assertEquals(e.getMessage(), "ZStandard compression is not supported for magic " + magic);
    });
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) MAGIC_VALUE_V2(org.apache.kafka.common.record.RecordBatch.MAGIC_VALUE_V2) MAGIC_VALUE_V1(org.apache.kafka.common.record.RecordBatch.MAGIC_VALUE_V1) BiFunction(java.util.function.BiFunction) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) MAGIC_VALUE_V0(org.apache.kafka.common.record.RecordBatch.MAGIC_VALUE_V0) Supplier(java.util.function.Supplier) ByteBuffer(java.nio.ByteBuffer) ArrayList(java.util.ArrayList) OptionalLong(java.util.OptionalLong) RecordHeaders(org.apache.kafka.common.header.internals.RecordHeaders) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) BufferSupplier(org.apache.kafka.common.utils.BufferSupplier) RecordFilter(org.apache.kafka.common.record.MemoryRecords.RecordFilter) Arrays.asList(java.util.Arrays.asList) ArgumentsProvider(org.junit.jupiter.params.provider.ArgumentsProvider) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) LeaderChangeMessage(org.apache.kafka.common.message.LeaderChangeMessage) Utils(org.apache.kafka.common.utils.Utils) TopicPartition(org.apache.kafka.common.TopicPartition) TestUtils(org.apache.kafka.test.TestUtils) Voter(org.apache.kafka.common.message.LeaderChangeMessage.Voter) Arguments(org.junit.jupiter.params.provider.Arguments) CloseableIterator(org.apache.kafka.common.utils.CloseableIterator) Test(org.junit.jupiter.api.Test) BatchRetention(org.apache.kafka.common.record.MemoryRecords.RecordFilter.BatchRetention) CorruptRecordException(org.apache.kafka.common.errors.CorruptRecordException) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) List(java.util.List) Stream(java.util.stream.Stream) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource) Collections(java.util.Collections) CorruptRecordException(org.apache.kafka.common.errors.CorruptRecordException) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with MAGIC_VALUE_V0

use of org.apache.kafka.common.record.RecordBatch.MAGIC_VALUE_V0 in project kafka by apache.

the class MemoryRecordsBuilderTest method testUnsupportedCompress.

@Test
public void testUnsupportedCompress() {
    BiFunction<Byte, CompressionType, MemoryRecordsBuilder> builderBiFunction = (magic, compressionType) -> new MemoryRecordsBuilder(ByteBuffer.allocate(128), magic, compressionType, TimestampType.CREATE_TIME, 0L, 0L, RecordBatch.NO_PRODUCER_ID, RecordBatch.NO_PRODUCER_EPOCH, RecordBatch.NO_SEQUENCE, false, false, RecordBatch.NO_PARTITION_LEADER_EPOCH, 128);
    Arrays.asList(MAGIC_VALUE_V0, MAGIC_VALUE_V1).forEach(magic -> {
        Exception e = assertThrows(IllegalArgumentException.class, () -> builderBiFunction.apply(magic, CompressionType.ZSTD));
        assertEquals(e.getMessage(), "ZStandard compression is not supported for magic " + magic);
    });
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) MAGIC_VALUE_V2(org.apache.kafka.common.record.RecordBatch.MAGIC_VALUE_V2) MAGIC_VALUE_V1(org.apache.kafka.common.record.RecordBatch.MAGIC_VALUE_V1) BiFunction(java.util.function.BiFunction) EnumSource(org.junit.jupiter.params.provider.EnumSource) Random(java.util.Random) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) MAGIC_VALUE_V0(org.apache.kafka.common.record.RecordBatch.MAGIC_VALUE_V0) Supplier(java.util.function.Supplier) ByteBuffer(java.nio.ByteBuffer) ArrayList(java.util.ArrayList) OptionalLong(java.util.OptionalLong) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) BufferSupplier(org.apache.kafka.common.utils.BufferSupplier) Arrays.asList(java.util.Arrays.asList) ArgumentsProvider(org.junit.jupiter.params.provider.ArgumentsProvider) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) LeaderChangeMessage(org.apache.kafka.common.message.LeaderChangeMessage) Utils(org.apache.kafka.common.utils.Utils) Time(org.apache.kafka.common.utils.Time) TestUtils(org.apache.kafka.test.TestUtils) Utils.utf8(org.apache.kafka.common.utils.Utils.utf8) Voter(org.apache.kafka.common.message.LeaderChangeMessage.Voter) Arguments(org.junit.jupiter.params.provider.Arguments) Collectors(java.util.stream.Collectors) CloseableIterator(org.apache.kafka.common.utils.CloseableIterator) Test(org.junit.jupiter.api.Test) UnsupportedCompressionTypeException(org.apache.kafka.common.errors.UnsupportedCompressionTypeException) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) List(java.util.List) Stream(java.util.stream.Stream) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ByteBufferOutputStream(org.apache.kafka.common.utils.ByteBufferOutputStream) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource) Collections(java.util.Collections) UnsupportedCompressionTypeException(org.apache.kafka.common.errors.UnsupportedCompressionTypeException) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ByteBuffer (java.nio.ByteBuffer)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Arrays.asList (java.util.Arrays.asList)2 Collections (java.util.Collections)2 List (java.util.List)2 OptionalLong (java.util.OptionalLong)2 BiFunction (java.util.function.BiFunction)2 Supplier (java.util.function.Supplier)2 Stream (java.util.stream.Stream)2 LeaderChangeMessage (org.apache.kafka.common.message.LeaderChangeMessage)2 Voter (org.apache.kafka.common.message.LeaderChangeMessage.Voter)2 MAGIC_VALUE_V0 (org.apache.kafka.common.record.RecordBatch.MAGIC_VALUE_V0)2 MAGIC_VALUE_V1 (org.apache.kafka.common.record.RecordBatch.MAGIC_VALUE_V1)2 MAGIC_VALUE_V2 (org.apache.kafka.common.record.RecordBatch.MAGIC_VALUE_V2)2 BufferSupplier (org.apache.kafka.common.utils.BufferSupplier)2 CloseableIterator (org.apache.kafka.common.utils.CloseableIterator)2 Utils (org.apache.kafka.common.utils.Utils)2 TestUtils (org.apache.kafka.test.TestUtils)2 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)2