1858
1859
// TestCreateNamespaceWithDuplicateID tests creating a namespace with an ID that already exists
1861
>
id := uuid.NewString()
1862
>
name1 := "duplicate-id-test-namespace-1"
1863
>
name2 := "duplicate-id-test-namespace-2"
1864
>
state := enumspb.NAMESPACE_STATE_REGISTERED
1865
>
description := "duplicate-id-test-description"
1866
>
owner := "duplicate-id-test-owner"
1867
>
data := map[string]string{"k1": "v1"}
1868
>
retention := int32(10)
1869
>
historyArchivalState := enumspb.ARCHIVAL_STATE_ENABLED
1870
>
historyArchivalURI := "test://history/uri"
1871
>
visibilityArchivalState := enumspb.ARCHIVAL_STATE_ENABLED
1872
>
visibilityArchivalURI := "test://visibility/uri"
1873
>
1874
>
clusterActive := "some random active cluster name"
1875
>
clusterStandby := "some random standby cluster name"
1876
>
configVersion := int64(10)
1877
>
failoverVersion := int64(59)
1878
>
isGlobalNamespace := true
1879
>
clusters := []string{clusterActive, clusterStandby}
1880
>
1881
>
// Create first namespace
1882
>
resp1, err1 := m.CreateNamespace(
1883
>
&persistencespb.NamespaceInfo{
1884
>
Id: id,
1885
>
Name: name1,
1886
>
State: state,
1887
>
Description: description,
1888
>
Owner: owner,
1889
>
Data: data,
1890
>
},
1891
>
&persistencespb.NamespaceConfig{
1892
>
Retention: timestamp.DurationFromDays(retention),
1893
>
HistoryArchivalState: historyArchivalState,
1894
>
HistoryArchivalUri: historyArchivalURI,
1895
>
VisibilityArchivalState: visibilityArchivalState,
1896
>
VisibilityArchivalUri: visibilityArchivalURI,
1897
>
},
1898
>
&persistencespb.NamespaceReplicationConfig{
1899
>
ActiveClusterName: clusterActive,
1900
>
Clusters: clusters,
1901
>
},
1902
>
isGlobalNamespace,
1903
>
configVersion,
1904
>
failoverVersion,
1905
>
)
1906
>
m.NoError(err1)
1907
>
m.NotNil(resp1)
1908
>
1909
>
// Verify the namespace was created
1910
>
getResp1, err2 := m.GetNamespace(id, "")
1911
>
m.NoError(err2)
1912
>
m.NotNil(getResp1)
1913
>
m.Equal(name1, getResp1.Namespace.Info.Name)
1914
>
m.Equal(id, getResp1.Namespace.Info.Id)
1915
>
1916
>
// Try to create another namespace with the same ID but different name
1917
>
_, err3 := m.CreateNamespace(
1918
>
&persistencespb.NamespaceInfo{
1919
>
Id: id, // Same ID as the first namespace
1920
>
Name: name2,
1921
>
State: state,
1922
>
Description: "different description",
1923
>
Owner: "different owner",
1924
>
Data: map[string]string{"k2": "v2"},
1925
>
},
1926
>
&persistencespb.NamespaceConfig{
1927
>
Retention: timestamp.DurationFromDays(retention * 2),
1928
>
HistoryArchivalState: enumspb.ARCHIVAL_STATE_DISABLED,
1929
>
HistoryArchivalUri: "",
1930
>
VisibilityArchivalState: enumspb.ARCHIVAL_STATE_DISABLED,
1931
>
VisibilityArchivalUri: "",
1932
>
},
1933
>
&persistencespb.NamespaceReplicationConfig{
1934
>
ActiveClusterName: clusterActive,
1935
>
Clusters: clusters,
1936
>
},
1937
>
isGlobalNamespace,
1938
>
configVersion,
1939
>
failoverVersion,
1940
>
)
1941
>
m.ErrorAs(err3, new(*serviceerror.NamespaceAlreadyExists))
1942
>
1943
>
// Verify that the original namespace still exists and was not modified
1944
>
getResp2, err4 := m.GetNamespace(id, "")
1945
>
m.NoError(err4)
1946
>
m.NotNil(getResp2)
1947
>
m.Equal(name1, getResp2.Namespace.Info.Name) // Should still have the original name
1948
>
m.Equal(description, getResp2.Namespace.Info.Description)
1949
>
m.Equal(owner, getResp2.Namespace.Info.Owner)
1950
>
m.Equal(id, getResp2.Namespace.Info.Id)
1951
>
1952
>
// Verify that the second name doesn't exist in the system
1953
>
_, err5 := m.GetNamespace("", name2)
1954
>
m.ErrorAs(err5, new(*serviceerror.NamespaceNotFound))
1955
>
}
1956
1957
// TestInitializeSystemNamespaces tests the initialization of system namespaces