github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/pingcap/tidb/store/tikv/scan_mock_test.go (about)

     1  // Copyright 2016 PingCAP, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package tikv
    15  
    16  import (
    17  	. "github.com/insionng/yougam/libraries/pingcap/check"
    18  	"github.com/insionng/yougam/libraries/pingcap/tidb/kv"
    19  )
    20  
    21  type testScanMockSuite struct {
    22  }
    23  
    24  var _ = Suite(&testScanMockSuite{})
    25  
    26  func (s *testScanMockSuite) TestScanMultipleRegions(c *C) {
    27  	store := NewMockTikvStore().(*tikvStore)
    28  	txn, err := store.Begin()
    29  	c.Assert(err, IsNil)
    30  	for ch := byte('a'); ch <= byte('z'); ch++ {
    31  		err = txn.Set([]byte{ch}, []byte{ch})
    32  		c.Assert(err, IsNil)
    33  	}
    34  	err = txn.Commit()
    35  	c.Assert(err, IsNil)
    36  
    37  	txn, err = store.Begin()
    38  	c.Assert(err, IsNil)
    39  	snapshot := newTiKVSnapshot(store, kv.Version{Ver: txn.StartTS()})
    40  	scanner, err := newScanner(snapshot, []byte("a"), 10)
    41  	c.Assert(err, IsNil)
    42  	for ch := byte('a'); ch <= byte('z'); ch++ {
    43  		c.Assert([]byte{ch}, BytesEquals, []byte(scanner.Key()))
    44  		if ch < byte('z') {
    45  			c.Assert(scanner.Next(), IsNil)
    46  		}
    47  	}
    48  	c.Assert(scanner.Next(), NotNil)
    49  	c.Assert(scanner.Valid(), IsFalse)
    50  }