From f3aa84d05b92fbe7c9870e2e6603a8ce06bb99fb Mon Sep 17 00:00:00 2001 From: Alexey Edelev Date: Sun, 6 Aug 2023 22:53:17 +0200 Subject: [PATCH] Rename QGrpcStream to QGrpcServerStream Rename QGrpcStream and all related functionality to QGrpcServerStream and corresponding names. The stream only implements server-side streaming, and should be named accordingly. Task-number: QTBUG-105494 Change-Id: I6b94452a447609186b1aa68ff8795293eef9dc28 Reviewed-by: Konrad Kujawa --- .../grpc/chat/client/simplechatengine.cpp | 25 ++-- examples/grpc/doc/src/chat.qdoc | 12 +- src/grpc/qabstractgrpcchannel.cpp | 20 ++-- src/grpc/qabstractgrpcchannel.h | 8 +- src/grpc/qabstractgrpcclient.cpp | 24 ++-- src/grpc/qabstractgrpcclient.h | 6 +- src/grpc/qgrpcchannel.cpp | 6 +- src/grpc/qgrpcchannel.h | 2 +- src/grpc/qgrpcchannel_p.h | 2 +- src/grpc/qgrpchttp2channel.cpp | 2 +- src/grpc/qgrpchttp2channel.h | 2 +- src/grpc/qgrpcstream.cpp | 14 +-- src/grpc/qgrpcstream.h | 6 +- src/tools/qtgrpcgen/grpctemplates.cpp | 6 +- tests/auto/grpc/client/BLACKLIST | 2 +- tests/auto/grpc/client/tst_grpc_client.cpp | 112 +++++++++--------- .../tests/testservice_client.grpc.qpb.cpp | 4 +- .../tests/testservice_client.grpc.qpb.h | 2 +- .../testservice_client.grpc.qpb.cpp | 4 +- .../no-options/testservice_client.grpc.qpb.h | 2 +- 20 files changed, 131 insertions(+), 130 deletions(-) diff --git a/examples/grpc/chat/client/simplechatengine.cpp b/examples/grpc/chat/client/simplechatengine.cpp index 73c3c3ff..be1afa39 100644 --- a/examples/grpc/chat/client/simplechatengine.cpp +++ b/examples/grpc/chat/client/simplechatengine.cpp @@ -57,7 +57,7 @@ void SimpleChatEngine::login(const QString &name, const QString &password) // ![1] auto stream = m_client->streamMessageList(qtgrpc::examples::chat::None()); - QObject::connect(stream.get(), &QGrpcStream::errorOccurred, this, + QObject::connect(stream.get(), &QGrpcServerStream::errorOccurred, this, [this, stream](const QGrpcStatus &status) { qCritical() << "Stream error(" << status.code() << "):" << status.message(); @@ -65,19 +65,20 @@ void SimpleChatEngine::login(const QString &name, const QString &password) emit authFailed(); }); - QObject::connect(stream.get(), &QGrpcStream::finished, this, + QObject::connect(stream.get(), &QGrpcServerStream::finished, this, [this, stream]() { setState(Disconnected); }); - QObject::connect( - stream.get(), &QGrpcStream::messageReceived, this, [this, name, password, stream]() { - if (m_userName != name) { - m_userName = name; - m_password = password; - emit userNameChanged(); - } - setState(Connected); - m_messages.append(stream->read().messages()); - }); + QObject::connect(stream.get(), &QGrpcServerStream::messageReceived, this, + [this, name, password, stream]() { + if (m_userName != name) { + m_userName = name; + m_password = password; + emit userNameChanged(); + } + setState(Connected); + m_messages.append( + stream->read().messages()); + }); // ![1] } diff --git a/examples/grpc/doc/src/chat.qdoc b/examples/grpc/doc/src/chat.qdoc index 9b28e96e..3128daf3 100644 --- a/examples/grpc/doc/src/chat.qdoc +++ b/examples/grpc/doc/src/chat.qdoc @@ -42,21 +42,21 @@ \snippet chat/client/simplechatengine.cpp 1 - The \l QGrpcStream handler provides the signals that the client application + The \l QGrpcServerStream handler provides the signals that the client application should connect to. - The \l QGrpcStream::errorOccurred signal indicates the error that occurred + The \l QGrpcServerStream::errorOccurred signal indicates the error that occurred either on the server side or in the communication channel. Typically, an error results in the connection to the server being closed and - the \l QGrpcStream::finished signal being emitted. + the \l QGrpcServerStream::finished signal being emitted. - When the server sends new messages to the stream, \l QGrpcStream emits the - \l QGrpcStream::messageReceived signal. The slot connected to this signal + When the server sends new messages to the stream, \l QGrpcServerStream emits the + \l QGrpcServerStream::messageReceived signal. The slot connected to this signal processes the chat message. Messages that are received from the \c {SimpleChat/messageList} server stream are collected in the custom \l QAbstractListModel model and displayed to the user. - When the \l QGrpcStream::finished signal is emitted, there is nothing more + When the \l QGrpcServerStream::finished signal is emitted, there is nothing more you can do with this stream instance, so you need to initiate a new subscription. diff --git a/src/grpc/qabstractgrpcchannel.cpp b/src/grpc/qabstractgrpcchannel.cpp index 3e5bf991..03140301 100644 --- a/src/grpc/qabstractgrpcchannel.cpp +++ b/src/grpc/qabstractgrpcchannel.cpp @@ -46,11 +46,11 @@ QT_BEGIN_NAMESPACE */ /*! - \fn virtual void startStream(std::shared_ptr channelOperation) = 0 + \fn virtual void startServerStream(std::shared_ptr channelOperation) = 0 This pure virtual function that the starts of the server-side stream. The \a channelOperation is the pointer to a channel side - \l QGrpcChannelOperation primitive that is connected with \l QGrpcStream + \l QGrpcChannelOperation primitive that is connected with \l QGrpcServerStream primitive, that is used in \l QAbstractGrpcClient implementations. The function should implement the channel-side logic of server-side stream. @@ -90,27 +90,27 @@ std::shared_ptr QAbstractGrpcChannel::call(QLatin1StringView met /*! \internal - Function constructs \l QGrpcStream and \l QGrpcChannelOperation + Function constructs \l QGrpcServerStream and \l QGrpcChannelOperation primitives and makes the required for server-side gRPC stream connections between them. The function should not be called directly, but only by \l QAbstractGrpcClient implementations. */ -std::shared_ptr -QAbstractGrpcChannel::startStream(QLatin1StringView method, QLatin1StringView service, +std::shared_ptr +QAbstractGrpcChannel::startServerStream(QLatin1StringView method, QLatin1StringView service, QByteArrayView arg, const QGrpcCallOptions &options) { auto channelOperation = std::make_shared(method, service, arg, options); QObject::connect(channelOperation.get(), &QGrpcChannelOperation::sendData, []() { - Q_ASSERT_X(false, "QAbstractGrpcChannel::startStream", - "QAbstractGrpcChannel::startStream disallows sendData signal from " + Q_ASSERT_X(false, "QAbstractGrpcChannel::startServerStream", + "QAbstractGrpcChannel::startServerStream disallows sendData signal from " "QGrpcChannelOperation"); }); - std::shared_ptr stream( - new QGrpcStream(channelOperation, serializer())); - startStream(channelOperation); + std::shared_ptr stream( + new QGrpcServerStream(channelOperation, serializer())); + startServerStream(channelOperation); return stream; } diff --git a/src/grpc/qabstractgrpcchannel.h b/src/grpc/qabstractgrpcchannel.h index f498b624..68e8b44c 100644 --- a/src/grpc/qabstractgrpcchannel.h +++ b/src/grpc/qabstractgrpcchannel.h @@ -19,7 +19,7 @@ QT_BEGIN_NAMESPACE class QAbstractGrpcClient; class QAbstractProtobufSerializer; struct QAbstractGrpcChannelPrivate; -class QGrpcStream; +class QGrpcServerStream; class QGrpcCallReply; class QGrpcChannelOperation; @@ -29,14 +29,14 @@ public: std::shared_ptr call(QLatin1StringView method, QLatin1StringView service, QByteArrayView arg, const QGrpcCallOptions &options = QGrpcCallOptions()); - std::shared_ptr - startStream(QLatin1StringView method, QLatin1StringView service, QByteArrayView arg, + std::shared_ptr + startServerStream(QLatin1StringView method, QLatin1StringView service, QByteArrayView arg, const QGrpcCallOptions &options = QGrpcCallOptions()); virtual std::shared_ptr serializer() const = 0; protected: virtual void call(std::shared_ptr channelOperation) = 0; - virtual void startStream(std::shared_ptr channelOperation) = 0; + virtual void startServerStream(std::shared_ptr channelOperation) = 0; friend class QAbstractGrpcClient; QAbstractGrpcChannel(); diff --git a/src/grpc/qabstractgrpcclient.cpp b/src/grpc/qabstractgrpcclient.cpp index 7feb295c..e225a30b 100644 --- a/src/grpc/qabstractgrpcclient.cpp +++ b/src/grpc/qabstractgrpcclient.cpp @@ -37,9 +37,9 @@ static QString threadSafetyWarning(QLatin1StringView methodName) QAbstractGrpcClient provides a set of functions for client classes generated out of protobuf services. - QAbstractGrpcClient enforces thread safety for startStream() and call() methods + QAbstractGrpcClient enforces thread safety for startServerStream() and call() methods of generated clients. - The methods QAbstractGrpcClient::call() and QAbstractGrpcClient::startStream() + The methods QAbstractGrpcClient::call() and QAbstractGrpcClient::startServerStream() should only be called by the generated client classes. */ @@ -61,8 +61,8 @@ static QString threadSafetyWarning(QLatin1StringView methodName) */ /*! - \fn template QSharedPointer - QAbstractGrpcClient::startStream(QLatin1StringView method, const QProtobufMessage &arg, + \fn template QSharedPointer + QAbstractGrpcClient::startServerStream(QLatin1StringView method, const QProtobufMessage &arg, const QGrpcCallOptions &options); Streams messages from the server stream \a method with the message @@ -82,7 +82,7 @@ public: std::shared_ptr channel; const std::string service; - std::vector> activeStreams; + std::vector> activeStreams; }; QGrpcStatus QAbstractGrpcClientPrivate::checkThread(QLatin1StringView warningPreamble) @@ -166,23 +166,23 @@ std::shared_ptr QAbstractGrpcClient::call(QLatin1StringView meth return reply; } -std::shared_ptr -QAbstractGrpcClient::startStream(QLatin1StringView method, QByteArrayView arg, +std::shared_ptr +QAbstractGrpcClient::startServerStream(QLatin1StringView method, QByteArrayView arg, const QGrpcCallOptions &options) { Q_D(QAbstractGrpcClient); - std::shared_ptr grpcStream; - if (d->checkThread("QAbstractGrpcClient::startStream"_L1) != QGrpcStatus::Ok) + std::shared_ptr grpcStream; + if (d->checkThread("QAbstractGrpcClient::startServerStream"_L1) != QGrpcStatus::Ok) return grpcStream; if (d->channel) { grpcStream = - d->channel->startStream(method, QLatin1StringView(d->service), arg, options); + d->channel->startServerStream(method, QLatin1StringView(d->service), arg, options); auto errorConnection = std::make_shared(); *errorConnection = - connect(grpcStream.get(), &QGrpcStream::errorOccurred, this, + connect(grpcStream.get(), &QGrpcServerStream::errorOccurred, this, [this, grpcStream, method, errorConnection](const QGrpcStatus &status) { QObject::disconnect(*errorConnection); @@ -194,7 +194,7 @@ QAbstractGrpcClient::startStream(QLatin1StringView method, QByteArrayView arg, auto finishedConnection = std::make_shared(); *finishedConnection = connect( - grpcStream.get(), &QGrpcStream::finished, this, + grpcStream.get(), &QGrpcServerStream::finished, this, [this, grpcStream, errorConnection, finishedConnection, method]() mutable { QObject::disconnect(*errorConnection); QObject::disconnect(*finishedConnection); diff --git a/src/grpc/qabstractgrpcclient.h b/src/grpc/qabstractgrpcclient.h index 9d791e62..290b2fae 100644 --- a/src/grpc/qabstractgrpcclient.h +++ b/src/grpc/qabstractgrpcclient.h @@ -75,21 +75,21 @@ protected: } template - std::shared_ptr startStream(QLatin1StringView method, + std::shared_ptr startServerStream(QLatin1StringView method, const QProtobufMessage &arg, const QGrpcCallOptions &options) { std::optional argData = trySerialize(arg); if (!argData) return {}; - return startStream(method, *argData, options); + return startServerStream(method, *argData, options); } private: std::shared_ptr call(QLatin1StringView method, QByteArrayView arg, const QGrpcCallOptions &options); - std::shared_ptr startStream(QLatin1StringView method, + std::shared_ptr startServerStream(QLatin1StringView method, QByteArrayView arg, const QGrpcCallOptions &options); diff --git a/src/grpc/qgrpcchannel.cpp b/src/grpc/qgrpcchannel.cpp index df24c35f..92d3c7f6 100644 --- a/src/grpc/qgrpcchannel.cpp +++ b/src/grpc/qgrpcchannel.cpp @@ -270,7 +270,7 @@ void QGrpcChannelPrivate::call(std::shared_ptr channelOpe QTimer::singleShot(*deadline, call.get(), [call] { call->cancel(); }); } -void QGrpcChannelPrivate::startStream(std::shared_ptr channelOperation) +void QGrpcChannelPrivate::startServerStream(std::shared_ptr channelOperation) { const QByteArray rpcName = buildRpcName(channelOperation->service(), channelOperation->method()); @@ -353,9 +353,9 @@ void QGrpcChannel::call(std::shared_ptr channelOperation) Implementation of server-side gRPC stream based on the reference gRPC C++ API. */ -void QGrpcChannel::startStream(std::shared_ptr channelOperation) +void QGrpcChannel::startServerStream(std::shared_ptr channelOperation) { - dPtr->startStream(std::move(channelOperation)); + dPtr->startServerStream(std::move(channelOperation)); } /*! diff --git a/src/grpc/qgrpcchannel.h b/src/grpc/qgrpcchannel.h index b4688475..4174b9e5 100644 --- a/src/grpc/qgrpcchannel.h +++ b/src/grpc/qgrpcchannel.h @@ -30,7 +30,7 @@ public: ~QGrpcChannel() override; void call(std::shared_ptr channelOperation) override; - void startStream(std::shared_ptr channelOperation) override; + void startServerStream(std::shared_ptr channelOperation) override; std::shared_ptr serializer() const override; private: diff --git a/src/grpc/qgrpcchannel_p.h b/src/grpc/qgrpcchannel_p.h index 7d17d6b7..319ee5e3 100644 --- a/src/grpc/qgrpcchannel_p.h +++ b/src/grpc/qgrpcchannel_p.h @@ -96,7 +96,7 @@ struct QGrpcChannelPrivate ~QGrpcChannelPrivate(); void call(std::shared_ptr channelOperation); - void startStream(std::shared_ptr channelOperation); + void startServerStream(std::shared_ptr channelOperation); std::shared_ptr serializer() const; }; diff --git a/src/grpc/qgrpchttp2channel.cpp b/src/grpc/qgrpchttp2channel.cpp index af58ec87..90c8fe0e 100644 --- a/src/grpc/qgrpchttp2channel.cpp +++ b/src/grpc/qgrpchttp2channel.cpp @@ -288,7 +288,7 @@ void QGrpcHttp2Channel::call(std::shared_ptr channelOpera \internal Implementation of server-side gRPC stream based on \l QNetworkAccessManager. */ -void QGrpcHttp2Channel::startStream(std::shared_ptr channelOperation) +void QGrpcHttp2Channel::startServerStream(std::shared_ptr channelOperation) { QNetworkReply *networkReply = dPtr->post(channelOperation->method(), channelOperation->service(), diff --git a/src/grpc/qgrpchttp2channel.h b/src/grpc/qgrpchttp2channel.h index 9981c35a..d2e5537c 100644 --- a/src/grpc/qgrpchttp2channel.h +++ b/src/grpc/qgrpchttp2channel.h @@ -22,7 +22,7 @@ public: private: void call(std::shared_ptr channelOperation) override; - void startStream(std::shared_ptr channelOperation) override; + void startServerStream(std::shared_ptr channelOperation) override; std::shared_ptr serializer() const override; Q_DISABLE_COPY_MOVE(QGrpcHttp2Channel) diff --git a/src/grpc/qgrpcstream.cpp b/src/grpc/qgrpcstream.cpp index e6e18415..e61eb782 100644 --- a/src/grpc/qgrpcstream.cpp +++ b/src/grpc/qgrpcstream.cpp @@ -11,22 +11,22 @@ QT_BEGIN_NAMESPACE /*! - \class QGrpcStream + \class QGrpcServerStream \inmodule QtGrpc - \brief The QGrpcStream class provides the interface to access the + \brief The QGrpcServerStream class provides the interface to access the server-side gRPC stream functionality from gRPC client side. - The QGrpcStream object is owned by the client object that created it. + The QGrpcServerStream object is owned by the client object that created it. */ /*! - \fn void QGrpcStream::messageReceived() + \fn void QGrpcServerStream::messageReceived() The signal is emitted when the stream receives an updated value from server. */ -QGrpcStream::QGrpcStream(std::shared_ptr channelOperation, +QGrpcServerStream::QGrpcServerStream(std::shared_ptr channelOperation, std::shared_ptr serializer) : QGrpcOperation(std::move(channelOperation), std::move(serializer)) { @@ -35,9 +35,9 @@ QGrpcStream::QGrpcStream(std::shared_ptr channelOperation } /*! - Destroys the QGrpcStream object. + Destroys the QGrpcServerStream object. */ -QGrpcStream::~QGrpcStream() = default; +QGrpcServerStream::~QGrpcServerStream() = default; QT_END_NAMESPACE diff --git a/src/grpc/qgrpcstream.h b/src/grpc/qgrpcstream.h index 540ce237..ec818658 100644 --- a/src/grpc/qgrpcstream.h +++ b/src/grpc/qgrpcstream.h @@ -17,14 +17,14 @@ QT_BEGIN_NAMESPACE class QAbstractGrpcClient; -class Q_GRPC_EXPORT QGrpcStream final : public QGrpcOperation +class Q_GRPC_EXPORT QGrpcServerStream final : public QGrpcOperation { Q_OBJECT public: - explicit QGrpcStream(std::shared_ptr channelOperation, + explicit QGrpcServerStream(std::shared_ptr channelOperation, std::shared_ptr serializer); - ~QGrpcStream() override; + ~QGrpcServerStream() override; Q_SIGNALS: void messageReceived(); diff --git a/src/tools/qtgrpcgen/grpctemplates.cpp b/src/tools/qtgrpcgen/grpctemplates.cpp index 18583507..16dce091 100644 --- a/src/tools/qtgrpcgen/grpctemplates.cpp +++ b/src/tools/qtgrpcgen/grpctemplates.cpp @@ -133,17 +133,17 @@ const char *GrpcTemplates::ClientMethodDefinitionQmlTemplate() const char *GrpcTemplates::ClientMethodServerStreamDeclarationTemplate() { - return "std::shared_ptr stream$method_name_upper$(const $param_type$ " + return "std::shared_ptr stream$method_name_upper$(const $param_type$ " "&$param_name$, const QGrpcCallOptions &options = {});\n"; } const char *GrpcTemplates::ClientMethodServerStreamDefinitionTemplate() { - return "std::shared_ptr $classname$::stream$method_name_upper$(const " + return "std::shared_ptr $classname$::stream$method_name_upper$(const " "$param_type$ " "&$param_name$, const QGrpcCallOptions &options)\n" "{\n" - " return startStream<$param_type$>(\"$method_name$\"_L1, $param_name$, " + " return startServerStream<$param_type$>(\"$method_name$\"_L1, $param_name$, " "options);\n" "}\n\n"; } diff --git a/tests/auto/grpc/client/BLACKLIST b/tests/auto/grpc/client/BLACKLIST index 5cf195d1..cdc5cdc3 100644 --- a/tests/auto/grpc/client/BLACKLIST +++ b/tests/auto/grpc/client/BLACKLIST @@ -1,4 +1,4 @@ [CallDeadlineTest] macos 64bit arm -[StreamDeadlineTest] +[ServerStreamDeadlineTest] macos 64bit arm diff --git a/tests/auto/grpc/client/tst_grpc_client.cpp b/tests/auto/grpc/client/tst_grpc_client.cpp index 879de83c..8df79b55 100644 --- a/tests/auto/grpc/client/tst_grpc_client.cpp +++ b/tests/auto/grpc/client/tst_grpc_client.cpp @@ -112,28 +112,28 @@ private slots: void CallAndAsyncRecieveWithLambdaStringTest(); void CallAndAsyncImmediateCancelStringTest(); void CallAndAsyncDeferredAbortStringTest(); - void StreamStringTest(); - void StreamStringAndAbortTest(); - void StreamStringAndDeferredAbortTest(); + void ServerStreamStringTest(); + void ServerStreamStringAndAbortTest(); + void ServerStreamStringAndDeferredAbortTest(); // void StreamStringAndGetChangedSignalsTests(); - void StreamBlobTest(); + void ServerStreamBlobTest(); void CallMessageAsyncTest(); void CallMessageClientAsyncTest(); void CallMessageClientTest(); void StatusMessageClientTest(); - void StreamAndGetAsyncReplyTest(); - void MultipleStreamsTest(); - void MultipleStreamsCancelTest(); + void ServerStreamAndGetAsyncReplyTest(); + void MultipleServerStreamsTest(); + void MultipleServerStreamsCancelTest(); void CallNonCompatibleArgRetTest(); void CallStringThreadTest(); void StringAsyncThreadTest(); - void StreamStringThreadTest(); - void StreamCancelWhileErrorTimeoutTest(); + void ServerStreamStringThreadTest(); + void ServerStreamCancelWhileErrorTimeoutTest(); void MetadataTest(); void CallDeadlineTest_data(); void CallDeadlineTest(); - void StreamDeadlineTest_data(); - void StreamDeadlineTest(); + void ServerStreamDeadlineTest_data(); + void ServerStreamDeadlineTest(); private: ServerProcRunner serverProc{ QFINDTESTDATA(TEST_GRPC_SERVER_PATH) }; @@ -232,7 +232,7 @@ void QtGrpcClientTest::CallAndAsyncDeferredAbortStringTest() QCOMPARE_EQ(result.testFieldString(), "Result not changed by echo"); } -void QtGrpcClientTest::StreamStringTest() +void QtGrpcClientTest::ServerStreamStringTest() { const int ExpectedMessageCount = 4; @@ -242,13 +242,13 @@ void QtGrpcClientTest::StreamStringTest() auto stream = _client->streamTestMethodServerStream(request); - QSignalSpy messageReceivedSpy(stream.get(), &QGrpcStream::messageReceived); + QSignalSpy messageReceivedSpy(stream.get(), &QGrpcServerStream::messageReceived); QVERIFY(messageReceivedSpy.isValid()); - QSignalSpy streamErrorSpy(stream.get(), &QGrpcStream::errorOccurred); + QSignalSpy streamErrorSpy(stream.get(), &QGrpcServerStream::errorOccurred); QVERIFY(streamErrorSpy.isValid()); - QSignalSpy streamFinishedSpy(stream.get(), &QGrpcStream::finished); - QObject::connect(stream.get(), &QGrpcStream::messageReceived, this, [&result, stream] { + QSignalSpy streamFinishedSpy(stream.get(), &QGrpcServerStream::finished); + QObject::connect(stream.get(), &QGrpcServerStream::messageReceived, this, [&result, stream] { SimpleStringMessage ret = stream->read(); result.setTestFieldString(result.testFieldString() + ret.testFieldString()); }); @@ -261,7 +261,7 @@ void QtGrpcClientTest::StreamStringTest() QCOMPARE_EQ(result.testFieldString(), "Stream1Stream2Stream3Stream4"); } -void QtGrpcClientTest::StreamStringAndAbortTest() +void QtGrpcClientTest::ServerStreamStringAndAbortTest() { const int ExpectedMessageCount = 2; @@ -271,14 +271,14 @@ void QtGrpcClientTest::StreamStringAndAbortTest() auto stream = _client->streamTestMethodServerStream(request); - QSignalSpy streamFinishedSpy(stream.get(), &QGrpcStream::finished); + QSignalSpy streamFinishedSpy(stream.get(), &QGrpcServerStream::finished); QVERIFY(streamFinishedSpy.isValid()); - QSignalSpy streamErrorSpy(stream.get(), &QGrpcStream::errorOccurred); + QSignalSpy streamErrorSpy(stream.get(), &QGrpcServerStream::errorOccurred); QVERIFY(streamErrorSpy.isValid()); int i = 0; QObject::connect( - stream.get(), &QGrpcStream::messageReceived, this, [&result, &i, stream] { + stream.get(), &QGrpcServerStream::messageReceived, this, [&result, &i, stream] { SimpleStringMessage ret = stream->read(); result.setTestFieldString(result.testFieldString() + ret.testFieldString()); if (++i == ExpectedMessageCount) @@ -292,7 +292,7 @@ void QtGrpcClientTest::StreamStringAndAbortTest() QCOMPARE_EQ(result.testFieldString(), "Stream1Stream2"); } -void QtGrpcClientTest::StreamStringAndDeferredAbortTest() +void QtGrpcClientTest::ServerStreamStringAndDeferredAbortTest() { const int ExpectedMessageCount = 3; @@ -302,23 +302,23 @@ void QtGrpcClientTest::StreamStringAndDeferredAbortTest() auto stream = _client->streamTestMethodServerStream(request); - QSignalSpy streamFinishedSpy(stream.get(), &QGrpcStream::finished); + QSignalSpy streamFinishedSpy(stream.get(), &QGrpcServerStream::finished); QVERIFY(streamFinishedSpy.isValid()); - QSignalSpy streamErrorSpy(stream.get(), &QGrpcStream::errorOccurred); + QSignalSpy streamErrorSpy(stream.get(), &QGrpcServerStream::errorOccurred); QVERIFY(streamErrorSpy.isValid()); - QSignalSpy messageReceivedSpy(stream.get(), &QGrpcStream::messageReceived); + QSignalSpy messageReceivedSpy(stream.get(), &QGrpcServerStream::messageReceived); QVERIFY(messageReceivedSpy.isValid()); int i = 0; QObject::connect( - stream.get(), &QGrpcStream::messageReceived, this, [&result, stream, &i] { + stream.get(), &QGrpcServerStream::messageReceived, this, [&result, stream, &i] { SimpleStringMessage ret = stream->read(); result.setTestFieldString(result.testFieldString() + ret.testFieldString()); if (++i == ExpectedMessageCount) QTimer::singleShot(MessageLatencyThreshold, stream.get(), - &QGrpcStream::cancel); + &QGrpcServerStream::cancel); }); QTRY_COMPARE_EQ_WITH_TIMEOUT(streamErrorSpy.count(), 1, @@ -348,7 +348,7 @@ void QtGrpcClientTest::StreamStringAndGetChangedSignalsTests } */ -void QtGrpcClientTest::StreamBlobTest() +void QtGrpcClientTest::ServerStreamBlobTest() { BlobMessage result; BlobMessage request; @@ -360,12 +360,12 @@ void QtGrpcClientTest::StreamBlobTest() auto stream = _client->streamTestMethodBlobServerStream(request); - QSignalSpy streamFinishedSpy(stream.get(), &QGrpcStream::finished); + QSignalSpy streamFinishedSpy(stream.get(), &QGrpcServerStream::finished); QVERIFY(streamFinishedSpy.isValid()); - QSignalSpy streamErrorSpy(stream.get(), &QGrpcStream::errorOccurred); + QSignalSpy streamErrorSpy(stream.get(), &QGrpcServerStream::errorOccurred); QVERIFY(streamErrorSpy.isValid()); - QObject::connect(stream.get(), &QGrpcStream::messageReceived, this, [&result, stream] { + QObject::connect(stream.get(), &QGrpcServerStream::messageReceived, this, [&result, stream] { BlobMessage ret = stream->read(); result.setTestBytes(ret.testBytes()); }); @@ -438,7 +438,7 @@ void QtGrpcClientTest::StatusMessageClientTest() QCOMPARE_EQ(status.message(), request.testFieldString()); } -void QtGrpcClientTest::StreamAndGetAsyncReplyTest() +void QtGrpcClientTest::ServerStreamAndGetAsyncReplyTest() { SimpleStringMessage request; request.setTestFieldString("Some status message"); @@ -478,7 +478,7 @@ void QtGrpcClientTest::StreamAndGetAsyncReplyTest() MessageLatencyWithThreshold); } -void QtGrpcClientTest::MultipleStreamsTest() +void QtGrpcClientTest::MultipleServerStreamsTest() { const int ExpectedMessageCount = 4; SimpleStringMessage result; @@ -489,16 +489,16 @@ void QtGrpcClientTest::MultipleStreamsTest() // Ensure we're not reusing streams QCOMPARE_NE(stream, _client->streamTestMethodServerStream(request)); - QSignalSpy streamFinishedSpy(stream.get(), &QGrpcStream::finished); + QSignalSpy streamFinishedSpy(stream.get(), &QGrpcServerStream::finished); QVERIFY(streamFinishedSpy.isValid()); - QSignalSpy streamErrorSpy(stream.get(), &QGrpcStream::errorOccurred); + QSignalSpy streamErrorSpy(stream.get(), &QGrpcServerStream::errorOccurred); QVERIFY(streamErrorSpy.isValid()); - QSignalSpy steamMessageRecievedSpy(stream.get(), &QGrpcStream::messageReceived); + QSignalSpy steamMessageRecievedSpy(stream.get(), &QGrpcServerStream::messageReceived); QVERIFY(steamMessageRecievedSpy.isValid()); - QObject::connect(stream.get(), &QGrpcStream::messageReceived, this, [&result, stream] { + QObject::connect(stream.get(), &QGrpcServerStream::messageReceived, this, [&result, stream] { SimpleStringMessage ret = stream->read(); result.setTestFieldString(result.testFieldString() + ret.testFieldString()); }); @@ -511,7 +511,7 @@ void QtGrpcClientTest::MultipleStreamsTest() QCOMPARE_EQ(result.testFieldString(), "Stream1Stream2Stream3Stream4"); } -void QtGrpcClientTest::MultipleStreamsCancelTest() +void QtGrpcClientTest::MultipleServerStreamsCancelTest() { SimpleStringMessage result; SimpleStringMessage request; @@ -522,14 +522,14 @@ void QtGrpcClientTest::MultipleStreamsCancelTest() QCOMPARE_NE(stream, streamNext); - QSignalSpy streamFinishedSpy(stream.get(), &QGrpcStream::finished); + QSignalSpy streamFinishedSpy(stream.get(), &QGrpcServerStream::finished); QVERIFY(streamFinishedSpy.isValid()); - QSignalSpy streamErrorSpy(stream.get(), &QGrpcStream::errorOccurred); + QSignalSpy streamErrorSpy(stream.get(), &QGrpcServerStream::errorOccurred); QVERIFY(streamErrorSpy.isValid()); - QSignalSpy streamNextFinishedSpy(streamNext.get(), &QGrpcStream::finished); + QSignalSpy streamNextFinishedSpy(streamNext.get(), &QGrpcServerStream::finished); QVERIFY(streamNextFinishedSpy.isValid()); - QSignalSpy streamNextErrorSpy(streamNext.get(), &QGrpcStream::errorOccurred); + QSignalSpy streamNextErrorSpy(streamNext.get(), &QGrpcServerStream::errorOccurred); QVERIFY(streamNextErrorSpy.isValid()); streamNext->cancel(); @@ -547,14 +547,14 @@ void QtGrpcClientTest::MultipleStreamsCancelTest() QCOMPARE_NE(stream, streamNext); - QSignalSpy otherStreamFinishedSpy(stream.get(), &QGrpcStream::finished); + QSignalSpy otherStreamFinishedSpy(stream.get(), &QGrpcServerStream::finished); QVERIFY(streamFinishedSpy.isValid()); - QSignalSpy otherStreamErrorSpy(stream.get(), &QGrpcStream::errorOccurred); + QSignalSpy otherStreamErrorSpy(stream.get(), &QGrpcServerStream::errorOccurred); QVERIFY(otherStreamErrorSpy.isValid()); - QSignalSpy otherStreamNextFinishedSpy(streamNext.get(), &QGrpcStream::finished); + QSignalSpy otherStreamNextFinishedSpy(streamNext.get(), &QGrpcServerStream::finished); QVERIFY(streamNextFinishedSpy.isValid()); - QSignalSpy otherStreamNextErrorSpy(streamNext.get(), &QGrpcStream::errorOccurred); + QSignalSpy otherStreamNextErrorSpy(streamNext.get(), &QGrpcServerStream::errorOccurred); QVERIFY(otherStreamNextErrorSpy.isValid()); stream->cancel(); @@ -633,7 +633,7 @@ void QtGrpcClientTest::StringAsyncThreadTest() ; } -void QtGrpcClientTest::StreamStringThreadTest() +void QtGrpcClientTest::ServerStreamStringThreadTest() { SimpleStringMessage result; SimpleStringMessage request; @@ -646,7 +646,7 @@ void QtGrpcClientTest::StreamStringThreadTest() const std::unique_ptr thread(QThread::create([&] { QEventLoop waiter; auto stream = _client->streamTestMethodServerStream(request); - QObject::connect(stream.get(), &QGrpcStream::messageReceived, &waiter, + QObject::connect(stream.get(), &QGrpcServerStream::messageReceived, &waiter, [&result, &i, &waiter, stream] { SimpleStringMessage ret = stream->read(); result.setTestFieldString(result.testFieldString() @@ -664,11 +664,11 @@ void QtGrpcClientTest::StreamStringThreadTest() QTRY_VERIFY(result.testFieldString().isEmpty()); QTRY_VERIFY(qvariant_cast(clientErrorSpy.at(0).first()) .message() - .startsWith("QAbstractGrpcClient::startStream is called from a " + .startsWith("QAbstractGrpcClient::startServerStream is called from a " "different thread.")); } -void QtGrpcClientTest::StreamCancelWhileErrorTimeoutTest() +void QtGrpcClientTest::ServerStreamCancelWhileErrorTimeoutTest() { SimpleStringMessage result; SimpleStringMessage request; @@ -676,9 +676,9 @@ void QtGrpcClientTest::StreamCancelWhileErrorTimeoutTest() auto stream = _client->streamTestMethodServerStream(request); - QSignalSpy streamFinishedSpy(stream.get(), &QGrpcStream::finished); + QSignalSpy streamFinishedSpy(stream.get(), &QGrpcServerStream::finished); QVERIFY(streamFinishedSpy.isValid()); - QSignalSpy streamErrorSpy(stream.get(), &QGrpcStream::errorOccurred); + QSignalSpy streamErrorSpy(stream.get(), &QGrpcServerStream::errorOccurred); QVERIFY(streamErrorSpy.isValid()); stream->cancel(); @@ -765,7 +765,7 @@ void QtGrpcClientTest::CallDeadlineTest() } } -void QtGrpcClientTest::StreamDeadlineTest_data() +void QtGrpcClientTest::ServerStreamDeadlineTest_data() { const int ExpectedMessageCount = 4; QTest::addColumn("timeout"); @@ -781,7 +781,7 @@ void QtGrpcClientTest::StreamDeadlineTest_data() << ExpectedMessageCount; } -void QtGrpcClientTest::StreamDeadlineTest() +void QtGrpcClientTest::ServerStreamDeadlineTest() { QFETCH(const std::chrono::milliseconds, timeout); QFETCH(const int, ExpectedMessageCount); @@ -794,13 +794,13 @@ void QtGrpcClientTest::StreamDeadlineTest() auto stream = _client->streamTestMethodServerStream(request, opt); - QSignalSpy streamErrorSpy(stream.get(), &QGrpcStream::errorOccurred); + QSignalSpy streamErrorSpy(stream.get(), &QGrpcServerStream::errorOccurred); QVERIFY(streamErrorSpy.isValid()); - QSignalSpy streamFinishedSpy(stream.get(), &QGrpcStream::finished); + QSignalSpy streamFinishedSpy(stream.get(), &QGrpcServerStream::finished); QVERIFY(streamFinishedSpy.isValid()); SimpleStringMessage result; - QObject::connect(stream.get(), &QGrpcStream::messageReceived, this, [&result, stream] { + QObject::connect(stream.get(), &QGrpcServerStream::messageReceived, this, [&result, stream] { SimpleStringMessage ret = stream->read(); result.setTestFieldString(result.testFieldString() + ret.testFieldString()); }); diff --git a/tests/auto/grpcgen/data/expected_result/folder/qtgrpc/tests/testservice_client.grpc.qpb.cpp b/tests/auto/grpcgen/data/expected_result/folder/qtgrpc/tests/testservice_client.grpc.qpb.cpp index b094041c..584ea495 100644 --- a/tests/auto/grpcgen/data/expected_result/folder/qtgrpc/tests/testservice_client.grpc.qpb.cpp +++ b/tests/auto/grpcgen/data/expected_result/folder/qtgrpc/tests/testservice_client.grpc.qpb.cpp @@ -29,9 +29,9 @@ void Client::testMethod(const qtgrpc::tests::SimpleStringMessage &arg, const QOb }, Qt::SingleShotConnection); } -std::shared_ptr Client::streamTestMethodServerStream(const qtgrpc::tests::SimpleStringMessage &arg, const QGrpcCallOptions &options) +std::shared_ptr Client::streamTestMethodServerStream(const qtgrpc::tests::SimpleStringMessage &arg, const QGrpcCallOptions &options) { - return startStream("testMethodServerStream"_L1, arg, options); + return startServerStream("testMethodServerStream"_L1, arg, options); } } // namespace TestService diff --git a/tests/auto/grpcgen/data/expected_result/folder/qtgrpc/tests/testservice_client.grpc.qpb.h b/tests/auto/grpcgen/data/expected_result/folder/qtgrpc/tests/testservice_client.grpc.qpb.h index 8f73434d..18513ca9 100644 --- a/tests/auto/grpcgen/data/expected_result/folder/qtgrpc/tests/testservice_client.grpc.qpb.h +++ b/tests/auto/grpcgen/data/expected_result/folder/qtgrpc/tests/testservice_client.grpc.qpb.h @@ -29,7 +29,7 @@ public: std::shared_ptr testMethod(const qtgrpc::tests::SimpleStringMessage &arg, const QGrpcCallOptions &options = {}); Q_INVOKABLE void testMethod(const qtgrpc::tests::SimpleStringMessage &arg, const QObject *context, const std::function)> &callback, const QGrpcCallOptions &options = {}); - std::shared_ptr streamTestMethodServerStream(const qtgrpc::tests::SimpleStringMessage &arg, const QGrpcCallOptions &options = {}); + std::shared_ptr streamTestMethodServerStream(const qtgrpc::tests::SimpleStringMessage &arg, const QGrpcCallOptions &options = {}); }; diff --git a/tests/auto/grpcgen/data/expected_result/no-options/testservice_client.grpc.qpb.cpp b/tests/auto/grpcgen/data/expected_result/no-options/testservice_client.grpc.qpb.cpp index db428f99..8d7af960 100644 --- a/tests/auto/grpcgen/data/expected_result/no-options/testservice_client.grpc.qpb.cpp +++ b/tests/auto/grpcgen/data/expected_result/no-options/testservice_client.grpc.qpb.cpp @@ -29,9 +29,9 @@ void Client::testMethod(const qtgrpc::tests::SimpleStringMessage &arg, const QOb }, Qt::SingleShotConnection); } -std::shared_ptr Client::streamTestMethodServerStream(const qtgrpc::tests::SimpleStringMessage &arg, const QGrpcCallOptions &options) +std::shared_ptr Client::streamTestMethodServerStream(const qtgrpc::tests::SimpleStringMessage &arg, const QGrpcCallOptions &options) { - return startStream("testMethodServerStream"_L1, arg, options); + return startServerStream("testMethodServerStream"_L1, arg, options); } } // namespace TestService diff --git a/tests/auto/grpcgen/data/expected_result/no-options/testservice_client.grpc.qpb.h b/tests/auto/grpcgen/data/expected_result/no-options/testservice_client.grpc.qpb.h index 59c4988a..2cd3d1df 100644 --- a/tests/auto/grpcgen/data/expected_result/no-options/testservice_client.grpc.qpb.h +++ b/tests/auto/grpcgen/data/expected_result/no-options/testservice_client.grpc.qpb.h @@ -29,7 +29,7 @@ public: std::shared_ptr testMethod(const qtgrpc::tests::SimpleStringMessage &arg, const QGrpcCallOptions &options = {}); Q_INVOKABLE void testMethod(const qtgrpc::tests::SimpleStringMessage &arg, const QObject *context, const std::function)> &callback, const QGrpcCallOptions &options = {}); - std::shared_ptr streamTestMethodServerStream(const qtgrpc::tests::SimpleStringMessage &arg, const QGrpcCallOptions &options = {}); + std::shared_ptr streamTestMethodServerStream(const qtgrpc::tests::SimpleStringMessage &arg, const QGrpcCallOptions &options = {}); };