Skip to content

Commit

Permalink
sstable: extract formatWriterMetadata test helper
Browse files Browse the repository at this point in the history
Extract logic to format the WriterMetadata in sstable unit tests into a common
test helper.
  • Loading branch information
jbowens committed Aug 1, 2024
1 parent a466dad commit 62cd2a2
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 117 deletions.
6 changes: 1 addition & 5 deletions sstable/block_property_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1262,11 +1262,7 @@ func runBlockPropertiesBuildCmd(td *datadriven.TestData) (r *Reader, out string)
if err != nil {
return r, err.Error()
}
return r, fmt.Sprintf("point: [%s,%s]\nrangedel: [%s,%s]\nrangekey: [%s,%s]\nseqnums: [%d,%d]\n",
meta.SmallestPoint, meta.LargestPoint,
meta.SmallestRangeDel, meta.LargestRangeDel,
meta.SmallestRangeKey, meta.LargestRangeKey,
meta.SmallestSeqNum, meta.LargestSeqNum)
return r, formatWriterMetadata(td, meta)
}

func runBlockPropsCmd(r *Reader, td *datadriven.TestData) string {
Expand Down
17 changes: 1 addition & 16 deletions sstable/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,21 +227,6 @@ func runVirtualReaderTest(t *testing.T, path string, blockSize, indexBlockSize i
}
}()

formatWMeta := func(m *WriterMetadata) string {
var b bytes.Buffer
if m.HasPointKeys {
fmt.Fprintf(&b, "point: [%s-%s]\n", m.SmallestPoint, m.LargestPoint)
}
if m.HasRangeDelKeys {
fmt.Fprintf(&b, "rangedel: [%s-%s]\n", m.SmallestRangeDel, m.LargestRangeDel)
}
if m.HasRangeKeys {
fmt.Fprintf(&b, "rangekey: [%s-%s]\n", m.SmallestRangeKey, m.LargestRangeKey)
}
fmt.Fprintf(&b, "seqnums: [%d-%d]\n", m.SmallestSeqNum, m.LargestSeqNum)
return b.String()
}

formatVirtualReader := func(v *VirtualReader, showProps bool) string {
var b bytes.Buffer
fmt.Fprintf(&b, "bounds: [%s-%s]\n", v.vState.lower, v.vState.upper)
Expand Down Expand Up @@ -279,7 +264,7 @@ func runVirtualReaderTest(t *testing.T, path string, blockSize, indexBlockSize i
return err.Error()
}
bp.Init(5)
return formatWMeta(wMeta)
return formatWriterMetadata(td, wMeta)

case "virtualize":
// virtualize will split the previously built physical sstable into
Expand Down
82 changes: 30 additions & 52 deletions sstable/testdata/block_properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ a.SET.1:10
b.SET.2:20
c.SET.3:30
----
point: [a#1,SET,c#3,SET]
rangedel: [#0,DEL,#0,DEL]
rangekey: [#0,DEL,#0,DEL]
seqnums: [1,3]
point: [a#1,SET-c#3,SET]
seqnums: [1-3]

# collectors returns the collectors used when writing the table, keyed by the
# shortID of the collector.
Expand All @@ -43,10 +41,8 @@ a.SET.1:17
b.SET.2:29
c.SET.3:38
----
point: [a#1,SET,c#3,SET]
rangedel: [#0,DEL,#0,DEL]
rangekey: [#0,DEL,#0,DEL]
seqnums: [1,3]
point: [a#1,SET-c#3,SET]
seqnums: [1-3]

collectors
----
Expand Down Expand Up @@ -77,10 +73,8 @@ f.SET.6:54
g.SET.7:63
h.SET.8:38
----
point: [a#1,SET,h#8,SET]
rangedel: [#0,DEL,#0,DEL]
rangekey: [#0,DEL,#0,DEL]
seqnums: [1,8]
point: [a#1,SET-h#8,SET]
seqnums: [1-8]

collectors
----
Expand Down Expand Up @@ -118,10 +112,9 @@ rangekey: d@10-e@15:{(#4,RANGEKEYSET,@20,foo)}
rangekey: e@15-f@20:{(#5,RANGEKEYUNSET,@25)}
rangekey: f@20-z@25:{(#6,RANGEKEYDEL)}
----
point: [a@5#1,SET,c@15#3,SET]
rangedel: [#0,DEL,#0,DEL]
rangekey: [d@10#4,RANGEKEYSET,z@25#inf,RANGEKEYDEL]
seqnums: [1,6]
point: [a@5#1,SET-c@15#3,SET]
rangekey: [d@10#4,RANGEKEYSET-z@25#inf,RANGEKEYDEL]
seqnums: [1-6]

collectors
----
Expand All @@ -146,10 +139,9 @@ rangekey: d@10-e@15:{(#4,RANGEKEYSET,@20,foo)}
rangekey: e@15-f@20:{(#5,RANGEKEYUNSET,@25)}
rangekey: f@20-z@25:{(#6,RANGEKEYDEL)}
----
point: [a@5#1,SET,c@15#3,SET]
rangedel: [#0,DEL,#0,DEL]
rangekey: [d@10#4,RANGEKEYSET,z@25#inf,RANGEKEYDEL]
seqnums: [1,6]
point: [a@5#1,SET-c@15#3,SET]
rangekey: [d@10#4,RANGEKEYSET-z@25#inf,RANGEKEYDEL]
seqnums: [1-6]

collectors
----
Expand All @@ -174,10 +166,9 @@ rangekey: d@10-e@15:{(#4,RANGEKEYSET,@20,foo)}
rangekey: e@15-f@20:{(#5,RANGEKEYUNSET,@25)}
rangekey: f@20-z@25:{(#6,RANGEKEYDEL)}
----
point: [a@5#1,SET,c@15#3,SET]
rangedel: [#0,DEL,#0,DEL]
rangekey: [d@10#4,RANGEKEYSET,z@25#inf,RANGEKEYDEL]
seqnums: [1,6]
point: [a@5#1,SET-c@15#3,SET]
rangekey: [d@10#4,RANGEKEYSET-z@25#inf,RANGEKEYDEL]
seqnums: [1-6]

collectors
----
Expand All @@ -203,10 +194,9 @@ rangekey: d@10-e@15:{(#4,RANGEKEYSET,@20,foo)}
rangekey: e@15-f@20:{(#5,RANGEKEYUNSET,@25)}
rangekey: f@20-z@25:{(#6,RANGEKEYDEL)}
----
point: [a@5#1,SET,c@15#3,SET]
rangedel: [#0,DEL,#0,DEL]
rangekey: [d@10#4,RANGEKEYSET,z@25#inf,RANGEKEYDEL]
seqnums: [1,6]
point: [a@5#1,SET-c@15#3,SET]
rangekey: [d@10#4,RANGEKEYSET-z@25#inf,RANGEKEYDEL]
seqnums: [1-6]

collectors
----
Expand Down Expand Up @@ -300,10 +290,8 @@ [email protected]:bax
[email protected]:box
[email protected]:mop
----
point: [a@1#1,SET,f@5#3,SET]
rangedel: [#0,DEL,#0,DEL]
rangekey: [#0,DEL,#0,DEL]
seqnums: [1,5]
point: [a@1#1,SET-f@5#3,SET]
seqnums: [1-5]

collectors
----
Expand Down Expand Up @@ -356,10 +344,8 @@ [email protected]:bax
[email protected]:box
[email protected]:mop
----
point: [a@1#1,SET,f@5#3,SET]
rangedel: [#0,DEL,#0,DEL]
rangekey: [#0,DEL,#0,DEL]
seqnums: [1,5]
point: [a@1#1,SET-f@5#3,SET]
seqnums: [1-5]

collectors
----
Expand Down Expand Up @@ -406,10 +392,8 @@ [email protected]:bax
[email protected]:box
[email protected]:mop
----
point: [a@1#1,SET,f@5#3,SET]
rangedel: [#0,DEL,#0,DEL]
rangekey: [#0,DEL,#0,DEL]
seqnums: [1,5]
point: [a@1#1,SET-f@5#3,SET]
seqnums: [1-5]

block-props
----
Expand Down Expand Up @@ -604,10 +588,8 @@ [email protected]:bax
[email protected]:box
[email protected]:mop
----
point: [a@1#1,SET,f@5#3,SET]
rangedel: [#0,DEL,#0,DEL]
rangekey: [#0,DEL,#0,DEL]
seqnums: [1,5]
point: [a@1#1,SET-f@5#3,SET]
seqnums: [1-5]

block-props
----
Expand Down Expand Up @@ -645,10 +627,8 @@ [email protected]:bax
[email protected]:box
[email protected]:mop
----
point: [a@1#1,SET,f@5#3,SET]
rangedel: [#0,DEL,#0,DEL]
rangekey: [#0,DEL,#0,DEL]
seqnums: [1,5]
point: [a@1#1,SET-f@5#3,SET]
seqnums: [1-5]

block-props
----
Expand Down Expand Up @@ -678,10 +658,8 @@ [email protected]:foo
[email protected]:bar
[email protected]:baz
----
point: [a@5#1,SET,c@7#3,SET]
rangedel: [#0,DEL,#0,DEL]
rangekey: [#0,DEL,#0,DEL]
seqnums: [1,3]
point: [a@5#1,SET-c@7#3,SET]
seqnums: [1-3]

collectors
----
Expand Down
6 changes: 2 additions & 4 deletions sstable/testdata/block_properties_boundlimited
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ [email protected]:54
[email protected]:63
[email protected]:38
----
point: [a@5#1,SET,h@3#8,SET]
rangedel: [#0,DEL,#0,DEL]
rangekey: [#0,DEL,#0,DEL]
seqnums: [1,8]
point: [a@5#1,SET-h@3#8,SET]
seqnums: [1-8]

collectors
----
Expand Down
1 change: 0 additions & 1 deletion sstable/testdata/writer
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ point: [a#1,SET-h#8,SINGLEDEL]
rangekey: [j#9,RANGEKEYDEL-m#inf,RANGEKEYSET]
seqnums: [1-11]
props "deletions":
rocksdb.num.range-deletions: 0
props "deleted":
rocksdb.deleted.keys: 5

Expand Down
77 changes: 38 additions & 39 deletions sstable/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,41 @@ func TestRewriterParallel(t *testing.T) {
testRewriterParallelism(t, true)
}

func formatWriterMetadata(td *datadriven.TestData, m *WriterMetadata) string {
var requestedProps []string
for _, cmdArg := range td.CmdArgs {
switch cmdArg.Key {
case "props":
requestedProps = cmdArg.Vals
}
}

var b bytes.Buffer
if m.HasPointKeys {
fmt.Fprintf(&b, "point: [%s-%s]\n", m.SmallestPoint, m.LargestPoint)
}
if m.HasRangeDelKeys {
fmt.Fprintf(&b, "rangedel: [%s-%s]\n", m.SmallestRangeDel, m.LargestRangeDel)
}
if m.HasRangeKeys {
fmt.Fprintf(&b, "rangekey: [%s-%s]\n", m.SmallestRangeKey, m.LargestRangeKey)
}
fmt.Fprintf(&b, "seqnums: [%d-%d]\n", m.SmallestSeqNum, m.LargestSeqNum)

if len(requestedProps) > 0 {
props := strings.Split(m.Properties.String(), "\n")
for _, requestedProp := range requestedProps {
fmt.Fprintf(&b, "props %q:\n", requestedProp)
for _, prop := range props {
if strings.Contains(prop, requestedProp) {
fmt.Fprintf(&b, " %s\n", prop)
}
}
}
}
return b.String()
}

func runDataDriven(t *testing.T, file string, tableFormat TableFormat, parallelism bool) {
var r *Reader
defer func() {
Expand All @@ -80,42 +115,6 @@ func runDataDriven(t *testing.T, file string, tableFormat TableFormat, paralleli
}
}()

format := func(td *datadriven.TestData, m *WriterMetadata) string {
var requestedProps []string
for _, cmdArg := range td.CmdArgs {
switch cmdArg.Key {
case "props":
requestedProps = cmdArg.Vals
}
}

var b bytes.Buffer
if m.HasPointKeys {
fmt.Fprintf(&b, "point: [%s-%s]\n", m.SmallestPoint, m.LargestPoint)
}
if m.HasRangeDelKeys {
fmt.Fprintf(&b, "rangedel: [%s-%s]\n", m.SmallestRangeDel, m.LargestRangeDel)
}
if m.HasRangeKeys {
fmt.Fprintf(&b, "rangekey: [%s-%s]\n", m.SmallestRangeKey, m.LargestRangeKey)
}
fmt.Fprintf(&b, "seqnums: [%d-%d]\n", m.SmallestSeqNum, m.LargestSeqNum)

if len(requestedProps) > 0 {
props := strings.Split(r.Properties.String(), "\n")
for _, requestedProp := range requestedProps {
fmt.Fprintf(&b, "props %q:\n", requestedProp)
for _, prop := range props {
if strings.Contains(prop, requestedProp) {
fmt.Fprintf(&b, " %s\n", prop)
}
}
}
}

return b.String()
}

datadriven.RunTest(t, file, func(t *testing.T, td *datadriven.TestData) string {
switch td.Cmd {
case "build":
Expand All @@ -132,7 +131,7 @@ func runDataDriven(t *testing.T, file string, tableFormat TableFormat, paralleli
if err != nil {
return err.Error()
}
return format(td, meta)
return formatWriterMetadata(td, meta)

case "build-raw":
if r != nil {
Expand All @@ -147,7 +146,7 @@ func runDataDriven(t *testing.T, file string, tableFormat TableFormat, paralleli
if err != nil {
return err.Error()
}
return format(td, meta)
return formatWriterMetadata(td, meta)

case "scan":
origIter, err := r.NewIter(NoTransforms, nil /* lower */, nil /* upper */)
Expand Down Expand Up @@ -241,7 +240,7 @@ func runDataDriven(t *testing.T, file string, tableFormat TableFormat, paralleli
if err != nil {
return err.Error()
}
return format(td, meta)
return formatWriterMetadata(td, meta)

default:
return fmt.Sprintf("unknown command: %s", td.Cmd)
Expand Down

0 comments on commit 62cd2a2

Please sign in to comment.