Skip to content

Commit f4d48a8

Browse files
authored
YMQ: Add more tests for Queue methods (#10203)
1 parent 8599b38 commit f4d48a8

File tree

7 files changed

+1050
-807
lines changed

7 files changed

+1050
-807
lines changed

ydb/core/http_proxy/ut/datastreams_fixture.h

Lines changed: 106 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <ydb/library/folder_service/folder_service.h>
3737
#include <ydb/core/ymq/actor/serviceid.h>
3838

39+
#include <thread>
3940

4041
using TJMap = NJson::TJsonValue::TMapType;
4142
using TJVector = NJson::TJsonValue::TArray;
@@ -335,6 +336,107 @@ class THttpProxyTestMock : public NUnitTest::TBaseFixture {
335336
return {httpCode, "", ""};
336337
}
337338

339+
NJson::TJsonMap CreateQueue(NJson::TJsonMap request, ui32 expectedHttpCode = 200) {
340+
auto res = SendHttpRequest("/Root", "AmazonSQS.CreateQueue", request, FormAuthorizationStr("ru-central1"));
341+
UNIT_ASSERT_VALUES_EQUAL(res.HttpCode, expectedHttpCode);
342+
NJson::TJsonMap json;
343+
UNIT_ASSERT(NJson::ReadJsonTree(res.Body, &json, true));
344+
if (expectedHttpCode == 200) {
345+
UNIT_ASSERT(GetByPath<TString>(json, "QueueUrl").EndsWith(GetByPath<TString>(request, "QueueName")));
346+
}
347+
return json;
348+
}
349+
350+
NJson::TJsonMap DeleteQueue(NJson::TJsonMap request, ui32 expectedHttpCode = 200) {
351+
auto res = SendHttpRequest("/Root", "AmazonSQS.DeleteQueue", request, FormAuthorizationStr("ru-central1"));
352+
UNIT_ASSERT_VALUES_EQUAL(res.HttpCode, expectedHttpCode);
353+
NJson::TJsonMap json;
354+
UNIT_ASSERT(NJson::ReadJsonTree(res.Body, &json));
355+
return json;
356+
}
357+
358+
NJson::TJsonMap GetQueueAttributes(NJson::TJsonMap request, ui32 expectedHttpCode = 200) {
359+
auto res = SendHttpRequest("/Root", "AmazonSQS.GetQueueAttributes", request, FormAuthorizationStr("ru-central1"));
360+
UNIT_ASSERT_VALUES_EQUAL(res.HttpCode, expectedHttpCode);
361+
NJson::TJsonMap json;
362+
UNIT_ASSERT(NJson::ReadJsonTree(res.Body, &json));
363+
return json;
364+
}
365+
366+
NJson::TJsonMap SendMessage(NJson::TJsonMap request, ui32 expectedHttpCode = 200) {
367+
auto res = SendHttpRequest("/Root", "AmazonSQS.SendMessage", request, FormAuthorizationStr("ru-central1"));
368+
UNIT_ASSERT_VALUES_EQUAL(res.HttpCode, expectedHttpCode);
369+
NJson::TJsonMap json;
370+
UNIT_ASSERT(NJson::ReadJsonTree(res.Body, &json));
371+
return json;
372+
}
373+
374+
NJson::TJsonMap ReceiveMessage(NJson::TJsonMap request, ui32 expectedHttpCode = 200) {
375+
auto res = SendHttpRequest("/Root", "AmazonSQS.ReceiveMessage", request, FormAuthorizationStr("ru-central1"));
376+
UNIT_ASSERT_VALUES_EQUAL(res.HttpCode, expectedHttpCode);
377+
NJson::TJsonMap json;
378+
UNIT_ASSERT(NJson::ReadJsonTree(res.Body, &json));
379+
return json;
380+
}
381+
382+
NJson::TJsonMap DeleteMessage(NJson::TJsonMap request, ui32 expectedHttpCode = 200) {
383+
auto res = SendHttpRequest("/Root", "AmazonSQS.DeleteMessage", request, FormAuthorizationStr("ru-central1"));
384+
UNIT_ASSERT_VALUES_EQUAL(res.HttpCode, expectedHttpCode);
385+
NJson::TJsonMap json;
386+
UNIT_ASSERT(NJson::ReadJsonTree(res.Body, &json));
387+
return json;
388+
}
389+
390+
NJson::TJsonMap GetQueueUrl(NJson::TJsonMap request, ui32 expectedHttpCode = 200) {
391+
auto res = SendHttpRequest("/Root", "AmazonSQS.GetQueueUrl", request, FormAuthorizationStr("ru-central1"));
392+
UNIT_ASSERT_VALUES_EQUAL(res.HttpCode, expectedHttpCode);
393+
NJson::TJsonMap json;
394+
UNIT_ASSERT(NJson::ReadJsonTree(res.Body, &json));
395+
return json;
396+
}
397+
398+
NJson::TJsonMap ListQueues(NJson::TJsonMap request, ui32 expectedHttpCode = 200) {
399+
auto res = SendHttpRequest("/Root", "AmazonSQS.ListQueues", request, FormAuthorizationStr("ru-central1"));
400+
UNIT_ASSERT_VALUES_EQUAL(res.HttpCode, expectedHttpCode);
401+
NJson::TJsonMap json;
402+
UNIT_ASSERT(NJson::ReadJsonTree(res.Body, &json));
403+
return json;
404+
}
405+
406+
NJson::TJsonMap PurgeQueue(NJson::TJsonMap request, ui32 expectedHttpCode = 200) {
407+
auto res = SendHttpRequest("/Root", "AmazonSQS.PurgeQueue", request, FormAuthorizationStr("ru-central1"));
408+
UNIT_ASSERT_VALUES_EQUAL(res.HttpCode, expectedHttpCode);
409+
NJson::TJsonMap json;
410+
UNIT_ASSERT(NJson::ReadJsonTree(res.Body, &json));
411+
return json;
412+
}
413+
414+
NJson::TJsonMap SetQueueAttributes(NJson::TJsonMap request, ui32 expectedHttpCode = 200) {
415+
auto res = SendHttpRequest("/Root", "AmazonSQS.SetQueueAttributes", request, FormAuthorizationStr("ru-central1"));
416+
UNIT_ASSERT_VALUES_EQUAL(res.HttpCode, expectedHttpCode);
417+
NJson::TJsonMap json;
418+
UNIT_ASSERT(NJson::ReadJsonTree(res.Body, &json));
419+
return json;
420+
}
421+
422+
bool WaitQueueAttributes(TString queueUrl, size_t retries, std::function<bool (NJson::TJsonMap json)> predicate) {
423+
for (size_t i = 0; i < retries; ++i) {
424+
auto json = GetQueueAttributes({
425+
{"QueueUrl", queueUrl},
426+
{"AttributeNames", NJson::TJsonArray{"All"}}
427+
});
428+
429+
if (predicate(json)) {
430+
return true;
431+
}
432+
433+
if (i + 1 < retries) {
434+
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
435+
}
436+
}
437+
return false;
438+
}
439+
338440
private:
339441
TMaybe<NYdb::TResultSet> RunYqlDataQuery(TString query) {
340442
TString endpoint = TStringBuilder() << "localhost:" << KikimrGrpcPort;
@@ -476,7 +578,7 @@ class THttpProxyTestMock : public NUnitTest::TBaseFixture {
476578
);
477579

478580
client.MkDir("/Root/SQS", ".FIFO");
479-
client.CreateTable("/Root/SQS/.FIFO",
581+
client.CreateTable("/Root/SQS/.FIFO",
480582
"Name: \"Messages\""
481583
"Columns { Name: \"QueueIdNumberHash\" Type: \"Uint64\"}"
482584
"Columns { Name: \"QueueIdNumber\" Type: \"Uint64\"}"
@@ -536,7 +638,7 @@ class THttpProxyTestMock : public NUnitTest::TBaseFixture {
536638
"KeyColumnNames: [\"Account\", \"QueueName\", \"EventType\"]"
537639
);
538640

539-
auto stateTableCommon =
641+
auto stateTableCommon =
540642
"Name: \"State\""
541643
"Columns { Name: \"QueueIdNumberHash\" Type: \"Uint64\"}"
542644
"Columns { Name: \"QueueIdNumber\" Type: \"Uint64\"}"
@@ -580,7 +682,7 @@ class THttpProxyTestMock : public NUnitTest::TBaseFixture {
580682
"KeyColumnNames: [\"QueueIdNumberAndShardHash\", \"QueueIdNumber\", \"Shard\", \"Offset\"]"
581683
);
582684

583-
auto sentTimestampIdxCommonColumns=
685+
auto sentTimestampIdxCommonColumns=
584686
"Columns { Name: \"QueueIdNumberAndShardHash\" Type: \"Uint64\"}"
585687
"Columns { Name: \"QueueIdNumber\" Type: \"Uint64\"}"
586688
"Columns { Name: \"Shard\" Type: \"Uint32\"}"
@@ -699,7 +801,7 @@ class THttpProxyTestMock : public NUnitTest::TBaseFixture {
699801
folderServiceConfig.SetEnable(false);
700802
actorId = as->Register(NKikimr::NFolderService::CreateFolderServiceActor(folderServiceConfig, "cloud4"));
701803
as->RegisterLocalService(NFolderService::FolderServiceActorId(), actorId);
702-
804+
703805
actorId = as->Register(NKikimr::NFolderService::CreateFolderServiceActor(folderServiceConfig, "cloud4"));
704806
as->RegisterLocalService(NSQS::MakeSqsFolderServiceID(), actorId);
705807

ydb/core/http_proxy/ut/inside_ydb_ut/ya.make

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ PEERDIR(
2020
)
2121

2222
SRCS(
23-
../http_proxy_ut.cpp
23+
../kinesis_ut.cpp
24+
../ymq_ut.cpp
2425
inside_ydb_ut.cpp
2526
)
2627

ydb/core/http_proxy/ut/http_proxy_ut.cpp renamed to ydb/core/http_proxy/ut/kinesis_ut.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,4 @@ void compareJsons(ui16 port, const TString& query, const TString& referenceFile)
127127

128128
}
129129

130-
#include "http_proxy_ut.h"
130+
#include "kinesis_ut.h"

0 commit comments

Comments
 (0)