Files
seaweedfs/test/kafka/metadata_comparison_test.go
T
chrislu aecc020b14 fix: kafka-go writer compatibility and debug cleanup
- Fixed kafka-go writer metadata loop by addressing protocol mismatches:
  * ApiVersions v0: Removed throttle_time field that kafka-go doesn't expect
  * Metadata v1: Removed correlation ID from response body (transport handles it)
  * Metadata v0: Fixed broker ID consistency (node_id=1 matches leader_id=1)
  * Metadata v4+: Implemented AllowAutoTopicCreation flag parsing and auto-creation
  * Produce acks=0: Added minimal success response for kafka-go internal state updates

- Cleaned up debug messages while preserving core functionality
- Verified kafka-go writer works correctly with WriteMessages completing in ~0.15s
- Added comprehensive test coverage for kafka-go client compatibility

The kafka-go writer now works seamlessly with SeaweedFS Kafka Gateway.
2025-09-12 12:50:56 -07:00

47 lines
1.3 KiB
Go

package kafka
import (
"fmt"
"testing"
"time"
"github.com/seaweedfs/seaweedfs/weed/mq/kafka/gateway"
)
func TestMetadataResponseComparison(t *testing.T) {
// Start gateway
gatewayServer := gateway.NewServer(gateway.Options{Listen: "127.0.0.1:0"})
go func() {
if err := gatewayServer.Start(); err != nil {
t.Errorf("Failed to start gateway: %v", err)
}
}()
defer gatewayServer.Close()
time.Sleep(100 * time.Millisecond)
host, port := gatewayServer.GetListenerAddr()
addr := fmt.Sprintf("%s:%d", host, port)
// Add the same topic for both tests
topic := "comparison-topic"
gatewayServer.GetHandler().AddTopicForTesting(topic, 1)
t.Logf("=== COMPARISON TEST ===")
t.Logf("Gateway: %s", addr)
t.Logf("Topic: %s", topic)
// The key insight: Both Sarama and kafka-go should get the SAME metadata response
// But Sarama works and kafka-go doesn't - this suggests kafka-go has stricter validation
// Let's examine what our current Metadata v4 response looks like
t.Logf("Run Sarama test and kafka-go test separately to compare logs")
t.Logf("Look for differences in:")
t.Logf("1. Response byte counts")
t.Logf("2. Broker ID consistency")
t.Logf("3. Partition leader/ISR values")
t.Logf("4. Error codes")
// This test is just for documentation - the real comparison happens in logs
}