Skip to content

Commit

Permalink
Changed RegisterNamespace to initialize new Namespaces in REPLICATION…
Browse files Browse the repository at this point in the history
…_STATE_NORMAL (#2887)

* Changed RegisterNamespace to initialize new Namespaces in REPLICATION_STATE_NORMAL

* goimports
  • Loading branch information
Jason Roselander committed May 21, 2022
1 parent 04f2094 commit df43fba
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
1 change: 1 addition & 0 deletions common/namespace/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ func (d *HandlerImpl) RegisterNamespace(
replicationConfig := &persistencespb.NamespaceReplicationConfig{
ActiveClusterName: activeClusterName,
Clusters: clusters,
State: enumspb.REPLICATION_STATE_NORMAL,
}
isGlobalNamespace := registerRequest.GetIsGlobalNamespace()

Expand Down
53 changes: 51 additions & 2 deletions common/namespace/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import (
"testing"
"time"

persistence2 "go.temporal.io/server/api/persistence/v1"

"github.com/gogo/protobuf/proto"
"github.com/golang/mock/gomock"
"github.com/pborman/uuid"
Expand Down Expand Up @@ -376,12 +378,59 @@ func (s *namespaceHandlerCommonSuite) TestListNamespace() {
FailoverVersion: s.ClusterMetadata.GetNextFailoverVersion(activeClusterName2, 0),
IsGlobalNamespace: isGlobalNamespace2,
},
}, namespaces)
}, namespaces,
)
}

func (s *namespaceHandlerCommonSuite) TestRegisterNamespace() {
const namespace = "namespace-to-register"
retention := timestamp.DurationPtr(10 * 24 * time.Hour)
registerRequest := &workflowservice.RegisterNamespaceRequest{
Namespace: namespace,
Description: namespace,
WorkflowExecutionRetentionPeriod: retention,
IsGlobalNamespace: true,
}
_, err := s.handler.RegisterNamespace(context.Background(), registerRequest)
s.NoError(err)

nsResp, err := s.MetadataManager.GetNamespace(
context.Background(),
&persistence.GetNamespaceRequest{Name: namespace},
)
s.NoError(err)

wantNsDetail := persistence2.NamespaceDetail{
Info: &persistence2.NamespaceInfo{
State: enumspb.NAMESPACE_STATE_REGISTERED,
Name: namespace,
Description: namespace,
},
Config: &persistence2.NamespaceConfig{Retention: retention},
ReplicationConfig: &persistence2.NamespaceReplicationConfig{
ActiveClusterName: s.ClusterMetadata.GetMasterClusterName(),
Clusters: []string{s.ClusterMetadata.GetMasterClusterName()},
State: enumspb.REPLICATION_STATE_NORMAL,
},
}

s.Equal(registerRequest.IsGlobalNamespace, nsResp.IsGlobalNamespace)
gotNsDetail := nsResp.Namespace
s.Equal(wantNsDetail.Info.Name, gotNsDetail.Info.Name)
s.Equal(wantNsDetail.Info.Description, gotNsDetail.Info.Description)
s.Equal(wantNsDetail.Info.State, gotNsDetail.Info.State)
s.Equal(wantNsDetail.Config.Retention, gotNsDetail.Config.Retention)
s.Equal(wantNsDetail.ReplicationConfig, gotNsDetail.ReplicationConfig)
}

func (s *namespaceHandlerCommonSuite) TestRegisterNamespace_InvalidRetentionPeriod() {
// local
for _, invalidDuration := range []time.Duration{0, -1 * time.Hour, 1 * time.Millisecond, 10 * 365 * 24 * time.Hour} {
for _, invalidDuration := range []time.Duration{
0,
-1 * time.Hour,
1 * time.Millisecond,
10 * 365 * 24 * time.Hour,
} {
registerRequest := &workflowservice.RegisterNamespaceRequest{
Namespace: "random namespace name",
Description: "random namespace name",
Expand Down

0 comments on commit df43fba

Please sign in to comment.