@@ -49,13 +49,18 @@ func mvccKey(k interface{}) MVCCKey {
4949 }
5050}
5151
52- func testBatchBasics (t * testing.T , commit func (e Engine , b Batch ) error ) {
52+ func testBatchBasics (t * testing.T , writeOnly bool , commit func (e Engine , b Batch ) error ) {
5353 stopper := stop .NewStopper ()
5454 defer stopper .Stop ()
5555 e := NewInMem (roachpb.Attributes {}, 1 << 20 )
5656 stopper .AddCloser (e )
5757
58- b := e .NewBatch ()
58+ var b Batch
59+ if writeOnly {
60+ b = e .NewWriteOnlyBatch ()
61+ } else {
62+ b = e .NewBatch ()
63+ }
5964 defer b .Close ()
6065
6166 if err := b .Put (mvccKey ("a" ), []byte ("value" )); err != nil {
@@ -95,13 +100,15 @@ func testBatchBasics(t *testing.T, commit func(e Engine, b Batch) error) {
95100 {Key : mvccKey ("a" ), Value : []byte ("value" )},
96101 {Key : mvccKey ("c" ), Value : appender ("foobar" )},
97102 }
98- // Scan values from batch directly.
99- kvs , err = Scan (b , mvccKey (roachpb .RKeyMin ), mvccKey (roachpb .RKeyMax ), 0 )
100- if err != nil {
101- t .Fatal (err )
102- }
103- if ! reflect .DeepEqual (expValues , kvs ) {
104- t .Errorf ("%v != %v" , kvs , expValues )
103+ if ! writeOnly {
104+ // Scan values from batch directly.
105+ kvs , err = Scan (b , mvccKey (roachpb .RKeyMin ), mvccKey (roachpb .RKeyMax ), 0 )
106+ if err != nil {
107+ t .Fatal (err )
108+ }
109+ if ! reflect .DeepEqual (expValues , kvs ) {
110+ t .Errorf ("%v != %v" , kvs , expValues )
111+ }
105112 }
106113
107114 // Commit batch and verify direct engine scan yields correct values.
@@ -121,14 +128,14 @@ func testBatchBasics(t *testing.T, commit func(e Engine, b Batch) error) {
121128// visible until commit, and then are all visible after commit.
122129func TestBatchBasics (t * testing.T ) {
123130 defer leaktest .AfterTest (t )()
124- testBatchBasics (t , func (e Engine , b Batch ) error {
131+ testBatchBasics (t , false /* writeOnly */ , func (e Engine , b Batch ) error {
125132 return b .Commit ()
126133 })
127134}
128135
129136func TestBatchRepr (t * testing.T ) {
130137 defer leaktest .AfterTest (t )()
131- testBatchBasics (t , func (e Engine , b Batch ) error {
138+ testBatchBasics (t , false /* writeOnly */ , func (e Engine , b Batch ) error {
132139 repr := b .Repr ()
133140
134141 // Simple sanity checks about the format of the batch representation. This
@@ -228,6 +235,13 @@ func TestBatchRepr(t *testing.T) {
228235 })
229236}
230237
238+ func TestWriteBatchBasics (t * testing.T ) {
239+ defer leaktest .AfterTest (t )()
240+ testBatchBasics (t , true /* writeOnly */ , func (e Engine , b Batch ) error {
241+ return b .Commit ()
242+ })
243+ }
244+
231245// Regression test for flush issue which caused
232246// b2.ApplyBatchRepr(b1.Repr()).Repr() to not equal a noop.
233247func TestApplyBatchRepr (t * testing.T ) {
0 commit comments