775
776
// TestUpdateNamespace test
778
>
id := uuid.NewString()
779
>
name := "update-namespace-test-name"
780
>
state := enumspb.NAMESPACE_STATE_REGISTERED
781
>
description := "update-namespace-test-description"
782
>
owner := "update-namespace-test-owner"
783
>
data := map[string]string{"k1": "v1"}
784
>
retention := int32(10)
785
>
historyArchivalState := enumspb.ARCHIVAL_STATE_ENABLED
786
>
historyArchivalURI := "test://history/uri"
787
>
visibilityArchivalState := enumspb.ARCHIVAL_STATE_ENABLED
788
>
visibilityArchivalURI := "test://visibility/uri"
789
>
790
>
clusterActive := "some random active cluster name"
791
>
clusterStandby := "some random standby cluster name"
792
>
configVersion := int64(10)
793
>
failoverVersion := int64(59)
794
>
failoverEndTime := time.Now().UTC()
795
>
isGlobalNamespace := true
796
>
clusters := []string{clusterActive, clusterStandby}
797
>
798
>
resp1, err1 := m.CreateNamespace(
799
>
&persistencespb.NamespaceInfo{
800
>
Id: id,
801
>
Name: name,
802
>
State: state,
803
>
Description: description,
804
>
Owner: owner,
805
>
Data: data,
806
>
},
807
>
&persistencespb.NamespaceConfig{
808
>
Retention: timestamp.DurationFromDays(retention),
809
>
HistoryArchivalState: historyArchivalState,
810
>
HistoryArchivalUri: historyArchivalURI,
811
>
VisibilityArchivalState: visibilityArchivalState,
812
>
VisibilityArchivalUri: visibilityArchivalURI,
813
>
},
814
>
&persistencespb.NamespaceReplicationConfig{
815
>
ActiveClusterName: clusterActive,
816
>
Clusters: clusters,
817
>
},
818
>
isGlobalNamespace,
819
>
configVersion,
820
>
failoverVersion,
821
>
)
822
>
m.NoError(err1)
823
>
m.EqualValues(id, resp1.ID)
824
>
825
>
resp2, err2 := m.GetNamespace(id, "")
826
>
m.NoError(err2)
827
>
metadata, err := m.MetadataManager.GetMetadata(m.ctx)
828
>
m.NoError(err)
829
>
notificationVersion := metadata.NotificationVersion
830
>
831
>
updatedState := enumspb.NAMESPACE_STATE_DEPRECATED
832
>
updatedDescription := "description-updated"
833
>
updatedOwner := "owner-updated"
834
>
// This will overriding the previous key-value pair
835
>
updatedData := map[string]string{"k1": "v2"}
836
>
updatedRetention := timestamp.DurationFromDays(20)
837
>
updatedHistoryArchivalState := enumspb.ARCHIVAL_STATE_DISABLED
838
>
updatedHistoryArchivalURI := ""
839
>
updatedVisibilityArchivalState := enumspb.ARCHIVAL_STATE_DISABLED
840
>
updatedVisibilityArchivalURI := ""
841
>
842
>
updateClusterActive := "other random active cluster name"
843
>
updateClusterStandby := "other random standby cluster name"
844
>
updateConfigVersion := int64(12)
845
>
updateFailoverVersion := int64(28)
846
>
updateFailoverNotificationVersion := int64(14)
847
>
updateClusters := []string{updateClusterActive, updateClusterStandby}
848
>
849
>
testBinaries := &namespacepb.BadBinaries{
850
>
Binaries: map[string]*namespacepb.BadBinaryInfo{
851
>
"abc": {
852
>
Reason: "test-reason",
853
>
Operator: "test-operator",
854
>
CreateTime: timestamppb.New(time.Date(2020, 8, 22, 0, 0, 0, 0, time.UTC)),
855
>
},
856
>
},
857
>
}
858
>
859
>
err3 := m.UpdateNamespace(
860
>
&persistencespb.NamespaceInfo{
861
>
Id: resp2.Namespace.Info.Id,
862
>
Name: resp2.Namespace.Info.Name,
863
>
State: updatedState,
864
>
Description: updatedDescription,
865
>
Owner: updatedOwner,
866
>
Data: updatedData,
867
>
},
868
>
&persistencespb.NamespaceConfig{
869
>
Retention: updatedRetention,
870
>
HistoryArchivalState: updatedHistoryArchivalState,
871
>
HistoryArchivalUri: updatedHistoryArchivalURI,
872
>
VisibilityArchivalState: updatedVisibilityArchivalState,
873
>
VisibilityArchivalUri: updatedVisibilityArchivalURI,
874
>
BadBinaries: testBinaries,
875
>
},
876
>
&persistencespb.NamespaceReplicationConfig{
877
>
ActiveClusterName: updateClusterActive,
878
>
Clusters: updateClusters,
879
>
},
880
>
updateConfigVersion,
881
>
updateFailoverVersion,
882
>
updateFailoverNotificationVersion,
883
>
failoverEndTime,
884
>
notificationVersion,
885
>
isGlobalNamespace,
886
>
)
887
>
m.NoError(err3)
888
>
889
>
resp4, err4 := m.GetNamespace("", name)
890
>
m.NoError(err4)
891
>
m.NotNil(resp4)
892
>
m.EqualValues(id, resp4.Namespace.Info.Id)
893
>
m.Equal(name, resp4.Namespace.Info.Name)
894
>
m.Equal(isGlobalNamespace, resp4.IsGlobalNamespace)
895
>
m.Equal(updatedState, resp4.Namespace.Info.State)
896
>
m.Equal(updatedDescription, resp4.Namespace.Info.Description)
897
>
m.Equal(updatedOwner, resp4.Namespace.Info.Owner)
898
>
m.Equal(updatedData, resp4.Namespace.Info.Data)
899
>
m.ProtoEqual(updatedRetention, resp4.Namespace.Config.Retention)
900
>
m.Equal(updatedHistoryArchivalState, resp4.Namespace.Config.HistoryArchivalState)
901
>
m.Equal(updatedHistoryArchivalURI, resp4.Namespace.Config.HistoryArchivalUri)
902
>
m.Equal(updatedVisibilityArchivalState, resp4.Namespace.Config.VisibilityArchivalState)
903
>
m.Equal(updatedVisibilityArchivalURI, resp4.Namespace.Config.VisibilityArchivalUri)
904
>
m.ProtoEqual(testBinaries, resp4.Namespace.Config.BadBinaries)
905
>
m.Equal(updateClusterActive, resp4.Namespace.ReplicationConfig.ActiveClusterName)
906
>
m.Equal(len(updateClusters), len(resp4.Namespace.ReplicationConfig.Clusters))
907
>
for index := range clusters {
908
>
m.Equal(updateClusters[index], resp4.Namespace.ReplicationConfig.Clusters[index])
909
>
}
910
>
m.Equal(updateConfigVersion, resp4.Namespace.ConfigVersion)
911
>
m.Equal(updateFailoverVersion, resp4.Namespace.FailoverVersion)
912
>
m.Equal(updateFailoverNotificationVersion, resp4.Namespace.FailoverNotificationVersion)
913
>
m.Equal(notificationVersion, resp4.NotificationVersion)
914
>
m.EqualTimes(failoverEndTime, resp4.Namespace.FailoverEndTime.AsTime())
915
>
916
>
resp5, err5 := m.GetNamespace(id, "")
917
>
m.NoError(err5)
918
>
m.NotNil(resp5)
919
>
m.EqualValues(id, resp5.Namespace.Info.Id)
920
>
m.Equal(name, resp5.Namespace.Info.Name)
921
>
m.Equal(isGlobalNamespace, resp5.IsGlobalNamespace)
922
>
m.Equal(updatedState, resp5.Namespace.Info.State)
923
>
m.Equal(updatedDescription, resp5.Namespace.Info.Description)
924
>
m.Equal(updatedOwner, resp5.Namespace.Info.Owner)
925
>
m.Equal(updatedData, resp5.Namespace.Info.Data)
926
>
m.ProtoEqual(updatedRetention, resp5.Namespace.Config.Retention)
927
>
m.Equal(updatedHistoryArchivalState, resp5.Namespace.Config.HistoryArchivalState)
928
>
m.Equal(updatedHistoryArchivalURI, resp5.Namespace.Config.HistoryArchivalUri)
929
>
m.Equal(updatedVisibilityArchivalState, resp5.Namespace.Config.VisibilityArchivalState)
930
>
m.Equal(updatedVisibilityArchivalURI, resp5.Namespace.Config.VisibilityArchivalUri)
931
>
m.Equal(updateClusterActive, resp5.Namespace.ReplicationConfig.ActiveClusterName)
932
>
m.Equal(len(updateClusters), len(resp5.Namespace.ReplicationConfig.Clusters))
933
>
for index := range clusters {
934
>
m.Equal(updateClusters[index], resp5.Namespace.ReplicationConfig.Clusters[index])
935
>
}
936
>
m.Equal(updateConfigVersion, resp5.Namespace.ConfigVersion)
937
>
m.Equal(updateFailoverVersion, resp5.Namespace.FailoverVersion)
938
>
m.Equal(updateFailoverNotificationVersion, resp5.Namespace.FailoverNotificationVersion)
939
>
m.Equal(notificationVersion, resp5.NotificationVersion)
940
>
m.EqualTimes(failoverEndTime, resp4.Namespace.FailoverEndTime.AsTime())
941
>
942
>
notificationVersion++
943
>
err6 := m.UpdateNamespace(
944
>
&persistencespb.NamespaceInfo{
945
>
Id: resp2.Namespace.Info.Id,
946
>
Name: resp2.Namespace.Info.Name,
947
>
State: updatedState,
948
>
Description: updatedDescription,
949
>
Owner: updatedOwner,
950
>
Data: updatedData,
951
>
},
952
>
&persistencespb.NamespaceConfig{
953
>
Retention: updatedRetention,
954
>
HistoryArchivalState: updatedHistoryArchivalState,
955
>
HistoryArchivalUri: updatedHistoryArchivalURI,
956
>
VisibilityArchivalState: updatedVisibilityArchivalState,
957
>
VisibilityArchivalUri: updatedVisibilityArchivalURI,
958
>
BadBinaries: testBinaries,
959
>
},
960
>
&persistencespb.NamespaceReplicationConfig{
961
>
ActiveClusterName: updateClusterActive,
962
>
Clusters: updateClusters,
963
>
},
964
>
updateConfigVersion,
965
>
updateFailoverVersion,
966
>
updateFailoverNotificationVersion,
967
>
time.Time{},
968
>
notificationVersion,
969
>
isGlobalNamespace,
970
>
)
971
>
m.NoError(err6)
972
>
973
>
resp6, err6 := m.GetNamespace(id, "")
974
>
m.NoError(err6)
975
>
m.NotNil(resp6)
976
>
m.EqualValues(id, resp6.Namespace.Info.Id)
977
>
m.Equal(name, resp6.Namespace.Info.Name)
978
>
m.Equal(isGlobalNamespace, resp6.IsGlobalNamespace)
979
>
m.Equal(updatedState, resp6.Namespace.Info.State)
980
>
m.Equal(updatedDescription, resp6.Namespace.Info.Description)
981
>
m.Equal(updatedOwner, resp6.Namespace.Info.Owner)
982
>
m.Equal(updatedData, resp6.Namespace.Info.Data)
983
>
m.ProtoEqual(updatedRetention, resp6.Namespace.Config.Retention)
984
>
m.Equal(updatedHistoryArchivalState, resp6.Namespace.Config.HistoryArchivalState)
985
>
m.Equal(updatedHistoryArchivalURI, resp6.Namespace.Config.HistoryArchivalUri)
986
>
m.Equal(updatedVisibilityArchivalState, resp6.Namespace.Config.VisibilityArchivalState)
987
>
m.Equal(updatedVisibilityArchivalURI, resp6.Namespace.Config.VisibilityArchivalUri)
988
>
m.ProtoEqual(testBinaries, resp6.Namespace.Config.BadBinaries)
989
>
m.Equal(updateClusterActive, resp6.Namespace.ReplicationConfig.ActiveClusterName)
990
>
m.Equal(len(updateClusters), len(resp6.Namespace.ReplicationConfig.Clusters))
991
>
for index := range clusters {
992
>
m.Equal(updateClusters[index], resp4.Namespace.ReplicationConfig.Clusters[index])
993
>
}
994
>
m.Equal(updateConfigVersion, resp6.Namespace.ConfigVersion)
995
>
m.Equal(updateFailoverVersion, resp6.Namespace.FailoverVersion)
996
>
m.Equal(updateFailoverNotificationVersion, resp6.Namespace.FailoverNotificationVersion)
997
>
m.Equal(notificationVersion, resp6.NotificationVersion)
998
>
m.EqualTimes(time.Unix(0, 0).UTC(), resp6.Namespace.FailoverEndTime.AsTime())
999
}
1000