MCPcopy
hub / github.com/grafana/dskit / TestPartitionRingDesc_Merge_EdgeCases

Function TestPartitionRingDesc_Merge_EdgeCases

ring/partition_ring_model_test.go:1048–1094  ·  ring/partition_ring_model_test.go::TestPartitionRingDesc_Merge_EdgeCases
(t *testing.T)

Source from the content-addressed store, hash-verified

1046}
1047
1048func TestPartitionRingDesc_Merge_EdgeCases(t *testing.T) {
1049 t.Run("should not panic if the mergerable is nil", func(t *testing.T) {
1050 desc := NewPartitionRingDesc()
1051
1052 actual, err := desc.Merge(nil, false)
1053 require.NoError(t, err)
1054 require.Nil(t, actual)
1055
1056 actual, err = desc.Merge((*PartitionRingDesc)(nil), false)
1057 require.NoError(t, err)
1058 require.Nil(t, actual)
1059 })
1060
1061 t.Run("should not panic if local version has been decoded from an empty struct received via pull-push mechanism", func(t *testing.T) {
1062 // Let's assume there's a remote endpoint with empty partitions and owners.
1063 // These maps are non-nil but empty in the remote endpoint.
1064 remote := NewPartitionRingDesc()
1065 require.NotNil(t, remote.Partitions)
1066 require.NotNil(t, remote.Owners)
1067 require.Empty(t, remote.Partitions)
1068 require.Empty(t, remote.Owners)
1069
1070 // The local process pull the state from the remote endpoint.
1071 // The remote endpoint encodes the struct and then the local process decodes it.
1072 codec := GetPartitionRingCodec()
1073 encoded, err := codec.Encode(remote)
1074 require.NoError(t, err)
1075 decoded, err := codec.Decode(encoded)
1076 require.NoError(t, err)
1077
1078 local := decoded.(*PartitionRingDesc)
1079 require.NotNil(t, local.Partitions)
1080 require.NotNil(t, local.Owners)
1081 require.Empty(t, local.Partitions)
1082 require.Empty(t, local.Owners)
1083
1084 // Then the local process receives an incoming update with some partitions and owners.
1085 incoming := NewPartitionRingDesc()
1086 incoming.AddPartition(1, PartitionActive, time.Unix(10, 0))
1087 incoming.AddOrUpdateOwner("instance-1", OwnerActive, 1, time.Unix(10, 0))
1088
1089 change, err := local.Merge(incoming, false)
1090 require.NoError(t, err)
1091 assert.Equal(t, incoming, local)
1092 assert.Equal(t, incoming, change)
1093 })
1094}
1095
1096func TestPartitionRingDesc_RemoveTombstones(t *testing.T) {
1097 now := time.Now()

Callers

nothing calls this directly

Calls 10

MergeMethod · 0.95
AddPartitionMethod · 0.95
AddOrUpdateOwnerMethod · 0.95
NewPartitionRingDescFunction · 0.85
GetPartitionRingCodecFunction · 0.85
RunMethod · 0.80
EncodeMethod · 0.65
DecodeMethod · 0.65
MergeMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected