-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
storage/metamorphic: add TestCompareFiles
Add a new MVCC metamorphic test entrypoint, TestCompareFiles, that takes a check file through `--check` and one or more output.metas through `--compare-files`. The test runs the configurations specified through `--compare-files` against the specified `--check` file, parsing out the encoded Pebble options. Release note: None Release justification: Non-production code changes
- Loading branch information
Showing
6 changed files
with
517 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// Copyright 2022 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package metamorphic | ||
|
||
import ( | ||
"bufio" | ||
"bytes" | ||
"fmt" | ||
"io" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/storage" | ||
"github.com/cockroachdb/pebble" | ||
"github.com/cockroachdb/pebble/bloom" | ||
) | ||
|
||
// parseOutputPreamble reads the commented preamble of an output.meta file, | ||
// paring out the engine configuration. | ||
func parseOutputPreamble(f io.Reader) (cfg engineConfig, seed int64, err error) { | ||
r := bufio.NewReader(f) | ||
|
||
seed, err = readCommentInt64(r, "seed:") | ||
if err != nil { | ||
return cfg, seed, err | ||
} | ||
cfg.name, err = readCommentString(r, "name:") | ||
if err != nil { | ||
return cfg, seed, err | ||
} | ||
if _, err = readCommentString(r, "engine options:"); err != nil { | ||
return cfg, seed, err | ||
} | ||
|
||
var optsBuf bytes.Buffer | ||
for { | ||
// Read the first byte to check if this line is a comment. | ||
if firstByte, err := r.ReadByte(); err != nil { | ||
if err == io.EOF { | ||
break | ||
} | ||
return cfg, seed, err | ||
} else if firstByte != '#' { | ||
// The end of the comment preamble. | ||
break | ||
} | ||
|
||
b, err := r.ReadBytes('\n') | ||
if err != nil { | ||
if err == io.EOF { | ||
break | ||
} | ||
return cfg, seed, err | ||
} | ||
optsBuf.Write(b) | ||
} | ||
cfg.opts = storage.DefaultPebbleOptions() | ||
err = cfg.opts.Parse(optsBuf.String(), &pebble.ParseHooks{ | ||
NewFilterPolicy: func(name string) (pebble.FilterPolicy, error) { | ||
switch name { | ||
case "none": | ||
return nil, nil | ||
case "rocksdb.BuiltinBloomFilter": | ||
return bloom.FilterPolicy(10), nil | ||
} | ||
return nil, nil | ||
}, | ||
}) | ||
return cfg, seed, err | ||
} | ||
|
||
func readCommentString(r *bufio.Reader, prefix string) (string, error) { | ||
firstByte, err := r.ReadByte() | ||
if err == io.EOF { | ||
err = io.ErrUnexpectedEOF | ||
} | ||
if err != nil { | ||
return "", err | ||
} | ||
if firstByte != '#' { | ||
return "", fmt.Errorf("expected comment with prefix %q, but not a comment", prefix) | ||
} | ||
s, err := r.ReadString('\n') | ||
if err == io.EOF { | ||
err = io.ErrUnexpectedEOF | ||
} | ||
s = strings.TrimSpace(s) | ||
s = strings.TrimPrefix(s, prefix) | ||
s = strings.TrimSpace(s) | ||
return s, err | ||
} | ||
|
||
func readCommentInt64(r *bufio.Reader, prefix string) (int64, error) { | ||
s, err := readCommentString(r, prefix) | ||
if err != nil { | ||
return 0, err | ||
} | ||
return strconv.ParseInt(s, 10, 64) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2022 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package metamorphic | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/testutils" | ||
"github.com/cockroachdb/cockroach/pkg/util/leaktest" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestParseOutputPreamble(t *testing.T) { | ||
defer leaktest.AfterTest(t)() | ||
|
||
f, err := os.Open(testutils.TestDataPath(t, "sample.meta")) | ||
require.NoError(t, err) | ||
|
||
cfg, seed, err := parseOutputPreamble(f) | ||
require.NoError(t, err) | ||
require.Equal(t, seed, int64(7375396416917217630)) | ||
require.Equal(t, cfg.name, "random-007") | ||
// TODO(jackson): Assert roundtrip equality. | ||
t.Log(cfg.opts.EnsureDefaults().String()) | ||
} |
Oops, something went wrong.