lame_client_test.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #include <string.h>
20 
21 #include <grpc/grpc.h>
22 #include <grpc/support/alloc.h>
23 #include <grpc/support/log.h>
24 
31 
33  public:
35  const absl::Status& /* status */) override {
36  GPR_ASSERT(new_state == GRPC_CHANNEL_SHUTDOWN);
37  }
38 };
39 
40 static void* tag(intptr_t t) { return reinterpret_cast<void*>(t); }
41 
43 
44 static void do_nothing(void* /*arg*/, grpc_error_handle /*error*/) {}
45 
49  op->start_connectivity_watch = grpc_core::MakeOrphanable<Watcher>();
52  elem->filter->start_transport_op(elem, op);
53 
55  grpc_schedule_on_exec_ctx);
57  elem->filter->start_transport_op(elem, op);
58 }
59 
60 int main(int argc, char** argv) {
61  grpc_channel* chan;
62  grpc_call* call;
64  cq_verifier* cqv;
65  grpc_op ops[6];
66  grpc_op* op;
72  char* peer;
73 
75  grpc_init();
76 
79 
80  const char* error_message = "Rpc sent on a lame channel.";
82  chan = grpc_lame_client_channel_create("lampoon:national", error_code,
83  error_message);
84  GPR_ASSERT(chan);
85 
86  test_transport_op(chan);
87 
90 
92 
93  grpc_slice host = grpc_slice_from_static_string("anywhere");
94  call =
96  grpc_slice_from_static_string("/Foo"), &host,
97  grpc_timeout_seconds_to_deadline(100), nullptr);
99  cqv = cq_verifier_create(cq);
100 
101  memset(ops, 0, sizeof(ops));
102  op = ops;
105  op->flags = 0;
106  op->reserved = nullptr;
107  op++;
110  op->flags = 0;
111  op->reserved = nullptr;
112  op++;
113  error = grpc_call_start_batch(call, ops, static_cast<size_t>(op - ops),
114  tag(1), nullptr);
116 
117  /* the call should immediately fail */
118  CQ_EXPECT_COMPLETION(cqv, tag(1), 0);
119  cq_verify(cqv);
120 
121  memset(ops, 0, sizeof(ops));
122  op = ops;
127  op->flags = 0;
128  op->reserved = nullptr;
129  op++;
130  error = grpc_call_start_batch(call, ops, static_cast<size_t>(op - ops),
131  tag(2), nullptr);
133 
134  /* the call should immediately fail */
135  CQ_EXPECT_COMPLETION(cqv, tag(2), 1);
136  cq_verify(cqv);
137 
138  peer = grpc_call_get_peer(call);
139  GPR_ASSERT(strcmp(peer, "lampoon:national") == 0);
140  gpr_free(peer);
141 
142  GPR_ASSERT(status == error_code);
143  GPR_ASSERT(grpc_slice_str_cmp(details, error_message) == 0);
144 
146  grpc_channel_destroy(chan);
147  cq_verifier_destroy(cqv);
149 
153 
154  grpc_shutdown();
155 
156  return 0;
157 }
GRPC_CLOSURE_INIT
#define GRPC_CLOSURE_INIT(closure, cb, cb_arg, scheduler)
Definition: closure.h:115
grpc_slice_unref
GPRAPI void grpc_slice_unref(grpc_slice s)
Definition: slice_api.cc:32
Watcher::Notify
void Notify(grpc_connectivity_state new_state, const absl::Status &) override
Definition: lame_client_test.cc:34
grpc_op::flags
uint32_t flags
Definition: grpc_types.h:644
grpc_call_error
grpc_call_error
Definition: grpc_types.h:464
grpc_op::grpc_op_data::grpc_op_recv_status_on_client::trailing_metadata
grpc_metadata_array * trailing_metadata
Definition: grpc_types.h:701
grpc_timeout_seconds_to_deadline
gpr_timespec grpc_timeout_seconds_to_deadline(int64_t time_s)
Definition: test/core/util/test_config.cc:81
log.h
grpc_core::ConnectivityStateWatcherInterface
Definition: src/core/lib/transport/connectivity_state.h:49
grpc_op::grpc_op_data::grpc_op_recv_status_on_client::status
grpc_status_code * status
Definition: grpc_types.h:702
generate.env
env
Definition: generate.py:37
memset
return memset(p, 0, total)
grpc_channel_stack_element
grpc_channel_element * grpc_channel_stack_element(grpc_channel_stack *channel_stack, size_t index)
Definition: channel_stack.cc:78
Watcher
Definition: lame_client_test.cc:32
grpc_op::grpc_op_data::send_initial_metadata
struct grpc_op::grpc_op_data::grpc_op_send_initial_metadata send_initial_metadata
grpc_call_get_peer
GRPCAPI char * grpc_call_get_peer(grpc_call *call)
Definition: call.cc:1774
grpc_metadata_array
Definition: grpc_types.h:579
grpc_op::reserved
void * reserved
Definition: grpc_types.h:646
string.h
grpc_channel_check_connectivity_state
GRPCAPI grpc_connectivity_state grpc_channel_check_connectivity_state(grpc_channel *channel, int try_to_connect)
Definition: channel_connectivity.cc:56
grpc_lame_client_channel_create
GRPCAPI grpc_channel * grpc_lame_client_channel_create(const char *target, grpc_status_code error_code, const char *error_message)
Definition: lame_client.cc:131
gpr_free
GPRAPI void gpr_free(void *ptr)
Definition: alloc.cc:51
grpc_channel_element
Definition: channel_stack.h:186
elem
Timer elem
Definition: event_engine/iomgr_event_engine/timer_heap_test.cc:109
error
grpc_error_handle error
Definition: retry_filter.cc:499
grpc_status_code
grpc_status_code
Definition: include/grpc/impl/codegen/status.h:28
do_nothing
static void do_nothing(void *, grpc_error_handle)
Definition: lame_client_test.cc:44
GRPC_CHANNEL_TRANSIENT_FAILURE
@ GRPC_CHANNEL_TRANSIENT_FAILURE
Definition: include/grpc/impl/codegen/connectivity_state.h:38
grpc_channel_get_channel_stack
grpc_channel_stack * grpc_channel_get_channel_stack(grpc_channel *channel)
Definition: src/core/lib/surface/channel.h:178
closure.h
GRPC_CALL_OK
@ GRPC_CALL_OK
Definition: grpc_types.h:466
status
absl::Status status
Definition: rls.cc:251
transport_op_cb
static grpc_closure transport_op_cb
Definition: lame_client_test.cc:42
grpc_transport_op
Definition: transport.h:452
grpc_connectivity_state
grpc_connectivity_state
Definition: include/grpc/impl/codegen/connectivity_state.h:30
call
FilterStackCall * call
Definition: call.cc:750
grpc_op::data
union grpc_op::grpc_op_data data
grpc_metadata_array_destroy
GRPCAPI void grpc_metadata_array_destroy(grpc_metadata_array *array)
Definition: metadata_array.cc:35
trailing_metadata_recv
static grpc_metadata_array trailing_metadata_recv
Definition: test/core/fling/client.cc:43
channel
wrapped_grpc_channel * channel
Definition: src/php/ext/grpc/call.h:33
GRPC_OP_RECV_INITIAL_METADATA
@ GRPC_OP_RECV_INITIAL_METADATA
Definition: grpc_types.h:617
GPR_ASSERT
#define GPR_ASSERT(x)
Definition: include/grpc/impl/codegen/log.h:94
grpc_call_unref
GRPCAPI void grpc_call_unref(grpc_call *call)
Definition: call.cc:1770
channel_stack.h
grpc_completion_queue
Definition: completion_queue.cc:347
cq_verifier_destroy
void cq_verifier_destroy(cq_verifier *v)
Definition: cq_verifier.cc:92
grpc.h
grpc_call
struct grpc_call grpc_call
Definition: grpc_types.h:70
grpc_op
Definition: grpc_types.h:640
grpc_slice_from_static_string
GPRAPI grpc_slice grpc_slice_from_static_string(const char *source)
Definition: slice/slice.cc:89
cq_verifier_create
cq_verifier * cq_verifier_create(grpc_completion_queue *cq)
Definition: cq_verifier.cc:86
grpc_slice
Definition: include/grpc/impl/codegen/slice.h:65
intptr_t
_W64 signed int intptr_t
Definition: stdint-msvc2008.h:118
cq_verifier
Definition: cq_verifier.cc:76
grpc_make_transport_op
grpc_transport_op * grpc_make_transport_op(grpc_closure *on_complete)
Definition: transport.cc:205
CQ_EXPECT_COMPLETION
#define CQ_EXPECT_COMPLETION(v, tag, success)
Definition: cq_verifier.h:58
grpc_core::ExecCtx
Definition: exec_ctx.h:97
grpc_op::op
grpc_op_type op
Definition: grpc_types.h:642
grpc_op::grpc_op_data::grpc_op_send_initial_metadata::count
size_t count
Definition: grpc_types.h:653
grpc_op::grpc_op_data::grpc_op_recv_status_on_client::status_details
grpc_slice * status_details
Definition: grpc_types.h:703
details
static grpc_slice details
Definition: test/core/fling/client.cc:46
test_config.h
grpc_channel_create_call
GRPCAPI grpc_call * grpc_channel_create_call(grpc_channel *channel, grpc_call *parent_call, uint32_t propagation_mask, grpc_completion_queue *completion_queue, grpc_slice method, const grpc_slice *host, gpr_timespec deadline, void *reserved)
Definition: channel.cc:311
tag
static void * tag(intptr_t t)
Definition: lame_client_test.cc:40
GRPC_PROPAGATE_DEFAULTS
#define GRPC_PROPAGATE_DEFAULTS
Definition: propagation_bits.h:45
cq_verifier.h
grpc_completion_queue_destroy
GRPCAPI void grpc_completion_queue_destroy(grpc_completion_queue *cq)
Definition: completion_queue.cc:1424
GRPC_OP_SEND_INITIAL_METADATA
@ GRPC_OP_SEND_INITIAL_METADATA
Definition: grpc_types.h:598
exec_ctx
grpc_core::ExecCtx exec_ctx
Definition: end2end_binder_transport_test.cc:75
absl::Status
Definition: third_party/abseil-cpp/absl/status/status.h:424
GRPC_STATUS_ABORTED
@ GRPC_STATUS_ABORTED
Definition: include/grpc/impl/codegen/status.h:104
alloc.h
grpc_op::grpc_op_data::recv_status_on_client
struct grpc_op::grpc_op_data::grpc_op_recv_status_on_client recv_status_on_client
grpc::testing::TestEnvironment
Definition: test/core/util/test_config.h:54
cq_verify
void cq_verify(cq_verifier *v, int timeout_sec)
Definition: cq_verifier.cc:268
main
int main(int argc, char **argv)
Definition: lame_client_test.cc:60
grpc_channel_destroy
GRPCAPI void grpc_channel_destroy(grpc_channel *channel)
Definition: channel.cc:437
grpc_channel
struct grpc_channel grpc_channel
Definition: grpc_types.h:62
transport.h
grpc_completion_queue_create_for_next
GRPCAPI grpc_completion_queue * grpc_completion_queue_create_for_next(void *reserved)
Definition: completion_queue_factory.cc:62
GRPC_CHANNEL_SHUTDOWN
@ GRPC_CHANNEL_SHUTDOWN
Definition: include/grpc/impl/codegen/connectivity_state.h:40
grpc_op::grpc_op_data::recv_initial_metadata
struct grpc_op::grpc_op_data::grpc_op_recv_initial_metadata recv_initial_metadata
grpc_init
GRPCAPI void grpc_init(void)
Definition: init.cc:146
grpc_error
Definition: error_internal.h:42
GRPC_OP_RECV_STATUS_ON_CLIENT
@ GRPC_OP_RECV_STATUS_ON_CLIENT
Definition: grpc_types.h:627
grpc_op::grpc_op_data::grpc_op_recv_initial_metadata::recv_initial_metadata
grpc_metadata_array * recv_initial_metadata
Definition: grpc_types.h:685
grpc_slice_str_cmp
GPRAPI int grpc_slice_str_cmp(grpc_slice a, const char *b)
Definition: slice/slice.cc:426
grpc_closure
Definition: closure.h:56
op
static grpc_op * op
Definition: test/core/fling/client.cc:47
ops
static grpc_op ops[6]
Definition: test/core/fling/client.cc:39
initial_metadata_recv
static grpc_metadata_array initial_metadata_recv
Definition: test/core/fling/client.cc:42
grpc_call_start_batch
GRPCAPI grpc_call_error grpc_call_start_batch(grpc_call *call, const grpc_op *ops, size_t nops, void *tag, void *reserved)
Definition: call.cc:1831
grpc_shutdown
GRPCAPI void grpc_shutdown(void)
Definition: init.cc:209
test_transport_op
void test_transport_op(grpc_channel *channel)
Definition: lame_client_test.cc:46
cq
static grpc_completion_queue * cq
Definition: test/core/fling/client.cc:37
grpc_metadata_array_init
GRPCAPI void grpc_metadata_array_init(grpc_metadata_array *array)
Definition: metadata_array.cc:30
channel.h


grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:14