mirror of https://github.com/qt/qtgrpc.git
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 <konrad.kujawa@qt.io>
This commit is contained in:
parent
3f515047ad
commit
f3aa84d05b
|
@ -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,18 +65,19 @@ 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]() {
|
||||
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<qtgrpc::examples::chat::ChatMessages>().messages());
|
||||
m_messages.append(
|
||||
stream->read<qtgrpc::examples::chat::ChatMessages>().messages());
|
||||
});
|
||||
// ![1]
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
|
@ -46,11 +46,11 @@ QT_BEGIN_NAMESPACE
|
|||
*/
|
||||
|
||||
/*!
|
||||
\fn virtual void startStream(std::shared_ptr<QGrpcChannelOperation> channelOperation) = 0
|
||||
\fn virtual void startServerStream(std::shared_ptr<QGrpcChannelOperation> 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<QGrpcCallReply> 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<QGrpcStream>
|
||||
QAbstractGrpcChannel::startStream(QLatin1StringView method, QLatin1StringView service,
|
||||
std::shared_ptr<QGrpcServerStream>
|
||||
QAbstractGrpcChannel::startServerStream(QLatin1StringView method, QLatin1StringView service,
|
||||
QByteArrayView arg, const QGrpcCallOptions &options)
|
||||
{
|
||||
auto channelOperation = std::make_shared<QGrpcChannelOperation>(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<QGrpcStream> stream(
|
||||
new QGrpcStream(channelOperation, serializer()));
|
||||
startStream(channelOperation);
|
||||
std::shared_ptr<QGrpcServerStream> stream(
|
||||
new QGrpcServerStream(channelOperation, serializer()));
|
||||
startServerStream(channelOperation);
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<QGrpcCallReply> call(QLatin1StringView method, QLatin1StringView service,
|
||||
QByteArrayView arg,
|
||||
const QGrpcCallOptions &options = QGrpcCallOptions());
|
||||
std::shared_ptr<QGrpcStream>
|
||||
startStream(QLatin1StringView method, QLatin1StringView service, QByteArrayView arg,
|
||||
std::shared_ptr<QGrpcServerStream>
|
||||
startServerStream(QLatin1StringView method, QLatin1StringView service, QByteArrayView arg,
|
||||
const QGrpcCallOptions &options = QGrpcCallOptions());
|
||||
virtual std::shared_ptr<QAbstractProtobufSerializer> serializer() const = 0;
|
||||
|
||||
protected:
|
||||
virtual void call(std::shared_ptr<QGrpcChannelOperation> channelOperation) = 0;
|
||||
virtual void startStream(std::shared_ptr<QGrpcChannelOperation> channelOperation) = 0;
|
||||
virtual void startServerStream(std::shared_ptr<QGrpcChannelOperation> channelOperation) = 0;
|
||||
|
||||
friend class QAbstractGrpcClient;
|
||||
QAbstractGrpcChannel();
|
||||
|
|
|
@ -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 <typename ParamType> QSharedPointer<QGrpcStream>
|
||||
QAbstractGrpcClient::startStream(QLatin1StringView method, const QProtobufMessage &arg,
|
||||
\fn template <typename ParamType> QSharedPointer<QGrpcServerStream>
|
||||
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<QAbstractGrpcChannel> channel;
|
||||
const std::string service;
|
||||
std::vector<std::shared_ptr<QGrpcStream>> activeStreams;
|
||||
std::vector<std::shared_ptr<QGrpcServerStream>> activeStreams;
|
||||
};
|
||||
|
||||
QGrpcStatus QAbstractGrpcClientPrivate::checkThread(QLatin1StringView warningPreamble)
|
||||
|
@ -166,23 +166,23 @@ std::shared_ptr<QGrpcCallReply> QAbstractGrpcClient::call(QLatin1StringView meth
|
|||
return reply;
|
||||
}
|
||||
|
||||
std::shared_ptr<QGrpcStream>
|
||||
QAbstractGrpcClient::startStream(QLatin1StringView method, QByteArrayView arg,
|
||||
std::shared_ptr<QGrpcServerStream>
|
||||
QAbstractGrpcClient::startServerStream(QLatin1StringView method, QByteArrayView arg,
|
||||
const QGrpcCallOptions &options)
|
||||
{
|
||||
Q_D(QAbstractGrpcClient);
|
||||
|
||||
std::shared_ptr<QGrpcStream> grpcStream;
|
||||
if (d->checkThread("QAbstractGrpcClient::startStream"_L1) != QGrpcStatus::Ok)
|
||||
std::shared_ptr<QGrpcServerStream> 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<QMetaObject::Connection>();
|
||||
*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<QMetaObject::Connection>();
|
||||
*finishedConnection = connect(
|
||||
grpcStream.get(), &QGrpcStream::finished, this,
|
||||
grpcStream.get(), &QGrpcServerStream::finished, this,
|
||||
[this, grpcStream, errorConnection, finishedConnection, method]() mutable {
|
||||
QObject::disconnect(*errorConnection);
|
||||
QObject::disconnect(*finishedConnection);
|
||||
|
|
|
@ -75,21 +75,21 @@ protected:
|
|||
}
|
||||
|
||||
template<typename ParamType>
|
||||
std::shared_ptr<QGrpcStream> startStream(QLatin1StringView method,
|
||||
std::shared_ptr<QGrpcServerStream> startServerStream(QLatin1StringView method,
|
||||
const QProtobufMessage &arg,
|
||||
const QGrpcCallOptions &options)
|
||||
{
|
||||
std::optional<QByteArray> argData = trySerialize<ParamType>(arg);
|
||||
if (!argData)
|
||||
return {};
|
||||
return startStream(method, *argData, options);
|
||||
return startServerStream(method, *argData, options);
|
||||
}
|
||||
|
||||
private:
|
||||
std::shared_ptr<QGrpcCallReply> call(QLatin1StringView method, QByteArrayView arg,
|
||||
const QGrpcCallOptions &options);
|
||||
|
||||
std::shared_ptr<QGrpcStream> startStream(QLatin1StringView method,
|
||||
std::shared_ptr<QGrpcServerStream> startServerStream(QLatin1StringView method,
|
||||
QByteArrayView arg,
|
||||
const QGrpcCallOptions &options);
|
||||
|
||||
|
|
|
@ -270,7 +270,7 @@ void QGrpcChannelPrivate::call(std::shared_ptr<QGrpcChannelOperation> channelOpe
|
|||
QTimer::singleShot(*deadline, call.get(), [call] { call->cancel(); });
|
||||
}
|
||||
|
||||
void QGrpcChannelPrivate::startStream(std::shared_ptr<QGrpcChannelOperation> channelOperation)
|
||||
void QGrpcChannelPrivate::startServerStream(std::shared_ptr<QGrpcChannelOperation> channelOperation)
|
||||
{
|
||||
const QByteArray rpcName =
|
||||
buildRpcName(channelOperation->service(), channelOperation->method());
|
||||
|
@ -353,9 +353,9 @@ void QGrpcChannel::call(std::shared_ptr<QGrpcChannelOperation> channelOperation)
|
|||
Implementation of server-side gRPC stream based on the
|
||||
reference gRPC C++ API.
|
||||
*/
|
||||
void QGrpcChannel::startStream(std::shared_ptr<QGrpcChannelOperation> channelOperation)
|
||||
void QGrpcChannel::startServerStream(std::shared_ptr<QGrpcChannelOperation> channelOperation)
|
||||
{
|
||||
dPtr->startStream(std::move(channelOperation));
|
||||
dPtr->startServerStream(std::move(channelOperation));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
@ -30,7 +30,7 @@ public:
|
|||
~QGrpcChannel() override;
|
||||
|
||||
void call(std::shared_ptr<QGrpcChannelOperation> channelOperation) override;
|
||||
void startStream(std::shared_ptr<QGrpcChannelOperation> channelOperation) override;
|
||||
void startServerStream(std::shared_ptr<QGrpcChannelOperation> channelOperation) override;
|
||||
std::shared_ptr<QAbstractProtobufSerializer> serializer() const override;
|
||||
|
||||
private:
|
||||
|
|
|
@ -96,7 +96,7 @@ struct QGrpcChannelPrivate
|
|||
~QGrpcChannelPrivate();
|
||||
|
||||
void call(std::shared_ptr<QGrpcChannelOperation> channelOperation);
|
||||
void startStream(std::shared_ptr<QGrpcChannelOperation> channelOperation);
|
||||
void startServerStream(std::shared_ptr<QGrpcChannelOperation> channelOperation);
|
||||
std::shared_ptr<QAbstractProtobufSerializer> serializer() const;
|
||||
};
|
||||
|
||||
|
|
|
@ -288,7 +288,7 @@ void QGrpcHttp2Channel::call(std::shared_ptr<QGrpcChannelOperation> channelOpera
|
|||
\internal
|
||||
Implementation of server-side gRPC stream based on \l QNetworkAccessManager.
|
||||
*/
|
||||
void QGrpcHttp2Channel::startStream(std::shared_ptr<QGrpcChannelOperation> channelOperation)
|
||||
void QGrpcHttp2Channel::startServerStream(std::shared_ptr<QGrpcChannelOperation> channelOperation)
|
||||
{
|
||||
QNetworkReply *networkReply =
|
||||
dPtr->post(channelOperation->method(), channelOperation->service(),
|
||||
|
|
|
@ -22,7 +22,7 @@ public:
|
|||
|
||||
private:
|
||||
void call(std::shared_ptr<QGrpcChannelOperation> channelOperation) override;
|
||||
void startStream(std::shared_ptr<QGrpcChannelOperation> channelOperation) override;
|
||||
void startServerStream(std::shared_ptr<QGrpcChannelOperation> channelOperation) override;
|
||||
std::shared_ptr<QAbstractProtobufSerializer> serializer() const override;
|
||||
|
||||
Q_DISABLE_COPY_MOVE(QGrpcHttp2Channel)
|
||||
|
|
|
@ -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<QGrpcChannelOperation> channelOperation,
|
||||
QGrpcServerStream::QGrpcServerStream(std::shared_ptr<QGrpcChannelOperation> channelOperation,
|
||||
std::shared_ptr<QAbstractProtobufSerializer> serializer)
|
||||
: QGrpcOperation(std::move(channelOperation), std::move(serializer))
|
||||
{
|
||||
|
@ -35,9 +35,9 @@ QGrpcStream::QGrpcStream(std::shared_ptr<QGrpcChannelOperation> channelOperation
|
|||
}
|
||||
|
||||
/*!
|
||||
Destroys the QGrpcStream object.
|
||||
Destroys the QGrpcServerStream object.
|
||||
*/
|
||||
QGrpcStream::~QGrpcStream() = default;
|
||||
QGrpcServerStream::~QGrpcServerStream() = default;
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
|
|
|
@ -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<QGrpcChannelOperation> channelOperation,
|
||||
explicit QGrpcServerStream(std::shared_ptr<QGrpcChannelOperation> channelOperation,
|
||||
std::shared_ptr<QAbstractProtobufSerializer> serializer);
|
||||
~QGrpcStream() override;
|
||||
~QGrpcServerStream() override;
|
||||
|
||||
Q_SIGNALS:
|
||||
void messageReceived();
|
||||
|
|
|
@ -133,17 +133,17 @@ const char *GrpcTemplates::ClientMethodDefinitionQmlTemplate()
|
|||
|
||||
const char *GrpcTemplates::ClientMethodServerStreamDeclarationTemplate()
|
||||
{
|
||||
return "std::shared_ptr<QGrpcStream> stream$method_name_upper$(const $param_type$ "
|
||||
return "std::shared_ptr<QGrpcServerStream> stream$method_name_upper$(const $param_type$ "
|
||||
"&$param_name$, const QGrpcCallOptions &options = {});\n";
|
||||
}
|
||||
|
||||
const char *GrpcTemplates::ClientMethodServerStreamDefinitionTemplate()
|
||||
{
|
||||
return "std::shared_ptr<QGrpcStream> $classname$::stream$method_name_upper$(const "
|
||||
return "std::shared_ptr<QGrpcServerStream> $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";
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
[CallDeadlineTest]
|
||||
macos 64bit arm
|
||||
[StreamDeadlineTest]
|
||||
[ServerStreamDeadlineTest]
|
||||
macos 64bit arm
|
||||
|
|
|
@ -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<SimpleStringMessage>();
|
||||
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<SimpleStringMessage>();
|
||||
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<SimpleStringMessage>();
|
||||
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<BlobMessage>();
|
||||
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<SimpleStringMessage>();
|
||||
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<QThread> 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<SimpleStringMessage>();
|
||||
result.setTestFieldString(result.testFieldString()
|
||||
|
@ -664,11 +664,11 @@ void QtGrpcClientTest::StreamStringThreadTest()
|
|||
QTRY_VERIFY(result.testFieldString().isEmpty());
|
||||
QTRY_VERIFY(qvariant_cast<QGrpcStatus>(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<std::chrono::milliseconds>("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<SimpleStringMessage>();
|
||||
result.setTestFieldString(result.testFieldString() + ret.testFieldString());
|
||||
});
|
||||
|
|
|
@ -29,9 +29,9 @@ void Client::testMethod(const qtgrpc::tests::SimpleStringMessage &arg, const QOb
|
|||
}, Qt::SingleShotConnection);
|
||||
}
|
||||
|
||||
std::shared_ptr<QGrpcStream> Client::streamTestMethodServerStream(const qtgrpc::tests::SimpleStringMessage &arg, const QGrpcCallOptions &options)
|
||||
std::shared_ptr<QGrpcServerStream> Client::streamTestMethodServerStream(const qtgrpc::tests::SimpleStringMessage &arg, const QGrpcCallOptions &options)
|
||||
{
|
||||
return startStream<qtgrpc::tests::SimpleStringMessage>("testMethodServerStream"_L1, arg, options);
|
||||
return startServerStream<qtgrpc::tests::SimpleStringMessage>("testMethodServerStream"_L1, arg, options);
|
||||
}
|
||||
|
||||
} // namespace TestService
|
||||
|
|
|
@ -29,7 +29,7 @@ public:
|
|||
std::shared_ptr<QGrpcCallReply> testMethod(const qtgrpc::tests::SimpleStringMessage &arg, const QGrpcCallOptions &options = {});
|
||||
Q_INVOKABLE void testMethod(const qtgrpc::tests::SimpleStringMessage &arg, const QObject *context, const std::function<void(std::shared_ptr<QGrpcCallReply>)> &callback, const QGrpcCallOptions &options = {});
|
||||
|
||||
std::shared_ptr<QGrpcStream> streamTestMethodServerStream(const qtgrpc::tests::SimpleStringMessage &arg, const QGrpcCallOptions &options = {});
|
||||
std::shared_ptr<QGrpcServerStream> streamTestMethodServerStream(const qtgrpc::tests::SimpleStringMessage &arg, const QGrpcCallOptions &options = {});
|
||||
|
||||
|
||||
};
|
||||
|
|
|
@ -29,9 +29,9 @@ void Client::testMethod(const qtgrpc::tests::SimpleStringMessage &arg, const QOb
|
|||
}, Qt::SingleShotConnection);
|
||||
}
|
||||
|
||||
std::shared_ptr<QGrpcStream> Client::streamTestMethodServerStream(const qtgrpc::tests::SimpleStringMessage &arg, const QGrpcCallOptions &options)
|
||||
std::shared_ptr<QGrpcServerStream> Client::streamTestMethodServerStream(const qtgrpc::tests::SimpleStringMessage &arg, const QGrpcCallOptions &options)
|
||||
{
|
||||
return startStream<qtgrpc::tests::SimpleStringMessage>("testMethodServerStream"_L1, arg, options);
|
||||
return startServerStream<qtgrpc::tests::SimpleStringMessage>("testMethodServerStream"_L1, arg, options);
|
||||
}
|
||||
|
||||
} // namespace TestService
|
||||
|
|
|
@ -29,7 +29,7 @@ public:
|
|||
std::shared_ptr<QGrpcCallReply> testMethod(const qtgrpc::tests::SimpleStringMessage &arg, const QGrpcCallOptions &options = {});
|
||||
Q_INVOKABLE void testMethod(const qtgrpc::tests::SimpleStringMessage &arg, const QObject *context, const std::function<void(std::shared_ptr<QGrpcCallReply>)> &callback, const QGrpcCallOptions &options = {});
|
||||
|
||||
std::shared_ptr<QGrpcStream> streamTestMethodServerStream(const qtgrpc::tests::SimpleStringMessage &arg, const QGrpcCallOptions &options = {});
|
||||
std::shared_ptr<QGrpcServerStream> streamTestMethodServerStream(const qtgrpc::tests::SimpleStringMessage &arg, const QGrpcCallOptions &options = {});
|
||||
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue