opensource4you / astraea

釋放kafka的無限潛能
Apache License 2.0
129 stars 46 forks source link

[SERIALIZATION] Unable to retrieve broker configs from deserialized `ClusterInfo` #1704

Open garyparrot opened 1 year ago

garyparrot commented 1 year ago

ByteUtils.toBytes(ClusterInfo) 似乎沒有序列化到 Broker 的設定

  @Test
  void testSerialization() {
    try (var service = Service.builder()
        .numberOfBrokers(3)
        .brokerConfigs(Map.of(BrokerConfigs.LOG_RETENTION_BYTES_CONFIG, "5566"))
        .build()) {
      try (var admin = Admin.of(service.bootstrapServers())) {
        var clusterInfo = admin.topicNames(false)
            .thenCompose(admin::clusterInfo)
            .toCompletableFuture()
            .join();

        byte[] serialized = ByteUtils.toBytes(clusterInfo);
        ClusterInfo deserialized = ByteUtils.readClusterInfo(serialized);

        Assertions.assertEquals(3, clusterInfo.brokers().size());
        Assertions.assertEquals("5566", clusterInfo.brokers().get(0).config().value(BrokerConfigs.LOG_RETENTION_BYTES_CONFIG).orElseThrow());
        Assertions.assertEquals("5566", clusterInfo.brokers().get(1).config().value(BrokerConfigs.LOG_RETENTION_BYTES_CONFIG).orElseThrow());
        Assertions.assertEquals("5566", clusterInfo.brokers().get(2).config().value(BrokerConfigs.LOG_RETENTION_BYTES_CONFIG).orElseThrow());
        // test failed 
        Assertions.assertEquals(3, deserialized.brokers().size());
        Assertions.assertEquals("5566", deserialized.brokers().get(0).config().value(BrokerConfigs.LOG_RETENTION_BYTES_CONFIG).orElseThrow());
        Assertions.assertEquals("5566", deserialized.brokers().get(1).config().value(BrokerConfigs.LOG_RETENTION_BYTES_CONFIG).orElseThrow());
        Assertions.assertEquals("5566", deserialized.brokers().get(2).config().value(BrokerConfigs.LOG_RETENTION_BYTES_CONFIG).orElseThrow());
      }
    }
  }
chia7712 commented 1 year ago

@garyparrot 你要自己處理嗎?

garyparrot commented 1 year ago

ProtocolBuffer 的部分我不太熟悉要上手可能需要一些時間,然後我還有其他的項目可以處理,可能看有沒有人能幫忙,如果沒有的話時機到了我會再處理。

chia7712 commented 1 year ago

@Haser0305 @chaohengstudent 你們可否協助處理一下?

Haser0305 commented 1 year ago

@Haser0305 @chaohengstudent 你們可否協助處理一下?

好的,沒問題