@@ -1665,7 +1665,7 @@ Y_UNIT_TEST_SUITE(TestHttpProxy) {
1665
1665
1666
1666
Y_UNIT_TEST_F (TestReceiveMessage, THttpProxyTestMock) {
1667
1667
auto createQueueReq = CreateSqsCreateQueueRequest ();
1668
- auto res = SendHttpRequest (" /Root" , " AmazonSQS.CreateQueue" , std::move ( createQueueReq) , FormAuthorizationStr (" ru-central1" ));
1668
+ auto res = SendHttpRequest (" /Root" , " AmazonSQS.CreateQueue" , createQueueReq, FormAuthorizationStr (" ru-central1" ));
1669
1669
UNIT_ASSERT_VALUES_EQUAL (res.HttpCode , 200 );
1670
1670
NJson::TJsonValue json;
1671
1671
UNIT_ASSERT (NJson::ReadJsonTree (res.Body , &json));
@@ -1674,29 +1674,110 @@ Y_UNIT_TEST_SUITE(TestHttpProxy) {
1674
1674
1675
1675
NJson::TJsonValue sendMessageReq;
1676
1676
sendMessageReq[" QueueUrl" ] = resultQueueUrl;
1677
- auto body = " MessageBody-0" ;
1678
- sendMessageReq[" MessageBody" ] = body;
1679
- sendMessageReq[" MessageBody" ] = body;
1677
+ auto body0 = " MessageBody-0" ;
1678
+ sendMessageReq[" MessageBody" ] = body0;
1680
1679
1681
- res = SendHttpRequest (" /Root" , " AmazonSQS.SendMessage" , std::move ( sendMessageReq) , FormAuthorizationStr (" ru-central1" ));
1680
+ res = SendHttpRequest (" /Root" , " AmazonSQS.SendMessage" , sendMessageReq, FormAuthorizationStr (" ru-central1" ));
1682
1681
UNIT_ASSERT (NJson::ReadJsonTree (res.Body , &json));
1683
1682
UNIT_ASSERT (!GetByPath<TString>(json, " MD5OfMessageBody" ).empty ());
1684
1683
UNIT_ASSERT_VALUES_EQUAL (res.HttpCode , 200 );
1685
1684
1685
+ NJson::TJsonValue receiveMessageReq;
1686
+ receiveMessageReq[" QueueUrl" ] = resultQueueUrl;
1686
1687
for (int i = 0 ; i < 20 ; ++i) {
1687
- NJson::TJsonValue receiveMessageReq;
1688
- receiveMessageReq[" QueueUrl" ] = resultQueueUrl;
1689
- res = SendHttpRequest (" /Root" , " AmazonSQS.ReceiveMessage" , std::move (receiveMessageReq), FormAuthorizationStr (" ru-central1" ));
1690
- if (res.Body != TString (" {}" )) {
1691
- break ;;
1688
+ res = SendHttpRequest (" /Root" , " AmazonSQS.ReceiveMessage" , receiveMessageReq, FormAuthorizationStr (" ru-central1" ));
1689
+ if (res.Body != " {}" ) {
1690
+ break ;
1692
1691
}
1693
1692
std::this_thread::sleep_for (std::chrono::milliseconds (1000 ));
1694
1693
}
1695
1694
1696
1695
UNIT_ASSERT (NJson::ReadJsonTree (res.Body , &json));
1697
1696
UNIT_ASSERT_VALUES_EQUAL (res.HttpCode , 200 );
1698
1697
UNIT_ASSERT_VALUES_EQUAL (json[" Messages" ].GetArray ().size (), 1 );
1699
- UNIT_ASSERT_VALUES_EQUAL (json[" Messages" ][0 ][" Body" ], body);
1698
+ UNIT_ASSERT_VALUES_EQUAL (json[" Messages" ][0 ][" Body" ], body0);
1699
+ }
1700
+
1701
+ Y_UNIT_TEST_F (TestReceiveMessageWithAttributes, THttpProxyTestMock) {
1702
+ // Test if we process AttributeNames, MessageSystemAttributeNames, MessageAttributeNames correctly.
1703
+
1704
+ auto createQueueReq = CreateSqsCreateQueueRequest ();
1705
+ auto res = SendHttpRequest (" /Root" , " AmazonSQS.CreateQueue" , createQueueReq, FormAuthorizationStr (" ru-central1" ));
1706
+ UNIT_ASSERT_VALUES_EQUAL (res.HttpCode , 200 );
1707
+ NJson::TJsonValue json;
1708
+ UNIT_ASSERT (NJson::ReadJsonTree (res.Body , &json));
1709
+ TString resultQueueUrl = GetByPath<TString>(json, " QueueUrl" );
1710
+ UNIT_ASSERT (resultQueueUrl.EndsWith (" ExampleQueueName" ));
1711
+
1712
+ auto sendMessage = [this , resultQueueUrl](const TString& body) {
1713
+ NJson::TJsonValue sendMessageReq;
1714
+ sendMessageReq[" QueueUrl" ] = resultQueueUrl;
1715
+ sendMessageReq[" MessageBody" ] = body;
1716
+
1717
+ auto res = SendHttpRequest (" /Root" , " AmazonSQS.SendMessage" , sendMessageReq, FormAuthorizationStr (" ru-central1" ));
1718
+ NJson::TJsonValue json;
1719
+ UNIT_ASSERT (NJson::ReadJsonTree (res.Body , &json));
1720
+ UNIT_ASSERT (!GetByPath<TString>(json, " MD5OfMessageBody" ).empty ());
1721
+ UNIT_ASSERT_VALUES_EQUAL (res.HttpCode , 200 );
1722
+ };
1723
+
1724
+ TString body = " MessageBody-0" ;
1725
+ sendMessage (body);
1726
+
1727
+ auto receiveMessage = [this ](NJson::TJsonValue request, const TString& expectedBody) -> NJson::TJsonValue {
1728
+ request[" VisibilityTimeout" ] = 0 ; // Keep the message visible for next ReceiveMessage requests.
1729
+ THttpResult res;
1730
+ for (int i = 0 ; i < 20 ; ++i) {
1731
+ res = SendHttpRequest (" /Root" , " AmazonSQS.ReceiveMessage" , request, FormAuthorizationStr (" ru-central1" ));
1732
+ if (res.Body != " {}" ) {
1733
+ break ;
1734
+ }
1735
+ std::this_thread::sleep_for (std::chrono::milliseconds (1000 ));
1736
+ }
1737
+
1738
+ NJson::TJsonValue json;
1739
+ UNIT_ASSERT (NJson::ReadJsonTree (res.Body , &json));
1740
+ UNIT_ASSERT_VALUES_EQUAL (res.HttpCode , 200 );
1741
+ UNIT_ASSERT_VALUES_EQUAL (json[" Messages" ].GetArray ().size (), 1 );
1742
+ UNIT_ASSERT_VALUES_EQUAL (json[" Messages" ][0 ][" Body" ], expectedBody);
1743
+ return json;
1744
+ };
1745
+
1746
+ {
1747
+ // Request SentTimestamp message system attribute using deprecated AttributeNames field.
1748
+ NJson::TJsonValue receiveMessageReq;
1749
+ receiveMessageReq[" QueueUrl" ] = resultQueueUrl;
1750
+ receiveMessageReq[" AttributeNames" ] = NJson::TJsonArray{" SentTimestamp" };
1751
+ json = receiveMessage (receiveMessageReq, body);
1752
+ UNIT_ASSERT (!json[" Messages" ][0 ][" Attributes" ][" SentTimestamp" ].GetString ().empty ());
1753
+ }
1754
+
1755
+ {
1756
+ // Request SentTimestamp message system attribute using MessageSystemAttributeNames field.
1757
+ NJson::TJsonValue receiveMessageReq;
1758
+ receiveMessageReq[" QueueUrl" ] = resultQueueUrl;
1759
+ receiveMessageReq[" MessageSystemAttributeNames" ] = NJson::TJsonArray{" SentTimestamp" };
1760
+ json = receiveMessage (receiveMessageReq, body);
1761
+ UNIT_ASSERT (!json[" Messages" ][0 ][" Attributes" ][" SentTimestamp" ].GetString ().empty ());
1762
+ }
1763
+
1764
+ {
1765
+ // Request All message system attributes using deprecated AttributeNames field.
1766
+ NJson::TJsonValue receiveMessageReq;
1767
+ receiveMessageReq[" QueueUrl" ] = resultQueueUrl;
1768
+ receiveMessageReq[" AttributeNames" ] = NJson::TJsonArray{" All" };
1769
+ json = receiveMessage (receiveMessageReq, body);
1770
+ UNIT_ASSERT (!json[" Messages" ][0 ][" Attributes" ][" SentTimestamp" ].GetString ().empty ());
1771
+ }
1772
+
1773
+ {
1774
+ // Request All message system attributes using MessageSystemAttributeNames field.
1775
+ NJson::TJsonValue receiveMessageReq;
1776
+ receiveMessageReq[" QueueUrl" ] = resultQueueUrl;
1777
+ receiveMessageReq[" MessageSystemAttributeNames" ] = NJson::TJsonArray{" All" };
1778
+ json = receiveMessage (receiveMessageReq, body);
1779
+ UNIT_ASSERT (!json[" Messages" ][0 ][" Attributes" ][" SentTimestamp" ].GetString ().empty ());
1780
+ }
1700
1781
}
1701
1782
1702
1783
Y_UNIT_TEST_F (TestGetQueueAttributes, THttpProxyTestMock) {
0 commit comments