MCPcopy
hub / github.com/segmentio/kafka-go / makeTestDuplicateSequence

Function makeTestDuplicateSequence

reader_test.go:1884–1920  ·  view source on GitHub ↗

makeTestDuplicateSequence creates messages for compacted log testing All keys and values are 4 characters long to tightly control how many messages are per log segment.

()

Source from the content-addressed store, hash-verified

1882// All keys and values are 4 characters long to tightly control how many
1883// messages are per log segment.
1884func makeTestDuplicateSequence() []Message {
1885 var msgs []Message
1886 // `n` is an increasing counter so it is never compacted.
1887 n := 0
1888 // `i` determines how many compacted records to create
1889 for i := 0; i < 5; i++ {
1890 // `j` is how many times the current pattern repeats. We repeat because
1891 // as long as we have a pattern that is slightly larger/smaller than
1892 // the log segment size then if we repeat enough it will eventually
1893 // try all configurations.
1894 for j := 0; j < 30; j++ {
1895 msgs = append(msgs, Message{
1896 Key: []byte(fmt.Sprintf("%04d", n)),
1897 Value: []byte(fmt.Sprintf("%04d", n)),
1898 })
1899 n++
1900
1901 // This produces the duplicated messages to compact.
1902 for k := 0; k < i; k++ {
1903 msgs = append(msgs, Message{
1904 Key: []byte("dup_"),
1905 Value: []byte("dup_"),
1906 })
1907 }
1908 }
1909 }
1910
1911 // "end markers" to force duplicate message outside of the last segment of
1912 // the log so that they can all be compacted.
1913 for i := 0; i < 10; i++ {
1914 msgs = append(msgs, Message{
1915 Key: []byte(fmt.Sprintf("e-%02d", i)),
1916 Value: []byte(fmt.Sprintf("e-%02d", i)),
1917 })
1918 }
1919 return msgs
1920}
1921
1922// countKeys counts unique keys from given Message slice.
1923func countKeys(msgs []Message) int {

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected