1599
1600
// TestRenameNamespaceWithNameConflict tests name conflict when trying to rename a namespace
1602
>
id1 := uuid.NewString()
1603
>
name1 := "rename-conflict-namespace-1"
1604
>
id2 := uuid.NewString()
1605
>
name2 := "rename-conflict-namespace-2"
1606
>
state := enumspb.NAMESPACE_STATE_REGISTERED
1607
>
description := "rename-conflict-test-description"
1608
>
owner := "rename-conflict-test-owner"
1609
>
data := map[string]string{"k1": "v1"}
1610
>
retention := int32(10)
1611
>
historyArchivalState := enumspb.ARCHIVAL_STATE_ENABLED
1612
>
historyArchivalURI := "test://history/uri"
1613
>
visibilityArchivalState := enumspb.ARCHIVAL_STATE_ENABLED
1614
>
visibilityArchivalURI := "test://visibility/uri"
1615
>
1616
>
clusterActive := "some random active cluster name"
1617
>
clusterStandby := "some random standby cluster name"
1618
>
configVersion := int64(10)
1619
>
failoverVersion := int64(59)
1620
>
isGlobalNamespace := true
1621
>
clusters := []string{clusterActive, clusterStandby}
1622
>
1623
>
// Create first namespace
1624
>
resp1, err1 := m.CreateNamespace(
1625
>
&persistencespb.NamespaceInfo{
1626
>
Id: id1,
1627
>
Name: name1,
1628
>
State: state,
1629
>
Description: description,
1630
>
Owner: owner,
1631
>
Data: data,
1632
>
},
1633
>
&persistencespb.NamespaceConfig{
1634
>
Retention: timestamp.DurationFromDays(retention),
1635
>
HistoryArchivalState: historyArchivalState,
1636
>
HistoryArchivalUri: historyArchivalURI,
1637
>
VisibilityArchivalState: visibilityArchivalState,
1638
>
VisibilityArchivalUri: visibilityArchivalURI,
1639
>
},
1640
>
&persistencespb.NamespaceReplicationConfig{
1641
>
ActiveClusterName: clusterActive,
1642
>
Clusters: clusters,
1643
>
},
1644
>
isGlobalNamespace,
1645
>
configVersion,
1646
>
failoverVersion,
1647
>
)
1648
>
m.NoError(err1)
1649
>
m.EqualValues(id1, resp1.ID)
1650
>
1651
>
// Create second namespace
1652
>
resp2, err2 := m.CreateNamespace(
1653
>
&persistencespb.NamespaceInfo{
1654
>
Id: id2,
1655
>
Name: name2,
1656
>
State: state,
1657
>
Description: description,
1658
>
Owner: owner,
1659
>
Data: data,
1660
>
},
1661
>
&persistencespb.NamespaceConfig{
1662
>
Retention: timestamp.DurationFromDays(retention),
1663
>
HistoryArchivalState: historyArchivalState,
1664
>
HistoryArchivalUri: historyArchivalURI,
1665
>
VisibilityArchivalState: visibilityArchivalState,
1666
>
VisibilityArchivalUri: visibilityArchivalURI,
1667
>
},
1668
>
&persistencespb.NamespaceReplicationConfig{
1669
>
ActiveClusterName: clusterActive,
1670
>
Clusters: clusters,
1671
>
},
1672
>
isGlobalNamespace,
1673
>
configVersion,
1674
>
failoverVersion,
1675
>
)
1676
>
m.NoError(err2)
1677
>
m.EqualValues(id2, resp2.ID)
1678
>
1679
>
// Try to rename namespace1 to the same name as namespace2 (should fail)
1680
>
err3 := m.MetadataManager.RenameNamespace(m.ctx, &p.RenameNamespaceRequest{
1681
>
PreviousName: name1,
1682
>
NewName: name2,
1683
>
})
1684
>
// The error should be a conflict/unavailable error due to CAS failure
1685
>
m.ErrorAs(err3, new(*serviceerror.Unavailable))
1686
>
1687
>
// Verify that we can still query namespace2 by name, proving the rename didn't affect it
1688
>
resp5, err5 := m.GetNamespace("", name2)
1689
>
m.NoError(err5)
1690
>
m.Equal(name2, resp5.Namespace.Info.Name)
1691
>
m.Equal(id2, resp5.Namespace.Info.Id)
1692
>
1693
>
// Verify that namespace1 can still be queried by its original name
1694
>
resp6, err6 := m.GetNamespace("", name1)
1695
>
m.NoError(err6)
1696
>
m.Equal(name1, resp6.Namespace.Info.Name)
1697
>
m.Equal(id1, resp6.Namespace.Info.Id)
1698
>
}
1699
1700
// TestGetMetadataVersionIncrement tests that GetMetadata correctly increments the version after a namespace is created