forked from TrueCloudLab/frostfs-sdk-go
[#276] Merge repo with frostfs-api-go
Signed-off-by: Pavel Pogodaev <p.pogodaev@yadro.com>
This commit is contained in:
parent
5361f0eceb
commit
6ce73790ea
337 changed files with 66666 additions and 283 deletions
75
api/rpc/common/call.go
Normal file
75
api/rpc/common/call.go
Normal file
|
@ -0,0 +1,75 @@
|
|||
package common
|
||||
|
||||
type callType uint8
|
||||
|
||||
const (
|
||||
_ callType = iota
|
||||
callUnary
|
||||
callClientStream
|
||||
callServerStream
|
||||
callBidirStream
|
||||
)
|
||||
|
||||
// CallMethodInfo is an information about the RPC.
|
||||
type CallMethodInfo struct {
|
||||
// Name of the service.
|
||||
Service string
|
||||
|
||||
// Name of the RPC.
|
||||
Name string
|
||||
|
||||
t callType
|
||||
}
|
||||
|
||||
// ServerStream checks if CallMethodInfo contains
|
||||
// information about the server-side streaming RPC.
|
||||
func (c CallMethodInfo) ServerStream() bool {
|
||||
return c.t == callServerStream || c.t == callBidirStream
|
||||
}
|
||||
|
||||
// ClientStream checks if CallMethodInfo contains
|
||||
// information about the client-side streaming RPC.
|
||||
func (c CallMethodInfo) ClientStream() bool {
|
||||
return c.t == callClientStream || c.t == callBidirStream
|
||||
}
|
||||
|
||||
func (c *CallMethodInfo) setCommon(service, name string) {
|
||||
c.Service = service
|
||||
c.Name = name
|
||||
}
|
||||
|
||||
// CallMethodInfoUnary returns CallMethodInfo structure
|
||||
// initialized for the unary RPC.
|
||||
func CallMethodInfoUnary(service, name string) (info CallMethodInfo) {
|
||||
info.setCommon(service, name)
|
||||
info.t = callUnary
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// CallMethodInfoClientStream returns CallMethodInfo structure
|
||||
// initialized for the client-side streaming RPC.
|
||||
func CallMethodInfoClientStream(service, name string) (info CallMethodInfo) {
|
||||
info.setCommon(service, name)
|
||||
info.t = callClientStream
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// CallMethodInfoServerStream returns CallMethodInfo structure
|
||||
// initialized for the server-side streaming RPC.
|
||||
func CallMethodInfoServerStream(service, name string) (info CallMethodInfo) {
|
||||
info.setCommon(service, name)
|
||||
info.t = callServerStream
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// CallMethodInfoBidirectionalStream returns CallMethodInfo structure
|
||||
// initialized for the bidirectional streaming RPC.
|
||||
func CallMethodInfoBidirectionalStream(service, name string) (info CallMethodInfo) {
|
||||
info.setCommon(service, name)
|
||||
info.t = callBidirStream
|
||||
|
||||
return
|
||||
}
|
49
api/rpc/common/call_test.go
Normal file
49
api/rpc/common/call_test.go
Normal file
|
@ -0,0 +1,49 @@
|
|||
package common_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/rpc/common"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const (
|
||||
testServiceName = "test service"
|
||||
testRPCName = "test RPC"
|
||||
)
|
||||
|
||||
func TestCallMethodInfoUnary(t *testing.T) {
|
||||
i := common.CallMethodInfoUnary(testServiceName, testRPCName)
|
||||
|
||||
require.Equal(t, testServiceName, i.Service)
|
||||
require.Equal(t, testRPCName, i.Name)
|
||||
require.False(t, i.ClientStream())
|
||||
require.False(t, i.ServerStream())
|
||||
}
|
||||
|
||||
func TestCallMethodInfoServerStream(t *testing.T) {
|
||||
i := common.CallMethodInfoServerStream(testServiceName, testRPCName)
|
||||
|
||||
require.Equal(t, testServiceName, i.Service)
|
||||
require.Equal(t, testRPCName, i.Name)
|
||||
require.False(t, i.ClientStream())
|
||||
require.True(t, i.ServerStream())
|
||||
}
|
||||
|
||||
func TestCallMethodInfoClientStream(t *testing.T) {
|
||||
i := common.CallMethodInfoClientStream(testServiceName, testRPCName)
|
||||
|
||||
require.Equal(t, testServiceName, i.Service)
|
||||
require.Equal(t, testRPCName, i.Name)
|
||||
require.True(t, i.ClientStream())
|
||||
require.False(t, i.ServerStream())
|
||||
}
|
||||
|
||||
func TestCallMethodInfoBidirectionalStream(t *testing.T) {
|
||||
i := common.CallMethodInfoBidirectionalStream(testServiceName, testRPCName)
|
||||
|
||||
require.Equal(t, testServiceName, i.Service)
|
||||
require.Equal(t, testRPCName, i.Name)
|
||||
require.True(t, i.ClientStream())
|
||||
require.True(t, i.ServerStream())
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue