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
a6a9a6df
Commit
a6a9a6df
authored
9 years ago
by
murgatroid99
Browse files
Options
Downloads
Patches
Plain Diff
Add incompressible responses and status echoing to Node interop server
parent
77556c36
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/node/interop/interop_server.js
+36
-27
36 additions, 27 deletions
src/node/interop/interop_server.js
with
36 additions
and
27 deletions
src/node/interop/interop_server.js
+
36
−
27
View file @
a6a9a6df
...
...
@@ -44,6 +44,9 @@ var testProto = grpc.load({
var
ECHO_INITIAL_KEY
=
'
x-grpc-test-echo-initial
'
;
var
ECHO_TRAILING_KEY
=
'
x-grpc-test-echo-trailing-bin
'
;
var
incompressible_data
=
fs
.
readFileSync
(
__dirname
+
'
/../../../test/cpp/interop/rnd.dat
'
);
/**
* Create a buffer filled with size zeroes
* @param {number} size The length of the buffer
...
...
@@ -83,6 +86,19 @@ function getEchoTrailer(call) {
return
response_trailer
;
}
function
getPayload
(
payload_type
,
size
)
{
if
(
payload_type
===
'
RANDOM
'
)
{
payload_type
=
[
'
COMPRESSABLE
'
,
'
UNCOMPRESSABLE
'
][
Math
.
random
()
<
0.5
?
0
:
1
];
}
var
body
;
switch
(
payload_type
)
{
case
'
COMPRESSABLE
'
:
body
=
zeroBuffer
(
size
);
break
;
case
'
UNCOMPRESSABLE
'
:
incompressible_data
.
slice
(
size
);
break
;
}
return
{
type
:
payload_type
,
body
:
body
};
}
/**
* Respond to an empty parameter with an empty response.
* NOTE: this currently does not work due to issue #137
...
...
@@ -104,13 +120,14 @@ function handleEmpty(call, callback) {
function
handleUnary
(
call
,
callback
)
{
echoHeader
(
call
);
var
req
=
call
.
request
;
var
zeros
=
zeroBuffer
(
req
.
response_s
ize
);
var
payload_type
=
req
.
response_
type
;
if
(
payload_type
===
'
RANDOM
'
)
{
payload_type
=
[
'
COMPRESSABLE
'
,
'
UNCOMPRESSABLE
'
][
Math
.
random
()
<
0.5
?
0
:
1
]
;
if
(
req
.
response_s
tatus
)
{
var
status
=
req
.
response_
status
;
status
.
metadata
=
getEchoTrailer
(
call
);
callback
(
status
);
return
;
}
callback
(
null
,
{
payload
:
{
type
:
payload_type
,
body
:
zeros
}},
var
payload
=
getPayload
(
req
.
response_type
,
req
.
response_size
);
callback
(
null
,
{
payload
:
payload
},
getEchoTrailer
(
call
));
}
...
...
@@ -139,18 +156,14 @@ function handleStreamingInput(call, callback) {
function
handleStreamingOutput
(
call
)
{
echoHeader
(
call
);
var
req
=
call
.
request
;
var
payload_type
=
req
.
response_type
;
if
(
payload_type
===
'
RANDOM
'
)
{
payload_type
=
[
'
COMPRESSABLE
'
,
'
UNCOMPRESSABLE
'
][
Math
.
random
()
<
0.5
?
0
:
1
];
if
(
req
.
response_status
)
{
var
status
=
req
.
response_status
;
status
.
metadata
=
getEchoTrailer
(
call
);
call
.
emit
(
'
error
'
,
status
);
return
;
}
_
.
each
(
req
.
response_parameters
,
function
(
resp_param
)
{
call
.
write
({
payload
:
{
body
:
zeroBuffer
(
resp_param
.
size
),
type
:
payload_type
}
});
call
.
write
({
payload
:
getPayload
(
req
.
response_type
,
resp_param
.
size
)});
});
call
.
end
(
getEchoTrailer
(
call
));
}
...
...
@@ -163,18 +176,14 @@ function handleStreamingOutput(call) {
function
handleFullDuplex
(
call
)
{
echoHeader
(
call
);
call
.
on
(
'
data
'
,
function
(
value
)
{
var
payload_type
=
value
.
response_type
;
if
(
payload_type
===
'
RANDOM
'
)
{
payload_type
=
[
'
COMPRESSABLE
'
,
'
UNCOMPRESSABLE
'
][
Math
.
random
()
<
0.5
?
0
:
1
];
if
(
value
.
response_status
)
{
var
status
=
value
.
response_status
;
status
.
metadata
=
getEchoTrailer
(
call
);
call
.
emit
(
'
error
'
,
status
);
return
;
}
_
.
each
(
value
.
response_parameters
,
function
(
resp_param
)
{
call
.
write
({
payload
:
{
body
:
zeroBuffer
(
resp_param
.
size
),
type
:
payload_type
}
});
call
.
write
({
payload
:
getPayload
(
value
.
response_type
,
resp_param
.
size
)});
});
});
call
.
on
(
'
end
'
,
function
()
{
...
...
@@ -188,7 +197,7 @@ function handleFullDuplex(call) {
* @param {Call} call Call to handle
*/
function
handleHalfDuplex
(
call
)
{
throw
new
Error
(
'
HalfDuplexCall not yet implemented
'
);
call
.
emit
(
'
error
'
,
Error
(
'
HalfDuplexCall not yet implemented
'
)
)
;
}
/**
...
...
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