Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize add ut for message #154

Merged
merged 2 commits into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
32 changes: 32 additions & 0 deletions pkg/protocol/message/message_apis_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package message

import (
"testing"

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

func TestMergedWarpMessage_GetTypeCode(t *testing.T) {
assert.Equal(t, MessageType_SeataMerge, MergedWarpMessage{}.GetTypeCode())
}

func TestMergedResultMessage_GetTYpeCode(t *testing.T) {
assert.Equal(t, MessageType_SeataMergeResult, MergeResultMessage{}.GetTypeCode())
}
38 changes: 38 additions & 0 deletions pkg/protocol/message/other_message_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package message

import (
"testing"

106umao marked this conversation as resolved.
Show resolved Hide resolved
"github.com/stretchr/testify/assert"
)

func TestNewMessageFuture(t *testing.T) {
rpcMessage := RpcMessage{ID: 0}
assert.Equal(t, 0, NewMessageFuture(rpcMessage).ID)
}

func TestHeartBeatMessage_ToString(t *testing.T) {
assert.Equal(t, "services ping", HeartBeatMessagePing.ToString())
assert.Equal(t, "services pong", HeartBeatMessagePong.ToString())
106umao marked this conversation as resolved.
Show resolved Hide resolved
}

func TestHeartBeatMessage_GetTypeCode(t *testing.T) {
assert.Equal(t, MessageType_HeartbeatMsg, HeartBeatMessage{}.GetTypeCode())
}
8 changes: 0 additions & 8 deletions pkg/protocol/message/request_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,3 @@ type RegisterRMRequest struct {
func (req RegisterRMRequest) GetTypeCode() MessageType {
return MessageType_RegRm
}

type RegisterRMResponse struct {
AbstractIdentifyResponse
}

func (resp RegisterRMResponse) GetTypeCode() MessageType {
return MessageType_RegRmResult
}
76 changes: 76 additions & 0 deletions pkg/protocol/message/request_message_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package message

import (
"testing"

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

func TestBranchRegisterRequest_GetTypeCode(t *testing.T) {
assert.Equal(t, MessageType_BranchRegister, BranchRegisterRequest{}.GetTypeCode())
106umao marked this conversation as resolved.
Show resolved Hide resolved
}

func TestBranchReportRequest_GetTypeCode(t *testing.T) {
assert.Equal(t, MessageType_BranchStatusReport, BranchReportRequest{}.GetTypeCode())
}

func TestBranchCommitRequest_GetTypeCode(t *testing.T) {
assert.Equal(t, MessageType_BranchCommit, BranchCommitRequest{}.GetTypeCode())
}

func TestBranchRollbackRequest_GetTypeCode(t *testing.T) {
assert.Equal(t, MessageType_BranchRollback, BranchRollbackRequest{}.GetTypeCode())
}

func TestGlobalBeginRequest_GetTypeCode(t *testing.T) {
assert.Equal(t, MessageType_GlobalBegin, GlobalBeginRequest{}.GetTypeCode())
}

func TestGlobalCommitRequest_GetTypeCode(t *testing.T) {
assert.Equal(t, MessageType_GlobalCommit, GlobalCommitRequest{}.GetTypeCode())
}

func TestGlobalRollbackRequest_GetTypeCode(t *testing.T) {
assert.Equal(t, MessageType_GlobalRollback, GlobalRollbackRequest{}.GetTypeCode())
}

func TestGlobalLockQueryRequest_GetTypeCode(t *testing.T) {
assert.Equal(t, MessageType_GlobalLockQuery, GlobalLockQueryRequest{}.GetTypeCode())
}

func TestGlobalReportRequest_GetTypeCode(t *testing.T) {
assert.Equal(t, MessageType_GlobalReport, GlobalReportRequest{}.GetTypeCode())
}

func TestUndoLogDeleteRequest_GetTypeCode(t *testing.T) {
assert.Equal(t, MessageType_RmDeleteUndolog, UndoLogDeleteRequest{}.GetTypeCode())
}

func TestRegisterTMRequest_GetTypeCode(t *testing.T) {
assert.Equal(t, MessageType_RegClt, RegisterTMRequest{}.GetTypeCode())
}

func TestRegisterRMRequest_GetTypeCode(t *testing.T) {
assert.Equal(t, MessageType_RegRm, RegisterRMRequest{}.GetTypeCode())
}

func TestGlobalStatusRequest_GetTypeCode(t *testing.T) {
assert.Equal(t, MessageType_GlobalStatusResult, GlobalStatusResponse{}.GetTypeCode())
}
8 changes: 8 additions & 0 deletions pkg/protocol/message/response_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,11 @@ type GlobalRollbackResponse struct {
func (resp GlobalRollbackResponse) GetTypeCode() MessageType {
return MessageType_GlobalRollbackResult
}

type RegisterRMResponse struct {
AbstractIdentifyResponse
}

func (resp RegisterRMResponse) GetTypeCode() MessageType {
return MessageType_RegRmResult
}
72 changes: 72 additions & 0 deletions pkg/protocol/message/response_message_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package message

import (
"testing"

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

func TestRegisterRMResponse_GetTypeCode(t *testing.T) {
assert.Equal(t, MessageType_RegRmResult, RegisterRMResponse{}.GetTypeCode())
}

func TestRegisterTMResponse_GetTypeCode(t *testing.T) {
assert.Equal(t, MessageType_RegCltResult, RegisterTMResponse{}.GetTypeCode())
}

func TestGlobalReportResponse_GetTypeCode(t *testing.T) {
assert.Equal(t, MessageType_GlobalReportResult, GlobalReportResponse{}.GetTypeCode())
}

func TestGlobalLockQueryResponse_GetTypeCode(t *testing.T) {
assert.Equal(t, MessageType_GlobalLockQueryResult, GlobalLockQueryResponse{}.GetTypeCode())
}

func TestGlobalRollbackResponse_GetTypeCode(t *testing.T) {
assert.Equal(t, MessageType_GlobalRollbackResult, GlobalRollbackResponse{}.GetTypeCode())
}

func TestGlobalCommitResponse_GetTypeCode(t *testing.T) {
assert.Equal(t, MessageType_GlobalCommitResult, GlobalCommitResponse{}.GetTypeCode())
}

func TestGlobalBeginResponse_GetTypeCode(t *testing.T) {
assert.Equal(t, MessageType_GlobalBeginResult, GlobalBeginResponse{}.GetTypeCode())
}

func TestBranchRollbackResponse_GetTypeCode(t *testing.T) {
assert.Equal(t, MessageType_BranchRollbackResult, BranchRollbackResponse{}.GetTypeCode())
}

func TestBranchCommitResponse_GetTypeCode(t *testing.T) {
assert.Equal(t, MessageType_BranchCommitResult, BranchCommitResponse{}.GetTypeCode())
}

func TestBranchRegisterResponse_GetTypeCode(t *testing.T) {
assert.Equal(t, MessageType_BranchRegisterResult, BranchRegisterResponse{}.GetTypeCode())
}

func TestBranchReportResponse_GetTypeCode(t *testing.T) {
assert.Equal(t, MessageType_BranchStatusReportResult, BranchReportResponse{}.GetTypeCode())
}

func TestGlobalStatusResponse_GetTypeCode(t *testing.T) {
assert.Equal(t, MessageType_GlobalStatusResult, GlobalStatusResponse{}.GetTypeCode())
}