This repository has been archived by the owner on Feb 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add transfer leader procedure (#67)
- Loading branch information
1 parent
ed69aad
commit 1564d8a
Showing
7 changed files
with
342 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright 2022 CeresDB Project Authors. Licensed under Apache-2.0. | ||
|
||
package procedure | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/CeresDB/ceresmeta/server/cluster" | ||
"github.com/CeresDB/ceresmeta/server/coordinator/eventdispatch" | ||
"github.com/CeresDB/ceresmeta/server/etcdutil" | ||
"github.com/CeresDB/ceresmeta/server/storage" | ||
"github.com/stretchr/testify/require" | ||
clientv3 "go.etcd.io/etcd/client/v3" | ||
) | ||
|
||
const ( | ||
nodeName0 = "node0" | ||
nodeName1 = "node1" | ||
testRootPath = "/rootPath" | ||
defaultIDAllocatorStep = 20 | ||
clusterName = "ceresdbCluster1" | ||
defaultNodeCount = 2 | ||
defaultReplicationFactor = 1 | ||
defaultShardTotal = 2 | ||
) | ||
|
||
type MockDispatch struct{} | ||
|
||
func (m MockDispatch) OpenShard(_ context.Context, _ string, _ *eventdispatch.OpenShardRequest) error { | ||
return nil | ||
} | ||
|
||
func (m MockDispatch) CloseShard(_ context.Context, _ string, _ *eventdispatch.CloseShardRequest) error { | ||
return nil | ||
} | ||
|
||
func (m MockDispatch) CreateTableOnShard(_ context.Context, _ string, _ *eventdispatch.CreateTableOnShardRequest) error { | ||
return nil | ||
} | ||
|
||
func (m MockDispatch) DropTableOnShard(_ context.Context, _ string, _ *eventdispatch.DropTableOnShardRequest) error { | ||
return nil | ||
} | ||
|
||
func newTestEtcdStorage(t *testing.T) (storage.Storage, clientv3.KV, etcdutil.CloseFn) { | ||
_, client, closeSrv := etcdutil.PrepareEtcdServerAndClient(t) | ||
storage := storage.NewStorageWithEtcdBackend(client, testRootPath, storage.Options{ | ||
MaxScanLimit: 100, MinScanLimit: 10, | ||
}) | ||
return storage, client, closeSrv | ||
} | ||
|
||
func newTestCluster(ctx context.Context, t *testing.T) *cluster.Cluster { | ||
re := require.New(t) | ||
storage, kv, _ := newTestEtcdStorage(t) | ||
manager, err := cluster.NewManagerImpl(storage, kv, testRootPath, defaultIDAllocatorStep) | ||
re.NoError(err) | ||
|
||
cluster, err := manager.CreateCluster(ctx, clusterName, defaultNodeCount, defaultReplicationFactor, defaultShardTotal) | ||
re.NoError(err) | ||
return cluster | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.