(t *testing.T)
| 1046 | } |
| 1047 | |
| 1048 | func 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 | |
| 1096 | func TestPartitionRingDesc_RemoveTombstones(t *testing.T) { |
| 1097 | now := time.Now() |
nothing calls this directly
no test coverage detected