12
12
#include < sstream>
13
13
14
14
using namespace Aws ::Eventstreamrpc;
15
+ using namespace Awstest ;
15
16
16
17
static int s_TestEventStreamConnect (struct aws_allocator *allocator, void *ctx);
18
+ static int s_TestOperationWhileDisconnected (struct aws_allocator *allocator, void *ctx);
17
19
18
20
class TestLifecycleHandler : public ConnectionLifecycleHandler
19
21
{
@@ -54,6 +56,11 @@ class TestLifecycleHandler : public ConnectionLifecycleHandler
54
56
int lastErrorCode;
55
57
};
56
58
59
+ static void s_onMessageFlush (int errorCode)
60
+ {
61
+ (void ) errorCode;
62
+ }
63
+
57
64
static int s_TestEventStreamConnect (struct aws_allocator *allocator, void *ctx)
58
65
{
59
66
(void )ctx;
@@ -75,7 +82,7 @@ static int s_TestEventStreamConnect(struct aws_allocator *allocator, void *ctx)
75
82
ASSERT_TRUE (clientBootstrap);
76
83
clientBootstrap.EnableBlockingShutdown ();
77
84
MessageAmendment connectionAmendment;
78
- auto messageAmender = [&](void ) -> MessageAmendment & { return connectionAmendment; };
85
+ auto messageAmender = [&](void ) -> const MessageAmendment & { return connectionAmendment; };
79
86
80
87
ConnectionConfig config;
81
88
config.SetHostName (Aws::Crt::String (" 127.0.0.1" ));
@@ -113,4 +120,58 @@ static int s_TestEventStreamConnect(struct aws_allocator *allocator, void *ctx)
113
120
return AWS_OP_SUCCESS;
114
121
}
115
122
123
+ static int s_TestOperationWhileDisconnected (struct aws_allocator *allocator, void *ctx)
124
+ {
125
+ (void )ctx;
126
+ {
127
+ Aws::Crt::ApiHandle apiHandle (allocator);
128
+ Aws::Crt::Io::TlsContextOptions tlsCtxOptions = Aws::Crt::Io::TlsContextOptions::InitDefaultClient ();
129
+ Aws::Crt::Io::TlsContext tlsContext (tlsCtxOptions, Aws::Crt::Io::TlsMode::CLIENT, allocator);
130
+ ASSERT_TRUE (tlsContext);
131
+
132
+ Aws::Crt::Io::TlsConnectionOptions tlsConnectionOptions = tlsContext.NewConnectionOptions ();
133
+
134
+ Aws::Crt::Io::EventLoopGroup eventLoopGroup (0 , allocator);
135
+ ASSERT_TRUE (eventLoopGroup);
136
+
137
+ Aws::Crt::Io::DefaultHostResolver defaultHostResolver (eventLoopGroup, 8 , 30 , allocator);
138
+ ASSERT_TRUE (defaultHostResolver);
139
+
140
+ Aws::Crt::Io::ClientBootstrap clientBootstrap (eventLoopGroup, defaultHostResolver, allocator);
141
+ ASSERT_TRUE (clientBootstrap);
142
+ clientBootstrap.EnableBlockingShutdown ();
143
+ MessageAmendment connectionAmendment;
144
+ auto messageAmender = [&](void ) -> MessageAmendment & { return connectionAmendment; };
145
+
146
+ {
147
+ ConnectionLifecycleHandler lifecycleHandler;
148
+ Awstest::EchoTestRpcClient client (clientBootstrap, allocator);
149
+ auto connectedStatus = client.Connect (lifecycleHandler);
150
+ ASSERT_TRUE (connectedStatus.get ().baseStatus == EVENT_STREAM_RPC_SUCCESS);
151
+ auto echoMessage = client.NewEchoMessage ();
152
+ EchoMessageRequest echoMessageRequest;
153
+ MessageData messageData;
154
+ messageData.SetStringMessage (" wtf" );
155
+ echoMessageRequest.SetMessage (messageData);
156
+ auto requestFuture = echoMessage.Activate (echoMessageRequest, s_onMessageFlush);
157
+ ASSERT_TRUE (requestFuture.get ().baseStatus == EVENT_STREAM_RPC_CONNECTION_CLOSED);
158
+ auto result = echoMessage.GetResult ().get ();
159
+ if (result) {
160
+ std::cout << result.GetOperationResponse () << std::endl;
161
+ } else {
162
+ auto errorType = result.GetResultType ();
163
+ if (errorType == RPC_ERROR) {
164
+ std::cout << result.GetRpcError () << std::endl;
165
+ } else {
166
+ auto *error = result.GetOperationError ();
167
+ (void )error;
168
+ }
169
+ }
170
+ }
171
+ }
172
+
173
+ return AWS_OP_SUCCESS;
174
+ }
175
+
116
176
AWS_TEST_CASE (EventStreamConnect, s_TestEventStreamConnect)
177
+ AWS_TEST_CASE(OperateWhileDisconnected, s_TestOperationWhileDisconnected)
0 commit comments