public static void setOffloadDriverMetadata(LedgerInfo.Builder infoBuilder,
                                                String driverName,
                                                Map<String, String> offloadDriverMetadata) {
        infoBuilder.getOffloadContextBuilder()
            .getDriverMetadataBuilder()
            .setName(driverName);
        infoBuilder.getOffloadContextBuilder().getDriverMetadataBuilder().clearProperties();
        offloadDriverMetadata.forEach((k, v) -> infoBuilder
                .getOffloadContextBuilder()
                .getDriverMetadataBuilder()
                .addProperties(KeyValue.newBuilder()
                        .setKey(k)
                        .setValue(v)
                        .build()));
    }
@Test
    void testOffloadMetadataShouldClearBeforeSet() {
        MLDataFormats.ManagedLedgerInfo.LedgerInfo.Builder builder =
                MLDataFormats.ManagedLedgerInfo.LedgerInfo.newBuilder();
        builder.setLedgerId(1L);

        Map<String, String> map = new HashMap<>();
        map.put("key1", "value1");
        map.put("key2", "value2");

        //only one copy of the offload metadata information is stored in metadata store,
        // and the original properties need to be cleared during offload
        OffloadUtils.setOffloadDriverMetadata(builder, "offload", map);

        OffloadUtils.setOffloadDriverMetadata(builder, "offload", map);

        MLDataFormats.OffloadDriverMetadata offloadDriverMetadata =
                builder.build().getOffloadContext().getDriverMetadata();
        Assert.assertEquals(offloadDriverMetadata.getPropertiesList().size(), 2);

        Assert.assertEquals(offloadDriverMetadata.getProperties(0).getKey(), "key1");
        Assert.assertEquals(offloadDriverMetadata.getProperties(1).getKey(), "key2");
        Assert.assertEquals(offloadDriverMetadata.getProperties(0).getValue(), "value1");
        Assert.assertEquals(offloadDriverMetadata.getProperties(1).getValue(), "value2");
    }