Skip to content

Commit e397bbf

Browse files
authored
YMQ: fix GetQueueAttributesResult builder (#9751)
1 parent 9f848dd commit e397bbf

File tree

2 files changed

+85
-77
lines changed

2 files changed

+85
-77
lines changed

ydb/core/http_proxy/ut/http_proxy_ut.h

+51-9
Original file line numberDiff line numberDiff line change
@@ -1712,16 +1712,58 @@ Y_UNIT_TEST_SUITE(TestHttpProxy) {
17121712
TString resultQueueUrl = GetByPath<TString>(json, "QueueUrl");
17131713
UNIT_ASSERT(resultQueueUrl.EndsWith("ExampleQueueName"));
17141714

1715-
NJson::TJsonValue getQueueAttributes;
1716-
getQueueAttributes["QueueUrl"] = resultQueueUrl;
1717-
NJson::TJsonArray attributeNames = {"DelaySeconds"};
1718-
getQueueAttributes["AttributeNames"] = attributeNames;
1715+
{
1716+
NJson::TJsonValue getQueueAttributes;
1717+
getQueueAttributes["QueueUrl"] = resultQueueUrl;
1718+
NJson::TJsonArray attributeNames = {"DelaySeconds"};
1719+
getQueueAttributes["AttributeNames"] = attributeNames;
17191720

1720-
res = SendHttpRequest("/Root", "AmazonSQS.GetQueueAttributes", std::move(getQueueAttributes), FormAuthorizationStr("ru-central1"));
1721-
UNIT_ASSERT_VALUES_EQUAL(res.HttpCode, 200);
1722-
NJson::TJsonValue resultJson;
1723-
UNIT_ASSERT(NJson::ReadJsonTree(res.Body, &resultJson));
1724-
UNIT_ASSERT_VALUES_EQUAL(resultJson["Attributes"]["DelaySeconds"], "1");
1721+
res = SendHttpRequest("/Root", "AmazonSQS.GetQueueAttributes", std::move(getQueueAttributes), FormAuthorizationStr("ru-central1"));
1722+
UNIT_ASSERT_VALUES_EQUAL(res.HttpCode, 200);
1723+
NJson::TJsonValue resultJson;
1724+
UNIT_ASSERT(NJson::ReadJsonTree(res.Body, &resultJson));
1725+
UNIT_ASSERT_VALUES_EQUAL(resultJson["Attributes"]["DelaySeconds"], "1");
1726+
}
1727+
1728+
{
1729+
NJson::TJsonValue getQueueAttributes;
1730+
getQueueAttributes["QueueUrl"] = resultQueueUrl;
1731+
NJson::TJsonArray attributeNames = {
1732+
"ApproximateNumberOfMessages",
1733+
"ApproximateNumberOfMessagesDelayed",
1734+
"ApproximateNumberOfMessagesNotVisible",
1735+
"CreatedTimestamp",
1736+
"DelaySeconds",
1737+
"MaximumMessageSize",
1738+
"MessageRetentionPeriod",
1739+
"ReceiveMessageWaitTimeSeconds",
1740+
"RedrivePolicy",
1741+
"VisibilityTimeout",
1742+
"FifoQueue",
1743+
"ContentBasedDeduplication",
1744+
"QueueArn"
1745+
};
1746+
getQueueAttributes["AttributeNames"] = attributeNames;
1747+
1748+
res = SendHttpRequest("/Root", "AmazonSQS.GetQueueAttributes", std::move(getQueueAttributes), FormAuthorizationStr("ru-central1"));
1749+
UNIT_ASSERT_VALUES_EQUAL(res.HttpCode, 200);
1750+
NJson::TJsonValue resultJson;
1751+
UNIT_ASSERT(NJson::ReadJsonTree(res.Body, &resultJson));
1752+
UNIT_ASSERT_VALUES_EQUAL(resultJson["Attributes"]["DelaySeconds"], "1");
1753+
}
1754+
1755+
{
1756+
NJson::TJsonValue getQueueAttributes;
1757+
getQueueAttributes["QueueUrl"] = resultQueueUrl;
1758+
NJson::TJsonArray attributeNames = {"All"};
1759+
getQueueAttributes["AttributeNames"] = attributeNames;
1760+
1761+
res = SendHttpRequest("/Root", "AmazonSQS.GetQueueAttributes", std::move(getQueueAttributes), FormAuthorizationStr("ru-central1"));
1762+
UNIT_ASSERT_VALUES_EQUAL(res.HttpCode, 200);
1763+
NJson::TJsonValue resultJson;
1764+
UNIT_ASSERT(NJson::ReadJsonTree(res.Body, &resultJson));
1765+
UNIT_ASSERT_VALUES_EQUAL(resultJson["Attributes"]["DelaySeconds"], "1");
1766+
}
17251767
}
17261768

17271769
Y_UNIT_TEST_F(TestListQueues, THttpProxyTestMock) {

ydb/services/ymq/ymq_proxy.cpp

+34-68
Original file line numberDiff line numberDiff line change
@@ -449,75 +449,41 @@ namespace NKikimr::NYmq::V1 {
449449

450450
Ydb::Ymq::V1::GetQueueAttributesResult GetResult(const NKikimrClient::TSqsResponse& resp) override {
451451
Ydb::Ymq::V1::GetQueueAttributesResult result;
452-
for (const auto& attributeName : Attributes) {
453-
if (attributeName == APPROXIMATE_NUMBER_OF_MESSAGES) {
454-
AddAttribute(
455-
result,
456-
APPROXIMATE_NUMBER_OF_MESSAGES,
457-
GetResponse(resp).GetApproximateNumberOfMessages()
458-
);
459-
} else if (attributeName == APPROXIMATE_NUMBER_OF_MESSAGES_DELAYED) {
460-
AddAttribute(
461-
result,
462-
APPROXIMATE_NUMBER_OF_MESSAGES_DELAYED,
463-
GetResponse(resp).GetApproximateNumberOfMessagesDelayed()
464-
);
465-
} else if (attributeName == CREATED_TIMESTAMP) {
466-
AddAttribute(
467-
result,
468-
CREATED_TIMESTAMP,
469-
GetResponse(resp).GetCreatedTimestamp()
470-
);
471-
} else if (attributeName == DELAY_SECONDS) {
472-
AddAttribute(
473-
result,
474-
DELAY_SECONDS,
475-
GetResponse(resp).GetDelaySeconds()
476-
);
477-
} else if (attributeName == LAST_MODIFIED_TIMESTAMP) {
478-
AddAttribute(
479-
result,
480-
LAST_MODIFIED_TIMESTAMP,
481-
GetResponse(resp).GetLastModifiedTimestamp()
482-
);
483-
} else if (attributeName == MAXIMUM_MESSAGE_SIZE) {
484-
AddAttribute(
485-
result,
486-
MAXIMUM_MESSAGE_SIZE,
487-
GetResponse(resp).GetMaximumMessageSize()
488-
);
489-
} else if (attributeName == MESSAGE_RETENTION_PERIOD) {
490-
AddAttribute(
491-
result,
492-
MESSAGE_RETENTION_PERIOD,
493-
GetResponse(resp).GetMessageRetentionPeriod()
494-
);
495-
} else if (attributeName == QUEUE_ARN) {
496-
AddAttribute(
497-
result,
498-
QUEUE_ARN,
499-
GetResponse(resp).GetQueueArn()
500-
);
501-
} else if (attributeName == RECEIVE_MESSAGE_WAIT_TIME_SECONDS) {
502-
AddAttribute(
503-
result,
504-
RECEIVE_MESSAGE_WAIT_TIME_SECONDS,
505-
GetResponse(resp).GetReceiveMessageWaitTimeSeconds()
506-
);
507-
} else if (attributeName == VISIBILITY_TIMEOUT) {
508-
AddAttribute(
509-
result,
510-
VISIBILITY_TIMEOUT,
511-
GetResponse(resp).GetVisibilityTimeout()
512-
);
513-
} else if (attributeName == REDRIVE_POLICY) {
514-
AddAttribute(
515-
result,
516-
REDRIVE_POLICY,
517-
GetResponse(resp).GetRedrivePolicy()
518-
);
519-
}
452+
const auto& attrs = resp.GetGetQueueAttributes();
453+
if (attrs.HasApproximateNumberOfMessages()) {
454+
AddAttribute(result, APPROXIMATE_NUMBER_OF_MESSAGES, attrs.GetApproximateNumberOfMessages());
455+
}
456+
if (attrs.HasApproximateNumberOfMessagesDelayed()) {
457+
AddAttribute(result, APPROXIMATE_NUMBER_OF_MESSAGES_DELAYED, attrs.GetApproximateNumberOfMessagesDelayed());
458+
}
459+
if (attrs.HasCreatedTimestamp()) {
460+
AddAttribute(result, CREATED_TIMESTAMP, attrs.GetCreatedTimestamp());
461+
}
462+
if (attrs.HasDelaySeconds()) {
463+
AddAttribute(result, DELAY_SECONDS, attrs.GetDelaySeconds());
464+
}
465+
if (attrs.HasLastModifiedTimestamp()) {
466+
AddAttribute(result, LAST_MODIFIED_TIMESTAMP, attrs.GetLastModifiedTimestamp());
467+
}
468+
if (attrs.HasMaximumMessageSize()) {
469+
AddAttribute(result, MAXIMUM_MESSAGE_SIZE, attrs.GetMaximumMessageSize());
520470
}
471+
if (attrs.HasMessageRetentionPeriod()) {
472+
AddAttribute(result, MESSAGE_RETENTION_PERIOD, attrs.GetMessageRetentionPeriod());
473+
}
474+
if (attrs.HasQueueArn()) {
475+
AddAttribute(result, QUEUE_ARN, attrs.GetQueueArn());
476+
}
477+
if (attrs.HasReceiveMessageWaitTimeSeconds()) {
478+
AddAttribute(result, RECEIVE_MESSAGE_WAIT_TIME_SECONDS, attrs.GetReceiveMessageWaitTimeSeconds());
479+
}
480+
if (attrs.HasVisibilityTimeout()) {
481+
AddAttribute(result, VISIBILITY_TIMEOUT, attrs.GetVisibilityTimeout());
482+
}
483+
if (attrs.HasRedrivePolicy()) {
484+
AddAttribute(result, REDRIVE_POLICY, attrs.GetRedrivePolicy());
485+
}
486+
521487
return result;
522488
}
523489

0 commit comments

Comments
 (0)