@Override
        public long append(
            TopicPartition tp,
            VerificationGuard verificationGuard,
            MemoryRecords batch
        ) {
            if (batch.sizeInBytes() > config(tp).maxMessageSize())
                throw new RecordTooLargeException("Batch is larger than the max message size");

            if (writeCount.incrementAndGet() > maxWrites)
                throw new KafkaException("Maximum number of writes reached");

            if (failEndMarker && batch.firstBatch().isControlBatch())
                throw new KafkaException("Couldn't write end marker.");

            return super.append(tp, verificationGuard, batch);
        }
An in-memory partition writer that accepts a maximum number of writes.
group-coordinator/src/test/java/org/apache/kafka/coordinator/group/runtime/CoordinatorRuntimeTest.java