1762
1763
// TestCreateNamespaceWithDuplicateName tests creating a namespace with a name that already exists
1765
>
id1 := uuid.NewString()
1766
>
name := "duplicate-name-test-namespace"
1767
>
state := enumspb.NAMESPACE_STATE_REGISTERED
1768
>
description := "duplicate-name-test-description"
1769
>
owner := "duplicate-name-test-owner"
1770
>
data := map[string]string{"k1": "v1"}
1771
>
retention := int32(10)
1772
>
historyArchivalState := enumspb.ARCHIVAL_STATE_ENABLED
1773
>
historyArchivalURI := "test://history/uri"
1774
>
visibilityArchivalState := enumspb.ARCHIVAL_STATE_ENABLED
1775
>
visibilityArchivalURI := "test://visibility/uri"
1776
>
1777
>
clusterActive := "some random active cluster name"
1778
>
clusterStandby := "some random standby cluster name"
1779
>
configVersion := int64(10)
1780
>
failoverVersion := int64(59)
1781
>
isGlobalNamespace := true
1782
>
clusters := []string{clusterActive, clusterStandby}
1783
>
1784
>
// Create first namespace
1785
>
resp1, err1 := m.CreateNamespace(
1786
>
&persistencespb.NamespaceInfo{
1787
>
Id: id1,
1788
>
Name: name,
1789
>
State: state,
1790
>
Description: description,
1791
>
Owner: owner,
1792
>
Data: data,
1793
>
},
1794
>
&persistencespb.NamespaceConfig{
1795
>
Retention: timestamp.DurationFromDays(retention),
1796
>
HistoryArchivalState: historyArchivalState,
1797
>
HistoryArchivalUri: historyArchivalURI,
1798
>
VisibilityArchivalState: visibilityArchivalState,
1799
>
VisibilityArchivalUri: visibilityArchivalURI,
1800
>
},
1801
>
&persistencespb.NamespaceReplicationConfig{
1802
>
ActiveClusterName: clusterActive,
1803
>
Clusters: clusters,
1804
>
},
1805
>
isGlobalNamespace,
1806
>
configVersion,
1807
>
failoverVersion,
1808
>
)
1809
>
m.NoError(err1)
1810
>
m.NotNil(resp1)
1811
>
1812
>
// Verify the namespace was created
1813
>
getResp1, err2 := m.GetNamespace(id1, "")
1814
>
m.NoError(err2)
1815
>
m.NotNil(getResp1)
1816
>
m.Equal(name, getResp1.Namespace.Info.Name)
1817
>
1818
>
// Try to create another namespace with the same name but different ID
1819
>
id2 := uuid.NewString()
1820
>
_, err3 := m.CreateNamespace(
1821
>
&persistencespb.NamespaceInfo{
1822
>
Id: id2,
1823
>
Name: name, // Same name as the first namespace
1824
>
State: state,
1825
>
Description: "different description",
1826
>
Owner: "different owner",
1827
>
Data: map[string]string{"k2": "v2"},
1828
>
},
1829
>
&persistencespb.NamespaceConfig{
1830
>
Retention: timestamp.DurationFromDays(retention * 2),
1831
>
HistoryArchivalState: enumspb.ARCHIVAL_STATE_DISABLED,
1832
>
HistoryArchivalUri: "",
1833
>
VisibilityArchivalState: enumspb.ARCHIVAL_STATE_DISABLED,
1834
>
VisibilityArchivalUri: "",
1835
>
},
1836
>
&persistencespb.NamespaceReplicationConfig{
1837
>
ActiveClusterName: clusterActive,
1838
>
Clusters: clusters,
1839
>
},
1840
>
isGlobalNamespace,
1841
>
configVersion,
1842
>
failoverVersion,
1843
>
)
1844
>
m.ErrorAs(err3, new(*serviceerror.NamespaceAlreadyExists))
1845
>
1846
>
// Verify that the original namespace still exists and was not modified
1847
>
getResp2, err4 := m.GetNamespace(id1, "")
1848
>
m.NoError(err4)
1849
>
m.NotNil(getResp2)
1850
>
m.Equal(name, getResp2.Namespace.Info.Name)
1851
>
m.Equal(description, getResp2.Namespace.Info.Description)
1852
>
m.Equal(owner, getResp2.Namespace.Info.Owner)
1853
>
1854
>
// Verify that the second namespace ID does not exist
1855
>
_, err5 := m.GetNamespace(id2, "")
1856
>
m.ErrorAs(err5, new(*serviceerror.NamespaceNotFound))
1857
>
}
1858
1859
// TestCreateNamespaceWithDuplicateID tests creating a namespace with an ID that already exists