Skip to content

Commit

Permalink
Merge github.com:grpc/grpc into shindig
Browse files Browse the repository at this point in the history
  • Loading branch information
ctiller committed Sep 11, 2015
2 parents 8664ca6 + 35fea62 commit 1701b09
Show file tree
Hide file tree
Showing 177 changed files with 1,869 additions and 1,102 deletions.
12 changes: 12 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ cc_library(
"src/core/client_config/connector.h",
"src/core/client_config/lb_policies/pick_first.h",
"src/core/client_config/lb_policy.h",
"src/core/client_config/lb_policy_factory.h",
"src/core/client_config/lb_policy_registry.h",
"src/core/client_config/resolver.h",
"src/core/client_config/resolver_factory.h",
"src/core/client_config/resolver_registry.h",
Expand Down Expand Up @@ -286,6 +288,8 @@ cc_library(
"src/core/client_config/connector.c",
"src/core/client_config/lb_policies/pick_first.c",
"src/core/client_config/lb_policy.c",
"src/core/client_config/lb_policy_factory.c",
"src/core/client_config/lb_policy_registry.c",
"src/core/client_config/resolver.c",
"src/core/client_config/resolver_factory.c",
"src/core/client_config/resolver_registry.c",
Expand Down Expand Up @@ -433,6 +437,8 @@ cc_library(
"src/core/client_config/connector.h",
"src/core/client_config/lb_policies/pick_first.h",
"src/core/client_config/lb_policy.h",
"src/core/client_config/lb_policy_factory.h",
"src/core/client_config/lb_policy_registry.h",
"src/core/client_config/resolver.h",
"src/core/client_config/resolver_factory.h",
"src/core/client_config/resolver_registry.h",
Expand Down Expand Up @@ -541,6 +547,8 @@ cc_library(
"src/core/client_config/connector.c",
"src/core/client_config/lb_policies/pick_first.c",
"src/core/client_config/lb_policy.c",
"src/core/client_config/lb_policy_factory.c",
"src/core/client_config/lb_policy_registry.c",
"src/core/client_config/resolver.c",
"src/core/client_config/resolver_factory.c",
"src/core/client_config/resolver_registry.c",
Expand Down Expand Up @@ -1057,6 +1065,8 @@ objc_library(
"src/core/client_config/connector.c",
"src/core/client_config/lb_policies/pick_first.c",
"src/core/client_config/lb_policy.c",
"src/core/client_config/lb_policy_factory.c",
"src/core/client_config/lb_policy_registry.c",
"src/core/client_config/resolver.c",
"src/core/client_config/resolver_factory.c",
"src/core/client_config/resolver_registry.c",
Expand Down Expand Up @@ -1201,6 +1211,8 @@ objc_library(
"src/core/client_config/connector.h",
"src/core/client_config/lb_policies/pick_first.h",
"src/core/client_config/lb_policy.h",
"src/core/client_config/lb_policy_factory.h",
"src/core/client_config/lb_policy_registry.h",
"src/core/client_config/resolver.h",
"src/core/client_config/resolver_factory.h",
"src/core/client_config/resolver_registry.h",
Expand Down
14 changes: 9 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ CC_tsan = clang
CXX_tsan = clang++
LD_tsan = clang
LDXX_tsan = clang++
CPPFLAGS_tsan = -O0 -fsanitize=thread -fno-omit-frame-pointer -Wno-error=unused-command-line-argument
CPPFLAGS_tsan = -O0 -fsanitize=thread -fno-omit-frame-pointer -Wno-unused-command-line-argument
LDFLAGS_tsan = -fsanitize=thread
DEFINES_tsan = NDEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=10

Expand All @@ -155,7 +155,7 @@ CC_asan = clang
CXX_asan = clang++
LD_asan = clang
LDXX_asan = clang++
CPPFLAGS_asan = -O0 -fsanitize=address -fno-omit-frame-pointer -Wno-error=unused-command-line-argument
CPPFLAGS_asan = -O0 -fsanitize=address -fno-omit-frame-pointer -Wno-unused-command-line-argument
LDFLAGS_asan = -fsanitize=address
DEFINES_asan = GRPC_TEST_SLOWDOWN_BUILD_FACTOR=3

Expand All @@ -165,7 +165,7 @@ CC_msan = clang
CXX_msan = clang++-libc++
LD_msan = clang
LDXX_msan = clang++-libc++
CPPFLAGS_msan = -O0 -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_USE_OWN_TR1_TUPLE=1 -Wno-error=unused-command-line-argument
CPPFLAGS_msan = -O0 -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_USE_OWN_TR1_TUPLE=1 -Wno-unused-command-line-argument
OPENSSL_CFLAGS_msan = -DPURIFY
LDFLAGS_msan = -fsanitize=memory -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_USE_OWN_TR1_TUPLE=1
DEFINES_msan = NDEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=4
Expand All @@ -176,7 +176,7 @@ CC_ubsan = clang
CXX_ubsan = clang++
LD_ubsan = clang
LDXX_ubsan = clang++
CPPFLAGS_ubsan = -O1 -fsanitize=undefined -fno-omit-frame-pointer -Wno-error=unused-command-line-argument
CPPFLAGS_ubsan = -O1 -fsanitize=undefined -fno-omit-frame-pointer -Wno-unused-command-line-argument
OPENSSL_CFLAGS_ubsan = -DPURIFY
LDFLAGS_ubsan = -fsanitize=undefined
DEFINES_ubsan = NDEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=3
Expand Down Expand Up @@ -245,7 +245,7 @@ ifdef EXTRA_DEFINES
DEFINES += $(EXTRA_DEFINES)
endif

CFLAGS += -std=c89 -pedantic
CFLAGS += -std=c89 -pedantic -Wsign-conversion -Wconversion
ifeq ($(HAS_CXX11),true)
CXXFLAGS += -std=c++11
else
Expand Down Expand Up @@ -4054,6 +4054,8 @@ LIBGRPC_SRC = \
src/core/client_config/connector.c \
src/core/client_config/lb_policies/pick_first.c \
src/core/client_config/lb_policy.c \
src/core/client_config/lb_policy_factory.c \
src/core/client_config/lb_policy_registry.c \
src/core/client_config/resolver.c \
src/core/client_config/resolver_factory.c \
src/core/client_config/resolver_registry.c \
Expand Down Expand Up @@ -4331,6 +4333,8 @@ LIBGRPC_UNSECURE_SRC = \
src/core/client_config/connector.c \
src/core/client_config/lb_policies/pick_first.c \
src/core/client_config/lb_policy.c \
src/core/client_config/lb_policy_factory.c \
src/core/client_config/lb_policy_registry.c \
src/core/client_config/resolver.c \
src/core/client_config/resolver_factory.c \
src/core/client_config/resolver_registry.c \
Expand Down
2 changes: 2 additions & 0 deletions build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ filegroups:
src/core/channel/context.h, src/core/channel/http_client_filter.h, src/core/channel/http_server_filter.h,
src/core/channel/noop_filter.h, src/core/client_config/client_config.h, src/core/client_config/connector.h,
src/core/client_config/lb_policies/pick_first.h, src/core/client_config/lb_policy.h,
src/core/client_config/lb_policy_factory.h, src/core/client_config/lb_policy_registry.h,
src/core/client_config/resolver.h, src/core/client_config/resolver_factory.h,
src/core/client_config/resolver_registry.h, src/core/client_config/resolvers/dns_resolver.h,
src/core/client_config/resolvers/sockaddr_resolver.h, src/core/client_config/subchannel.h,
Expand Down Expand Up @@ -86,6 +87,7 @@ filegroups:
src/core/channel/connected_channel.c, src/core/channel/http_client_filter.c, src/core/channel/http_server_filter.c,
src/core/channel/noop_filter.c, src/core/client_config/client_config.c, src/core/client_config/connector.c,
src/core/client_config/lb_policies/pick_first.c, src/core/client_config/lb_policy.c,
src/core/client_config/lb_policy_factory.c, src/core/client_config/lb_policy_registry.c,
src/core/client_config/resolver.c, src/core/client_config/resolver_factory.c,
src/core/client_config/resolver_registry.c, src/core/client_config/resolvers/dns_resolver.c,
src/core/client_config/resolvers/sockaddr_resolver.c, src/core/client_config/subchannel.c,
Expand Down
12 changes: 9 additions & 3 deletions doc/interop-test-descriptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,9 @@ token (created by the project's key file)
Test caller should set flag `--service_account_key_file` with the
path to json key file downloaded from
https://console.developers.google.com.
https://console.developers.google.com. Alternately, if using a
usable auth implementation, she may specify the file location in the environment
variable GOOGLE_APPLICATION_CREDENTIALS.
Server features:
* [UnaryCall][]
Expand All @@ -540,7 +542,7 @@ Client asserts:
* call was successful
* received SimpleResponse.username is not empty and is in the json key file used
by the auth library. The client can optionally check the username matches the
email address in the key file.
email address in the key file or equals the value of `--default_service_account` flag.
* response payload body is 314159 bytes in size
* clients are free to assert that the response payload body contents are zero
and comparing the entire response message against a golden response
Expand Down Expand Up @@ -598,14 +600,18 @@ json key file or GCE default service account email.
Similar to the other auth tests, this test is only for cloud-to-prod path.
This test verifies unary calls succeed in sending messages using a JWT
This test verifies unary calls succeed in sending messages using a JWT or a service account
credentials set on the RPC.
The test
- uses the flag `--service_account_key_file` with the path to a json key file
downloaded from https://console.developers.google.com. Alternately, if using a
usable auth implementation, it may specify the file location in the environment
variable GOOGLE_APPLICATION_CREDENTIALS
- optionally uses the flag `--oauth_scope` for the oauth scope if implementator
wishes to use service account credential instead of JWT credential. For testing
against grpc-test.sandbox.google.com, oauth scope
"https://www.googleapis.com/auth/xapi.zoo" should be used.
Server features:
* [UnaryCall][]
Expand Down
3 changes: 0 additions & 3 deletions examples/python/helloworld/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ Which internally invokes the proto-compiler as:
$ protoc -I ../../protos --python_out=. --grpc_out=. --plugin=protoc-gen-grpc=`which grpc_python_plugin` ../../protos/helloworld.proto
```

Optionally, you can just skip the code generation step as the generated python module has already
been generated for you (helloworld_pb2.py).

### The client

Client-side code can be found in [greeter_client.py](greeter_client.py).
Expand Down
9 changes: 6 additions & 3 deletions examples/python/helloworld/greeter_client.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,18 @@

"""The Python implementation of the GRPC helloworld.Greeter client."""

from grpc.beta import implementations

import helloworld_pb2

_TIMEOUT_SECONDS = 10


def run():
with helloworld_pb2.early_adopter_create_Greeter_stub('localhost', 50051) as stub:
response = stub.SayHello(helloworld_pb2.HelloRequest(name='you'), _TIMEOUT_SECONDS)
print "Greeter client received: " + response.message
channel = implementations.insecure_channel('localhost', 50051)
stub = helloworld_pb2.beta_create_Greeter_stub(channel)
response = stub.SayHello(helloworld_pb2.HelloRequest(name='you'), _TIMEOUT_SECONDS)
print "Greeter client received: " + response.message


if __name__ == '__main__':
Expand Down
6 changes: 3 additions & 3 deletions examples/python/helloworld/greeter_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@
_ONE_DAY_IN_SECONDS = 60 * 60 * 24


class Greeter(helloworld_pb2.EarlyAdopterGreeterServicer):
class Greeter(helloworld_pb2.BetaGreeterServicer):

def SayHello(self, request, context):
return helloworld_pb2.HelloReply(message='Hello, %s!' % request.name)


def serve():
server = helloworld_pb2.early_adopter_create_Greeter_server(
Greeter(), 50051, None, None)
server = helloworld_pb2.beta_create_Greeter_server(Greeter())
server.add_insecure_port('[::]:50051')
server.start()
try:
while True:
Expand Down
36 changes: 16 additions & 20 deletions examples/python/route_guide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Then change your current directory to `examples/python/route_guide`:
$ cd examples/python/route_guide
```

You also should have the relevant tools installed to generate the server and client interface code - if you don't already, follow the setup instructions in [the Python quick start guide](../python).
You also should have the relevant tools installed to generate the server and client interface code - if you don't already, follow the setup instructions in [the Python quick start guide](../helloworld).

## Defining the service

Expand Down Expand Up @@ -99,12 +99,11 @@ $ protoc -I ../../protos --python_out=. --grpc_out=. --plugin=protoc-gen-grpc=`w
Note that as we've already provided a version of the generated code in the example repository, running this command regenerates the appropriate file rather than creates a new one. The generated code file is called `route_guide_pb2.py` and contains:
- classes for the messages defined in route_guide.proto
- abstract classes for the service defined in route_guide.proto
- `EarlyAdopterRouteGuideServicer`, which defines the interface for implementations of the RouteGuide service
- `EarlyAdopterRouteGuideServer`, which may be started and stopped
- `EarlyAdopterRouteGuideStub`, which can be used by clients to invoke RouteGuide RPCs
- `BetaRouteGuideServicer`, which defines the interface for implementations of the RouteGuide service
- `BetaRouteGuideStub`, which can be used by clients to invoke RouteGuide RPCs
- functions for application use
- `early_adopter_create_RouteGuide_server`, which creates a gRPC server given an `EarlyAdopterRouteGuideServicer` object
- `early_adopter_create_RouteGuide_stub`, which can be used by clients to create a stub object
- `beta_create_RouteGuide_server`, which creates a gRPC server given a `BetaRouteGuideServicer` object
- `beta_create_RouteGuide_stub`, which can be used by clients to create a stub object

<a name="server"></a>
## Creating the server
Expand All @@ -119,11 +118,11 @@ You can find the example `RouteGuide` server in [route_guide_server.py](route_gu

### Implementing RouteGuide

`route_guide_server.py` has a `RouteGuideServicer` class that implements the generated interface `route_guide_pb2.EarlyAdopterRouteGuideServicer`:
`route_guide_server.py` has a `RouteGuideServicer` class that implements the generated interface `route_guide_pb2.BetaRouteGuideServicer`:

```python
# RouteGuideServicer provides an implementation of the methods of the RouteGuide service.
class RouteGuideServicer(route_guide_pb2.EarlyAdopterRouteGuideServicer):
class RouteGuideServicer(route_guide_pb2.BetaRouteGuideServicer):
```

`RouteGuideServicer` implements all the `RouteGuide` service methods.
Expand All @@ -141,7 +140,7 @@ Let's look at the simplest type first, `GetFeature`, which just gets a `Point` f
return feature
```

The method is passed a `route_guide_pb2.Point` request for the RPC, and an `RpcContext` object that provides RPC-specific information such as timeout limits. It returns a `route_guide_pb2.Feature` response.
The method is passed a `route_guide_pb2.Point` request for the RPC, and a `ServicerContext` object that provides RPC-specific information such as timeout limits. It returns a `route_guide_pb2.Feature` response.

#### Response-streaming RPC

Expand Down Expand Up @@ -212,8 +211,8 @@ Once you have implemented all the `RouteGuide` methods, the next step is to star

```python
def serve():
server = route_guide_pb2.early_adopter_create_RouteGuide_server(
RouteGuideServicer(), 50051, None, None)
server = route_guide_pb2.beta_create_RouteGuide_server(RouteGuideServicer())
server.add_insecure_port('[::]:50051')
server.start()
```

Expand All @@ -228,17 +227,14 @@ You can see the complete example client code in [route_guide_client.py](route_gu

To call service methods, we first need to create a *stub*.

We use the `early_adopter_create_RouteGuide_stub` function of the `route_guide_pb2` module, generated from our .proto.
We use the `beta_create_RouteGuide_stub` function of the `route_guide_pb2` module, generated from our .proto.

```python
stub = RouteGuide::Stub.new('localhost', 50051)
channel = implementations.insecure_channel('localhost', 50051)
stub = beta_create_RouteGuide_stub(channel)
```

The returned object implements all the methods defined by the `EarlyAdopterRouteGuideStub` interface, and is also a [context manager](https://docs.python.org/2/library/stdtypes.html#typecontextmanager). All RPCs invoked on the stub must be invoked within the stub's context, so it is common for stubs to be created and used with a [with statement](https://docs.python.org/2/reference/compound_stmts.html#the-with-statement):

```python
with route_guide_pb2.early_adopter_create_RouteGuide_stub('localhost', 50051) as stub:
```
The returned object implements all the methods defined by the `BetaRouteGuideStub` interface.

### Calling service methods

Expand All @@ -255,7 +251,7 @@ feature = stub.GetFeature(point, timeout_in_seconds)
An asynchronous call to `GetFeature` is similar, but like calling a local method asynchronously in a thread pool:

```python
feature_future = stub.GetFeature.async(point, timeout_in_seconds)
feature_future = stub.GetFeature.future(point, timeout_in_seconds)
feature = feature_future.result()
```

Expand All @@ -276,7 +272,7 @@ route_summary = stub.RecordRoute(point_sequence, timeout_in_seconds)
```

```python
route_summary_future = stub.RecordRoute.async(point_sequence, timeout_in_seconds)
route_summary_future = stub.RecordRoute.future(point_sequence, timeout_in_seconds)
route_summary = route_summary_future.result()
```

Expand Down
21 changes: 12 additions & 9 deletions examples/python/route_guide/route_guide_client.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import random
import time

from grpc.beta import implementations

import route_guide_pb2
import route_guide_resources

Expand Down Expand Up @@ -115,15 +117,16 @@ def guide_route_chat(stub):


def run():
with route_guide_pb2.early_adopter_create_RouteGuide_stub('localhost', 50051) as stub:
print "-------------- GetFeature --------------"
guide_get_feature(stub)
print "-------------- ListFeatures --------------"
guide_list_features(stub)
print "-------------- RecordRoute --------------"
guide_record_route(stub)
print "-------------- RouteChat --------------"
guide_route_chat(stub)
channel = implementations.insecure_channel('localhost', 50051)
stub = route_guide_pb2.beta_create_RouteGuide_stub(channel)
print "-------------- GetFeature --------------"
guide_get_feature(stub)
print "-------------- ListFeatures --------------"
guide_list_features(stub)
print "-------------- RecordRoute --------------"
guide_record_route(stub)
print "-------------- RouteChat --------------"
guide_route_chat(stub)


if __name__ == '__main__':
Expand Down
Loading

0 comments on commit 1701b09

Please sign in to comment.