1504
1505
// TestCASFailureUpdateNamespace tests CAS failure when trying to update a namespace
1507
>
id := uuid.NewString()
1508
>
name := "cas-update-namespace-test-name"
1509
>
state := enumspb.NAMESPACE_STATE_REGISTERED
1510
>
description := "cas-update-namespace-test-description"
1511
>
owner := "cas-update-namespace-test-owner"
1512
>
data := map[string]string{"k1": "v1"}
1513
>
retention := int32(10)
1514
>
historyArchivalState := enumspb.ARCHIVAL_STATE_ENABLED
1515
>
historyArchivalURI := "test://history/uri"
1516
>
visibilityArchivalState := enumspb.ARCHIVAL_STATE_ENABLED
1517
>
visibilityArchivalURI := "test://visibility/uri"
1518
>
badBinaries := &namespacepb.BadBinaries{Binaries: map[string]*namespacepb.BadBinaryInfo{}}
1519
>
1520
>
clusterActive := "some random active cluster name"
1521
>
clusterStandby := "some random standby cluster name"
1522
>
configVersion := int64(10)
1523
>
failoverVersion := int64(59)
1524
>
isGlobalNamespace := true
1525
>
clusters := []string{clusterActive, clusterStandby}
1526
>
1527
>
resp1, err1 := m.CreateNamespace(
1528
>
&persistencespb.NamespaceInfo{
1529
>
Id: id,
1530
>
Name: name,
1531
>
State: state,
1532
>
Description: description,
1533
>
Owner: owner,
1534
>
Data: data,
1535
>
},
1536
>
&persistencespb.NamespaceConfig{
1537
>
Retention: timestamp.DurationFromDays(retention),
1538
>
HistoryArchivalState: historyArchivalState,
1539
>
HistoryArchivalUri: historyArchivalURI,
1540
>
VisibilityArchivalState: visibilityArchivalState,
1541
>
VisibilityArchivalUri: visibilityArchivalURI,
1542
>
BadBinaries: badBinaries,
1543
>
},
1544
>
&persistencespb.NamespaceReplicationConfig{
1545
>
ActiveClusterName: clusterActive,
1546
>
Clusters: clusters,
1547
>
},
1548
>
isGlobalNamespace,
1549
>
configVersion,
1550
>
failoverVersion,
1551
>
)
1552
>
m.NoError(err1)
1553
>
m.EqualValues(id, resp1.ID)
1554
>
1555
>
resp2, err2 := m.GetNamespace(id, "")
1556
>
m.NoError(err2)
1557
>
metadata, err := m.MetadataManager.GetMetadata(m.ctx)
1558
>
m.NoError(err)
1559
>
notificationVersion := metadata.NotificationVersion
1560
>
1561
>
updatedDescription := "description-updated"
1562
>
1563
>
// Try to update with wrong notification version (stale version)
1564
>
err3 := m.UpdateNamespace(
1565
>
&persistencespb.NamespaceInfo{
1566
>
Id: resp2.Namespace.Info.Id,
1567
>
Name: resp2.Namespace.Info.Name,
1568
>
State: resp2.Namespace.Info.State,
1569
>
Description: updatedDescription,
1570
>
Owner: resp2.Namespace.Info.Owner,
1571
>
Data: resp2.Namespace.Info.Data,
1572
>
},
1573
>
&persistencespb.NamespaceConfig{
1574
>
Retention: resp2.Namespace.Config.Retention,
1575
>
HistoryArchivalState: resp2.Namespace.Config.HistoryArchivalState,
1576
>
HistoryArchivalUri: resp2.Namespace.Config.HistoryArchivalUri,
1577
>
VisibilityArchivalState: resp2.Namespace.Config.VisibilityArchivalState,
1578
>
VisibilityArchivalUri: resp2.Namespace.Config.VisibilityArchivalUri,
1579
>
BadBinaries: badBinaries,
1580
>
},
1581
>
&persistencespb.NamespaceReplicationConfig{
1582
>
ActiveClusterName: resp2.Namespace.ReplicationConfig.ActiveClusterName,
1583
>
Clusters: resp2.Namespace.ReplicationConfig.Clusters,
1584
>
},
1585
>
resp2.Namespace.ConfigVersion,
1586
>
resp2.Namespace.FailoverVersion,
1587
>
resp2.Namespace.FailoverNotificationVersion,
1588
>
time.Time{},
1589
>
notificationVersion-1, // Use stale notification version to trigger CAS failure
1590
>
isGlobalNamespace,
1591
>
)
1592
>
m.ErrorAs(err3, new(*serviceerror.Unavailable))
1593
>
1594
>
// Verify that the namespace was not updated
1595
>
resp4, err4 := m.GetNamespace(id, "")
1596
>
m.NoError(err4)
1597
>
m.Equal(description, resp4.Namespace.Info.Description) // Should still have old description
1598
>
}
1599
1600
// TestRenameNamespaceWithNameConflict tests name conflict when trying to rename a namespace