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]
|
// ![1]
|
||||||
auto stream = m_client->streamMessageList(qtgrpc::examples::chat::None());
|
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) {
|
[this, stream](const QGrpcStatus &status) {
|
||||||
qCritical()
|
qCritical()
|
||||||
<< "Stream error(" << status.code() << "):" << status.message();
|
<< "Stream error(" << status.code() << "):" << status.message();
|
||||||
|
@ -65,19 +65,20 @@ void SimpleChatEngine::login(const QString &name, const QString &password)
|
||||||
emit authFailed();
|
emit authFailed();
|
||||||
});
|
});
|
||||||
|
|
||||||
QObject::connect(stream.get(), &QGrpcStream::finished, this,
|
QObject::connect(stream.get(), &QGrpcServerStream::finished, this,
|
||||||
[this, stream]() { setState(Disconnected); });
|
[this, stream]() { setState(Disconnected); });
|
||||||
|
|
||||||
QObject::connect(
|
QObject::connect(stream.get(), &QGrpcServerStream::messageReceived, this,
|
||||||
stream.get(), &QGrpcStream::messageReceived, this, [this, name, password, stream]() {
|
[this, name, password, stream]() {
|
||||||
if (m_userName != name) {
|
if (m_userName != name) {
|
||||||
m_userName = name;
|
m_userName = name;
|
||||||
m_password = password;
|
m_password = password;
|
||||||
emit userNameChanged();
|
emit userNameChanged();
|
||||||
}
|
}
|
||||||
setState(Connected);
|
setState(Connected);
|
||||||
m_messages.append(stream->read<qtgrpc::examples::chat::ChatMessages>().messages());
|
m_messages.append(
|
||||||
});
|
stream->read<qtgrpc::examples::chat::ChatMessages>().messages());
|
||||||
|
});
|
||||||
// ![1]
|
// ![1]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,21 +42,21 @@
|
||||||
|
|
||||||
\snippet chat/client/simplechatengine.cpp 1
|
\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.
|
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
|
either on the server side or in the communication channel. Typically, an
|
||||||
error results in the connection to the server being closed and
|
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
|
When the server sends new messages to the stream, \l QGrpcServerStream emits the
|
||||||
\l QGrpcStream::messageReceived signal. The slot connected to this signal
|
\l QGrpcServerStream::messageReceived signal. The slot connected to this signal
|
||||||
processes the chat message. Messages that are received from the
|
processes the chat message. Messages that are received from the
|
||||||
\c {SimpleChat/messageList} server stream are collected in the custom
|
\c {SimpleChat/messageList} server stream are collected in the custom
|
||||||
\l QAbstractListModel model and displayed to the user.
|
\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
|
you can do with this stream instance, so you need to initiate a new
|
||||||
subscription.
|
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
|
This pure virtual function that the starts of the server-side stream. The
|
||||||
\a channelOperation is the pointer to a channel side
|
\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.
|
primitive, that is used in \l QAbstractGrpcClient implementations.
|
||||||
|
|
||||||
The function should implement the channel-side logic of server-side stream.
|
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
|
\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
|
primitives and makes the required for server-side gRPC stream connections
|
||||||
between them.
|
between them.
|
||||||
|
|
||||||
The function should not be called directly, but only by
|
The function should not be called directly, but only by
|
||||||
\l QAbstractGrpcClient implementations.
|
\l QAbstractGrpcClient implementations.
|
||||||
*/
|
*/
|
||||||
std::shared_ptr<QGrpcStream>
|
std::shared_ptr<QGrpcServerStream>
|
||||||
QAbstractGrpcChannel::startStream(QLatin1StringView method, QLatin1StringView service,
|
QAbstractGrpcChannel::startServerStream(QLatin1StringView method, QLatin1StringView service,
|
||||||
QByteArrayView arg, const QGrpcCallOptions &options)
|
QByteArrayView arg, const QGrpcCallOptions &options)
|
||||||
{
|
{
|
||||||
auto channelOperation = std::make_shared<QGrpcChannelOperation>(method, service, arg, options);
|
auto channelOperation = std::make_shared<QGrpcChannelOperation>(method, service, arg, options);
|
||||||
QObject::connect(channelOperation.get(), &QGrpcChannelOperation::sendData, []() {
|
QObject::connect(channelOperation.get(), &QGrpcChannelOperation::sendData, []() {
|
||||||
Q_ASSERT_X(false, "QAbstractGrpcChannel::startStream",
|
Q_ASSERT_X(false, "QAbstractGrpcChannel::startServerStream",
|
||||||
"QAbstractGrpcChannel::startStream disallows sendData signal from "
|
"QAbstractGrpcChannel::startServerStream disallows sendData signal from "
|
||||||
"QGrpcChannelOperation");
|
"QGrpcChannelOperation");
|
||||||
});
|
});
|
||||||
|
|
||||||
std::shared_ptr<QGrpcStream> stream(
|
std::shared_ptr<QGrpcServerStream> stream(
|
||||||
new QGrpcStream(channelOperation, serializer()));
|
new QGrpcServerStream(channelOperation, serializer()));
|
||||||
startStream(channelOperation);
|
startServerStream(channelOperation);
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ QT_BEGIN_NAMESPACE
|
||||||
class QAbstractGrpcClient;
|
class QAbstractGrpcClient;
|
||||||
class QAbstractProtobufSerializer;
|
class QAbstractProtobufSerializer;
|
||||||
struct QAbstractGrpcChannelPrivate;
|
struct QAbstractGrpcChannelPrivate;
|
||||||
class QGrpcStream;
|
class QGrpcServerStream;
|
||||||
class QGrpcCallReply;
|
class QGrpcCallReply;
|
||||||
class QGrpcChannelOperation;
|
class QGrpcChannelOperation;
|
||||||
|
|
||||||
|
@ -29,14 +29,14 @@ public:
|
||||||
std::shared_ptr<QGrpcCallReply> call(QLatin1StringView method, QLatin1StringView service,
|
std::shared_ptr<QGrpcCallReply> call(QLatin1StringView method, QLatin1StringView service,
|
||||||
QByteArrayView arg,
|
QByteArrayView arg,
|
||||||
const QGrpcCallOptions &options = QGrpcCallOptions());
|
const QGrpcCallOptions &options = QGrpcCallOptions());
|
||||||
std::shared_ptr<QGrpcStream>
|
std::shared_ptr<QGrpcServerStream>
|
||||||
startStream(QLatin1StringView method, QLatin1StringView service, QByteArrayView arg,
|
startServerStream(QLatin1StringView method, QLatin1StringView service, QByteArrayView arg,
|
||||||
const QGrpcCallOptions &options = QGrpcCallOptions());
|
const QGrpcCallOptions &options = QGrpcCallOptions());
|
||||||
virtual std::shared_ptr<QAbstractProtobufSerializer> serializer() const = 0;
|
virtual std::shared_ptr<QAbstractProtobufSerializer> serializer() const = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void call(std::shared_ptr<QGrpcChannelOperation> channelOperation) = 0;
|
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;
|
friend class QAbstractGrpcClient;
|
||||||
QAbstractGrpcChannel();
|
QAbstractGrpcChannel();
|
||||||
|
|
|
@ -37,9 +37,9 @@ static QString threadSafetyWarning(QLatin1StringView methodName)
|
||||||
|
|
||||||
QAbstractGrpcClient provides a set of functions for client classes
|
QAbstractGrpcClient provides a set of functions for client classes
|
||||||
generated out of protobuf services.
|
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.
|
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.
|
should only be called by the generated client classes.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -61,8 +61,8 @@ static QString threadSafetyWarning(QLatin1StringView methodName)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\fn template <typename ParamType> QSharedPointer<QGrpcStream>
|
\fn template <typename ParamType> QSharedPointer<QGrpcServerStream>
|
||||||
QAbstractGrpcClient::startStream(QLatin1StringView method, const QProtobufMessage &arg,
|
QAbstractGrpcClient::startServerStream(QLatin1StringView method, const QProtobufMessage &arg,
|
||||||
const QGrpcCallOptions &options);
|
const QGrpcCallOptions &options);
|
||||||
|
|
||||||
Streams messages from the server stream \a method with the message
|
Streams messages from the server stream \a method with the message
|
||||||
|
@ -82,7 +82,7 @@ public:
|
||||||
|
|
||||||
std::shared_ptr<QAbstractGrpcChannel> channel;
|
std::shared_ptr<QAbstractGrpcChannel> channel;
|
||||||
const std::string service;
|
const std::string service;
|
||||||
std::vector<std::shared_ptr<QGrpcStream>> activeStreams;
|
std::vector<std::shared_ptr<QGrpcServerStream>> activeStreams;
|
||||||
};
|
};
|
||||||
|
|
||||||
QGrpcStatus QAbstractGrpcClientPrivate::checkThread(QLatin1StringView warningPreamble)
|
QGrpcStatus QAbstractGrpcClientPrivate::checkThread(QLatin1StringView warningPreamble)
|
||||||
|
@ -166,23 +166,23 @@ std::shared_ptr<QGrpcCallReply> QAbstractGrpcClient::call(QLatin1StringView meth
|
||||||
return reply;
|
return reply;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<QGrpcStream>
|
std::shared_ptr<QGrpcServerStream>
|
||||||
QAbstractGrpcClient::startStream(QLatin1StringView method, QByteArrayView arg,
|
QAbstractGrpcClient::startServerStream(QLatin1StringView method, QByteArrayView arg,
|
||||||
const QGrpcCallOptions &options)
|
const QGrpcCallOptions &options)
|
||||||
{
|
{
|
||||||
Q_D(QAbstractGrpcClient);
|
Q_D(QAbstractGrpcClient);
|
||||||
|
|
||||||
std::shared_ptr<QGrpcStream> grpcStream;
|
std::shared_ptr<QGrpcServerStream> grpcStream;
|
||||||
if (d->checkThread("QAbstractGrpcClient::startStream"_L1) != QGrpcStatus::Ok)
|
if (d->checkThread("QAbstractGrpcClient::startServerStream"_L1) != QGrpcStatus::Ok)
|
||||||
return grpcStream;
|
return grpcStream;
|
||||||
|
|
||||||
if (d->channel) {
|
if (d->channel) {
|
||||||
grpcStream =
|
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>();
|
auto errorConnection = std::make_shared<QMetaObject::Connection>();
|
||||||
*errorConnection =
|
*errorConnection =
|
||||||
connect(grpcStream.get(), &QGrpcStream::errorOccurred, this,
|
connect(grpcStream.get(), &QGrpcServerStream::errorOccurred, this,
|
||||||
[this, grpcStream, method, errorConnection](const QGrpcStatus &status) {
|
[this, grpcStream, method, errorConnection](const QGrpcStatus &status) {
|
||||||
QObject::disconnect(*errorConnection);
|
QObject::disconnect(*errorConnection);
|
||||||
|
|
||||||
|
@ -194,7 +194,7 @@ QAbstractGrpcClient::startStream(QLatin1StringView method, QByteArrayView arg,
|
||||||
|
|
||||||
auto finishedConnection = std::make_shared<QMetaObject::Connection>();
|
auto finishedConnection = std::make_shared<QMetaObject::Connection>();
|
||||||
*finishedConnection = connect(
|
*finishedConnection = connect(
|
||||||
grpcStream.get(), &QGrpcStream::finished, this,
|
grpcStream.get(), &QGrpcServerStream::finished, this,
|
||||||
[this, grpcStream, errorConnection, finishedConnection, method]() mutable {
|
[this, grpcStream, errorConnection, finishedConnection, method]() mutable {
|
||||||
QObject::disconnect(*errorConnection);
|
QObject::disconnect(*errorConnection);
|
||||||
QObject::disconnect(*finishedConnection);
|
QObject::disconnect(*finishedConnection);
|
||||||
|
|
|
@ -75,21 +75,21 @@ protected:
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename ParamType>
|
template<typename ParamType>
|
||||||
std::shared_ptr<QGrpcStream> startStream(QLatin1StringView method,
|
std::shared_ptr<QGrpcServerStream> startServerStream(QLatin1StringView method,
|
||||||
const QProtobufMessage &arg,
|
const QProtobufMessage &arg,
|
||||||
const QGrpcCallOptions &options)
|
const QGrpcCallOptions &options)
|
||||||
{
|
{
|
||||||
std::optional<QByteArray> argData = trySerialize<ParamType>(arg);
|
std::optional<QByteArray> argData = trySerialize<ParamType>(arg);
|
||||||
if (!argData)
|
if (!argData)
|
||||||
return {};
|
return {};
|
||||||
return startStream(method, *argData, options);
|
return startServerStream(method, *argData, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<QGrpcCallReply> call(QLatin1StringView method, QByteArrayView arg,
|
std::shared_ptr<QGrpcCallReply> call(QLatin1StringView method, QByteArrayView arg,
|
||||||
const QGrpcCallOptions &options);
|
const QGrpcCallOptions &options);
|
||||||
|
|
||||||
std::shared_ptr<QGrpcStream> startStream(QLatin1StringView method,
|
std::shared_ptr<QGrpcServerStream> startServerStream(QLatin1StringView method,
|
||||||
QByteArrayView arg,
|
QByteArrayView arg,
|
||||||
const QGrpcCallOptions &options);
|
const QGrpcCallOptions &options);
|
||||||
|
|
||||||
|
|
|
@ -270,7 +270,7 @@ void QGrpcChannelPrivate::call(std::shared_ptr<QGrpcChannelOperation> channelOpe
|
||||||
QTimer::singleShot(*deadline, call.get(), [call] { call->cancel(); });
|
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 =
|
const QByteArray rpcName =
|
||||||
buildRpcName(channelOperation->service(), channelOperation->method());
|
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
|
Implementation of server-side gRPC stream based on the
|
||||||
reference gRPC C++ API.
|
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;
|
~QGrpcChannel() override;
|
||||||
|
|
||||||
void call(std::shared_ptr<QGrpcChannelOperation> channelOperation) 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;
|
std::shared_ptr<QAbstractProtobufSerializer> serializer() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -96,7 +96,7 @@ struct QGrpcChannelPrivate
|
||||||
~QGrpcChannelPrivate();
|
~QGrpcChannelPrivate();
|
||||||
|
|
||||||
void call(std::shared_ptr<QGrpcChannelOperation> channelOperation);
|
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;
|
std::shared_ptr<QAbstractProtobufSerializer> serializer() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -288,7 +288,7 @@ void QGrpcHttp2Channel::call(std::shared_ptr<QGrpcChannelOperation> channelOpera
|
||||||
\internal
|
\internal
|
||||||
Implementation of server-side gRPC stream based on \l QNetworkAccessManager.
|
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 =
|
QNetworkReply *networkReply =
|
||||||
dPtr->post(channelOperation->method(), channelOperation->service(),
|
dPtr->post(channelOperation->method(), channelOperation->service(),
|
||||||
|
|
|
@ -22,7 +22,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void call(std::shared_ptr<QGrpcChannelOperation> channelOperation) 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;
|
std::shared_ptr<QAbstractProtobufSerializer> serializer() const override;
|
||||||
|
|
||||||
Q_DISABLE_COPY_MOVE(QGrpcHttp2Channel)
|
Q_DISABLE_COPY_MOVE(QGrpcHttp2Channel)
|
||||||
|
|
|
@ -11,22 +11,22 @@
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\class QGrpcStream
|
\class QGrpcServerStream
|
||||||
\inmodule QtGrpc
|
\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.
|
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.
|
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)
|
std::shared_ptr<QAbstractProtobufSerializer> serializer)
|
||||||
: QGrpcOperation(std::move(channelOperation), std::move(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
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
|
|
@ -17,14 +17,14 @@ QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
class QAbstractGrpcClient;
|
class QAbstractGrpcClient;
|
||||||
|
|
||||||
class Q_GRPC_EXPORT QGrpcStream final : public QGrpcOperation
|
class Q_GRPC_EXPORT QGrpcServerStream final : public QGrpcOperation
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit QGrpcStream(std::shared_ptr<QGrpcChannelOperation> channelOperation,
|
explicit QGrpcServerStream(std::shared_ptr<QGrpcChannelOperation> channelOperation,
|
||||||
std::shared_ptr<QAbstractProtobufSerializer> serializer);
|
std::shared_ptr<QAbstractProtobufSerializer> serializer);
|
||||||
~QGrpcStream() override;
|
~QGrpcServerStream() override;
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void messageReceived();
|
void messageReceived();
|
||||||
|
|
|
@ -133,17 +133,17 @@ const char *GrpcTemplates::ClientMethodDefinitionQmlTemplate()
|
||||||
|
|
||||||
const char *GrpcTemplates::ClientMethodServerStreamDeclarationTemplate()
|
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";
|
"&$param_name$, const QGrpcCallOptions &options = {});\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *GrpcTemplates::ClientMethodServerStreamDefinitionTemplate()
|
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_type$ "
|
||||||
"&$param_name$, const QGrpcCallOptions &options)\n"
|
"&$param_name$, const QGrpcCallOptions &options)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" return startStream<$param_type$>(\"$method_name$\"_L1, $param_name$, "
|
" return startServerStream<$param_type$>(\"$method_name$\"_L1, $param_name$, "
|
||||||
"options);\n"
|
"options);\n"
|
||||||
"}\n\n";
|
"}\n\n";
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
[CallDeadlineTest]
|
[CallDeadlineTest]
|
||||||
macos 64bit arm
|
macos 64bit arm
|
||||||
[StreamDeadlineTest]
|
[ServerStreamDeadlineTest]
|
||||||
macos 64bit arm
|
macos 64bit arm
|
||||||
|
|
|
@ -112,28 +112,28 @@ private slots:
|
||||||
void CallAndAsyncRecieveWithLambdaStringTest();
|
void CallAndAsyncRecieveWithLambdaStringTest();
|
||||||
void CallAndAsyncImmediateCancelStringTest();
|
void CallAndAsyncImmediateCancelStringTest();
|
||||||
void CallAndAsyncDeferredAbortStringTest();
|
void CallAndAsyncDeferredAbortStringTest();
|
||||||
void StreamStringTest();
|
void ServerStreamStringTest();
|
||||||
void StreamStringAndAbortTest();
|
void ServerStreamStringAndAbortTest();
|
||||||
void StreamStringAndDeferredAbortTest();
|
void ServerStreamStringAndDeferredAbortTest();
|
||||||
// void StreamStringAndGetChangedSignalsTests();
|
// void StreamStringAndGetChangedSignalsTests();
|
||||||
void StreamBlobTest();
|
void ServerStreamBlobTest();
|
||||||
void CallMessageAsyncTest();
|
void CallMessageAsyncTest();
|
||||||
void CallMessageClientAsyncTest();
|
void CallMessageClientAsyncTest();
|
||||||
void CallMessageClientTest();
|
void CallMessageClientTest();
|
||||||
void StatusMessageClientTest();
|
void StatusMessageClientTest();
|
||||||
void StreamAndGetAsyncReplyTest();
|
void ServerStreamAndGetAsyncReplyTest();
|
||||||
void MultipleStreamsTest();
|
void MultipleServerStreamsTest();
|
||||||
void MultipleStreamsCancelTest();
|
void MultipleServerStreamsCancelTest();
|
||||||
void CallNonCompatibleArgRetTest();
|
void CallNonCompatibleArgRetTest();
|
||||||
void CallStringThreadTest();
|
void CallStringThreadTest();
|
||||||
void StringAsyncThreadTest();
|
void StringAsyncThreadTest();
|
||||||
void StreamStringThreadTest();
|
void ServerStreamStringThreadTest();
|
||||||
void StreamCancelWhileErrorTimeoutTest();
|
void ServerStreamCancelWhileErrorTimeoutTest();
|
||||||
void MetadataTest();
|
void MetadataTest();
|
||||||
void CallDeadlineTest_data();
|
void CallDeadlineTest_data();
|
||||||
void CallDeadlineTest();
|
void CallDeadlineTest();
|
||||||
void StreamDeadlineTest_data();
|
void ServerStreamDeadlineTest_data();
|
||||||
void StreamDeadlineTest();
|
void ServerStreamDeadlineTest();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ServerProcRunner serverProc{ QFINDTESTDATA(TEST_GRPC_SERVER_PATH) };
|
ServerProcRunner serverProc{ QFINDTESTDATA(TEST_GRPC_SERVER_PATH) };
|
||||||
|
@ -232,7 +232,7 @@ void QtGrpcClientTest::CallAndAsyncDeferredAbortStringTest()
|
||||||
QCOMPARE_EQ(result.testFieldString(), "Result not changed by echo");
|
QCOMPARE_EQ(result.testFieldString(), "Result not changed by echo");
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtGrpcClientTest::StreamStringTest()
|
void QtGrpcClientTest::ServerStreamStringTest()
|
||||||
{
|
{
|
||||||
const int ExpectedMessageCount = 4;
|
const int ExpectedMessageCount = 4;
|
||||||
|
|
||||||
|
@ -242,13 +242,13 @@ void QtGrpcClientTest::StreamStringTest()
|
||||||
|
|
||||||
auto stream = _client->streamTestMethodServerStream(request);
|
auto stream = _client->streamTestMethodServerStream(request);
|
||||||
|
|
||||||
QSignalSpy messageReceivedSpy(stream.get(), &QGrpcStream::messageReceived);
|
QSignalSpy messageReceivedSpy(stream.get(), &QGrpcServerStream::messageReceived);
|
||||||
QVERIFY(messageReceivedSpy.isValid());
|
QVERIFY(messageReceivedSpy.isValid());
|
||||||
QSignalSpy streamErrorSpy(stream.get(), &QGrpcStream::errorOccurred);
|
QSignalSpy streamErrorSpy(stream.get(), &QGrpcServerStream::errorOccurred);
|
||||||
QVERIFY(streamErrorSpy.isValid());
|
QVERIFY(streamErrorSpy.isValid());
|
||||||
|
|
||||||
QSignalSpy streamFinishedSpy(stream.get(), &QGrpcStream::finished);
|
QSignalSpy streamFinishedSpy(stream.get(), &QGrpcServerStream::finished);
|
||||||
QObject::connect(stream.get(), &QGrpcStream::messageReceived, this, [&result, stream] {
|
QObject::connect(stream.get(), &QGrpcServerStream::messageReceived, this, [&result, stream] {
|
||||||
SimpleStringMessage ret = stream->read<SimpleStringMessage>();
|
SimpleStringMessage ret = stream->read<SimpleStringMessage>();
|
||||||
result.setTestFieldString(result.testFieldString() + ret.testFieldString());
|
result.setTestFieldString(result.testFieldString() + ret.testFieldString());
|
||||||
});
|
});
|
||||||
|
@ -261,7 +261,7 @@ void QtGrpcClientTest::StreamStringTest()
|
||||||
QCOMPARE_EQ(result.testFieldString(), "Stream1Stream2Stream3Stream4");
|
QCOMPARE_EQ(result.testFieldString(), "Stream1Stream2Stream3Stream4");
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtGrpcClientTest::StreamStringAndAbortTest()
|
void QtGrpcClientTest::ServerStreamStringAndAbortTest()
|
||||||
{
|
{
|
||||||
const int ExpectedMessageCount = 2;
|
const int ExpectedMessageCount = 2;
|
||||||
|
|
||||||
|
@ -271,14 +271,14 @@ void QtGrpcClientTest::StreamStringAndAbortTest()
|
||||||
|
|
||||||
auto stream = _client->streamTestMethodServerStream(request);
|
auto stream = _client->streamTestMethodServerStream(request);
|
||||||
|
|
||||||
QSignalSpy streamFinishedSpy(stream.get(), &QGrpcStream::finished);
|
QSignalSpy streamFinishedSpy(stream.get(), &QGrpcServerStream::finished);
|
||||||
QVERIFY(streamFinishedSpy.isValid());
|
QVERIFY(streamFinishedSpy.isValid());
|
||||||
QSignalSpy streamErrorSpy(stream.get(), &QGrpcStream::errorOccurred);
|
QSignalSpy streamErrorSpy(stream.get(), &QGrpcServerStream::errorOccurred);
|
||||||
QVERIFY(streamErrorSpy.isValid());
|
QVERIFY(streamErrorSpy.isValid());
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
QObject::connect(
|
QObject::connect(
|
||||||
stream.get(), &QGrpcStream::messageReceived, this, [&result, &i, stream] {
|
stream.get(), &QGrpcServerStream::messageReceived, this, [&result, &i, stream] {
|
||||||
SimpleStringMessage ret = stream->read<SimpleStringMessage>();
|
SimpleStringMessage ret = stream->read<SimpleStringMessage>();
|
||||||
result.setTestFieldString(result.testFieldString() + ret.testFieldString());
|
result.setTestFieldString(result.testFieldString() + ret.testFieldString());
|
||||||
if (++i == ExpectedMessageCount)
|
if (++i == ExpectedMessageCount)
|
||||||
|
@ -292,7 +292,7 @@ void QtGrpcClientTest::StreamStringAndAbortTest()
|
||||||
QCOMPARE_EQ(result.testFieldString(), "Stream1Stream2");
|
QCOMPARE_EQ(result.testFieldString(), "Stream1Stream2");
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtGrpcClientTest::StreamStringAndDeferredAbortTest()
|
void QtGrpcClientTest::ServerStreamStringAndDeferredAbortTest()
|
||||||
{
|
{
|
||||||
const int ExpectedMessageCount = 3;
|
const int ExpectedMessageCount = 3;
|
||||||
|
|
||||||
|
@ -302,23 +302,23 @@ void QtGrpcClientTest::StreamStringAndDeferredAbortTest()
|
||||||
|
|
||||||
auto stream = _client->streamTestMethodServerStream(request);
|
auto stream = _client->streamTestMethodServerStream(request);
|
||||||
|
|
||||||
QSignalSpy streamFinishedSpy(stream.get(), &QGrpcStream::finished);
|
QSignalSpy streamFinishedSpy(stream.get(), &QGrpcServerStream::finished);
|
||||||
QVERIFY(streamFinishedSpy.isValid());
|
QVERIFY(streamFinishedSpy.isValid());
|
||||||
|
|
||||||
QSignalSpy streamErrorSpy(stream.get(), &QGrpcStream::errorOccurred);
|
QSignalSpy streamErrorSpy(stream.get(), &QGrpcServerStream::errorOccurred);
|
||||||
QVERIFY(streamErrorSpy.isValid());
|
QVERIFY(streamErrorSpy.isValid());
|
||||||
|
|
||||||
QSignalSpy messageReceivedSpy(stream.get(), &QGrpcStream::messageReceived);
|
QSignalSpy messageReceivedSpy(stream.get(), &QGrpcServerStream::messageReceived);
|
||||||
QVERIFY(messageReceivedSpy.isValid());
|
QVERIFY(messageReceivedSpy.isValid());
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
QObject::connect(
|
QObject::connect(
|
||||||
stream.get(), &QGrpcStream::messageReceived, this, [&result, stream, &i] {
|
stream.get(), &QGrpcServerStream::messageReceived, this, [&result, stream, &i] {
|
||||||
SimpleStringMessage ret = stream->read<SimpleStringMessage>();
|
SimpleStringMessage ret = stream->read<SimpleStringMessage>();
|
||||||
result.setTestFieldString(result.testFieldString() + ret.testFieldString());
|
result.setTestFieldString(result.testFieldString() + ret.testFieldString());
|
||||||
if (++i == ExpectedMessageCount)
|
if (++i == ExpectedMessageCount)
|
||||||
QTimer::singleShot(MessageLatencyThreshold, stream.get(),
|
QTimer::singleShot(MessageLatencyThreshold, stream.get(),
|
||||||
&QGrpcStream::cancel);
|
&QGrpcServerStream::cancel);
|
||||||
});
|
});
|
||||||
|
|
||||||
QTRY_COMPARE_EQ_WITH_TIMEOUT(streamErrorSpy.count(), 1,
|
QTRY_COMPARE_EQ_WITH_TIMEOUT(streamErrorSpy.count(), 1,
|
||||||
|
@ -348,7 +348,7 @@ void QtGrpcClientTest::StreamStringAndGetChangedSignalsTests
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void QtGrpcClientTest::StreamBlobTest()
|
void QtGrpcClientTest::ServerStreamBlobTest()
|
||||||
{
|
{
|
||||||
BlobMessage result;
|
BlobMessage result;
|
||||||
BlobMessage request;
|
BlobMessage request;
|
||||||
|
@ -360,12 +360,12 @@ void QtGrpcClientTest::StreamBlobTest()
|
||||||
|
|
||||||
auto stream = _client->streamTestMethodBlobServerStream(request);
|
auto stream = _client->streamTestMethodBlobServerStream(request);
|
||||||
|
|
||||||
QSignalSpy streamFinishedSpy(stream.get(), &QGrpcStream::finished);
|
QSignalSpy streamFinishedSpy(stream.get(), &QGrpcServerStream::finished);
|
||||||
QVERIFY(streamFinishedSpy.isValid());
|
QVERIFY(streamFinishedSpy.isValid());
|
||||||
QSignalSpy streamErrorSpy(stream.get(), &QGrpcStream::errorOccurred);
|
QSignalSpy streamErrorSpy(stream.get(), &QGrpcServerStream::errorOccurred);
|
||||||
QVERIFY(streamErrorSpy.isValid());
|
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>();
|
BlobMessage ret = stream->read<BlobMessage>();
|
||||||
result.setTestBytes(ret.testBytes());
|
result.setTestBytes(ret.testBytes());
|
||||||
});
|
});
|
||||||
|
@ -438,7 +438,7 @@ void QtGrpcClientTest::StatusMessageClientTest()
|
||||||
QCOMPARE_EQ(status.message(), request.testFieldString());
|
QCOMPARE_EQ(status.message(), request.testFieldString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtGrpcClientTest::StreamAndGetAsyncReplyTest()
|
void QtGrpcClientTest::ServerStreamAndGetAsyncReplyTest()
|
||||||
{
|
{
|
||||||
SimpleStringMessage request;
|
SimpleStringMessage request;
|
||||||
request.setTestFieldString("Some status message");
|
request.setTestFieldString("Some status message");
|
||||||
|
@ -478,7 +478,7 @@ void QtGrpcClientTest::StreamAndGetAsyncReplyTest()
|
||||||
MessageLatencyWithThreshold);
|
MessageLatencyWithThreshold);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtGrpcClientTest::MultipleStreamsTest()
|
void QtGrpcClientTest::MultipleServerStreamsTest()
|
||||||
{
|
{
|
||||||
const int ExpectedMessageCount = 4;
|
const int ExpectedMessageCount = 4;
|
||||||
SimpleStringMessage result;
|
SimpleStringMessage result;
|
||||||
|
@ -489,16 +489,16 @@ void QtGrpcClientTest::MultipleStreamsTest()
|
||||||
// Ensure we're not reusing streams
|
// Ensure we're not reusing streams
|
||||||
QCOMPARE_NE(stream, _client->streamTestMethodServerStream(request));
|
QCOMPARE_NE(stream, _client->streamTestMethodServerStream(request));
|
||||||
|
|
||||||
QSignalSpy streamFinishedSpy(stream.get(), &QGrpcStream::finished);
|
QSignalSpy streamFinishedSpy(stream.get(), &QGrpcServerStream::finished);
|
||||||
QVERIFY(streamFinishedSpy.isValid());
|
QVERIFY(streamFinishedSpy.isValid());
|
||||||
|
|
||||||
QSignalSpy streamErrorSpy(stream.get(), &QGrpcStream::errorOccurred);
|
QSignalSpy streamErrorSpy(stream.get(), &QGrpcServerStream::errorOccurred);
|
||||||
QVERIFY(streamErrorSpy.isValid());
|
QVERIFY(streamErrorSpy.isValid());
|
||||||
|
|
||||||
QSignalSpy steamMessageRecievedSpy(stream.get(), &QGrpcStream::messageReceived);
|
QSignalSpy steamMessageRecievedSpy(stream.get(), &QGrpcServerStream::messageReceived);
|
||||||
QVERIFY(steamMessageRecievedSpy.isValid());
|
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>();
|
SimpleStringMessage ret = stream->read<SimpleStringMessage>();
|
||||||
result.setTestFieldString(result.testFieldString() + ret.testFieldString());
|
result.setTestFieldString(result.testFieldString() + ret.testFieldString());
|
||||||
});
|
});
|
||||||
|
@ -511,7 +511,7 @@ void QtGrpcClientTest::MultipleStreamsTest()
|
||||||
QCOMPARE_EQ(result.testFieldString(), "Stream1Stream2Stream3Stream4");
|
QCOMPARE_EQ(result.testFieldString(), "Stream1Stream2Stream3Stream4");
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtGrpcClientTest::MultipleStreamsCancelTest()
|
void QtGrpcClientTest::MultipleServerStreamsCancelTest()
|
||||||
{
|
{
|
||||||
SimpleStringMessage result;
|
SimpleStringMessage result;
|
||||||
SimpleStringMessage request;
|
SimpleStringMessage request;
|
||||||
|
@ -522,14 +522,14 @@ void QtGrpcClientTest::MultipleStreamsCancelTest()
|
||||||
|
|
||||||
QCOMPARE_NE(stream, streamNext);
|
QCOMPARE_NE(stream, streamNext);
|
||||||
|
|
||||||
QSignalSpy streamFinishedSpy(stream.get(), &QGrpcStream::finished);
|
QSignalSpy streamFinishedSpy(stream.get(), &QGrpcServerStream::finished);
|
||||||
QVERIFY(streamFinishedSpy.isValid());
|
QVERIFY(streamFinishedSpy.isValid());
|
||||||
QSignalSpy streamErrorSpy(stream.get(), &QGrpcStream::errorOccurred);
|
QSignalSpy streamErrorSpy(stream.get(), &QGrpcServerStream::errorOccurred);
|
||||||
QVERIFY(streamErrorSpy.isValid());
|
QVERIFY(streamErrorSpy.isValid());
|
||||||
|
|
||||||
QSignalSpy streamNextFinishedSpy(streamNext.get(), &QGrpcStream::finished);
|
QSignalSpy streamNextFinishedSpy(streamNext.get(), &QGrpcServerStream::finished);
|
||||||
QVERIFY(streamNextFinishedSpy.isValid());
|
QVERIFY(streamNextFinishedSpy.isValid());
|
||||||
QSignalSpy streamNextErrorSpy(streamNext.get(), &QGrpcStream::errorOccurred);
|
QSignalSpy streamNextErrorSpy(streamNext.get(), &QGrpcServerStream::errorOccurred);
|
||||||
QVERIFY(streamNextErrorSpy.isValid());
|
QVERIFY(streamNextErrorSpy.isValid());
|
||||||
|
|
||||||
streamNext->cancel();
|
streamNext->cancel();
|
||||||
|
@ -547,14 +547,14 @@ void QtGrpcClientTest::MultipleStreamsCancelTest()
|
||||||
|
|
||||||
QCOMPARE_NE(stream, streamNext);
|
QCOMPARE_NE(stream, streamNext);
|
||||||
|
|
||||||
QSignalSpy otherStreamFinishedSpy(stream.get(), &QGrpcStream::finished);
|
QSignalSpy otherStreamFinishedSpy(stream.get(), &QGrpcServerStream::finished);
|
||||||
QVERIFY(streamFinishedSpy.isValid());
|
QVERIFY(streamFinishedSpy.isValid());
|
||||||
QSignalSpy otherStreamErrorSpy(stream.get(), &QGrpcStream::errorOccurred);
|
QSignalSpy otherStreamErrorSpy(stream.get(), &QGrpcServerStream::errorOccurred);
|
||||||
QVERIFY(otherStreamErrorSpy.isValid());
|
QVERIFY(otherStreamErrorSpy.isValid());
|
||||||
|
|
||||||
QSignalSpy otherStreamNextFinishedSpy(streamNext.get(), &QGrpcStream::finished);
|
QSignalSpy otherStreamNextFinishedSpy(streamNext.get(), &QGrpcServerStream::finished);
|
||||||
QVERIFY(streamNextFinishedSpy.isValid());
|
QVERIFY(streamNextFinishedSpy.isValid());
|
||||||
QSignalSpy otherStreamNextErrorSpy(streamNext.get(), &QGrpcStream::errorOccurred);
|
QSignalSpy otherStreamNextErrorSpy(streamNext.get(), &QGrpcServerStream::errorOccurred);
|
||||||
QVERIFY(otherStreamNextErrorSpy.isValid());
|
QVERIFY(otherStreamNextErrorSpy.isValid());
|
||||||
|
|
||||||
stream->cancel();
|
stream->cancel();
|
||||||
|
@ -633,7 +633,7 @@ void QtGrpcClientTest::StringAsyncThreadTest()
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtGrpcClientTest::StreamStringThreadTest()
|
void QtGrpcClientTest::ServerStreamStringThreadTest()
|
||||||
{
|
{
|
||||||
SimpleStringMessage result;
|
SimpleStringMessage result;
|
||||||
SimpleStringMessage request;
|
SimpleStringMessage request;
|
||||||
|
@ -646,7 +646,7 @@ void QtGrpcClientTest::StreamStringThreadTest()
|
||||||
const std::unique_ptr<QThread> thread(QThread::create([&] {
|
const std::unique_ptr<QThread> thread(QThread::create([&] {
|
||||||
QEventLoop waiter;
|
QEventLoop waiter;
|
||||||
auto stream = _client->streamTestMethodServerStream(request);
|
auto stream = _client->streamTestMethodServerStream(request);
|
||||||
QObject::connect(stream.get(), &QGrpcStream::messageReceived, &waiter,
|
QObject::connect(stream.get(), &QGrpcServerStream::messageReceived, &waiter,
|
||||||
[&result, &i, &waiter, stream] {
|
[&result, &i, &waiter, stream] {
|
||||||
SimpleStringMessage ret = stream->read<SimpleStringMessage>();
|
SimpleStringMessage ret = stream->read<SimpleStringMessage>();
|
||||||
result.setTestFieldString(result.testFieldString()
|
result.setTestFieldString(result.testFieldString()
|
||||||
|
@ -664,11 +664,11 @@ void QtGrpcClientTest::StreamStringThreadTest()
|
||||||
QTRY_VERIFY(result.testFieldString().isEmpty());
|
QTRY_VERIFY(result.testFieldString().isEmpty());
|
||||||
QTRY_VERIFY(qvariant_cast<QGrpcStatus>(clientErrorSpy.at(0).first())
|
QTRY_VERIFY(qvariant_cast<QGrpcStatus>(clientErrorSpy.at(0).first())
|
||||||
.message()
|
.message()
|
||||||
.startsWith("QAbstractGrpcClient::startStream is called from a "
|
.startsWith("QAbstractGrpcClient::startServerStream is called from a "
|
||||||
"different thread."));
|
"different thread."));
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtGrpcClientTest::StreamCancelWhileErrorTimeoutTest()
|
void QtGrpcClientTest::ServerStreamCancelWhileErrorTimeoutTest()
|
||||||
{
|
{
|
||||||
SimpleStringMessage result;
|
SimpleStringMessage result;
|
||||||
SimpleStringMessage request;
|
SimpleStringMessage request;
|
||||||
|
@ -676,9 +676,9 @@ void QtGrpcClientTest::StreamCancelWhileErrorTimeoutTest()
|
||||||
|
|
||||||
auto stream = _client->streamTestMethodServerStream(request);
|
auto stream = _client->streamTestMethodServerStream(request);
|
||||||
|
|
||||||
QSignalSpy streamFinishedSpy(stream.get(), &QGrpcStream::finished);
|
QSignalSpy streamFinishedSpy(stream.get(), &QGrpcServerStream::finished);
|
||||||
QVERIFY(streamFinishedSpy.isValid());
|
QVERIFY(streamFinishedSpy.isValid());
|
||||||
QSignalSpy streamErrorSpy(stream.get(), &QGrpcStream::errorOccurred);
|
QSignalSpy streamErrorSpy(stream.get(), &QGrpcServerStream::errorOccurred);
|
||||||
QVERIFY(streamErrorSpy.isValid());
|
QVERIFY(streamErrorSpy.isValid());
|
||||||
|
|
||||||
stream->cancel();
|
stream->cancel();
|
||||||
|
@ -765,7 +765,7 @@ void QtGrpcClientTest::CallDeadlineTest()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtGrpcClientTest::StreamDeadlineTest_data()
|
void QtGrpcClientTest::ServerStreamDeadlineTest_data()
|
||||||
{
|
{
|
||||||
const int ExpectedMessageCount = 4;
|
const int ExpectedMessageCount = 4;
|
||||||
QTest::addColumn<std::chrono::milliseconds>("timeout");
|
QTest::addColumn<std::chrono::milliseconds>("timeout");
|
||||||
|
@ -781,7 +781,7 @@ void QtGrpcClientTest::StreamDeadlineTest_data()
|
||||||
<< ExpectedMessageCount;
|
<< ExpectedMessageCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtGrpcClientTest::StreamDeadlineTest()
|
void QtGrpcClientTest::ServerStreamDeadlineTest()
|
||||||
{
|
{
|
||||||
QFETCH(const std::chrono::milliseconds, timeout);
|
QFETCH(const std::chrono::milliseconds, timeout);
|
||||||
QFETCH(const int, ExpectedMessageCount);
|
QFETCH(const int, ExpectedMessageCount);
|
||||||
|
@ -794,13 +794,13 @@ void QtGrpcClientTest::StreamDeadlineTest()
|
||||||
|
|
||||||
auto stream = _client->streamTestMethodServerStream(request, opt);
|
auto stream = _client->streamTestMethodServerStream(request, opt);
|
||||||
|
|
||||||
QSignalSpy streamErrorSpy(stream.get(), &QGrpcStream::errorOccurred);
|
QSignalSpy streamErrorSpy(stream.get(), &QGrpcServerStream::errorOccurred);
|
||||||
QVERIFY(streamErrorSpy.isValid());
|
QVERIFY(streamErrorSpy.isValid());
|
||||||
QSignalSpy streamFinishedSpy(stream.get(), &QGrpcStream::finished);
|
QSignalSpy streamFinishedSpy(stream.get(), &QGrpcServerStream::finished);
|
||||||
QVERIFY(streamFinishedSpy.isValid());
|
QVERIFY(streamFinishedSpy.isValid());
|
||||||
|
|
||||||
SimpleStringMessage result;
|
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>();
|
SimpleStringMessage ret = stream->read<SimpleStringMessage>();
|
||||||
result.setTestFieldString(result.testFieldString() + ret.testFieldString());
|
result.setTestFieldString(result.testFieldString() + ret.testFieldString());
|
||||||
});
|
});
|
||||||
|
|
|
@ -29,9 +29,9 @@ void Client::testMethod(const qtgrpc::tests::SimpleStringMessage &arg, const QOb
|
||||||
}, Qt::SingleShotConnection);
|
}, 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
|
} // namespace TestService
|
||||||
|
|
|
@ -29,7 +29,7 @@ public:
|
||||||
std::shared_ptr<QGrpcCallReply> testMethod(const qtgrpc::tests::SimpleStringMessage &arg, const QGrpcCallOptions &options = {});
|
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 = {});
|
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);
|
}, 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
|
} // namespace TestService
|
||||||
|
|
|
@ -29,7 +29,7 @@ public:
|
||||||
std::shared_ptr<QGrpcCallReply> testMethod(const qtgrpc::tests::SimpleStringMessage &arg, const QGrpcCallOptions &options = {});
|
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 = {});
|
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