Skip to content
Draft
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,7 @@ const (
ShardModeHashRing = "hash-ring"
ShardModeShardDistributor = "shard-distributor"
)

const (
StringSizeOverheadBytes = 16
)
11 changes: 11 additions & 0 deletions common/definition/workflowIdentifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

package definition

import "github.com/uber/cadence/common"

type (
// WorkflowIdentifier is the combinations which represent a workflow
WorkflowIdentifier struct {
Expand All @@ -29,6 +31,15 @@ type (
}
)

// Size calculates the size in bytes of the WorkflowIdentifier struct.
func (wi *WorkflowIdentifier) Size() uint64 {
// Calculate the size of strings in bytes, we assume that all those fields are using ASCII which is 1 byte per char
size := len(wi.DomainID) + len(wi.WorkflowID) + len(wi.RunID)
// Each string internally holds a reference pointer and a length, which are 8 bytes each
stringOverhead := 3 * common.StringSizeOverheadBytes
return uint64(size + stringOverhead)
}

// NewWorkflowIdentifier create a new WorkflowIdentifier
func NewWorkflowIdentifier(domainID string, workflowID string, runID string) WorkflowIdentifier {
return WorkflowIdentifier{
Expand Down
71 changes: 71 additions & 0 deletions common/definition/workflowidentifier_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// The MIT License (MIT)

// Copyright (c) 2017-2020 Uber Technologies Inc.

// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

package definition

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
)

// WorkflowIdentifierTestSuite is a test suite for the WorkflowIdentifier struct.
type WorkflowIdentifierTestSuite struct {
suite.Suite
}

// SetupTest runs before each test function in the suite.
func (suite *WorkflowIdentifierTestSuite) SetupTest() {
// Any necessary setup would go here, but it's not required in this case.
}

// TestSize verifies the Size method of WorkflowIdentifier.
func (suite *WorkflowIdentifierTestSuite) TestSize() {
tests := []struct {
wi WorkflowIdentifier
expected uint64
}{
{
wi: NewWorkflowIdentifier("domain", "workflow", "run"),
expected: uint64(len("domain") + len("workflow") + len("run") + 3*16),
},
{
wi: NewWorkflowIdentifier("", "", ""),
expected: uint64(3 * 16),
},
{
wi: NewWorkflowIdentifier("a", "b", "c"),
expected: uint64(3 + 3*16),
},
}

for _, test := range tests {
size := test.wi.Size()
assert.Equal(suite.T(), test.expected, size)
}
}

// TestWorkflowIdentifierTestSuite runs the test suite.
func TestWorkflowIdentifierTestSuite(t *testing.T) {
suite.Run(t, new(WorkflowIdentifierTestSuite))
}
Loading