Fix Kafka listeners and advertised listeners config to come out of sync by ThomasKasene · Pull Request #11068 · testcontainers/testcontainers-java

KafkaContainer and ConfluentKafkaContainer both have a pair of HashSet properties: listeners and advertisedListeners. At some point, these are being fed into KafkaHelper.resolveListeners(GenericContainer<?>, Set<String>) and KafkaHelper.resolveAdvertisedListeners(Set<Supplier<String>>) to help generate values for KAFKA_LISTENERS and KAFKA_ADVERTISED_LISTENERS, respectively. Each registered listener will get assigned the protocol TC-<X> where <X> essentially is the index position of the listener in each HashSet, but since HashSet doesn't guarantee any such order, a listener might be registered as TC-0 in the KAFKA_LISTENERS env variable and as TC-1 in KAFKA_ADVERTISED_LISTENERS.

The least intrusive solution I could think of was to replace HashSet with LinkedHashSet, which does guarantee insertion order, and should therefore work better with the way the KafkaHelper methods are designed.