public void write(ImageWriter writer, ImageWriterOptions options) {
        for (BrokerRegistration broker : brokers.values()) {
            writer.write(broker.toRecord(options));
        }
        if (!controllers.isEmpty()) {
            if (!options.metadataVersion().isControllerRegistrationSupported()) {
                options.handleLoss("controller registration data");
            } else {
                for (ControllerRegistration controller : controllers.values()) {
                    writer.write(controller.toRecord(options));
                }
            }
        }
    }
@Test
    public void testHandleLossOfControllerRegistrations() {
        ClusterImage testImage = new ClusterImage(Collections.emptyMap(),
            Collections.singletonMap(1000, new ControllerRegistration.Builder().
                setId(1000).
                setIncarnationId(Uuid.fromString("9ABu6HEgRuS-hjHLgC4cHw")).
                setListeners(Collections.singletonMap("PLAINTEXT",
                    new Endpoint("PLAINTEXT", SecurityProtocol.PLAINTEXT, "localhost", 19092))).
                setSupportedFeatures(Collections.emptyMap()).build()));
        RecordListWriter writer = new RecordListWriter();
        final AtomicReference<String> lossString = new AtomicReference<>("");
        testImage.write(writer, new ImageWriterOptions.Builder().
            setMetadataVersion(MetadataVersion.IBP_3_6_IV2).
            setLossHandler(loss -> lossString.compareAndSet("", loss.loss())).
                build());
        assertEquals("controller registration data", lossString.get());
    }