Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
refactor(metadata): use incremental hash and add CalAndGetRevision test
  • Loading branch information
Qiao-yq committed Jun 6, 2026
commit 2c8620762ce996259c9921593ea35c53e7184bc4
9 changes: 4 additions & 5 deletions metadata/info/metadata_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,12 +372,11 @@ func CalRevision(app string, services map[string]*ServiceInfo) string {
}
sort.Strings(matchKeys)

var b strings.Builder
b.WriteString(app)
h := sha512.New()
h.Write([]byte(app))
for _, mk := range matchKeys {
b.WriteString(services[mk].toDescString())
h.Write([]byte(services[mk].toDescString()))
}

sum := sha512.Sum512([]byte(b.String()))
return fmt.Sprintf("%x", sum)
return fmt.Sprintf("%x", h.Sum(nil))
}
24 changes: 24 additions & 0 deletions metadata/info/metadata_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,27 @@ func TestServiceInfoGetMatchKey(t *testing.T) {
func TestServiceInfoJavaClassName(t *testing.T) {
assert.Equalf(t, "org.apache.dubbo.metadata.MetadataInfo", NewAppMetadataInfo("dubbo").JavaClassName(), "JavaClassName()")
}

func TestMetadataInfoCalAndGetRevision(t *testing.T) {
svcURL, err := common.NewURL(
"dubbo://127.0.0.1:20880/com.example.TestService",
common.WithParamsValue(constant.ApplicationKey, "test-app"),
common.WithParamsValue(constant.GroupKey, "groupA"),
common.WithParamsValue(constant.VersionKey, "1.0.0"),
common.WithMethods([]string{"sayHello"}),
)
require.NoError(t, err)

info := NewAppMetadataInfo("")
info.AddService(svcURL)

// 1. Call CalAndGetRevision — should update info.Revision in-place
rev := info.CalAndGetRevision()

assert.NotEmpty(t, rev)
assert.Equal(t, rev, info.Revision, "CalAndGetRevision should update info.Revision in-place")

// 2. Result should match CalRevision for the same input
assert.Equal(t, CalRevision(info.App, info.Services), rev,
"CalAndGetRevision should return the same result as CalRevision")
}
Loading