github.com/matrixorigin/matrixone@v0.7.0/pkg/logservice/testclient.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 logservice
    16  
    17  import (
    18  	"github.com/google/uuid"
    19  	"github.com/lni/vfs"
    20  	"github.com/matrixorigin/matrixone/pkg/common/morpc"
    21  	pb "github.com/matrixorigin/matrixone/pkg/pb/logservice"
    22  	"github.com/matrixorigin/matrixone/pkg/testutil"
    23  )
    24  
    25  func NewTestService(fs vfs.FS) (*Service, ClientConfig, error) {
    26  	addr := []string{"localhost:9000"}
    27  	cfg := Config{
    28  		UUID:                 uuid.New().String(),
    29  		RTTMillisecond:       10,
    30  		GossipSeedAddresses:  []string{defaultGossipSeedAddress},
    31  		DeploymentID:         1,
    32  		FS:                   fs,
    33  		ServiceListenAddress: addr[0],
    34  		ServiceAddress:       addr[0],
    35  		DisableWorkers:       true,
    36  	}
    37  	cfg.Fill()
    38  	service, err := NewService(cfg,
    39  		testutil.NewFS(),
    40  		WithBackendFilter(func(msg morpc.Message, backendAddr string) bool {
    41  			return true
    42  		}),
    43  	)
    44  	if err != nil {
    45  		return nil, ClientConfig{}, err
    46  	}
    47  
    48  	cmd := pb.ScheduleCommand{
    49  		ConfigChange: &pb.ConfigChange{
    50  			ChangeType: pb.StartReplica,
    51  			Replica: pb.Replica{
    52  				ShardID:   1,
    53  				ReplicaID: 1,
    54  			},
    55  			InitialMembers: map[uint64]string{1: service.ID()},
    56  		},
    57  	}
    58  	service.handleCommands([]pb.ScheduleCommand{cmd})
    59  
    60  	ccfg := ClientConfig{
    61  		LogShardID:       1,
    62  		DNReplicaID:      10,
    63  		ServiceAddresses: addr,
    64  	}
    65  	return service, ccfg, nil
    66  }