github.com/matrixorigin/matrixone@v1.2.0/pkg/vm/engine/tae/index/indexwrapper/zmnode_test.go (about)

     1  // Copyright 2021 Matrix Origin
     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  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package indexwrapper
    16  
    17  import (
    18  	"context"
    19  	"fmt"
    20  	"path"
    21  	"testing"
    22  
    23  	"github.com/matrixorigin/matrixone/pkg/common/mpool"
    24  	"github.com/matrixorigin/matrixone/pkg/container/batch"
    25  	"github.com/matrixorigin/matrixone/pkg/container/types"
    26  	"github.com/matrixorigin/matrixone/pkg/defines"
    27  	"github.com/matrixorigin/matrixone/pkg/fileservice"
    28  	"github.com/matrixorigin/matrixone/pkg/objectio"
    29  	"github.com/matrixorigin/matrixone/pkg/testutil"
    30  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/testutils"
    31  	"github.com/stretchr/testify/assert"
    32  )
    33  
    34  const (
    35  	ModuleName = "IndexWrapper"
    36  )
    37  
    38  func TestBlockZoneMapIndex(t *testing.T) {
    39  	defer testutils.AfterTest(t)()
    40  	var err error
    41  	ctx := context.Background()
    42  
    43  	// var res bool
    44  	dir := testutils.InitTestEnv(ModuleName, t)
    45  	dir = path.Join(dir, "/local")
    46  	id := 1
    47  	name := fmt.Sprintf("%d.blk", id)
    48  	bat := newBatch()
    49  	c := fileservice.Config{
    50  		Name:    defines.LocalFileServiceName,
    51  		Backend: "DISK",
    52  		DataDir: dir,
    53  	}
    54  	service, err := fileservice.NewFileService(ctx, c, nil)
    55  	assert.Nil(t, err)
    56  
    57  	objectWriter, err := objectio.NewObjectWriterSpecial(objectio.WriterNormal, name, service)
    58  	assert.Nil(t, err)
    59  	/*fd*/ _, err = objectWriter.Write(bat)
    60  	assert.Nil(t, err)
    61  	blocks, err := objectWriter.WriteEnd(context.Background())
    62  	assert.Nil(t, err)
    63  	assert.Equal(t, 1, len(blocks))
    64  }
    65  
    66  func newBatch() *batch.Batch {
    67  	mp := mpool.MustNewZero()
    68  	types := []types.Type{
    69  		types.T_int32.ToType(),
    70  		types.T_int16.ToType(),
    71  		types.T_int32.ToType(),
    72  		types.T_int64.ToType(),
    73  		types.T_uint16.ToType(),
    74  		types.T_uint32.ToType(),
    75  		types.T_uint8.ToType(),
    76  		types.T_uint64.ToType(),
    77  	}
    78  	return testutil.NewBatch(types, false, int(40000*2), mp)
    79  }