@Test
    public void testBuildEndTxnMarker() {
        long producerId = 73;
        short producerEpoch = 13;
        long initialOffset = 983L;
        int coordinatorEpoch = 347;
        int partitionLeaderEpoch = 29;

        EndTransactionMarker marker = new EndTransactionMarker(ControlRecordType.COMMIT, coordinatorEpoch);
        MemoryRecords records = MemoryRecords.withEndTransactionMarker(initialOffset, System.currentTimeMillis(),
                partitionLeaderEpoch, producerId, producerEpoch, marker);
        // verify that buffer allocation was precise
        assertEquals(records.buffer().remaining(), records.buffer().capacity());

        List<MutableRecordBatch> batches = TestUtils.toList(records.batches());
        assertEquals(1, batches.size());

        RecordBatch batch = batches.get(0);
        assertTrue(batch.isControlBatch());
        assertEquals(producerId, batch.producerId());
        assertEquals(producerEpoch, batch.producerEpoch());
        assertEquals(initialOffset, batch.baseOffset());
        assertEquals(partitionLeaderEpoch, batch.partitionLeaderEpoch());
        assertTrue(batch.isValid());

        List<Record> createdRecords = TestUtils.toList(batch);
        assertEquals(1, createdRecords.size());

        Record record = createdRecords.get(0);
        record.ensureValid();
        EndTransactionMarker deserializedMarker = EndTransactionMarker.deserialize(record);
        assertEquals(ControlRecordType.COMMIT, deserializedMarker.controlType());
        assertEquals(coordinatorEpoch, deserializedMarker.coordinatorEpoch());
    }
This test verifies that the checksum returned for various versions matches hardcoded values to catch unintentional
changes to how the checksum is computed.
clients/src/test/java/org/apache/kafka/common/record/MemoryRecordsTest.java