mirror of https://github.com/grpc/grpc.git
Conflicts: src/ruby/ext/grpc/rb_byte_buffer.c src/ruby/ext/grpc/rb_byte_buffer.h src/ruby/ext/grpc/rb_call.c src/ruby/ext/grpc/rb_call.h src/ruby/ext/grpc/rb_channel.c src/ruby/ext/grpc/rb_completion_queue.h src/ruby/ext/grpc/rb_event.c src/ruby/ext/grpc/rb_grpc.c src/ruby/ext/grpc/rb_metadata.c src/ruby/ext/grpc/rb_server.c test/cpp/interop/client_helper.h test/cpp/interop/server_helper.hpull/1245/head
commit
0f75ff5d19
84 changed files with 3973 additions and 3159 deletions
@ -0,0 +1,77 @@ |
||||
/*
|
||||
* |
||||
* 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. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPC_SUPPORT_TLS_H |
||||
#define GRPC_SUPPORT_TLS_H |
||||
|
||||
#include "port_platform.h" |
||||
|
||||
/* Thread local storage.
|
||||
|
||||
A minimal wrapper that should be implementable across many compilers, |
||||
and implementable efficiently across most modern compilers. |
||||
|
||||
Thread locals have type gpr_intptr. |
||||
|
||||
Declaring a thread local variable 'foo': |
||||
GPR_TLS_DECL(foo, initial_value); |
||||
Thread locals always have static scope. |
||||
|
||||
Initializing a thread local (must be done at library initialization
|
||||
time): |
||||
gpr_tls_init(&foo); |
||||
|
||||
Destroying a thread local: |
||||
gpr_tls_destroy(&foo); |
||||
|
||||
Setting a thread local: |
||||
gpr_tls_set(&foo, new_value); |
||||
|
||||
Accessing a thread local: |
||||
current_value = gpr_tls_get(&foo, value);
|
||||
|
||||
ALL functions here may be implemented as macros. */ |
||||
|
||||
#ifdef GPR_GCC_TLS |
||||
#include "tls_gcc.h" |
||||
#endif |
||||
|
||||
#ifdef GPR_MSVC_TLS |
||||
#include "tls_msvc.h" |
||||
#endif |
||||
|
||||
#ifdef GPR_PTHREAD_TLS |
||||
#include "tls_pthread.h" |
||||
#endif |
||||
|
||||
#endif |
@ -0,0 +1,52 @@ |
||||
/*
|
||||
* |
||||
* 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. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPC_SUPPORT_TLS_GCC_H |
||||
#define GRPC_SUPPORT_TLS_GCC_H |
||||
|
||||
/* Thread local storage based on gcc compiler primitives.
|
||||
#include tls.h to use this - and see that file for documentation */ |
||||
|
||||
struct gpr_gcc_thread_local { |
||||
gpr_intptr value; |
||||
}; |
||||
|
||||
#define GPR_TLS_DECL(name) \ |
||||
static __thread struct gpr_gcc_thread_local name = {0} |
||||
|
||||
#define gpr_tls_init(tls) do {} while (0) |
||||
#define gpr_tls_destroy(tls) do {} while (0) |
||||
#define gpr_tls_set(tls, new_value) (((tls)->value) = (new_value)) |
||||
#define gpr_tls_get(tls) ((tls)->value) |
||||
|
||||
#endif |
@ -0,0 +1,52 @@ |
||||
/*
|
||||
* |
||||
* 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. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPC_SUPPORT_TLS_GCC_H |
||||
#define GRPC_SUPPORT_TLS_GCC_H |
||||
|
||||
/* Thread local storage based on ms visual c compiler primitives.
|
||||
#include tls.h to use this - and see that file for documentation */ |
||||
|
||||
struct gpr_msvc_thread_local { |
||||
gpr_intptr value; |
||||
}; |
||||
|
||||
#define GPR_TLS_DECL(name) \ |
||||
static __thread struct gpr_msvc_thread_local name = {0} |
||||
|
||||
#define gpr_tls_init(tls) do {} while (0) |
||||
#define gpr_tls_destroy(tls) do {} while (0) |
||||
#define gpr_tls_set(tls, new_value) (((tls)->value) = (new_value)) |
||||
#define gpr_tls_get(tls) ((tls)->value) |
||||
|
||||
#endif |
@ -0,0 +1,53 @@ |
||||
/*
|
||||
* |
||||
* 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. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPC_SUPPORT_TLS_PTHREAD_H |
||||
#define GRPC_SUPPORT_TLS_PTHREAD_H |
||||
|
||||
/* Thread local storage based on pthread library calls.
|
||||
#include tls.h to use this - and see that file for documentation */ |
||||
|
||||
struct gpr_pthread_thread_local { |
||||
pthread_key_t key; |
||||
}; |
||||
|
||||
#define GPR_TLS_DECL(name) \ |
||||
static struct gpr_pthread_thread_local name = {0} |
||||
|
||||
#define gpr_tls_init(tls) GPR_ASSERT(0 == pthread_key_create(&(tls)->key, NULL)) |
||||
#define gpr_tls_destroy(tls) pthread_key_delete((tls)->key) |
||||
#define gpr_tls_set(tls, new_value) \ |
||||
GPR_ASSERT(pthread_setspecific((tls)->key, (void*)(new_value)) == 0) |
||||
#define gpr_tls_get(tls) ((gpr_intptr)pthread_getspecific((tls)->key)) |
||||
|
||||
#endif |
@ -0,0 +1,61 @@ |
||||
/*
|
||||
* |
||||
* 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. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPC_INTERNAL_CPP_CLIENT_SECURE_CREDENTIALS_H |
||||
#define GRPC_INTERNAL_CPP_CLIENT_SECURE_CREDENTIALS_H |
||||
|
||||
#include <grpc/grpc_security.h> |
||||
|
||||
#include <grpc++/config.h> |
||||
#include <grpc++/credentials.h> |
||||
|
||||
namespace grpc { |
||||
|
||||
class SecureCredentials GRPC_FINAL : public Credentials { |
||||
public: |
||||
explicit SecureCredentials(grpc_credentials* c_creds) : c_creds_(c_creds) {} |
||||
~SecureCredentials() GRPC_OVERRIDE { grpc_credentials_release(c_creds_); } |
||||
grpc_credentials* GetRawCreds() { return c_creds_; } |
||||
|
||||
std::shared_ptr<grpc::ChannelInterface> CreateChannel( |
||||
const string& target, const grpc::ChannelArguments& args) GRPC_OVERRIDE; |
||||
SecureCredentials* AsSecureCredentials() GRPC_OVERRIDE { return this; } |
||||
|
||||
private: |
||||
grpc_credentials* const c_creds_; |
||||
}; |
||||
|
||||
} // namespace grpc
|
||||
|
||||
#endif // GRPC_INTERNAL_CPP_CLIENT_SECURE_CREDENTIALS_H
|
||||
|
@ -0,0 +1,60 @@ |
||||
/*
|
||||
* |
||||
* 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. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPC_INTERNAL_CPP_SERVER_SECURE_SERVER_CREDENTIALS_H |
||||
#define GRPC_INTERNAL_CPP_SERVER_SECURE_SERVER_CREDENTIALS_H |
||||
|
||||
#include <grpc/grpc_security.h> |
||||
|
||||
#include <grpc++/server_credentials.h> |
||||
|
||||
namespace grpc { |
||||
|
||||
class SecureServerCredentials GRPC_FINAL : public ServerCredentials { |
||||
public: |
||||
explicit SecureServerCredentials(grpc_server_credentials* creds) |
||||
: creds_(creds) {} |
||||
~SecureServerCredentials() GRPC_OVERRIDE { |
||||
grpc_server_credentials_release(creds_); |
||||
} |
||||
|
||||
int AddPortToServer(const grpc::string& addr, |
||||
grpc_server* server) GRPC_OVERRIDE; |
||||
|
||||
private: |
||||
grpc_server_credentials* const creds_; |
||||
}; |
||||
|
||||
} // namespace grpc
|
||||
|
||||
#endif // GRPC_INTERNAL_CPP_SERVER_SECURE_SERVER_CREDENTIALS_H
|
@ -1,361 +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. |
||||
* |
||||
*/ |
||||
|
||||
#include "rb_event.h" |
||||
|
||||
#include <ruby.h> |
||||
|
||||
#include <grpc/grpc.h> |
||||
#include "rb_grpc.h" |
||||
#include "rb_byte_buffer.h" |
||||
#include "rb_call.h" |
||||
#include "rb_metadata.h" |
||||
|
||||
/* grpc_rb_event wraps a grpc_event. It provides a peer ruby object,
|
||||
* 'mark' to minimize copying when an event is created from ruby. */ |
||||
typedef struct grpc_rb_event { |
||||
/* Holder of ruby objects involved in constructing the channel */ |
||||
VALUE mark; |
||||
/* The actual event */ |
||||
grpc_event *wrapped; |
||||
} grpc_rb_event; |
||||
|
||||
/* grpc_mCompletionType is a ruby module that holds the completion type values */ |
||||
VALUE grpc_mCompletionType = Qnil; |
||||
|
||||
/* Destroys Event instances. */ |
||||
static void grpc_rb_event_free(void *p) { |
||||
grpc_rb_event *ev = NULL; |
||||
if (p == NULL) { |
||||
return; |
||||
}; |
||||
ev = (grpc_rb_event *)p; |
||||
|
||||
/* Deletes the wrapped object if the mark object is Qnil, which indicates
|
||||
* that no other object is the actual owner. */ |
||||
if (ev->wrapped != NULL && ev->mark == Qnil) { |
||||
grpc_event_finish(ev->wrapped); |
||||
rb_warning("event gc: destroyed the c event"); |
||||
} else { |
||||
rb_warning("event gc: did not destroy the c event"); |
||||
} |
||||
|
||||
xfree(p); |
||||
} |
||||
|
||||
/* Protects the mark object from GC */ |
||||
static void grpc_rb_event_mark(void *p) { |
||||
grpc_rb_event *event = NULL; |
||||
if (p == NULL) { |
||||
return; |
||||
} |
||||
event = (grpc_rb_event *)p; |
||||
if (event->mark != Qnil) { |
||||
rb_gc_mark(event->mark); |
||||
} |
||||
} |
||||
|
||||
static VALUE grpc_rb_event_result(VALUE self); |
||||
|
||||
/* Obtains the type of an event. */ |
||||
static VALUE grpc_rb_event_type(VALUE self) { |
||||
grpc_event *event = NULL; |
||||
grpc_rb_event *wrapper = NULL; |
||||
Data_Get_Struct(self, grpc_rb_event, wrapper); |
||||
if (wrapper->wrapped == NULL) { |
||||
rb_raise(rb_eRuntimeError, "finished!"); |
||||
return Qnil; |
||||
} |
||||
|
||||
event = wrapper->wrapped; |
||||
switch (event->type) { |
||||
case GRPC_QUEUE_SHUTDOWN: |
||||
return rb_const_get(grpc_mCompletionType, rb_intern("QUEUE_SHUTDOWN")); |
||||
|
||||
case GRPC_READ: |
||||
return rb_const_get(grpc_mCompletionType, rb_intern("READ")); |
||||
|
||||
case GRPC_WRITE_ACCEPTED: |
||||
grpc_rb_event_result(self); /* validates the result */ |
||||
return rb_const_get(grpc_mCompletionType, rb_intern("WRITE_ACCEPTED")); |
||||
|
||||
case GRPC_FINISH_ACCEPTED: |
||||
grpc_rb_event_result(self); /* validates the result */ |
||||
return rb_const_get(grpc_mCompletionType, rb_intern("FINISH_ACCEPTED")); |
||||
|
||||
case GRPC_CLIENT_METADATA_READ: |
||||
return rb_const_get(grpc_mCompletionType, |
||||
rb_intern("CLIENT_METADATA_READ")); |
||||
|
||||
case GRPC_FINISHED: |
||||
return rb_const_get(grpc_mCompletionType, rb_intern("FINISHED")); |
||||
|
||||
case GRPC_SERVER_RPC_NEW: |
||||
return rb_const_get(grpc_mCompletionType, rb_intern("SERVER_RPC_NEW")); |
||||
|
||||
default: |
||||
rb_raise(rb_eRuntimeError, "unrecognized event code for an rpc event:%d", |
||||
event->type); |
||||
} |
||||
return Qnil; /* should not be reached */ |
||||
} |
||||
|
||||
/* Obtains the tag associated with an event. */ |
||||
static VALUE grpc_rb_event_tag(VALUE self) { |
||||
grpc_event *event = NULL; |
||||
grpc_rb_event *wrapper = NULL; |
||||
Data_Get_Struct(self, grpc_rb_event, wrapper); |
||||
if (wrapper->wrapped == NULL) { |
||||
rb_raise(rb_eRuntimeError, "finished!"); |
||||
return Qnil; |
||||
} |
||||
|
||||
event = wrapper->wrapped; |
||||
if (event->tag == NULL) { |
||||
return Qnil; |
||||
} |
||||
return (VALUE)event->tag; |
||||
} |
||||
|
||||
/* Obtains the call associated with an event. */ |
||||
static VALUE grpc_rb_event_call(VALUE self) { |
||||
grpc_event *event = NULL; |
||||
grpc_rb_event *wrapper = NULL; |
||||
Data_Get_Struct(self, grpc_rb_event, wrapper); |
||||
if (wrapper->wrapped == NULL) { |
||||
rb_raise(rb_eRuntimeError, "finished!"); |
||||
return Qnil; |
||||
} |
||||
|
||||
event = wrapper->wrapped; |
||||
if (event->call != NULL) { |
||||
return grpc_rb_wrap_call(event->call); |
||||
} |
||||
return Qnil; |
||||
} |
||||
|
||||
/* Obtains the metadata associated with an event. */ |
||||
static VALUE grpc_rb_event_metadata(VALUE self) { |
||||
grpc_event *event = NULL; |
||||
grpc_rb_event *wrapper = NULL; |
||||
grpc_metadata *metadata = NULL; |
||||
VALUE key = Qnil; |
||||
VALUE new_ary = Qnil; |
||||
VALUE result = Qnil; |
||||
VALUE value = Qnil; |
||||
size_t count = 0; |
||||
size_t i = 0; |
||||
Data_Get_Struct(self, grpc_rb_event, wrapper); |
||||
if (wrapper->wrapped == NULL) { |
||||
rb_raise(rb_eRuntimeError, "finished!"); |
||||
return Qnil; |
||||
} |
||||
|
||||
/* Figure out which metadata to read. */ |
||||
event = wrapper->wrapped; |
||||
switch (event->type) { |
||||
case GRPC_CLIENT_METADATA_READ: |
||||
count = event->data.client_metadata_read.count; |
||||
metadata = event->data.client_metadata_read.elements; |
||||
break; |
||||
|
||||
case GRPC_FINISHED: |
||||
count = event->data.finished.metadata_count; |
||||
metadata = event->data.finished.metadata_elements; |
||||
break; |
||||
|
||||
case GRPC_SERVER_RPC_NEW: |
||||
count = event->data.server_rpc_new.metadata_count; |
||||
metadata = event->data.server_rpc_new.metadata_elements; |
||||
break; |
||||
|
||||
default: |
||||
rb_raise(rb_eRuntimeError, |
||||
"bug: bad event type metadata. got %d; want %d|%d:%d", |
||||
event->type, GRPC_CLIENT_METADATA_READ, GRPC_FINISHED, |
||||
GRPC_SERVER_RPC_NEW); |
||||
return Qnil; |
||||
} |
||||
|
||||
result = rb_hash_new(); |
||||
for (i = 0; i < count; i++) { |
||||
key = rb_str_new2(metadata[i].key); |
||||
value = rb_hash_aref(result, key); |
||||
if (value == Qnil) { |
||||
value = rb_str_new(metadata[i].value, metadata[i].value_length); |
||||
rb_hash_aset(result, key, value); |
||||
} else if (TYPE(value) == T_ARRAY) { |
||||
/* Add the string to the returned array */ |
||||
rb_ary_push(value, |
||||
rb_str_new(metadata[i].value, metadata[i].value_length)); |
||||
} else { |
||||
/* Add the current value with this key and the new one to an array */ |
||||
new_ary = rb_ary_new(); |
||||
rb_ary_push(new_ary, value); |
||||
rb_ary_push(new_ary, |
||||
rb_str_new(metadata[i].value, metadata[i].value_length)); |
||||
rb_hash_aset(result, key, new_ary); |
||||
} |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
/* Obtains the data associated with an event. */ |
||||
static VALUE grpc_rb_event_result(VALUE self) { |
||||
grpc_event *event = NULL; |
||||
grpc_rb_event *wrapper = NULL; |
||||
Data_Get_Struct(self, grpc_rb_event, wrapper); |
||||
if (wrapper->wrapped == NULL) { |
||||
rb_raise(rb_eRuntimeError, "finished!"); |
||||
return Qnil; |
||||
} |
||||
event = wrapper->wrapped; |
||||
|
||||
switch (event->type) { |
||||
case GRPC_QUEUE_SHUTDOWN: |
||||
return Qnil; |
||||
|
||||
case GRPC_READ: |
||||
return grpc_rb_byte_buffer_create_with_mark(self, event->data.read); |
||||
|
||||
case GRPC_FINISH_ACCEPTED: |
||||
if (event->data.finish_accepted == GRPC_OP_OK) { |
||||
return Qnil; |
||||
} |
||||
rb_raise(grpc_eEventError, "finish failed, not sure why (code=%d)", |
||||
event->data.finish_accepted); |
||||
break; |
||||
|
||||
case GRPC_WRITE_ACCEPTED: |
||||
if (event->data.write_accepted == GRPC_OP_OK) { |
||||
return Qnil; |
||||
} |
||||
rb_raise(grpc_eEventError, "write failed, not sure why (code=%d)", |
||||
event->data.write_accepted); |
||||
break; |
||||
|
||||
case GRPC_CLIENT_METADATA_READ: |
||||
return grpc_rb_event_metadata(self); |
||||
|
||||
case GRPC_FINISHED: |
||||
return rb_struct_new(grpc_sStatus, UINT2NUM(event->data.finished.status), |
||||
(event->data.finished.details == NULL |
||||
? Qnil |
||||
: rb_str_new2(event->data.finished.details)), |
||||
grpc_rb_event_metadata(self), NULL); |
||||
break; |
||||
|
||||
case GRPC_SERVER_RPC_NEW: |
||||
return rb_struct_new( |
||||
grpc_sNewServerRpc, rb_str_new2(event->data.server_rpc_new.method), |
||||
rb_str_new2(event->data.server_rpc_new.host), |
||||
Data_Wrap_Struct(grpc_cTimeVal, GC_NOT_MARKED, GC_DONT_FREE, |
||||
(void *)&event->data.server_rpc_new.deadline), |
||||
grpc_rb_event_metadata(self), NULL); |
||||
|
||||
default: |
||||
rb_raise(rb_eRuntimeError, "unrecognized event code for an rpc event:%d", |
||||
event->type); |
||||
} |
||||
|
||||
return Qfalse; |
||||
} |
||||
|
||||
static VALUE grpc_rb_event_finish(VALUE self) { |
||||
grpc_event *event = NULL; |
||||
grpc_rb_event *wrapper = NULL; |
||||
Data_Get_Struct(self, grpc_rb_event, wrapper); |
||||
if (wrapper->wrapped == NULL) { /* already closed */ |
||||
return Qnil; |
||||
} |
||||
event = wrapper->wrapped; |
||||
grpc_event_finish(event); |
||||
wrapper->wrapped = NULL; |
||||
wrapper->mark = Qnil; |
||||
return Qnil; |
||||
} |
||||
|
||||
/* grpc_cEvent is the Event class whose instances proxy grpc_event */ |
||||
VALUE grpc_cEvent = Qnil; |
||||
|
||||
/* grpc_eEventError is the ruby class of the exception thrown on failures during
|
||||
rpc event processing. */ |
||||
VALUE grpc_eEventError = Qnil; |
||||
|
||||
void Init_grpc_event() { |
||||
grpc_eEventError = |
||||
rb_define_class_under(grpc_mGrpcCore, "EventError", rb_eStandardError); |
||||
grpc_cEvent = rb_define_class_under(grpc_mGrpcCore, "Event", rb_cObject); |
||||
|
||||
/* Prevent allocation or inialization from ruby. */ |
||||
rb_define_alloc_func(grpc_cEvent, grpc_rb_cannot_alloc); |
||||
rb_define_method(grpc_cEvent, "initialize", grpc_rb_cannot_init, 0); |
||||
rb_define_method(grpc_cEvent, "initialize_copy", grpc_rb_cannot_init_copy, 1); |
||||
|
||||
/* Accessors for the data available in an event. */ |
||||
rb_define_method(grpc_cEvent, "call", grpc_rb_event_call, 0); |
||||
rb_define_method(grpc_cEvent, "result", grpc_rb_event_result, 0); |
||||
rb_define_method(grpc_cEvent, "tag", grpc_rb_event_tag, 0); |
||||
rb_define_method(grpc_cEvent, "type", grpc_rb_event_type, 0); |
||||
rb_define_method(grpc_cEvent, "finish", grpc_rb_event_finish, 0); |
||||
rb_define_alias(grpc_cEvent, "close", "finish"); |
||||
|
||||
/* Constants representing the completion types */ |
||||
grpc_mCompletionType = |
||||
rb_define_module_under(grpc_mGrpcCore, "CompletionType"); |
||||
rb_define_const(grpc_mCompletionType, "QUEUE_SHUTDOWN", |
||||
INT2NUM(GRPC_QUEUE_SHUTDOWN)); |
||||
rb_define_const(grpc_mCompletionType, "OP_COMPLETE", INT2NUM(GRPC_OP_COMPLETE)); |
||||
rb_define_const(grpc_mCompletionType, "READ", INT2NUM(GRPC_READ)); |
||||
rb_define_const(grpc_mCompletionType, "WRITE_ACCEPTED", |
||||
INT2NUM(GRPC_WRITE_ACCEPTED)); |
||||
rb_define_const(grpc_mCompletionType, "FINISH_ACCEPTED", |
||||
INT2NUM(GRPC_FINISH_ACCEPTED)); |
||||
rb_define_const(grpc_mCompletionType, "CLIENT_METADATA_READ", |
||||
INT2NUM(GRPC_CLIENT_METADATA_READ)); |
||||
rb_define_const(grpc_mCompletionType, "FINISHED", INT2NUM(GRPC_FINISHED)); |
||||
rb_define_const(grpc_mCompletionType, "SERVER_RPC_NEW", |
||||
INT2NUM(GRPC_SERVER_RPC_NEW)); |
||||
rb_define_const(grpc_mCompletionType, "SERVER_SHUTDOWN", |
||||
INT2NUM(GRPC_SERVER_SHUTDOWN)); |
||||
rb_define_const(grpc_mCompletionType, "RESERVED", |
||||
INT2NUM(GRPC_COMPLETION_DO_NOT_USE)); |
||||
} |
||||
|
||||
VALUE grpc_rb_new_event(grpc_event *ev) { |
||||
grpc_rb_event *wrapper = ALLOC(grpc_rb_event); |
||||
wrapper->wrapped = ev; |
||||
wrapper->mark = Qnil; |
||||
return Data_Wrap_Struct(grpc_cEvent, grpc_rb_event_mark, grpc_rb_event_free, |
||||
wrapper); |
||||
} |
@ -1,215 +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. |
||||
* |
||||
*/ |
||||
|
||||
#include "rb_metadata.h" |
||||
|
||||
#include <ruby.h> |
||||
#include <string.h> |
||||
|
||||
#include <grpc/grpc.h> |
||||
#include "rb_grpc.h" |
||||
|
||||
/* grpc_rb_metadata wraps a grpc_metadata. It provides a peer ruby object,
|
||||
* 'mark' to minimize copying when a metadata is created from ruby. */ |
||||
typedef struct grpc_rb_metadata { |
||||
/* Holder of ruby objects involved in constructing the metadata */ |
||||
VALUE mark; |
||||
/* The actual metadata */ |
||||
grpc_metadata *wrapped; |
||||
} grpc_rb_metadata; |
||||
|
||||
/* Destroys Metadata instances. */ |
||||
static void grpc_rb_metadata_free(void *p) { |
||||
if (p == NULL) { |
||||
return; |
||||
}; |
||||
|
||||
/* Because metadata is only created during a call to grpc_call_add_metadata,
|
||||
* and the call takes ownership of the metadata, this does not free the |
||||
* wrapped struct, only the wrapper */ |
||||
xfree(p); |
||||
} |
||||
|
||||
/* Protects the mark object from GC */ |
||||
static void grpc_rb_metadata_mark(void *p) { |
||||
grpc_rb_metadata *md = NULL; |
||||
if (p == NULL) { |
||||
return; |
||||
} |
||||
|
||||
md = (grpc_rb_metadata *)p; |
||||
/* If it's not already cleaned up, mark the mark object */ |
||||
if (md->mark != Qnil && BUILTIN_TYPE(md->mark) != T_NONE) { |
||||
rb_gc_mark(md->mark); |
||||
} |
||||
} |
||||
|
||||
/* Allocates Metadata instances.
|
||||
|
||||
Provides safe default values for the Metadata fields. */ |
||||
static VALUE grpc_rb_metadata_alloc(VALUE cls) { |
||||
grpc_rb_metadata *wrapper = ALLOC(grpc_rb_metadata); |
||||
wrapper->wrapped = NULL; |
||||
wrapper->mark = Qnil; |
||||
return Data_Wrap_Struct(cls, grpc_rb_metadata_mark, grpc_rb_metadata_free, |
||||
wrapper); |
||||
} |
||||
|
||||
/* id_key and id_value are the names of the hidden ivars that preserve the
|
||||
* original byte_buffer source string */ |
||||
static ID id_key; |
||||
static ID id_value; |
||||
|
||||
/* Initializes Metadata instances. */ |
||||
static VALUE grpc_rb_metadata_init(VALUE self, VALUE key, VALUE value) { |
||||
grpc_rb_metadata *wrapper = NULL; |
||||
grpc_metadata *md = ALLOC(grpc_metadata); |
||||
|
||||
/* Use direct pointers to the strings wrapped by the ruby object to avoid
|
||||
* copying */ |
||||
Data_Get_Struct(self, grpc_rb_metadata, wrapper); |
||||
wrapper->wrapped = md; |
||||
if (TYPE(key) == T_SYMBOL) { |
||||
md->key = (char *)rb_id2name(SYM2ID(key)); |
||||
} else { /* StringValueCStr does all other type exclusions for us */ |
||||
md->key = StringValueCStr(key); |
||||
} |
||||
md->value = RSTRING_PTR(value); |
||||
md->value_length = RSTRING_LEN(value); |
||||
|
||||
/* Save references to the original values on the mark object so that the
|
||||
* pointers used there are valid for the lifetime of the object. */ |
||||
wrapper->mark = rb_class_new_instance(0, NULL, rb_cObject); |
||||
rb_ivar_set(wrapper->mark, id_key, key); |
||||
rb_ivar_set(wrapper->mark, id_value, value); |
||||
|
||||
return self; |
||||
} |
||||
|
||||
/* Clones Metadata instances.
|
||||
|
||||
Gives Metadata a consistent implementation of Ruby's object copy/dup |
||||
protocol. */ |
||||
static VALUE grpc_rb_metadata_init_copy(VALUE copy, VALUE orig) { |
||||
grpc_rb_metadata *orig_md = NULL; |
||||
grpc_rb_metadata *copy_md = NULL; |
||||
|
||||
if (copy == orig) { |
||||
return copy; |
||||
} |
||||
|
||||
/* Raise an error if orig is not a metadata object or a subclass. */ |
||||
if (TYPE(orig) != T_DATA || |
||||
RDATA(orig)->dfree != (RUBY_DATA_FUNC)grpc_rb_metadata_free) { |
||||
rb_raise(rb_eTypeError, "not a %s", rb_obj_classname(grpc_cMetadata)); |
||||
} |
||||
|
||||
Data_Get_Struct(orig, grpc_rb_metadata, orig_md); |
||||
Data_Get_Struct(copy, grpc_rb_metadata, copy_md); |
||||
|
||||
/* use ruby's MEMCPY to make a byte-for-byte copy of the metadata wrapper
|
||||
* object. */ |
||||
MEMCPY(copy_md, orig_md, grpc_rb_metadata, 1); |
||||
return copy; |
||||
} |
||||
|
||||
/* Gets the key from a metadata instance. */ |
||||
static VALUE grpc_rb_metadata_key(VALUE self) { |
||||
VALUE key = Qnil; |
||||
grpc_rb_metadata *wrapper = NULL; |
||||
grpc_metadata *md = NULL; |
||||
|
||||
Data_Get_Struct(self, grpc_rb_metadata, wrapper); |
||||
if (wrapper->mark != Qnil) { |
||||
key = rb_ivar_get(wrapper->mark, id_key); |
||||
if (key != Qnil) { |
||||
return key; |
||||
} |
||||
} |
||||
|
||||
md = wrapper->wrapped; |
||||
if (md == NULL || md->key == NULL) { |
||||
return Qnil; |
||||
} |
||||
return rb_str_new2(md->key); |
||||
} |
||||
|
||||
/* Gets the value from a metadata instance. */ |
||||
static VALUE grpc_rb_metadata_value(VALUE self) { |
||||
VALUE val = Qnil; |
||||
grpc_rb_metadata *wrapper = NULL; |
||||
grpc_metadata *md = NULL; |
||||
|
||||
Data_Get_Struct(self, grpc_rb_metadata, wrapper); |
||||
if (wrapper->mark != Qnil) { |
||||
val = rb_ivar_get(wrapper->mark, id_value); |
||||
if (val != Qnil) { |
||||
return val; |
||||
} |
||||
} |
||||
|
||||
md = wrapper->wrapped; |
||||
if (md == NULL || md->value == NULL) { |
||||
return Qnil; |
||||
} |
||||
return rb_str_new2(md->value); |
||||
} |
||||
|
||||
/* grpc_cMetadata is the Metadata class whose instances proxy grpc_metadata. */ |
||||
VALUE grpc_cMetadata = Qnil; |
||||
void Init_grpc_metadata() { |
||||
grpc_cMetadata = |
||||
rb_define_class_under(grpc_mGrpcCore, "Metadata", rb_cObject); |
||||
|
||||
/* Allocates an object managed by the ruby runtime */ |
||||
rb_define_alloc_func(grpc_cMetadata, grpc_rb_metadata_alloc); |
||||
|
||||
/* Provides a ruby constructor and support for dup/clone. */ |
||||
rb_define_method(grpc_cMetadata, "initialize", grpc_rb_metadata_init, 2); |
||||
rb_define_method(grpc_cMetadata, "initialize_copy", grpc_rb_metadata_init_copy, |
||||
1); |
||||
|
||||
/* Provides accessors for the code and details. */ |
||||
rb_define_method(grpc_cMetadata, "key", grpc_rb_metadata_key, 0); |
||||
rb_define_method(grpc_cMetadata, "value", grpc_rb_metadata_value, 0); |
||||
|
||||
id_key = rb_intern("__key"); |
||||
id_value = rb_intern("__value"); |
||||
} |
||||
|
||||
/* Gets the wrapped metadata from the ruby wrapper */ |
||||
grpc_metadata *grpc_rb_get_wrapped_metadata(VALUE v) { |
||||
grpc_rb_metadata *wrapper = NULL; |
||||
Data_Get_Struct(v, grpc_rb_metadata, wrapper); |
||||
return wrapper->wrapped; |
||||
} |
@ -1,44 +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. |
||||
|
||||
require 'grpc' |
||||
|
||||
# GRPC contains the General RPC module. |
||||
module GRPC |
||||
module Core |
||||
# Event is a class defined in the c extension |
||||
# |
||||
# Here, we add an inspect method. |
||||
class Event |
||||
def inspect |
||||
"<#{self.class}: type:#{type}, tag:#{tag} result:#{result}>" |
||||
end |
||||
end |
||||
end |
||||
end |
@ -1,44 +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. |
||||
|
||||
require 'grpc' |
||||
|
||||
describe 'Wrapped classes where .new cannot create an instance' do |
||||
describe GRPC::Core::Event do |
||||
it 'should fail .new fail with a runtime error' do |
||||
expect { GRPC::Core::Event.new }.to raise_error(TypeError) |
||||
end |
||||
end |
||||
|
||||
describe GRPC::Core::Call do |
||||
it 'should fail .new fail with a runtime error' do |
||||
expect { GRPC::Core::Event.new }.to raise_error(TypeError) |
||||
end |
||||
end |
||||
end |
@ -1,67 +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. |
||||
|
||||
require 'grpc' |
||||
|
||||
describe GRPC::Core::ByteBuffer do |
||||
describe '#new' do |
||||
it 'is constructed from a string' do |
||||
expect { GRPC::Core::ByteBuffer.new('#new') }.not_to raise_error |
||||
end |
||||
|
||||
it 'can be constructed from the empty string' do |
||||
expect { GRPC::Core::ByteBuffer.new('') }.not_to raise_error |
||||
end |
||||
|
||||
it 'cannot be constructed from nil' do |
||||
expect { GRPC::Core::ByteBuffer.new(nil) }.to raise_error TypeError |
||||
end |
||||
|
||||
it 'cannot be constructed from non-strings' do |
||||
[1, Object.new, :a_symbol].each do |x| |
||||
expect { GRPC::Core::ByteBuffer.new(x) }.to raise_error TypeError |
||||
end |
||||
end |
||||
end |
||||
|
||||
describe '#to_s' do |
||||
it 'is the string value the ByteBuffer was constructed with' do |
||||
expect(GRPC::Core::ByteBuffer.new('#to_s').to_s).to eq('#to_s') |
||||
end |
||||
end |
||||
|
||||
describe '#dup' do |
||||
it 'makes an instance whose #to_s is the original string value' do |
||||
bb = GRPC::Core::ByteBuffer.new('#dup') |
||||
a_copy = bb.dup |
||||
expect(a_copy.to_s).to eq('#dup') |
||||
expect(a_copy.dup.to_s).to eq('#dup') |
||||
end |
||||
end |
||||
end |
@ -1,53 +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. |
||||
|
||||
require 'grpc' |
||||
|
||||
describe GRPC::Core::CompletionType do |
||||
before(:each) do |
||||
@known_types = { |
||||
QUEUE_SHUTDOWN: 0, |
||||
OP_COMPLETE: 1, |
||||
READ: 2, |
||||
WRITE_ACCEPTED: 3, |
||||
FINISH_ACCEPTED: 4, |
||||
CLIENT_METADATA_READ: 5, |
||||
FINISHED: 6, |
||||
SERVER_RPC_NEW: 7, |
||||
SERVER_SHUTDOWN: 8, |
||||
RESERVED: 9 |
||||
} |
||||
end |
||||
|
||||
it 'should have all the known types' do |
||||
mod = GRPC::Core::CompletionType |
||||
blk = proc { Hash[mod.constants.collect { |c| [c, mod.const_get(c)] }] } |
||||
expect(blk.call).to eq(@known_types) |
||||
end |
||||
end |
@ -1,64 +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. |
||||
|
||||
require 'grpc' |
||||
|
||||
describe GRPC::Core::Metadata do |
||||
describe '#new' do |
||||
it 'should create instances' do |
||||
expect { GRPC::Core::Metadata.new('a key', 'a value') }.to_not raise_error |
||||
end |
||||
end |
||||
|
||||
describe '#key' do |
||||
md = GRPC::Core::Metadata.new('a key', 'a value') |
||||
it 'should be the constructor value' do |
||||
expect(md.key).to eq('a key') |
||||
end |
||||
end |
||||
|
||||
describe '#value' do |
||||
md = GRPC::Core::Metadata.new('a key', 'a value') |
||||
it 'should be the constuctor value' do |
||||
expect(md.value).to eq('a value') |
||||
end |
||||
end |
||||
|
||||
describe '#dup' do |
||||
it 'should create a copy that returns the correct key' do |
||||
md = GRPC::Core::Metadata.new('a key', 'a value') |
||||
expect(md.dup.key).to eq('a key') |
||||
end |
||||
|
||||
it 'should create a copy that returns the correct value' do |
||||
md = GRPC::Core::Metadata.new('a key', 'a value') |
||||
expect(md.dup.value).to eq('a value') |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,82 @@ |
||||
/*
|
||||
* |
||||
* 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 of gpr thread local storage support. */ |
||||
|
||||
#include <stdio.h> |
||||
#include <stdlib.h> |
||||
#include <grpc/support/log.h> |
||||
#include <grpc/support/sync.h> |
||||
#include <grpc/support/thd.h> |
||||
#include <grpc/support/tls.h> |
||||
#include "test/core/util/test_config.h" |
||||
|
||||
#define NUM_THREADS 100 |
||||
|
||||
GPR_TLS_DECL(test_var); |
||||
|
||||
static void thd_body(void *arg) { |
||||
gpr_intptr i; |
||||
|
||||
GPR_ASSERT(gpr_tls_get(&test_var) == 0); |
||||
|
||||
for (i = 0; i < 10000000; i++) { |
||||
gpr_tls_set(&test_var, i); |
||||
GPR_ASSERT(gpr_tls_get(&test_var) == i); |
||||
} |
||||
} |
||||
|
||||
/* ------------------------------------------------- */ |
||||
|
||||
int main(int argc, char *argv[]) { |
||||
gpr_thd_options opt = gpr_thd_options_default(); |
||||
int i; |
||||
gpr_thd_id threads[NUM_THREADS]; |
||||
|
||||
grpc_test_init(argc, argv); |
||||
|
||||
gpr_tls_init(&test_var); |
||||
|
||||
gpr_thd_options_set_joinable(&opt); |
||||
|
||||
for (i = 0; i < NUM_THREADS; i++) { |
||||
gpr_thd_new(&threads[i], thd_body, NULL, &opt); |
||||
} |
||||
for (i = 0; i < NUM_THREADS; i++) { |
||||
gpr_thd_join(threads[i]); |
||||
} |
||||
|
||||
gpr_tls_destroy(&test_var); |
||||
|
||||
return 0; |
||||
} |
@ -0,0 +1,119 @@ |
||||
/*
|
||||
* |
||||
* 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. |
||||
* |
||||
*/ |
||||
|
||||
#include "test/cpp/interop/client_helper.h" |
||||
|
||||
#include <fstream> |
||||
#include <memory> |
||||
#include <sstream> |
||||
|
||||
#include <unistd.h> |
||||
|
||||
#include <grpc/grpc.h> |
||||
#include <grpc/support/log.h> |
||||
#include <gflags/gflags.h> |
||||
#include <grpc++/channel_arguments.h> |
||||
#include <grpc++/channel_interface.h> |
||||
#include <grpc++/create_channel.h> |
||||
#include <grpc++/credentials.h> |
||||
#include <grpc++/stream.h> |
||||
#include "test/cpp/util/create_test_channel.h" |
||||
|
||||
DECLARE_bool(enable_ssl); |
||||
DECLARE_bool(use_prod_roots); |
||||
DECLARE_int32(server_port); |
||||
DECLARE_string(server_host); |
||||
DECLARE_string(server_host_override); |
||||
DECLARE_string(test_case); |
||||
DECLARE_string(default_service_account); |
||||
DECLARE_string(service_account_key_file); |
||||
DECLARE_string(oauth_scope); |
||||
|
||||
// In some distros, gflags is in the namespace google, and in some others,
|
||||
// in gflags. This hack is enabling us to find both.
|
||||
namespace google {} |
||||
namespace gflags {} |
||||
using namespace google; |
||||
using namespace gflags; |
||||
|
||||
namespace grpc { |
||||
namespace testing { |
||||
|
||||
grpc::string GetServiceAccountJsonKey() { |
||||
static grpc::string json_key; |
||||
if (json_key.empty()) { |
||||
std::ifstream json_key_file(FLAGS_service_account_key_file); |
||||
std::stringstream key_stream; |
||||
key_stream << json_key_file.rdbuf(); |
||||
json_key = key_stream.str(); |
||||
} |
||||
return json_key; |
||||
} |
||||
|
||||
std::shared_ptr<ChannelInterface> CreateChannelForTestCase( |
||||
const grpc::string& test_case) { |
||||
GPR_ASSERT(FLAGS_server_port); |
||||
const int host_port_buf_size = 1024; |
||||
char host_port[host_port_buf_size]; |
||||
snprintf(host_port, host_port_buf_size, "%s:%d", FLAGS_server_host.c_str(), |
||||
FLAGS_server_port); |
||||
|
||||
if (test_case == "service_account_creds") { |
||||
std::unique_ptr<Credentials> creds; |
||||
GPR_ASSERT(FLAGS_enable_ssl); |
||||
grpc::string json_key = GetServiceAccountJsonKey(); |
||||
creds = ServiceAccountCredentials(json_key, FLAGS_oauth_scope, |
||||
std::chrono::hours(1)); |
||||
return CreateTestChannel(host_port, FLAGS_server_host_override, |
||||
FLAGS_enable_ssl, FLAGS_use_prod_roots, creds); |
||||
} else if (test_case == "compute_engine_creds") { |
||||
std::unique_ptr<Credentials> creds; |
||||
GPR_ASSERT(FLAGS_enable_ssl); |
||||
creds = ComputeEngineCredentials(); |
||||
return CreateTestChannel(host_port, FLAGS_server_host_override, |
||||
FLAGS_enable_ssl, FLAGS_use_prod_roots, creds); |
||||
} else if (test_case == "jwt_token_creds") { |
||||
std::unique_ptr<Credentials> creds; |
||||
GPR_ASSERT(FLAGS_enable_ssl); |
||||
grpc::string json_key = GetServiceAccountJsonKey(); |
||||
creds = JWTCredentials(json_key, std::chrono::hours(1)); |
||||
return CreateTestChannel(host_port, FLAGS_server_host_override, |
||||
FLAGS_enable_ssl, FLAGS_use_prod_roots, creds); |
||||
} else { |
||||
return CreateTestChannel(host_port, FLAGS_server_host_override, |
||||
FLAGS_enable_ssl, FLAGS_use_prod_roots); |
||||
} |
||||
} |
||||
|
||||
} // namespace testing
|
||||
} // namespace grpc
|
@ -0,0 +1,311 @@ |
||||
/*
|
||||
* |
||||
* 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. |
||||
* |
||||
*/ |
||||
|
||||
#include "test/cpp/interop/interop_client.h" |
||||
|
||||
#include <memory> |
||||
|
||||
#include <unistd.h> |
||||
|
||||
#include <grpc/grpc.h> |
||||
#include <grpc/support/log.h> |
||||
#include <grpc++/channel_interface.h> |
||||
#include <grpc++/client_context.h> |
||||
#include <grpc++/status.h> |
||||
#include <grpc++/stream.h> |
||||
#include "test/cpp/interop/test.grpc.pb.h" |
||||
#include "test/cpp/interop/empty.grpc.pb.h" |
||||
#include "test/cpp/interop/messages.grpc.pb.h" |
||||
|
||||
namespace grpc { |
||||
namespace testing { |
||||
|
||||
namespace { |
||||
// The same value is defined by the Java client.
|
||||
const std::vector<int> request_stream_sizes = {27182, 8, 1828, 45904}; |
||||
const std::vector<int> response_stream_sizes = {31415, 9, 2653, 58979}; |
||||
const int kNumResponseMessages = 2000; |
||||
const int kResponseMessageSize = 1030; |
||||
const int kReceiveDelayMilliSeconds = 20; |
||||
const int kLargeRequestSize = 314159; |
||||
const int kLargeResponseSize = 271812; |
||||
} // namespace
|
||||
|
||||
InteropClient::InteropClient(std::shared_ptr<ChannelInterface> channel) |
||||
: channel_(channel) {} |
||||
|
||||
void InteropClient::AssertOkOrPrintErrorStatus(const Status& s) { |
||||
if (s.IsOk()) { |
||||
return; |
||||
} |
||||
gpr_log(GPR_INFO, "Error status code: %d, message: %s", s.code(), |
||||
s.details().c_str()); |
||||
GPR_ASSERT(0); |
||||
} |
||||
|
||||
void InteropClient::DoEmpty() { |
||||
gpr_log(GPR_INFO, "Sending an empty rpc..."); |
||||
std::unique_ptr<TestService::Stub> stub(TestService::NewStub(channel_)); |
||||
|
||||
Empty request = Empty::default_instance(); |
||||
Empty response = Empty::default_instance(); |
||||
ClientContext context; |
||||
|
||||
Status s = stub->EmptyCall(&context, request, &response); |
||||
AssertOkOrPrintErrorStatus(s); |
||||
|
||||
gpr_log(GPR_INFO, "Empty rpc done."); |
||||
} |
||||
|
||||
// Shared code to set large payload, make rpc and check response payload.
|
||||
void InteropClient::PerformLargeUnary(SimpleRequest* request, |
||||
SimpleResponse* response) { |
||||
std::unique_ptr<TestService::Stub> stub(TestService::NewStub(channel_)); |
||||
|
||||
ClientContext context; |
||||
request->set_response_type(PayloadType::COMPRESSABLE); |
||||
request->set_response_size(kLargeResponseSize); |
||||
grpc::string payload(kLargeRequestSize, '\0'); |
||||
request->mutable_payload()->set_body(payload.c_str(), kLargeRequestSize); |
||||
|
||||
Status s = stub->UnaryCall(&context, *request, response); |
||||
|
||||
AssertOkOrPrintErrorStatus(s); |
||||
GPR_ASSERT(response->payload().type() == PayloadType::COMPRESSABLE); |
||||
GPR_ASSERT(response->payload().body() == |
||||
grpc::string(kLargeResponseSize, '\0')); |
||||
} |
||||
|
||||
void InteropClient::DoComputeEngineCreds( |
||||
const grpc::string& default_service_account, |
||||
const grpc::string& oauth_scope) { |
||||
gpr_log(GPR_INFO, |
||||
"Sending a large unary rpc with compute engine credentials ..."); |
||||
SimpleRequest request; |
||||
SimpleResponse response; |
||||
request.set_fill_username(true); |
||||
request.set_fill_oauth_scope(true); |
||||
PerformLargeUnary(&request, &response); |
||||
gpr_log(GPR_INFO, "Got username %s", response.username().c_str()); |
||||
gpr_log(GPR_INFO, "Got oauth_scope %s", response.oauth_scope().c_str()); |
||||
GPR_ASSERT(!response.username().empty()); |
||||
GPR_ASSERT(response.username().c_str() == default_service_account); |
||||
GPR_ASSERT(!response.oauth_scope().empty()); |
||||
const char* oauth_scope_str = response.oauth_scope().c_str(); |
||||
GPR_ASSERT(oauth_scope.find(oauth_scope_str) != grpc::string::npos); |
||||
gpr_log(GPR_INFO, "Large unary with compute engine creds done."); |
||||
} |
||||
|
||||
void InteropClient::DoServiceAccountCreds(const grpc::string& username, |
||||
const grpc::string& oauth_scope) { |
||||
gpr_log(GPR_INFO, |
||||
"Sending a large unary rpc with service account credentials ..."); |
||||
SimpleRequest request; |
||||
SimpleResponse response; |
||||
request.set_fill_username(true); |
||||
request.set_fill_oauth_scope(true); |
||||
PerformLargeUnary(&request, &response); |
||||
GPR_ASSERT(!response.username().empty()); |
||||
GPR_ASSERT(!response.oauth_scope().empty()); |
||||
GPR_ASSERT(username.find(response.username()) != grpc::string::npos); |
||||
const char* oauth_scope_str = response.oauth_scope().c_str(); |
||||
GPR_ASSERT(oauth_scope.find(oauth_scope_str) != grpc::string::npos); |
||||
gpr_log(GPR_INFO, "Large unary with service account creds done."); |
||||
} |
||||
|
||||
void InteropClient::DoJwtTokenCreds(const grpc::string& username) { |
||||
gpr_log(GPR_INFO, "Sending a large unary rpc with JWT token credentials ..."); |
||||
SimpleRequest request; |
||||
SimpleResponse response; |
||||
request.set_fill_username(true); |
||||
PerformLargeUnary(&request, &response); |
||||
GPR_ASSERT(!response.username().empty()); |
||||
GPR_ASSERT(username.find(response.username()) != grpc::string::npos); |
||||
gpr_log(GPR_INFO, "Large unary with JWT token creds done."); |
||||
} |
||||
|
||||
void InteropClient::DoLargeUnary() { |
||||
gpr_log(GPR_INFO, "Sending a large unary rpc..."); |
||||
SimpleRequest request; |
||||
SimpleResponse response; |
||||
PerformLargeUnary(&request, &response); |
||||
gpr_log(GPR_INFO, "Large unary done."); |
||||
} |
||||
|
||||
void InteropClient::DoRequestStreaming() { |
||||
gpr_log(GPR_INFO, "Sending request steaming rpc ..."); |
||||
std::unique_ptr<TestService::Stub> stub(TestService::NewStub(channel_)); |
||||
|
||||
ClientContext context; |
||||
StreamingInputCallRequest request; |
||||
StreamingInputCallResponse response; |
||||
|
||||
std::unique_ptr<ClientWriter<StreamingInputCallRequest>> stream( |
||||
stub->StreamingInputCall(&context, &response)); |
||||
|
||||
int aggregated_payload_size = 0; |
||||
for (unsigned int i = 0; i < request_stream_sizes.size(); ++i) { |
||||
Payload* payload = request.mutable_payload(); |
||||
payload->set_body(grpc::string(request_stream_sizes[i], '\0')); |
||||
GPR_ASSERT(stream->Write(request)); |
||||
aggregated_payload_size += request_stream_sizes[i]; |
||||
} |
||||
stream->WritesDone(); |
||||
Status s = stream->Finish(); |
||||
|
||||
GPR_ASSERT(response.aggregated_payload_size() == aggregated_payload_size); |
||||
AssertOkOrPrintErrorStatus(s); |
||||
gpr_log(GPR_INFO, "Request streaming done."); |
||||
} |
||||
|
||||
void InteropClient::DoResponseStreaming() { |
||||
gpr_log(GPR_INFO, "Receiving response steaming rpc ..."); |
||||
std::unique_ptr<TestService::Stub> stub(TestService::NewStub(channel_)); |
||||
|
||||
ClientContext context; |
||||
StreamingOutputCallRequest request; |
||||
for (unsigned int i = 0; i < response_stream_sizes.size(); ++i) { |
||||
ResponseParameters* response_parameter = request.add_response_parameters(); |
||||
response_parameter->set_size(response_stream_sizes[i]); |
||||
} |
||||
StreamingOutputCallResponse response; |
||||
std::unique_ptr<ClientReader<StreamingOutputCallResponse>> stream( |
||||
stub->StreamingOutputCall(&context, request)); |
||||
|
||||
unsigned int i = 0; |
||||
while (stream->Read(&response)) { |
||||
GPR_ASSERT(response.payload().body() == |
||||
grpc::string(response_stream_sizes[i], '\0')); |
||||
++i; |
||||
} |
||||
GPR_ASSERT(response_stream_sizes.size() == i); |
||||
Status s = stream->Finish(); |
||||
|
||||
AssertOkOrPrintErrorStatus(s); |
||||
gpr_log(GPR_INFO, "Response streaming done."); |
||||
} |
||||
|
||||
void InteropClient::DoResponseStreamingWithSlowConsumer() { |
||||
gpr_log(GPR_INFO, "Receiving response steaming rpc with slow consumer ..."); |
||||
std::unique_ptr<TestService::Stub> stub(TestService::NewStub(channel_)); |
||||
|
||||
ClientContext context; |
||||
StreamingOutputCallRequest request; |
||||
|
||||
for (int i = 0; i < kNumResponseMessages; ++i) { |
||||
ResponseParameters* response_parameter = request.add_response_parameters(); |
||||
response_parameter->set_size(kResponseMessageSize); |
||||
} |
||||
StreamingOutputCallResponse response; |
||||
std::unique_ptr<ClientReader<StreamingOutputCallResponse>> stream( |
||||
stub->StreamingOutputCall(&context, request)); |
||||
|
||||
int i = 0; |
||||
while (stream->Read(&response)) { |
||||
GPR_ASSERT(response.payload().body() == |
||||
grpc::string(kResponseMessageSize, '\0')); |
||||
gpr_log(GPR_INFO, "received message %d", i); |
||||
usleep(kReceiveDelayMilliSeconds * 1000); |
||||
++i; |
||||
} |
||||
GPR_ASSERT(kNumResponseMessages == i); |
||||
Status s = stream->Finish(); |
||||
|
||||
AssertOkOrPrintErrorStatus(s); |
||||
gpr_log(GPR_INFO, "Response streaming done."); |
||||
} |
||||
|
||||
void InteropClient::DoHalfDuplex() { |
||||
gpr_log(GPR_INFO, "Sending half-duplex streaming rpc ..."); |
||||
std::unique_ptr<TestService::Stub> stub(TestService::NewStub(channel_)); |
||||
|
||||
ClientContext context; |
||||
std::unique_ptr<ClientReaderWriter<StreamingOutputCallRequest, |
||||
StreamingOutputCallResponse>> |
||||
stream(stub->HalfDuplexCall(&context)); |
||||
|
||||
StreamingOutputCallRequest request; |
||||
ResponseParameters* response_parameter = request.add_response_parameters(); |
||||
for (unsigned int i = 0; i < response_stream_sizes.size(); ++i) { |
||||
response_parameter->set_size(response_stream_sizes[i]); |
||||
GPR_ASSERT(stream->Write(request)); |
||||
} |
||||
stream->WritesDone(); |
||||
|
||||
unsigned int i = 0; |
||||
StreamingOutputCallResponse response; |
||||
while (stream->Read(&response)) { |
||||
GPR_ASSERT(response.payload().has_body()); |
||||
GPR_ASSERT(response.payload().body() == |
||||
grpc::string(response_stream_sizes[i], '\0')); |
||||
++i; |
||||
} |
||||
GPR_ASSERT(response_stream_sizes.size() == i); |
||||
Status s = stream->Finish(); |
||||
AssertOkOrPrintErrorStatus(s); |
||||
gpr_log(GPR_INFO, "Half-duplex streaming rpc done."); |
||||
} |
||||
|
||||
void InteropClient::DoPingPong() { |
||||
gpr_log(GPR_INFO, "Sending Ping Pong streaming rpc ..."); |
||||
std::unique_ptr<TestService::Stub> stub(TestService::NewStub(channel_)); |
||||
|
||||
ClientContext context; |
||||
std::unique_ptr<ClientReaderWriter<StreamingOutputCallRequest, |
||||
StreamingOutputCallResponse>> |
||||
stream(stub->FullDuplexCall(&context)); |
||||
|
||||
StreamingOutputCallRequest request; |
||||
request.set_response_type(PayloadType::COMPRESSABLE); |
||||
ResponseParameters* response_parameter = request.add_response_parameters(); |
||||
Payload* payload = request.mutable_payload(); |
||||
StreamingOutputCallResponse response; |
||||
for (unsigned int i = 0; i < request_stream_sizes.size(); ++i) { |
||||
response_parameter->set_size(response_stream_sizes[i]); |
||||
payload->set_body(grpc::string(request_stream_sizes[i], '\0')); |
||||
GPR_ASSERT(stream->Write(request)); |
||||
GPR_ASSERT(stream->Read(&response)); |
||||
GPR_ASSERT(response.payload().has_body()); |
||||
GPR_ASSERT(response.payload().body() == |
||||
grpc::string(response_stream_sizes[i], '\0')); |
||||
} |
||||
|
||||
stream->WritesDone(); |
||||
GPR_ASSERT(!stream->Read(&response)); |
||||
Status s = stream->Finish(); |
||||
AssertOkOrPrintErrorStatus(s); |
||||
gpr_log(GPR_INFO, "Ping pong streaming done."); |
||||
} |
||||
|
||||
} // namespace testing
|
||||
} // namespace grpc
|
@ -0,0 +1,79 @@ |
||||
/*
|
||||
* |
||||
* 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. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPC_TEST_CPP_INTEROP_INTEROP_CLIENT_H |
||||
#define GRPC_TEST_CPP_INTEROP_INTEROP_CLIENT_H |
||||
#include <memory> |
||||
|
||||
#include <grpc/grpc.h> |
||||
#include <grpc++/channel_interface.h> |
||||
#include <grpc++/status.h> |
||||
#include "test/cpp/interop/messages.grpc.pb.h" |
||||
|
||||
namespace grpc { |
||||
namespace testing { |
||||
|
||||
class InteropClient { |
||||
public: |
||||
explicit InteropClient(std::shared_ptr<ChannelInterface> channel); |
||||
~InteropClient() {} |
||||
|
||||
void Reset(std::shared_ptr<ChannelInterface> channel) { channel_ = channel; } |
||||
|
||||
void DoEmpty(); |
||||
void DoLargeUnary(); |
||||
void DoPingPong(); |
||||
void DoHalfDuplex(); |
||||
void DoRequestStreaming(); |
||||
void DoResponseStreaming(); |
||||
void DoResponseStreamingWithSlowConsumer(); |
||||
// Auth tests.
|
||||
// username is a string containing the user email
|
||||
void DoJwtTokenCreds(const grpc::string& username); |
||||
void DoComputeEngineCreds(const grpc::string& default_service_account, |
||||
const grpc::string& oauth_scope); |
||||
// username is a string containing the user email
|
||||
void DoServiceAccountCreds(const grpc::string& username, |
||||
const grpc::string& oauth_scope); |
||||
|
||||
private: |
||||
void PerformLargeUnary(SimpleRequest* request, SimpleResponse* response); |
||||
void AssertOkOrPrintErrorStatus(const Status& s); |
||||
|
||||
std::shared_ptr<ChannelInterface> channel_; |
||||
}; |
||||
|
||||
} // namespace testing
|
||||
} // namespace grpc
|
||||
|
||||
#endif // GRPC_TEST_CPP_INTEROP_INTEROP_CLIENT_H
|
@ -0,0 +1,69 @@ |
||||
/*
|
||||
* |
||||
* 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. |
||||
* |
||||
*/ |
||||
|
||||
#include "test/cpp/interop/server_helper.h" |
||||
|
||||
#include <memory> |
||||
|
||||
#include <gflags/gflags.h> |
||||
#include "test/core/end2end/data/ssl_test_data.h" |
||||
#include <grpc++/config.h> |
||||
#include <grpc++/server_credentials.h> |
||||
|
||||
DECLARE_bool(enable_ssl); |
||||
|
||||
// In some distros, gflags is in the namespace google, and in some others,
|
||||
// in gflags. This hack is enabling us to find both.
|
||||
namespace google {} |
||||
namespace gflags {} |
||||
using namespace google; |
||||
using namespace gflags; |
||||
|
||||
namespace grpc { |
||||
namespace testing { |
||||
|
||||
std::shared_ptr<ServerCredentials> CreateInteropServerCredentials() { |
||||
if (FLAGS_enable_ssl) { |
||||
SslServerCredentialsOptions::PemKeyCertPair pkcp = {test_server1_key, |
||||
test_server1_cert}; |
||||
SslServerCredentialsOptions ssl_opts; |
||||
ssl_opts.pem_root_certs = ""; |
||||
ssl_opts.pem_key_cert_pairs.push_back(pkcp); |
||||
return SslServerCredentials(ssl_opts); |
||||
} else { |
||||
return InsecureServerCredentials(); |
||||
} |
||||
} |
||||
|
||||
} // namespace testing
|
||||
} // namespace grpc
|
@ -0,0 +1,94 @@ |
||||
/*
|
||||
* |
||||
* 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. |
||||
* |
||||
*/ |
||||
|
||||
#include "test/cpp/qps/report.h" |
||||
|
||||
#include <grpc/support/log.h> |
||||
#include "test/cpp/qps/stats.h" |
||||
|
||||
namespace grpc { |
||||
namespace testing { |
||||
|
||||
// QPS: XXX
|
||||
void ReportQPS(const ScenarioResult& result) { |
||||
gpr_log(GPR_INFO, "QPS: %.1f", |
||||
result.latencies.Count() / |
||||
average(result.client_resources, |
||||
[](ResourceUsage u) { return u.wall_time; })); |
||||
} |
||||
|
||||
// QPS: XXX (YYY/server core)
|
||||
void ReportQPSPerCore(const ScenarioResult& result, const ServerConfig& server_config) { |
||||
auto qps =
|
||||
result.latencies.Count() / |
||||
average(result.client_resources, |
||||
[](ResourceUsage u) { return u.wall_time; }); |
||||
|
||||
gpr_log(GPR_INFO, "QPS: %.1f (%.1f/server core)", qps, qps/server_config.threads()); |
||||
} |
||||
|
||||
// Latency (50/90/95/99/99.9%-ile): AA/BB/CC/DD/EE us
|
||||
void ReportLatency(const ScenarioResult& result) { |
||||
gpr_log(GPR_INFO, "Latencies (50/90/95/99/99.9%%-ile): %.1f/%.1f/%.1f/%.1f/%.1f us", |
||||
result.latencies.Percentile(50) / 1000, |
||||
result.latencies.Percentile(90) / 1000, |
||||
result.latencies.Percentile(95) / 1000, |
||||
result.latencies.Percentile(99) / 1000, |
||||
result.latencies.Percentile(99.9) / 1000); |
||||
} |
||||
|
||||
void ReportTimes(const ScenarioResult& result) { |
||||
gpr_log(GPR_INFO, "Server system time: %.2f%%", |
||||
100.0 * sum(result.server_resources, |
||||
[](ResourceUsage u) { return u.system_time; }) / |
||||
sum(result.server_resources, |
||||
[](ResourceUsage u) { return u.wall_time; })); |
||||
gpr_log(GPR_INFO, "Server user time: %.2f%%", |
||||
100.0 * sum(result.server_resources, |
||||
[](ResourceUsage u) { return u.user_time; }) / |
||||
sum(result.server_resources, |
||||
[](ResourceUsage u) { return u.wall_time; })); |
||||
gpr_log(GPR_INFO, "Client system time: %.2f%%", |
||||
100.0 * sum(result.client_resources, |
||||
[](ResourceUsage u) { return u.system_time; }) / |
||||
sum(result.client_resources, |
||||
[](ResourceUsage u) { return u.wall_time; })); |
||||
gpr_log(GPR_INFO, "Client user time: %.2f%%", |
||||
100.0 * sum(result.client_resources, |
||||
[](ResourceUsage u) { return u.user_time; }) / |
||||
sum(result.client_resources, |
||||
[](ResourceUsage u) { return u.wall_time; })); |
||||
} |
||||
|
||||
} // namespace testing
|
||||
} // namespace grpc
|
@ -0,0 +1,57 @@ |
||||
/*
|
||||
* |
||||
* 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. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef TEST_QPS_REPORT_H |
||||
#define TEST_QPS_REPORT_H |
||||
|
||||
#include "test/cpp/qps/driver.h" |
||||
|
||||
namespace grpc { |
||||
namespace testing { |
||||
|
||||
// QPS: XXX
|
||||
void ReportQPS(const ScenarioResult& result); |
||||
// QPS: XXX (YYY/server core)
|
||||
void ReportQPSPerCore(const ScenarioResult& result, const ServerConfig& config); |
||||
// Latency (50/90/95/99/99.9%-ile): AA/BB/CC/DD/EE us
|
||||
void ReportLatency(const ScenarioResult& result); |
||||
// Server system time: XX%
|
||||
// Server user time: XX%
|
||||
// Client system time: XX%
|
||||
// Client user time: XX%
|
||||
void ReportTimes(const ScenarioResult& result); |
||||
|
||||
} // namespace testing
|
||||
} // namespace grpc
|
||||
|
||||
#endif |
@ -0,0 +1,149 @@ |
||||
/*
|
||||
* |
||||
* 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. |
||||
* |
||||
*/ |
||||
|
||||
#include <grpc/support/log.h> |
||||
|
||||
#include "test/cpp/qps/driver.h" |
||||
#include "test/cpp/qps/report.h" |
||||
|
||||
namespace grpc { |
||||
namespace testing { |
||||
|
||||
static const int WARMUP = 5; |
||||
static const int BENCHMARK = 10; |
||||
|
||||
static void RunSynchronousUnaryPingPong() { |
||||
gpr_log(GPR_INFO, "Running Synchronous Unary Ping Pong"); |
||||
|
||||
ClientConfig client_config; |
||||
client_config.set_client_type(SYNCHRONOUS_CLIENT); |
||||
client_config.set_enable_ssl(false); |
||||
client_config.set_outstanding_rpcs_per_channel(1); |
||||
client_config.set_client_channels(1); |
||||
client_config.set_payload_size(1); |
||||
client_config.set_rpc_type(UNARY); |
||||
|
||||
ServerConfig server_config; |
||||
server_config.set_server_type(SYNCHRONOUS_SERVER); |
||||
server_config.set_enable_ssl(false); |
||||
server_config.set_threads(1); |
||||
|
||||
auto result = RunScenario(client_config, 1, server_config, 1, WARMUP, BENCHMARK); |
||||
|
||||
ReportQPS(result); |
||||
ReportLatency(result); |
||||
} |
||||
|
||||
static void RunSynchronousStreamingPingPong() { |
||||
gpr_log(GPR_INFO, "Running Synchronous Streaming Ping Pong"); |
||||
|
||||
ClientConfig client_config; |
||||
client_config.set_client_type(SYNCHRONOUS_CLIENT); |
||||
client_config.set_enable_ssl(false); |
||||
client_config.set_outstanding_rpcs_per_channel(1); |
||||
client_config.set_client_channels(1); |
||||
client_config.set_payload_size(1); |
||||
client_config.set_rpc_type(STREAMING); |
||||
|
||||
ServerConfig server_config; |
||||
server_config.set_server_type(SYNCHRONOUS_SERVER); |
||||
server_config.set_enable_ssl(false); |
||||
server_config.set_threads(1); |
||||
|
||||
auto result = RunScenario(client_config, 1, server_config, 1, WARMUP, BENCHMARK); |
||||
|
||||
ReportQPS(result); |
||||
ReportLatency(result); |
||||
} |
||||
|
||||
static void RunAsyncUnaryPingPong() { |
||||
gpr_log(GPR_INFO, "Running Async Unary Ping Pong"); |
||||
|
||||
ClientConfig client_config; |
||||
client_config.set_client_type(ASYNC_CLIENT); |
||||
client_config.set_enable_ssl(false); |
||||
client_config.set_outstanding_rpcs_per_channel(1); |
||||
client_config.set_client_channels(1); |
||||
client_config.set_payload_size(1); |
||||
client_config.set_async_client_threads(1); |
||||
client_config.set_rpc_type(UNARY); |
||||
|
||||
ServerConfig server_config; |
||||
server_config.set_server_type(ASYNC_SERVER); |
||||
server_config.set_enable_ssl(false); |
||||
server_config.set_threads(1); |
||||
|
||||
auto result = RunScenario(client_config, 1, server_config, 1, WARMUP, BENCHMARK); |
||||
|
||||
ReportQPS(result); |
||||
ReportLatency(result); |
||||
} |
||||
|
||||
static void RunQPS() { |
||||
gpr_log(GPR_INFO, "Running QPS test"); |
||||
|
||||
ClientConfig client_config; |
||||
client_config.set_client_type(ASYNC_CLIENT); |
||||
client_config.set_enable_ssl(false); |
||||
client_config.set_outstanding_rpcs_per_channel(1000); |
||||
client_config.set_client_channels(8); |
||||
client_config.set_payload_size(1); |
||||
client_config.set_async_client_threads(8); |
||||
client_config.set_rpc_type(UNARY); |
||||
|
||||
ServerConfig server_config; |
||||
server_config.set_server_type(ASYNC_SERVER); |
||||
server_config.set_enable_ssl(false); |
||||
server_config.set_threads(4); |
||||
|
||||
auto result = RunScenario(client_config, 1, server_config, 1, WARMUP, BENCHMARK); |
||||
|
||||
ReportQPSPerCore(result, server_config); |
||||
ReportLatency(result); |
||||
} |
||||
|
||||
} // namespace testing
|
||||
} // namespace grpc
|
||||
|
||||
int main(int argc, char** argv) { |
||||
grpc_init(); |
||||
|
||||
using namespace grpc::testing; |
||||
RunSynchronousStreamingPingPong(); |
||||
RunSynchronousUnaryPingPong(); |
||||
RunAsyncUnaryPingPong(); |
||||
RunQPS(); |
||||
|
||||
grpc_shutdown(); |
||||
return 0; |
||||
} |
@ -0,0 +1,28 @@ |
||||
#!/bin/sh |
||||
|
||||
# performs a single qps run with one client and one server |
||||
|
||||
set -ex |
||||
|
||||
cd $(dirname $0)/../../.. |
||||
|
||||
killall qps_worker || true |
||||
|
||||
config=opt |
||||
|
||||
NUMCPUS=`python2.7 -c 'import multiprocessing; print multiprocessing.cpu_count()'` |
||||
|
||||
make CONFIG=$config qps_worker qps_smoke_test -j$NUMCPUS |
||||
|
||||
bins/$config/qps_worker -driver_port 10000 -server_port 10001 & |
||||
PID1=$! |
||||
bins/$config/qps_worker -driver_port 10010 -server_port 10011 & |
||||
PID2=$! |
||||
|
||||
export QPS_WORKERS="localhost:10000,localhost:10010" |
||||
|
||||
bins/$config/qps_smoke_test $* |
||||
|
||||
kill -2 $PID1 $PID2 |
||||
wait |
||||
|
Loading…
Reference in new issue