|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +package store |
| 19 | + |
| 20 | +import ( |
| 21 | + "context" |
| 22 | + "testing" |
| 23 | + |
| 24 | + "github.com/stretchr/testify/require" |
| 25 | +) |
| 26 | + |
| 27 | +func TestCluster_PromoteNewMaster_SequenceZero(t *testing.T) { |
| 28 | + shard := NewShard() |
| 29 | + shard.SlotRanges = []SlotRange{{Start: 0, Stop: 1023}} |
| 30 | + |
| 31 | + node0 := NewClusterMockNode() |
| 32 | + node0.SetRole(RoleMaster) |
| 33 | + node0.Sequence = 100 // Master has non-zero sequence |
| 34 | + |
| 35 | + node1 := NewClusterMockNode() |
| 36 | + node1.SetRole(RoleSlave) |
| 37 | + node1.Sequence = 0 // Slave has zero sequence |
| 38 | + |
| 39 | + shard.Nodes = []Node{node0, node1} |
| 40 | + cluster := &Cluster{ |
| 41 | + Shards: Shards{shard}, |
| 42 | + } |
| 43 | + |
| 44 | + ctx := context.Background() |
| 45 | + |
| 46 | + // Try to promote node1 (sequence 0) when master has sequence 100 |
| 47 | + // This currently fails because of the check in getNewMasterNodeIndex |
| 48 | + // We want this to succeed (or determine if it should). |
| 49 | + // Based on the task "handle sequence zero", we likely want to allow this. |
| 50 | + newMasterID, err := cluster.PromoteNewMaster(ctx, 0, node1.ID(), "") |
| 51 | + require.NoError(t, err, "PromoteNewMaster should succeed even if sequence is 0") |
| 52 | + require.Equal(t, node1.ID(), newMasterID) |
| 53 | +} |
0 commit comments