You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: cmd_add_sstable_test.go
    path of file: ./repos/cockroach/pkg/kv/kvserver/batcheval
    
    the code of the file until where you have to start completion: // Copyright 2017 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 batcheval_test

import (
	"bytes"
	"context"
	"os"
	"regexp"
	"strings"
	"testing"

	"github.com/cockroachdb/cockroach/pkg/base"
	"github.com/cockroachdb/cockroach/pkg/keys"
	"github.com/cockroachdb/cockroach/pkg/kv"
	"github.com/cockroachdb/cockroach/pkg/kv/kvpb"
	"github.com/cockroachdb/cockroach/pkg/kv/kvserver"
	"github.com/cockroachdb/cockroach/pkg/kv/kvserver/batcheval"
	"github.com/cockroachdb/cockroach/pkg/kv/kvserver/kvserverpb"
	"github.com/cockroachdb/cockroach/pkg/roachpb"
	"github.com/cockroachdb/cockroach/pkg/settings/cluster"
	"github.com/cockroachdb/cockroach/pkg/storage"
	"github.com/cockroachdb/cockroach/pkg/storage/enginepb"
	"github.com/cockroachdb/cockroach/pkg/storage/fs"
	"github.com/cockroachdb/cockroach/pkg/testutils"
	"github.com/cockroachdb/cockroach/pkg/testutils/serverutils"
	"github.com/cockroachdb/cockroach/pkg/testutils/storageutils"
	"github.com/cockroachdb/cockroach/pkg/util"
	"github.com/cockroachdb/cockroach/pkg/util/hlc"
	"github.com/cockroachdb/cockroach/pkg/util/leaktest"
	"github.com/cockroachdb/cockroach/pkg/util/log"
	"github.com/cockroachdb/cockroach/pkg/util/tracing"
	"github.com/cockroachdb/errors"
	"github.com/stretchr/testify/require"
)

// TestEvalAddSSTable tests EvalAddSSTable directly, using only an in-memory
// Pebble engine. This allows precise manipulation of timestamps.
func TestEvalAddSSTable(t *testing.T) {
	defer leaktest.AfterTest(t)()
	defer log.Scope(t).Close(t)

	storage.DisableMetamorphicSimpleValueEncoding(t)

	const intentTS = 100 // values with this timestamp are written as intents

	// These are run with IngestAsWrites both disabled and enabled, and
	// kv.bulk_io_write.sst_rewrite_concurrency.per_call of 0 and 8.
	testcases := map[string]struct {
		data           kvs
		sst            kvs
		reqTS          int64
		toReqTS        int64 // SSTTimestampToRequestTimestamp with given SST timestamp
		noConflict     bool  // DisallowConflicts
		noShadow       bool  // DisallowShadowing
		noShadowBelow  int64 // DisallowShadowingBelow
		requireReqTS   bool  // AddSSTableRequireAtRequestTimestamp
		expect         kvs
		ignoreExpect   bool
		expectErr      interface{} // error type, substring, substring slice, or true (any)
		expectErrRace  interface{}
		expectStatsEst bool // expect MVCCStats.ContainsEstimates, don't check stats
	}{
		// Blind writes.
		"blind writes below existing": {
			data: kvs{pointKV("a", 5, "a5"), pointKV("b", 7, ""), pointKV("c", 6, "c6")},
			sst:  kvs{pointKV("a", 3, "sst"), pointKV("b", 2, "sst"), pointKV("c", 3, "")},
			expect: kvs{
				pointKV("a", 5, "a5"), pointKV("a", 3, "sst"), pointKV("b", 7, ""), pointKV("b", 2, "sst"), pointKV("c", 6, "c6"), pointKV("c", 3, ""),
			},
			expectStatsEst: true,
		},
		"blind replaces existing": {
			data:           kvs{pointKV("a", 2, "a2"), pointKV("b", 2, "b2")},
			sst:            kvs{pointKV("a", 2, "sst"), pointKV("b", 2, "")},
			expect:         kvs{pointKV("a", 2, "sst"), pointKV("b", 2, "")},
			expectStatsEst: true,
		},
		"blind errors on AddSSTableRequireAtRequestTimestamp": {
			data:         kvs{pointKV("a", 5, "a5"), pointKV("b", 7, "")},
			sst:          kvs{poin
    
func TestAddSSTableMVCCStats(t *testing.T) {
	defer leaktest.AfterTest(t)()
	defer log.Scope(t).Close(t)
	storage.DisableMetamorphicSimpleValueEncoding(t)

	const max = 1 << 10
	ctx := context.Background()
	st := cluster.MakeTestingClusterSettings()
	evalCtx := &batcheval.MockEvalCtx{
		ClusterSettings: st,
		MaxBytes:        max,
		Desc:            &roachpb.RangeDescriptor{},
	}

	engine := storage.NewDefaultInMemForTesting()
	defer engine.Close()

	for _, kv := range []storage.MVCCKeyValue{
		pointKV("A", 1, "A"),
		pointKV("a", 1, "a"),
		pointKV("a", 6, ""),
		pointKV("b", 5, "bb"),
		pointKV("c", 6, "ccccccccccccccccccccccccccccccccccccccccccccc"), // key 4b, 50b, live 64b
		pointKV("d", 1, "d"),
		pointKV("d", 2, ""),
		pointKV("e", 1, "e"),
		pointKV("u", 3, "u"),
		pointKV("z", 2, "zzzzzz"),
	} {
		require.NoError(t, engine.PutRawMVCC(kv.Key, kv.Value))
	}

	sst, start, end := storageutils.MakeSST(t, st, kvs{
		pointKV("a", 4, "aaaaaa"), // mvcc-shadowed by existing delete.
		pointKV("a", 2, "aa"),     // mvcc-shadowed within SST.
		pointKV("c", 6, "ccc"),    // same TS as existing, LSM-shadows existing.
		pointKV("d", 4, "dddd"),   // mvcc-shadow existing deleted d.
		pointKV("e", 4, "eeee"),   // mvcc-shadow existing 1b.
		pointKV("j", 2, "jj"),     // no colission – via MVCC or LSM – with existing.
		pointKV("t", 3, ""),       // tombstone, no collission
		pointKV("u", 5, ""),       // tombstone, shadows existing
	})
	statsDelta := enginepb.MVCCStats{
		// the sst will think it added 5 keys here, but a, c, e, and t shadow or are shadowed.
		LiveCount: -4,
		LiveBytes: -129,
		// the sst will think it added 5 keys, but only j and t are new so 5 are over-counted.
		KeyCount: -5,
		KeyBytes: -22,
		// the sst will think it added 6 values, but since one was a perfect (key+ts)
		// collision, it *replaced* the existing value and is over-counted.
		ValCount: -1,
		ValBytes: -50,
	}

	// After EvalAddSSTable, cArgs.Stats contains a diff to the existing
	// stats. Make sure recomputing from scratch gets the same answer as
	// applying the diff to the stats
	statsBefore := storageutils.EngineStats(t, engine, 0)
	ts := hlc.Timestamp{WallTime: 7}
	evalCtx.Stats = *statsBefore

	cArgs := batcheval.CommandArgs{
		EvalCtx: evalCtx.EvalContext(),
		Header: kvpb.Header{
			Timestamp: ts,
		},
		Args: &kvpb.AddSSTableRequest{
			RequestHeader: kvpb.RequestHeader{Key: start, EndKey: end},
			Data:          sst,
		},
		Stats: &enginepb.MVCCStats{},
	}
	var resp kvpb.AddSSTableResponse
	_, err := batcheval.EvalAddSSTable(ctx, engine, cArgs, &resp)
	require.NoError(t, err)

	require.NoError(t, fs.WriteFile(engine, "sst", sst))
	require.NoError(t, engine.IngestLocalFiles(ctx, []string{"sst"}))

	statsEvaled := statsBefore
	statsEvaled.Add(*cArgs.Stats)
	statsEvaled.Add(statsDelta)
	statsEvaled.ContainsEstimates = 0

	newStats := storageutils.EngineStats(t, engine, statsEvaled.LastUpdateNanos)
	require.Equal(t, newStats, statsEvaled)

	// Check that actual remaining bytes equals the returned remaining bytes once
	// the delta for stats inaccuracy is applied.
	require.Equal(t, max-newStats.Total(), resp.AvailableBytes-statsDelta.Total())

	// Check stats for a single KV.
	sst, start, end = storageutils.MakeSST(t, st, kvs{pointKV("zzzzzzz", int(ts.WallTime), "zzz")})
	cArgs = batcheval.CommandArgs{
		EvalCtx: evalCtx.EvalContext(),
		Header:  kvpb.Header{Timestamp: ts},
		Args: &kvpb.AddSSTableRequest{
			RequestHeader: kvpb.RequestHeader{Key: start, EndKey: end},
			Data:          sst,
		},
		Stats: &enginepb.MVCCStats{},
	}
	_, err = batcheval.EvalAddSSTable(ctx, engine, cArgs, &kvpb.AddSSTableResponse{})
	require.NoError(t, err)
	require.Equal(t, enginepb.MVCCStats{
		ContainsEstimates: 1,
		LastUpdateNanos:   ts.WallTime,
		LiveBytes:         28,
		LiveCount:         1,
		KeyBytes:          20,
		KeyCount:          1,
		ValBytes:          8,
		ValCount:          1,
	}, *cArgs.Stats)
}