mirror of https://github.com/grpc/grpc.git
commit
121e7a9645
104 changed files with 2945 additions and 1561 deletions
@ -1,17 +1,14 @@ |
||||
{ |
||||
"name": "grpc/grpc-demo", |
||||
"description": "gRPC example for PHP", |
||||
"minimum-stability": "dev", |
||||
"repositories": [ |
||||
{ |
||||
"type": "vcs", |
||||
"url": "https://github.com/stanley-cheung/Protobuf-PHP" |
||||
} |
||||
], |
||||
"name": "grpc/grpc-demo", |
||||
"description": "gRPC example for PHP", |
||||
"minimum-stability": "dev", |
||||
"require": { |
||||
"php": ">=5.5.0", |
||||
"datto/protobuf-php": "dev-master", |
||||
"google/auth": "dev-master", |
||||
"grpc/grpc": "dev-release-0_11" |
||||
"grpc/grpc": "dev-release-0_13" |
||||
} |
||||
} |
||||
|
@ -0,0 +1,77 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2016, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#import <Foundation/Foundation.h> |
||||
#import <SystemConfiguration/SystemConfiguration.h> |
||||
|
||||
@interface GRPCReachabilityFlags : NSObject |
||||
|
||||
+ (nonnull instancetype)flagsWithFlags:(SCNetworkReachabilityFlags)flags; |
||||
|
||||
/**
|
||||
* One accessor method to query each of the different flags. Example: |
||||
|
||||
@property(nonatomic, readonly) BOOL isCell; |
||||
|
||||
*/ |
||||
#define GRPC_XMACRO_ITEM(methodName, FlagName) \ |
||||
@property(nonatomic, readonly) BOOL methodName; |
||||
|
||||
#include "GRPCReachabilityFlagNames.xmacro.h" |
||||
#undef GRPC_XMACRO_ITEM |
||||
|
||||
@property(nonatomic, readonly) BOOL isHostReachable; |
||||
@end |
||||
|
||||
|
||||
@interface GRPCConnectivityMonitor : NSObject |
||||
|
||||
+ (nullable instancetype)monitorWithHost:(nonnull NSString *)hostName; |
||||
|
||||
- (nonnull instancetype)init NS_UNAVAILABLE; |
||||
|
||||
/**
|
||||
* Queue on which callbacks will be dispatched. Default is the main queue. Set it before calling |
||||
* handleLossWithHandler:. |
||||
*/ |
||||
// TODO(jcanizales): Default to a serial background queue instead.
|
||||
@property(nonatomic, strong, null_resettable) dispatch_queue_t queue; |
||||
|
||||
/**
|
||||
* Calls handler every time the connectivity to this instance's host is lost. If this instance is |
||||
* released before that happens, the handler won't be called. |
||||
* Only one handler is active at a time, so if this method is called again before the previous |
||||
* handler has been called, it might never be called at all (or yes, if it has already been queued). |
||||
*/ |
||||
- (void)handleLossWithHandler:(nonnull void (^)())handler; |
||||
@end |
@ -0,0 +1,192 @@ |
||||
/* |
||||
* |
||||
* Copyright 2016, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#import "GRPCConnectivityMonitor.h" |
||||
|
||||
#pragma mark Flags |
||||
|
||||
@implementation GRPCReachabilityFlags { |
||||
SCNetworkReachabilityFlags _flags; |
||||
} |
||||
|
||||
+ (instancetype)flagsWithFlags:(SCNetworkReachabilityFlags)flags { |
||||
return [[self alloc] initWithFlags:flags]; |
||||
} |
||||
|
||||
- (instancetype)initWithFlags:(SCNetworkReachabilityFlags)flags { |
||||
if ((self = [super init])) { |
||||
_flags = flags; |
||||
} |
||||
return self; |
||||
} |
||||
|
||||
/* |
||||
* One accessor method implementation per flag. Example: |
||||
|
||||
- (BOOL)isCell { \ |
||||
return !!(_flags & kSCNetworkReachabilityFlagsIsWWAN); \ |
||||
} |
||||
|
||||
*/ |
||||
#define GRPC_XMACRO_ITEM(methodName, FlagName) \ |
||||
- (BOOL)methodName { \ |
||||
return !!(_flags & kSCNetworkReachabilityFlags ## FlagName); \ |
||||
} |
||||
#include "GRPCReachabilityFlagNames.xmacro.h" |
||||
#undef GRPC_XMACRO_ITEM |
||||
|
||||
- (BOOL)isHostReachable { |
||||
// Note: connectionOnDemand means it'll be reachable only if using the CFSocketStream API or APIs |
||||
// on top of it. |
||||
// connectionRequired means we can't tell until a connection is attempted (e.g. for VPN on |
||||
// demand). |
||||
return self.reachable && !self.interventionRequired && !self.connectionOnDemand; |
||||
} |
||||
|
||||
- (NSString *)description { |
||||
NSMutableArray *activeOptions = [NSMutableArray arrayWithCapacity:9]; |
||||
|
||||
/* |
||||
* For each flag, add its name to the array if it's ON. Example: |
||||
|
||||
if (self.isCell) { |
||||
[activeOptions addObject:@"isCell"]; |
||||
} |
||||
|
||||
*/ |
||||
#define GRPC_XMACRO_ITEM(methodName, FlagName) \ |
||||
if (self.methodName) { \ |
||||
[activeOptions addObject:@#methodName]; \ |
||||
} |
||||
#include "GRPCReachabilityFlagNames.xmacro.h" |
||||
#undef GRPC_XMACRO_ITEM |
||||
|
||||
return activeOptions.count == 0 ? @"(none)" : [activeOptions componentsJoinedByString:@", "]; |
||||
} |
||||
|
||||
- (BOOL)isEqual:(id)object { |
||||
return [object isKindOfClass:[GRPCReachabilityFlags class]] && |
||||
_flags == ((GRPCReachabilityFlags *)object)->_flags; |
||||
} |
||||
|
||||
- (NSUInteger)hash { |
||||
return _flags; |
||||
} |
||||
@end |
||||
|
||||
#pragma mark Connectivity Monitor |
||||
|
||||
// Assumes the third argument is a block that accepts a GRPCReachabilityFlags object, and passes the |
||||
// received ones to it. |
||||
static void PassFlagsToContextInfoBlock(SCNetworkReachabilityRef target, |
||||
SCNetworkReachabilityFlags flags, |
||||
void *info) { |
||||
#pragma unused (target) |
||||
// This can be called many times with the same info. The info is retained by SCNetworkReachability |
||||
// while this function is being executed. |
||||
void (^handler)(GRPCReachabilityFlags *) = (__bridge void (^)(GRPCReachabilityFlags *))info; |
||||
handler([[GRPCReachabilityFlags alloc] initWithFlags:flags]); |
||||
} |
||||
|
||||
@implementation GRPCConnectivityMonitor { |
||||
SCNetworkReachabilityRef _reachabilityRef; |
||||
} |
||||
|
||||
- (nullable instancetype)initWithReachability:(nullable SCNetworkReachabilityRef)reachability { |
||||
if (!reachability) { |
||||
return nil; |
||||
} |
||||
if ((self = [super init])) { |
||||
_reachabilityRef = CFRetain(reachability); |
||||
_queue = dispatch_get_main_queue(); |
||||
} |
||||
return self; |
||||
} |
||||
|
||||
+ (nullable instancetype)monitorWithHost:(nonnull NSString *)host { |
||||
const char *hostName = host.UTF8String; |
||||
if (!hostName) { |
||||
[NSException raise:NSInvalidArgumentException |
||||
format:@"host.UTF8String returns NULL for %@", host]; |
||||
} |
||||
SCNetworkReachabilityRef reachability = |
||||
SCNetworkReachabilityCreateWithName(NULL, hostName); |
||||
|
||||
GRPCConnectivityMonitor *returnValue = [[self alloc] initWithReachability:reachability]; |
||||
if (reachability) { |
||||
CFRelease(reachability); |
||||
} |
||||
return returnValue; |
||||
} |
||||
|
||||
- (void)handleLossWithHandler:(void (^)())handler { |
||||
[self startListeningWithHandler:^(GRPCReachabilityFlags *flags) { |
||||
if (!flags.isHostReachable) { |
||||
handler(); |
||||
} |
||||
}]; |
||||
} |
||||
|
||||
- (void)startListeningWithHandler:(void (^)(GRPCReachabilityFlags *))handler { |
||||
// Copy to ensure the handler block is in the heap (and so can't be deallocated when this method |
||||
// returns). |
||||
void (^copiedHandler)(GRPCReachabilityFlags *) = [handler copy]; |
||||
SCNetworkReachabilityContext context = { |
||||
.version = 0, |
||||
.info = (__bridge void *)copiedHandler, |
||||
.retain = CFRetain, |
||||
.release = CFRelease, |
||||
}; |
||||
// The following will retain context.info, and release it when the callback is set to NULL. |
||||
SCNetworkReachabilitySetCallback(_reachabilityRef, PassFlagsToContextInfoBlock, &context); |
||||
SCNetworkReachabilitySetDispatchQueue(_reachabilityRef, _queue); |
||||
} |
||||
|
||||
- (void)stopListening { |
||||
// This releases the block on context.info. |
||||
SCNetworkReachabilitySetCallback(_reachabilityRef, NULL, NULL); |
||||
SCNetworkReachabilitySetDispatchQueue(_reachabilityRef, NULL); |
||||
} |
||||
|
||||
- (void)setQueue:(dispatch_queue_t)queue { |
||||
_queue = queue ?: dispatch_get_main_queue(); |
||||
} |
||||
|
||||
- (void)dealloc { |
||||
if (_reachabilityRef) { |
||||
[self stopListening]; |
||||
CFRelease(_reachabilityRef); |
||||
} |
||||
} |
||||
|
||||
@end |
@ -0,0 +1,65 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2016, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
/**
|
||||
* "X-macro" file that lists the flags names of Apple's Network Reachability API, along with a nice |
||||
* Objective-C method name used to query each of them. |
||||
* |
||||
* Example usage: To generate a dictionary from flag value to name, one can do: |
||||
|
||||
NSDictionary *flagNames = @{ |
||||
#define GRPC_XMACRO_ITEM(methodName, FlagName) \ |
||||
@(kSCNetworkReachabilityFlags ## FlagName): @#methodName, |
||||
#include "GRXReachabilityFlagNames.xmacro.h" |
||||
#undef GRPC_XMACRO_ITEM |
||||
}; |
||||
|
||||
XCTAssertEqualObjects(flagNames[@(kSCNetworkReachabilityFlagsIsWWAN)], @"isCell"); |
||||
|
||||
*/ |
||||
|
||||
#ifndef GRPC_XMACRO_ITEM |
||||
#error This file is to be used with the "X-macro" pattern: Please #define \ |
||||
GRPC_XMACRO_ITEM(methodName, FlagName), then #include this file, and then #undef \
|
||||
GRPC_XMACRO_ITEM. |
||||
#endif |
||||
|
||||
GRPC_XMACRO_ITEM(isCell, IsWWAN) |
||||
GRPC_XMACRO_ITEM(reachable, Reachable) |
||||
GRPC_XMACRO_ITEM(transientConnection, TransientConnection) |
||||
GRPC_XMACRO_ITEM(connectionRequired, ConnectionRequired) |
||||
GRPC_XMACRO_ITEM(connectionOnTraffic, ConnectionOnTraffic) |
||||
GRPC_XMACRO_ITEM(interventionRequired, InterventionRequired) |
||||
GRPC_XMACRO_ITEM(connectionOnDemand, ConnectionOnDemand) |
||||
GRPC_XMACRO_ITEM(isLocalAddress, IsLocalAddress) |
||||
GRPC_XMACRO_ITEM(isDirect, IsDirect) |
@ -1,67 +0,0 @@ |
||||
gRPC PHP Extension |
||||
================== |
||||
|
||||
# Requirements |
||||
|
||||
* PHP 5.5+ |
||||
* [gRPC core library](https://github.com/grpc/grpc) 0.11.0 |
||||
|
||||
# Installation |
||||
|
||||
## Install PHP 5 |
||||
|
||||
``` |
||||
$ sudo apt-get install git php5 php5-dev php-pear unzip |
||||
``` |
||||
|
||||
## Compile gRPC Core Library |
||||
|
||||
Clone the gRPC source code repository |
||||
|
||||
``` |
||||
$ git clone https://github.com/grpc/grpc.git |
||||
``` |
||||
|
||||
Build and install the gRPC C core libraries |
||||
|
||||
```sh |
||||
$ cd grpc |
||||
$ git checkout --track origin/release-0_11 |
||||
$ git pull --recurse-submodules && git submodule update --init --recursive |
||||
$ make |
||||
$ sudo make install |
||||
``` |
||||
|
||||
Note: you may encounter a warning about the Protobuf compiler `protoc` 3.0.0+ not being installed. The following might help, and will be useful later on when we need to compile the `protoc-gen-php` tool. |
||||
|
||||
```sh |
||||
$ cd grpc/third_party/protobuf |
||||
$ sudo make install # 'make' should have been run by core grpc |
||||
``` |
||||
|
||||
## Install the gRPC PHP extension |
||||
|
||||
Quick install |
||||
|
||||
```sh |
||||
$ sudo pecl install grpc |
||||
``` |
||||
|
||||
Note: before a stable release, you may need to do |
||||
|
||||
```sh |
||||
$ sudo pecl install grpc-beta |
||||
``` |
||||
|
||||
OR |
||||
|
||||
Compile from source |
||||
|
||||
```sh |
||||
$ # from grpc |
||||
$ cd src/php/ext/grpc |
||||
$ phpize |
||||
$ ./configure |
||||
$ make |
||||
$ sudo make install |
||||
``` |
@ -1,381 +0,0 @@ |
||||
# Copyright 2015, Google Inc. |
||||
# All rights reserved. |
||||
# |
||||
# Redistribution and use in source and binary forms, with or without |
||||
# modification, are permitted provided that the following conditions are |
||||
# met: |
||||
# |
||||
# * Redistributions of source code must retain the above copyright |
||||
# notice, this list of conditions and the following disclaimer. |
||||
# * Redistributions in binary form must reproduce the above |
||||
# copyright notice, this list of conditions and the following disclaimer |
||||
# in the documentation and/or other materials provided with the |
||||
# distribution. |
||||
# * Neither the name of Google Inc. nor the names of its |
||||
# contributors may be used to endorse or promote products derived from |
||||
# this software without specific prior written permission. |
||||
# |
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
|
||||
"""Test code for the Face layer of RPC Framework.""" |
||||
|
||||
import abc |
||||
import unittest |
||||
|
||||
# test_interfaces is referenced from specification in this module. |
||||
from grpc.framework.interfaces.face import face |
||||
from tests.unit.framework.common import test_constants |
||||
from tests.unit.framework.common import test_control |
||||
from tests.unit.framework.common import test_coverage |
||||
from tests.unit.framework.interfaces.face import _3069_test_constant |
||||
from tests.unit.framework.interfaces.face import _digest |
||||
from tests.unit.framework.interfaces.face import _receiver |
||||
from tests.unit.framework.interfaces.face import _stock_service |
||||
from tests.unit.framework.interfaces.face import test_interfaces # pylint: disable=unused-import |
||||
|
||||
|
||||
class TestCase(test_coverage.Coverage, unittest.TestCase): |
||||
"""A test of the Face layer of RPC Framework. |
||||
|
||||
Concrete subclasses must have an "implementation" attribute of type |
||||
test_interfaces.Implementation and an "invoker_constructor" attribute of type |
||||
_invocation.InvokerConstructor. |
||||
""" |
||||
__metaclass__ = abc.ABCMeta |
||||
|
||||
NAME = 'EventInvocationSynchronousEventServiceTest' |
||||
|
||||
def setUp(self): |
||||
"""See unittest.TestCase.setUp for full specification. |
||||
|
||||
Overriding implementations must call this implementation. |
||||
""" |
||||
self._control = test_control.PauseFailControl() |
||||
self._digest = _digest.digest( |
||||
_stock_service.STOCK_TEST_SERVICE, self._control, None) |
||||
|
||||
generic_stub, dynamic_stubs, self._memo = self.implementation.instantiate( |
||||
self._digest.methods, self._digest.event_method_implementations, None) |
||||
self._invoker = self.invoker_constructor.construct_invoker( |
||||
generic_stub, dynamic_stubs, self._digest.methods) |
||||
|
||||
def tearDown(self): |
||||
"""See unittest.TestCase.tearDown for full specification. |
||||
|
||||
Overriding implementations must call this implementation. |
||||
""" |
||||
self._invoker = None |
||||
self.implementation.destantiate(self._memo) |
||||
|
||||
def testSuccessfulUnaryRequestUnaryResponse(self): |
||||
for (group, method), test_messages_sequence in ( |
||||
self._digest.unary_unary_messages_sequences.iteritems()): |
||||
for test_messages in test_messages_sequence: |
||||
request = test_messages.request() |
||||
receiver = _receiver.Receiver() |
||||
|
||||
self._invoker.event(group, method)( |
||||
request, receiver, receiver.abort, test_constants.LONG_TIMEOUT) |
||||
receiver.block_until_terminated() |
||||
response = receiver.unary_response() |
||||
|
||||
test_messages.verify(request, response, self) |
||||
|
||||
def testSuccessfulUnaryRequestStreamResponse(self): |
||||
for (group, method), test_messages_sequence in ( |
||||
self._digest.unary_stream_messages_sequences.iteritems()): |
||||
for test_messages in test_messages_sequence: |
||||
request = test_messages.request() |
||||
receiver = _receiver.Receiver() |
||||
|
||||
self._invoker.event(group, method)( |
||||
request, receiver, receiver.abort, test_constants.LONG_TIMEOUT) |
||||
receiver.block_until_terminated() |
||||
responses = receiver.stream_responses() |
||||
|
||||
test_messages.verify(request, responses, self) |
||||
|
||||
def testSuccessfulStreamRequestUnaryResponse(self): |
||||
for (group, method), test_messages_sequence in ( |
||||
self._digest.stream_unary_messages_sequences.iteritems()): |
||||
for test_messages in test_messages_sequence: |
||||
requests = test_messages.requests() |
||||
receiver = _receiver.Receiver() |
||||
|
||||
call_consumer = self._invoker.event(group, method)( |
||||
receiver, receiver.abort, test_constants.LONG_TIMEOUT) |
||||
for request in requests: |
||||
call_consumer.consume(request) |
||||
call_consumer.terminate() |
||||
receiver.block_until_terminated() |
||||
response = receiver.unary_response() |
||||
|
||||
test_messages.verify(requests, response, self) |
||||
|
||||
def testSuccessfulStreamRequestStreamResponse(self): |
||||
for (group, method), test_messages_sequence in ( |
||||
self._digest.stream_stream_messages_sequences.iteritems()): |
||||
for test_messages in test_messages_sequence: |
||||
requests = test_messages.requests() |
||||
receiver = _receiver.Receiver() |
||||
|
||||
call_consumer = self._invoker.event(group, method)( |
||||
receiver, receiver.abort, test_constants.LONG_TIMEOUT) |
||||
for request in requests: |
||||
call_consumer.consume(request) |
||||
call_consumer.terminate() |
||||
receiver.block_until_terminated() |
||||
responses = receiver.stream_responses() |
||||
|
||||
test_messages.verify(requests, responses, self) |
||||
|
||||
def testSequentialInvocations(self): |
||||
# pylint: disable=cell-var-from-loop |
||||
for (group, method), test_messages_sequence in ( |
||||
self._digest.unary_unary_messages_sequences.iteritems()): |
||||
for test_messages in test_messages_sequence: |
||||
first_request = test_messages.request() |
||||
second_request = test_messages.request() |
||||
second_receiver = _receiver.Receiver() |
||||
|
||||
def make_second_invocation(): |
||||
self._invoker.event(group, method)( |
||||
second_request, second_receiver, second_receiver.abort, |
||||
test_constants.LONG_TIMEOUT) |
||||
|
||||
class FirstReceiver(_receiver.Receiver): |
||||
|
||||
def complete(self, terminal_metadata, code, details): |
||||
super(FirstReceiver, self).complete( |
||||
terminal_metadata, code, details) |
||||
make_second_invocation() |
||||
|
||||
first_receiver = FirstReceiver() |
||||
|
||||
self._invoker.event(group, method)( |
||||
first_request, first_receiver, first_receiver.abort, |
||||
test_constants.LONG_TIMEOUT) |
||||
second_receiver.block_until_terminated() |
||||
|
||||
first_response = first_receiver.unary_response() |
||||
second_response = second_receiver.unary_response() |
||||
test_messages.verify(first_request, first_response, self) |
||||
test_messages.verify(second_request, second_response, self) |
||||
|
||||
def testParallelInvocations(self): |
||||
for (group, method), test_messages_sequence in ( |
||||
self._digest.unary_unary_messages_sequences.iteritems()): |
||||
for test_messages in test_messages_sequence: |
||||
first_request = test_messages.request() |
||||
first_receiver = _receiver.Receiver() |
||||
second_request = test_messages.request() |
||||
second_receiver = _receiver.Receiver() |
||||
|
||||
self._invoker.event(group, method)( |
||||
first_request, first_receiver, first_receiver.abort, |
||||
test_constants.LONG_TIMEOUT) |
||||
self._invoker.event(group, method)( |
||||
second_request, second_receiver, second_receiver.abort, |
||||
test_constants.LONG_TIMEOUT) |
||||
first_receiver.block_until_terminated() |
||||
second_receiver.block_until_terminated() |
||||
|
||||
first_response = first_receiver.unary_response() |
||||
second_response = second_receiver.unary_response() |
||||
test_messages.verify(first_request, first_response, self) |
||||
test_messages.verify(second_request, second_response, self) |
||||
|
||||
@unittest.skip('TODO(nathaniel): implement.') |
||||
def testWaitingForSomeButNotAllParallelInvocations(self): |
||||
raise NotImplementedError() |
||||
|
||||
def testCancelledUnaryRequestUnaryResponse(self): |
||||
for (group, method), test_messages_sequence in ( |
||||
self._digest.unary_unary_messages_sequences.iteritems()): |
||||
for test_messages in test_messages_sequence: |
||||
request = test_messages.request() |
||||
receiver = _receiver.Receiver() |
||||
|
||||
with self._control.pause(): |
||||
call = self._invoker.event(group, method)( |
||||
request, receiver, receiver.abort, test_constants.LONG_TIMEOUT) |
||||
call.cancel() |
||||
receiver.block_until_terminated() |
||||
|
||||
self.assertIs(face.Abortion.Kind.CANCELLED, receiver.abortion().kind) |
||||
|
||||
def testCancelledUnaryRequestStreamResponse(self): |
||||
for (group, method), test_messages_sequence in ( |
||||
self._digest.unary_stream_messages_sequences.iteritems()): |
||||
for test_messages in test_messages_sequence: |
||||
request = test_messages.request() |
||||
receiver = _receiver.Receiver() |
||||
|
||||
call = self._invoker.event(group, method)( |
||||
request, receiver, receiver.abort, test_constants.LONG_TIMEOUT) |
||||
call.cancel() |
||||
receiver.block_until_terminated() |
||||
|
||||
self.assertIs(face.Abortion.Kind.CANCELLED, receiver.abortion().kind) |
||||
|
||||
def testCancelledStreamRequestUnaryResponse(self): |
||||
for (group, method), test_messages_sequence in ( |
||||
self._digest.stream_unary_messages_sequences.iteritems()): |
||||
for test_messages in test_messages_sequence: |
||||
requests = test_messages.requests() |
||||
receiver = _receiver.Receiver() |
||||
|
||||
call_consumer = self._invoker.event(group, method)( |
||||
receiver, receiver.abort, test_constants.LONG_TIMEOUT) |
||||
for request in requests: |
||||
call_consumer.consume(request) |
||||
call_consumer.cancel() |
||||
receiver.block_until_terminated() |
||||
|
||||
self.assertIs(face.Abortion.Kind.CANCELLED, receiver.abortion().kind) |
||||
|
||||
def testCancelledStreamRequestStreamResponse(self): |
||||
for (group, method), test_messages_sequence in ( |
||||
self._digest.stream_stream_messages_sequences.iteritems()): |
||||
for unused_test_messages in test_messages_sequence: |
||||
receiver = _receiver.Receiver() |
||||
|
||||
call_consumer = self._invoker.event(group, method)( |
||||
receiver, receiver.abort, test_constants.LONG_TIMEOUT) |
||||
call_consumer.cancel() |
||||
receiver.block_until_terminated() |
||||
|
||||
self.assertIs(face.Abortion.Kind.CANCELLED, receiver.abortion().kind) |
||||
|
||||
def testExpiredUnaryRequestUnaryResponse(self): |
||||
for (group, method), test_messages_sequence in ( |
||||
self._digest.unary_unary_messages_sequences.iteritems()): |
||||
for test_messages in test_messages_sequence: |
||||
request = test_messages.request() |
||||
receiver = _receiver.Receiver() |
||||
|
||||
with self._control.pause(): |
||||
self._invoker.event(group, method)( |
||||
request, receiver, receiver.abort, |
||||
_3069_test_constant.REALLY_SHORT_TIMEOUT) |
||||
receiver.block_until_terminated() |
||||
|
||||
self.assertIs(face.Abortion.Kind.EXPIRED, receiver.abortion().kind) |
||||
|
||||
def testExpiredUnaryRequestStreamResponse(self): |
||||
for (group, method), test_messages_sequence in ( |
||||
self._digest.unary_stream_messages_sequences.iteritems()): |
||||
for test_messages in test_messages_sequence: |
||||
request = test_messages.request() |
||||
receiver = _receiver.Receiver() |
||||
|
||||
with self._control.pause(): |
||||
self._invoker.event(group, method)( |
||||
request, receiver, receiver.abort, |
||||
_3069_test_constant.REALLY_SHORT_TIMEOUT) |
||||
receiver.block_until_terminated() |
||||
|
||||
self.assertIs(face.Abortion.Kind.EXPIRED, receiver.abortion().kind) |
||||
|
||||
def testExpiredStreamRequestUnaryResponse(self): |
||||
for (group, method), test_messages_sequence in ( |
||||
self._digest.stream_unary_messages_sequences.iteritems()): |
||||
for unused_test_messages in test_messages_sequence: |
||||
receiver = _receiver.Receiver() |
||||
|
||||
self._invoker.event(group, method)( |
||||
receiver, receiver.abort, _3069_test_constant.REALLY_SHORT_TIMEOUT) |
||||
receiver.block_until_terminated() |
||||
|
||||
self.assertIs(face.Abortion.Kind.EXPIRED, receiver.abortion().kind) |
||||
|
||||
def testExpiredStreamRequestStreamResponse(self): |
||||
for (group, method), test_messages_sequence in ( |
||||
self._digest.stream_stream_messages_sequences.iteritems()): |
||||
for test_messages in test_messages_sequence: |
||||
requests = test_messages.requests() |
||||
receiver = _receiver.Receiver() |
||||
|
||||
call_consumer = self._invoker.event(group, method)( |
||||
receiver, receiver.abort, _3069_test_constant.REALLY_SHORT_TIMEOUT) |
||||
for request in requests: |
||||
call_consumer.consume(request) |
||||
receiver.block_until_terminated() |
||||
|
||||
self.assertIs(face.Abortion.Kind.EXPIRED, receiver.abortion().kind) |
||||
|
||||
def testFailedUnaryRequestUnaryResponse(self): |
||||
for (group, method), test_messages_sequence in ( |
||||
self._digest.unary_unary_messages_sequences.iteritems()): |
||||
for test_messages in test_messages_sequence: |
||||
request = test_messages.request() |
||||
receiver = _receiver.Receiver() |
||||
|
||||
with self._control.fail(): |
||||
self._invoker.event(group, method)( |
||||
request, receiver, receiver.abort, test_constants.LONG_TIMEOUT) |
||||
receiver.block_until_terminated() |
||||
|
||||
self.assertIs( |
||||
face.Abortion.Kind.REMOTE_FAILURE, receiver.abortion().kind) |
||||
|
||||
def testFailedUnaryRequestStreamResponse(self): |
||||
for (group, method), test_messages_sequence in ( |
||||
self._digest.unary_stream_messages_sequences.iteritems()): |
||||
for test_messages in test_messages_sequence: |
||||
request = test_messages.request() |
||||
receiver = _receiver.Receiver() |
||||
|
||||
with self._control.fail(): |
||||
self._invoker.event(group, method)( |
||||
request, receiver, receiver.abort, test_constants.LONG_TIMEOUT) |
||||
receiver.block_until_terminated() |
||||
|
||||
self.assertIs( |
||||
face.Abortion.Kind.REMOTE_FAILURE, receiver.abortion().kind) |
||||
|
||||
def testFailedStreamRequestUnaryResponse(self): |
||||
for (group, method), test_messages_sequence in ( |
||||
self._digest.stream_unary_messages_sequences.iteritems()): |
||||
for test_messages in test_messages_sequence: |
||||
requests = test_messages.requests() |
||||
receiver = _receiver.Receiver() |
||||
|
||||
with self._control.fail(): |
||||
call_consumer = self._invoker.event(group, method)( |
||||
receiver, receiver.abort, test_constants.LONG_TIMEOUT) |
||||
for request in requests: |
||||
call_consumer.consume(request) |
||||
call_consumer.terminate() |
||||
receiver.block_until_terminated() |
||||
|
||||
self.assertIs( |
||||
face.Abortion.Kind.REMOTE_FAILURE, receiver.abortion().kind) |
||||
|
||||
def testFailedStreamRequestStreamResponse(self): |
||||
for (group, method), test_messages_sequence in ( |
||||
self._digest.stream_stream_messages_sequences.iteritems()): |
||||
for test_messages in test_messages_sequence: |
||||
requests = test_messages.requests() |
||||
receiver = _receiver.Receiver() |
||||
|
||||
with self._control.fail(): |
||||
call_consumer = self._invoker.event(group, method)( |
||||
receiver, receiver.abort, test_constants.LONG_TIMEOUT) |
||||
for request in requests: |
||||
call_consumer.consume(request) |
||||
call_consumer.terminate() |
||||
receiver.block_until_terminated() |
||||
|
||||
self.assertIs( |
||||
face.Abortion.Kind.REMOTE_FAILURE, receiver.abortion().kind) |
@ -0,0 +1,39 @@ |
||||
%YAML 1.2 |
||||
--- | |
||||
# Copyright 2015-2016, Google Inc. |
||||
# All rights reserved. |
||||
# |
||||
# Redistribution and use in source and binary forms, with or without |
||||
# modification, are permitted provided that the following conditions are |
||||
# met: |
||||
# |
||||
# * Redistributions of source code must retain the above copyright |
||||
# notice, this list of conditions and the following disclaimer. |
||||
# * Redistributions in binary form must reproduce the above |
||||
# copyright notice, this list of conditions and the following disclaimer |
||||
# in the documentation and/or other materials provided with the |
||||
# distribution. |
||||
# * Neither the name of Google Inc. nor the names of its |
||||
# contributors may be used to endorse or promote products derived from |
||||
# this software without specific prior written permission. |
||||
# |
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
|
||||
FROM ubuntu:14.04 |
||||
|
||||
<%include file="../../apt_get_basic.include"/> |
||||
<%include file="../../cxx_deps.include"/> |
||||
<%include file="../../run_tests_addons.include"/> |
||||
# Define the default command. |
||||
CMD ["bash"] |
||||
|
@ -0,0 +1,43 @@ |
||||
%YAML 1.2 |
||||
--- | |
||||
# Copyright 2016, Google Inc. |
||||
# All rights reserved. |
||||
# |
||||
# Redistribution and use in source and binary forms, with or without |
||||
# modification, are permitted provided that the following conditions are |
||||
# met: |
||||
# |
||||
# * Redistributions of source code must retain the above copyright |
||||
# notice, this list of conditions and the following disclaimer. |
||||
# * Redistributions in binary form must reproduce the above |
||||
# copyright notice, this list of conditions and the following disclaimer |
||||
# in the documentation and/or other materials provided with the |
||||
# distribution. |
||||
# * Neither the name of Google Inc. nor the names of its |
||||
# contributors may be used to endorse or promote products derived from |
||||
# this software without specific prior written permission. |
||||
# |
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
|
||||
FROM debian:jessie |
||||
|
||||
<%include file="../../apt_get_basic.include"/> |
||||
<%include file="../../csharp_deps.include"/> |
||||
<%include file="../../cxx_deps.include"/> |
||||
<%include file="../../node_deps.include"/> |
||||
<%include file="../../php_deps.include"/> |
||||
<%include file="../../ruby_deps.include"/> |
||||
<%include file="../../python_deps.include"/> |
||||
<%include file="../../run_tests_addons.include"/> |
||||
# Define the default command. |
||||
CMD ["bash"] |
@ -0,0 +1,148 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015-2016, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#include "src/core/client_config/resolvers/dns_resolver.h" |
||||
|
||||
#include <string.h> |
||||
|
||||
#include <grpc/grpc.h> |
||||
#include <grpc/support/alloc.h> |
||||
|
||||
#include "src/core/iomgr/resolve_address.h" |
||||
#include "src/core/iomgr/timer.h" |
||||
#include "test/core/util/test_config.h" |
||||
|
||||
static void subchannel_factory_ref(grpc_subchannel_factory *scv) {} |
||||
static void subchannel_factory_unref(grpc_exec_ctx *exec_ctx, |
||||
grpc_subchannel_factory *scv) {} |
||||
static grpc_subchannel *subchannel_factory_create_subchannel( |
||||
grpc_exec_ctx *exec_ctx, grpc_subchannel_factory *factory, |
||||
grpc_subchannel_args *args) { |
||||
return NULL; |
||||
} |
||||
|
||||
static const grpc_subchannel_factory_vtable sc_vtable = { |
||||
subchannel_factory_ref, subchannel_factory_unref, |
||||
subchannel_factory_create_subchannel}; |
||||
|
||||
static grpc_subchannel_factory sc_factory = {&sc_vtable}; |
||||
|
||||
static gpr_mu g_mu; |
||||
static bool g_fail_resolution = true; |
||||
|
||||
static grpc_resolved_addresses *my_resolve_address(const char *name, |
||||
const char *addr) { |
||||
gpr_mu_lock(&g_mu); |
||||
GPR_ASSERT(0 == strcmp("test", name)); |
||||
if (g_fail_resolution) { |
||||
g_fail_resolution = false; |
||||
gpr_mu_unlock(&g_mu); |
||||
return NULL; |
||||
} else { |
||||
gpr_mu_unlock(&g_mu); |
||||
grpc_resolved_addresses *addrs = gpr_malloc(sizeof(*addrs)); |
||||
addrs->naddrs = 1; |
||||
addrs->addrs = gpr_malloc(sizeof(*addrs->addrs)); |
||||
addrs->addrs[0].len = 123; |
||||
return addrs; |
||||
} |
||||
} |
||||
|
||||
static grpc_resolver *create_resolver(const char *name) { |
||||
grpc_resolver_factory *factory = grpc_dns_resolver_factory_create(); |
||||
grpc_uri *uri = grpc_uri_parse(name, 0); |
||||
GPR_ASSERT(uri); |
||||
grpc_resolver_args args; |
||||
memset(&args, 0, sizeof(args)); |
||||
args.uri = uri; |
||||
args.subchannel_factory = &sc_factory; |
||||
grpc_resolver *resolver = |
||||
grpc_resolver_factory_create_resolver(factory, &args); |
||||
grpc_resolver_factory_unref(factory); |
||||
grpc_uri_destroy(uri); |
||||
return resolver; |
||||
} |
||||
|
||||
static void on_done(grpc_exec_ctx *exec_ctx, void *ev, bool success) { |
||||
gpr_event_set(ev, (void *)1); |
||||
} |
||||
|
||||
// interleave waiting for an event with a timer check
|
||||
static bool wait_loop(int deadline_seconds, gpr_event *ev) { |
||||
while (deadline_seconds) { |
||||
gpr_log(GPR_DEBUG, "Test: waiting for %d more seconds", deadline_seconds); |
||||
if (gpr_event_wait(ev, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1))) return true; |
||||
deadline_seconds--; |
||||
|
||||
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
||||
grpc_timer_check(&exec_ctx, gpr_now(GPR_CLOCK_MONOTONIC), NULL); |
||||
grpc_exec_ctx_finish(&exec_ctx); |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
int main(int argc, char **argv) { |
||||
grpc_test_init(argc, argv); |
||||
|
||||
grpc_init(); |
||||
gpr_mu_init(&g_mu); |
||||
grpc_blocking_resolve_address = my_resolve_address; |
||||
|
||||
grpc_resolver *resolver = create_resolver("dns:test"); |
||||
|
||||
grpc_client_config *config = (grpc_client_config *)1; |
||||
|
||||
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
||||
gpr_event ev1; |
||||
gpr_event_init(&ev1); |
||||
grpc_resolver_next(&exec_ctx, resolver, &config, |
||||
grpc_closure_create(on_done, &ev1)); |
||||
grpc_exec_ctx_flush(&exec_ctx); |
||||
GPR_ASSERT(wait_loop(5, &ev1)); |
||||
GPR_ASSERT(config == NULL); |
||||
|
||||
gpr_event ev2; |
||||
gpr_event_init(&ev2); |
||||
grpc_resolver_next(&exec_ctx, resolver, &config, |
||||
grpc_closure_create(on_done, &ev2)); |
||||
grpc_exec_ctx_flush(&exec_ctx); |
||||
GPR_ASSERT(wait_loop(30, &ev2)); |
||||
GPR_ASSERT(config != NULL); |
||||
|
||||
grpc_client_config_unref(&exec_ctx, config); |
||||
GRPC_RESOLVER_UNREF(&exec_ctx, resolver, "test"); |
||||
grpc_exec_ctx_finish(&exec_ctx); |
||||
|
||||
grpc_shutdown(); |
||||
gpr_mu_destroy(&g_mu); |
||||
} |
@ -0,0 +1,83 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2016, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#include <stdio.h> |
||||
|
||||
#include <grpc/grpc.h> |
||||
#include <grpc/support/alloc.h> |
||||
#include <grpc/support/log.h> |
||||
#include <grpc/support/thd.h> |
||||
#include "test/core/util/test_config.h" |
||||
|
||||
#define NUM_THREADS 100 |
||||
static grpc_channel* channels[NUM_THREADS]; |
||||
static grpc_completion_queue* queues[NUM_THREADS]; |
||||
|
||||
void create_loop_destroy(void* actually_an_int) { |
||||
int thread_index = (int)(intptr_t)(actually_an_int); |
||||
for (int i = 0; i < 10; ++i) { |
||||
grpc_completion_queue* cq = grpc_completion_queue_create(NULL); |
||||
grpc_channel* chan = grpc_insecure_channel_create("localhost", NULL, NULL); |
||||
|
||||
channels[thread_index] = chan; |
||||
queues[thread_index] = cq; |
||||
|
||||
for (int j = 0; j < 10; ++j) { |
||||
gpr_timespec later_time = GRPC_TIMEOUT_MILLIS_TO_DEADLINE(10); |
||||
grpc_connectivity_state state = |
||||
grpc_channel_check_connectivity_state(chan, 1); |
||||
grpc_channel_watch_connectivity_state(chan, state, later_time, cq, NULL); |
||||
GPR_ASSERT(grpc_completion_queue_next(cq, |
||||
GRPC_TIMEOUT_SECONDS_TO_DEADLINE(3), |
||||
NULL).type == GRPC_OP_COMPLETE); |
||||
} |
||||
grpc_channel_destroy(channels[thread_index]); |
||||
grpc_completion_queue_destroy(queues[thread_index]); |
||||
} |
||||
} |
||||
|
||||
int main(int argc, char** argv) { |
||||
grpc_test_init(argc, argv); |
||||
grpc_init(); |
||||
gpr_thd_id threads[NUM_THREADS]; |
||||
for (intptr_t i = 0; i < NUM_THREADS; ++i) { |
||||
gpr_thd_options options = gpr_thd_options_default(); |
||||
gpr_thd_options_set_joinable(&options); |
||||
gpr_thd_new(&threads[i], create_loop_destroy, (void*)i, &options); |
||||
} |
||||
for (int i = 0; i < NUM_THREADS; ++i) { |
||||
gpr_thd_join(threads[i]); |
||||
} |
||||
grpc_shutdown(); |
||||
return 0; |
||||
} |
@ -0,0 +1,86 @@ |
||||
# Copyright 2015-2016, Google Inc. |
||||
# All rights reserved. |
||||
# |
||||
# Redistribution and use in source and binary forms, with or without |
||||
# modification, are permitted provided that the following conditions are |
||||
# met: |
||||
# |
||||
# * Redistributions of source code must retain the above copyright |
||||
# notice, this list of conditions and the following disclaimer. |
||||
# * Redistributions in binary form must reproduce the above |
||||
# copyright notice, this list of conditions and the following disclaimer |
||||
# in the documentation and/or other materials provided with the |
||||
# distribution. |
||||
# * Neither the name of Google Inc. nor the names of its |
||||
# contributors may be used to endorse or promote products derived from |
||||
# this software without specific prior written permission. |
||||
# |
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
|
||||
FROM ubuntu:14.04 |
||||
|
||||
# Install Git and basic packages. |
||||
RUN apt-get update && apt-get install -y \ |
||||
autoconf \ |
||||
autotools-dev \ |
||||
build-essential \ |
||||
bzip2 \ |
||||
ccache \ |
||||
curl \ |
||||
gcc \ |
||||
gcc-multilib \ |
||||
git \ |
||||
golang \ |
||||
gyp \ |
||||
lcov \ |
||||
libc6 \ |
||||
libc6-dbg \ |
||||
libc6-dev \ |
||||
libgtest-dev \ |
||||
libtool \ |
||||
make \ |
||||
perl \ |
||||
strace \ |
||||
python-dev \ |
||||
python-setuptools \ |
||||
python-yaml \ |
||||
telnet \ |
||||
unzip \ |
||||
wget \ |
||||
zip && apt-get clean |
||||
|
||||
#================ |
||||
# Build profiling |
||||
RUN apt-get update && apt-get install -y time && apt-get clean |
||||
|
||||
#================= |
||||
# C++ dependencies |
||||
RUN apt-get update && apt-get -y install libgflags-dev libgtest-dev libc++-dev clang && apt-get clean |
||||
|
||||
# Prepare ccache |
||||
RUN ln -s /usr/bin/ccache /usr/local/bin/gcc |
||||
RUN ln -s /usr/bin/ccache /usr/local/bin/g++ |
||||
RUN ln -s /usr/bin/ccache /usr/local/bin/cc |
||||
RUN ln -s /usr/bin/ccache /usr/local/bin/c++ |
||||
RUN ln -s /usr/bin/ccache /usr/local/bin/clang |
||||
RUN ln -s /usr/bin/ccache /usr/local/bin/clang++ |
||||
|
||||
#====================== |
||||
# Zookeeper dependencies |
||||
# TODO(jtattermusch): is zookeeper still needed? |
||||
RUN apt-get install -y libzookeeper-mt-dev |
||||
|
||||
RUN mkdir /var/local/jenkins |
||||
|
||||
# Define the default command. |
||||
CMD ["bash"] |
@ -0,0 +1,155 @@ |
||||
# Copyright 2016, Google Inc. |
||||
# All rights reserved. |
||||
# |
||||
# Redistribution and use in source and binary forms, with or without |
||||
# modification, are permitted provided that the following conditions are |
||||
# met: |
||||
# |
||||
# * Redistributions of source code must retain the above copyright |
||||
# notice, this list of conditions and the following disclaimer. |
||||
# * Redistributions in binary form must reproduce the above |
||||
# copyright notice, this list of conditions and the following disclaimer |
||||
# in the documentation and/or other materials provided with the |
||||
# distribution. |
||||
# * Neither the name of Google Inc. nor the names of its |
||||
# contributors may be used to endorse or promote products derived from |
||||
# this software without specific prior written permission. |
||||
# |
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
|
||||
FROM debian:jessie |
||||
|
||||
# Install Git and basic packages. |
||||
RUN apt-get update && apt-get install -y \ |
||||
autoconf \ |
||||
autotools-dev \ |
||||
build-essential \ |
||||
bzip2 \ |
||||
ccache \ |
||||
curl \ |
||||
gcc \ |
||||
gcc-multilib \ |
||||
git \ |
||||
golang \ |
||||
gyp \ |
||||
lcov \ |
||||
libc6 \ |
||||
libc6-dbg \ |
||||
libc6-dev \ |
||||
libgtest-dev \ |
||||
libtool \ |
||||
make \ |
||||
perl \ |
||||
strace \ |
||||
python-dev \ |
||||
python-setuptools \ |
||||
python-yaml \ |
||||
telnet \ |
||||
unzip \ |
||||
wget \ |
||||
zip && apt-get clean |
||||
|
||||
#================ |
||||
# Build profiling |
||||
RUN apt-get update && apt-get install -y time && apt-get clean |
||||
|
||||
#================ |
||||
# C# dependencies |
||||
|
||||
# Update to a newer version of mono |
||||
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF |
||||
RUN echo "deb http://download.mono-project.com/repo/debian wheezy main" | tee /etc/apt/sources.list.d/mono-xamarin.list |
||||
RUN echo "deb http://download.mono-project.com/repo/debian wheezy-apache24-compat main" | tee -a /etc/apt/sources.list.d/mono-xamarin.list |
||||
RUN echo "deb http://download.mono-project.com/repo/debian wheezy-libjpeg62-compat main" | tee -a /etc/apt/sources.list.d/mono-xamarin.list |
||||
RUN echo "deb http://download.mono-project.com/repo/debian wheezy-libtiff-compat main" | tee -a /etc/apt/sources.list.d/mono-xamarin.list |
||||
|
||||
# Install dependencies |
||||
RUN apt-get update && apt-get -y dist-upgrade && apt-get install -y \ |
||||
mono-devel \ |
||||
ca-certificates-mono \ |
||||
nuget \ |
||||
&& apt-get clean |
||||
|
||||
#================= |
||||
# C++ dependencies |
||||
RUN apt-get update && apt-get -y install libgflags-dev libgtest-dev libc++-dev clang && apt-get clean |
||||
|
||||
#================== |
||||
# Node dependencies |
||||
|
||||
# Install nvm |
||||
RUN touch .profile |
||||
RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.25.4/install.sh | bash |
||||
RUN /bin/bash -l -c "nvm install 0.12 && npm config set cache /tmp/npm-cache" |
||||
|
||||
#================= |
||||
# PHP dependencies |
||||
|
||||
# Install dependencies |
||||
|
||||
RUN /bin/bash -l -c "echo 'deb http://packages.dotdeb.org wheezy-php55 all' \ |
||||
>> /etc/apt/sources.list.d/dotdeb.list" |
||||
RUN /bin/bash -l -c "echo 'deb-src http://packages.dotdeb.org wheezy-php55 all' \ |
||||
>> /etc/apt/sources.list.d/dotdeb.list" |
||||
RUN wget http://www.dotdeb.org/dotdeb.gpg -O- | apt-key add - |
||||
|
||||
RUN apt-get update && apt-get install -y \ |
||||
git php5 php5-dev phpunit unzip |
||||
|
||||
#================== |
||||
# Ruby dependencies |
||||
|
||||
# Install rvm |
||||
RUN gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 |
||||
RUN \curl -sSL https://get.rvm.io | bash -s stable |
||||
|
||||
# Install Ruby 2.1 |
||||
RUN /bin/bash -l -c "rvm install ruby-2.1" |
||||
RUN /bin/bash -l -c "rvm use --default ruby-2.1" |
||||
RUN /bin/bash -l -c "echo 'gem: --no-ri --no-rdoc' > ~/.gemrc" |
||||
RUN /bin/bash -l -c "echo 'export PATH=/usr/local/rvm/bin:$PATH' >> ~/.bashrc" |
||||
RUN /bin/bash -l -c "echo 'rvm --default use ruby-2.1' >> ~/.bashrc" |
||||
RUN /bin/bash -l -c "gem install bundler --no-ri --no-rdoc" |
||||
|
||||
#==================== |
||||
# Python dependencies |
||||
|
||||
# Install dependencies |
||||
|
||||
RUN apt-get update && apt-get install -y \ |
||||
python-all-dev \ |
||||
python3-all-dev \ |
||||
python-pip |
||||
|
||||
# Install Python packages from PyPI |
||||
RUN pip install pip --upgrade |
||||
RUN pip install virtualenv |
||||
RUN pip install futures==2.2.0 enum34==1.0.4 protobuf==3.0.0a2 tox |
||||
|
||||
# Prepare ccache |
||||
RUN ln -s /usr/bin/ccache /usr/local/bin/gcc |
||||
RUN ln -s /usr/bin/ccache /usr/local/bin/g++ |
||||
RUN ln -s /usr/bin/ccache /usr/local/bin/cc |
||||
RUN ln -s /usr/bin/ccache /usr/local/bin/c++ |
||||
RUN ln -s /usr/bin/ccache /usr/local/bin/clang |
||||
RUN ln -s /usr/bin/ccache /usr/local/bin/clang++ |
||||
|
||||
#====================== |
||||
# Zookeeper dependencies |
||||
# TODO(jtattermusch): is zookeeper still needed? |
||||
RUN apt-get install -y libzookeeper-mt-dev |
||||
|
||||
RUN mkdir /var/local/jenkins |
||||
|
||||
# Define the default command. |
||||
CMD ["bash"] |
@ -0,0 +1,37 @@ |
||||
#!/usr/bin/env bash |
||||
# Copyright 2016, Google Inc. |
||||
# All rights reserved. |
||||
# |
||||
# Redistribution and use in source and binary forms, with or without |
||||
# modification, are permitted provided that the following conditions are |
||||
# met: |
||||
# |
||||
# * Redistributions of source code must retain the above copyright |
||||
# notice, this list of conditions and the following disclaimer. |
||||
# * Redistributions in binary form must reproduce the above |
||||
# copyright notice, this list of conditions and the following disclaimer |
||||
# in the documentation and/or other materials provided with the |
||||
# distribution. |
||||
# * Neither the name of Google Inc. nor the names of its |
||||
# contributors may be used to endorse or promote products derived from |
||||
# this software without specific prior written permission. |
||||
# |
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
# |
||||
# This script is invoked by Jenkins and runs interop test suite. |
||||
set -ex |
||||
|
||||
# Enter the gRPC repo root |
||||
cd $(dirname $0)/../.. |
||||
|
||||
tools/run_tests/run_interop_tests.py -l all -s all --cloud_to_prod --cloud_to_prod_auth --prod_servers default cloud_gateway gateway_v2 cloud_gateway_v2 gateway_v4 cloud_gateway_v4 --use_docker --http2_interop -t -j 12 $@ || true |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue