@Test
    public void testConsumerShouldNotCloseOnRetriableError() {
        final TopicIdPartition tpId = getIdPartitions("world", 1).get(0);
        final int metadataPartition = partitioner.metadataPartition(tpId);
        consumer.updateEndOffsets(Collections.singletonMap(toRemoteLogPartition(metadataPartition), 1L));
        consumerTask.addAssignmentsForPartitions(Collections.singleton(tpId));
        consumerTask.ingestRecords();

        assertTrue(consumerTask.isUserPartitionAssigned(tpId), "Partition " + tpId + " has not been assigned");
        assertTrue(consumerTask.isMetadataPartitionAssigned(metadataPartition));

        consumer.setPollException(new LeaderNotAvailableException("Leader not available!"));
        consumerTask.ingestRecords();
        addRecord(consumer, metadataPartition, tpId, 0);
        consumerTask.ingestRecords();
        consumer.setPollException(new TimeoutException("Not able to complete the operation within the timeout"));
        consumerTask.ingestRecords();
        addRecord(consumer, metadataPartition, tpId, 1);
        consumerTask.ingestRecords();

        assertEquals(Optional.of(1L), consumerTask.readOffsetForMetadataPartition(metadataPartition));
        assertEquals(2, handler.metadataCounter);
    }
Tests that the consumer task shuts down gracefully when there were no assignments.
storage/src/test/java/org/apache/kafka/server/log/remote/metadata/storage/ConsumerTaskTest.java