Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Grpc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tci-gateway-module
Grpc
Commits
e45ca5f5
Commit
e45ca5f5
authored
9 years ago
by
Jan Tattermusch
Browse files
Options
Downloads
Patches
Plain Diff
add support for C# generic client
parent
e26e2e5a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/csharp/Grpc.IntegrationTesting/ClientRunners.cs
+60
-7
60 additions, 7 deletions
src/csharp/Grpc.IntegrationTesting/ClientRunners.cs
with
60 additions
and
7 deletions
src/csharp/Grpc.IntegrationTesting/ClientRunners.cs
+
60
−
7
View file @
e45ca5f5
...
...
@@ -97,22 +97,32 @@ namespace Grpc.IntegrationTesting
return
new
SimpleClientRunner
(
channel
,
config
.
ClientType
,
config
.
RpcType
,
config
.
PayloadConfig
.
SimpleParams
,
config
.
PayloadConfig
,
config
.
HistogramParams
);
}
}
/// <summary>
///
Client that starts synchronous unary calls in a closed loop
.
///
Simple protobuf client
.
/// </summary>
public
class
SimpleClientRunner
:
IClientRunner
{
const
double
SecondsToNanos
=
1e9
;
readonly
static
Marshaller
<
byte
[
]>
ByteArrayMarshaller
=
new
Marshaller
<
byte
[
]>
((
b
)
=>
b
,
(
b
)
=>
b
);
readonly
static
Method
<
byte
[],
byte
[
]>
StreamingCallMethod
=
new
Method
<
byte
[],
byte
[
]>
(
MethodType
.
DuplexStreaming
,
"grpc.testing.BenchmarkService"
,
"StreamingCall"
,
ByteArrayMarshaller
,
ByteArrayMarshaller
);
readonly
Channel
channel
;
readonly
ClientType
clientType
;
readonly
RpcType
rpcType
;
readonly
SimpleProtoParams
payload
Params
;
readonly
PayloadConfig
payload
Config
;
readonly
Histogram
histogram
;
readonly
BenchmarkService
.
IBenchmarkServiceClient
client
;
...
...
@@ -120,12 +130,12 @@ namespace Grpc.IntegrationTesting
readonly
CancellationTokenSource
stoppedCts
;
readonly
WallClockStopwatch
wallClockStopwatch
=
new
WallClockStopwatch
();
public
SimpleClientRunner
(
Channel
channel
,
ClientType
clientType
,
RpcType
rpcType
,
SimpleProtoParams
payload
Params
,
HistogramParams
histogramParams
)
public
SimpleClientRunner
(
Channel
channel
,
ClientType
clientType
,
RpcType
rpcType
,
PayloadConfig
payload
Config
,
HistogramParams
histogramParams
)
{
this
.
channel
=
GrpcPreconditions
.
CheckNotNull
(
channel
);
this
.
clientType
=
clientType
;
this
.
rpcType
=
rpcType
;
this
.
payload
Params
=
payload
Params
;
this
.
payload
Config
=
payload
Config
;
this
.
histogram
=
new
Histogram
(
histogramParams
.
Resolution
,
histogramParams
.
MaxPossible
);
this
.
stoppedCts
=
new
CancellationTokenSource
();
...
...
@@ -213,8 +223,45 @@ namespace Grpc.IntegrationTesting
}
}
private
async
Task
RunGenericClosedLoopStreamingAsync
()
{
var
request
=
CreateByteBufferRequest
();
var
stopwatch
=
new
Stopwatch
();
var
callDetails
=
new
CallInvocationDetails
<
byte
[],
byte
[
]>
(
channel
,
StreamingCallMethod
,
new
CallOptions
());
using
(
var
call
=
Calls
.
AsyncDuplexStreamingCall
(
callDetails
))
{
while
(!
stoppedCts
.
Token
.
IsCancellationRequested
)
{
stopwatch
.
Restart
();
await
call
.
RequestStream
.
WriteAsync
(
request
);
await
call
.
ResponseStream
.
MoveNext
();
stopwatch
.
Stop
();
// spec requires data point in nanoseconds.
histogram
.
AddObservation
(
stopwatch
.
Elapsed
.
TotalSeconds
*
SecondsToNanos
);
}
// finish the streaming call
await
call
.
RequestStream
.
CompleteAsync
();
Assert
.
IsFalse
(
await
call
.
ResponseStream
.
MoveNext
());
}
}
private
Action
GetThreadBody
()
{
if
(
payloadConfig
.
PayloadCase
==
PayloadConfig
.
PayloadOneofCase
.
BytebufParams
)
{
GrpcPreconditions
.
CheckArgument
(
clientType
==
ClientType
.
ASYNC_CLIENT
,
"Generic client only supports async API"
);
GrpcPreconditions
.
CheckArgument
(
rpcType
==
RpcType
.
STREAMING
,
"Generic client only supports streaming calls"
);
return
()
=>
{
RunGenericClosedLoopStreamingAsync
().
Wait
();
};
}
GrpcPreconditions
.
CheckNotNull
(
payloadConfig
.
SimpleParams
);
if
(
clientType
==
ClientType
.
SYNC_CLIENT
)
{
GrpcPreconditions
.
CheckArgument
(
rpcType
==
RpcType
.
UNARY
,
"Sync client can only be used for Unary calls in C#"
);
...
...
@@ -241,13 +288,19 @@ namespace Grpc.IntegrationTesting
private
SimpleRequest
CreateSimpleRequest
()
{
GrpcPreconditions
.
CheckNotNull
(
payloadConfig
.
SimpleParams
);
return
new
SimpleRequest
{
Payload
=
CreateZerosPayload
(
payloadParams
.
ReqSize
),
ResponseSize
=
payloadParams
.
RespSize
Payload
=
CreateZerosPayload
(
payload
Config
.
Simple
Params
.
ReqSize
),
ResponseSize
=
payload
Config
.
Simple
Params
.
RespSize
};
}
private
byte
[]
CreateByteBufferRequest
()
{
return
new
byte
[
payloadConfig
.
BytebufParams
.
ReqSize
];
}
private
static
Payload
CreateZerosPayload
(
int
size
)
{
return
new
Payload
{
Body
=
ByteString
.
CopyFrom
(
new
byte
[
size
])
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment