github.com/matrixorigin/matrixone@v1.2.0/pkg/tnservice/factory_test.go (about)

     1  // Copyright 2021 - 2022 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 tnservice
    16  
    17  import (
    18  	"context"
    19  	"testing"
    20  
    21  	"github.com/matrixorigin/matrixone/pkg/common/runtime"
    22  	"github.com/matrixorigin/matrixone/pkg/common/stopper"
    23  	"github.com/matrixorigin/matrixone/pkg/logservice"
    24  	"github.com/matrixorigin/matrixone/pkg/pb/metadata"
    25  	"github.com/matrixorigin/matrixone/pkg/txn/storage/mem"
    26  	"github.com/stretchr/testify/assert"
    27  )
    28  
    29  func TestCreateLogServiceClient(t *testing.T) {
    30  	s := &store{cfg: &Config{}, stopper: stopper.NewStopper("")}
    31  	s.options.logServiceClientFactory = func(d metadata.TNShard) (logservice.Client, error) {
    32  		return mem.NewMemLog(), nil
    33  	}
    34  	v, err := s.createLogServiceClient(metadata.TNShard{})
    35  	assert.NoError(t, err)
    36  	assert.NotNil(t, v)
    37  }
    38  
    39  func TestCreateTxnStorage(t *testing.T) {
    40  	ctx := context.TODO()
    41  	s := &store{rt: runtime.DefaultRuntime(), cfg: &Config{}, stopper: stopper.NewStopper("")}
    42  	s.options.logServiceClientFactory = func(d metadata.TNShard) (logservice.Client, error) {
    43  		return mem.NewMemLog(), nil
    44  	}
    45  
    46  	s.cfg.Txn.Storage.Backend = StorageMEMKV
    47  	v, err := s.createTxnStorage(ctx, metadata.TNShard{})
    48  	assert.NoError(t, err)
    49  	assert.NotNil(t, v)
    50  
    51  	s.cfg.Txn.Storage.Backend = "error"
    52  	v, err = s.createTxnStorage(ctx, metadata.TNShard{})
    53  	assert.Error(t, err)
    54  	assert.Nil(t, v)
    55  }