|
17 | 17 |
|
18 | 18 | #include <library/cpp/testing/unittest/registar.h>
|
19 | 19 | #include <library/cpp/testing/unittest/tests_data.h>
|
| 20 | +#include <ydb/core/kqp/common/kqp.h> |
20 | 21 | #include <ydb/core/testlib/test_client.h>
|
21 | 22 | #include <ydb/core/testlib/tenant_runtime.h>
|
22 | 23 | #include <ydb/public/lib/deprecated/kicli/kicli.h>
|
@@ -1593,6 +1594,91 @@ Y_UNIT_TEST_SUITE(Viewer) {
|
1593 | 1594 | size_t AuthorizeTicketFails = 0;
|
1594 | 1595 | };
|
1595 | 1596 |
|
| 1597 | + TString PostQuery(TKeepAliveHttpClient& httpClient, TString query, TString action = "", TString transactionMode = "") { |
| 1598 | + TStringStream requestBody; |
| 1599 | + requestBody |
| 1600 | + << "{ \"query\": \"" << query << "\"," |
| 1601 | + << " \"database\": \"/Root\"," |
| 1602 | + << " \"action\": \"" << action << "\"," |
| 1603 | + << " \"syntax\": \"yql_v1\"," |
| 1604 | + << " \"transaction_mode\": \"" << transactionMode << "\"," |
| 1605 | + << " \"stats\": \"none\" }"; |
| 1606 | + TStringStream responseStream; |
| 1607 | + TKeepAliveHttpClient::THeaders headers; |
| 1608 | + headers["Content-Type"] = "application/json"; |
| 1609 | + headers["Authorization"] = "test_ydb_token"; |
| 1610 | + const TKeepAliveHttpClient::THttpCode statusCode = httpClient.DoPost("/viewer/query?timeout=600000&base64=false&schema=modern", requestBody.Str(), &responseStream, headers); |
| 1611 | + const TString response = responseStream.ReadAll(); |
| 1612 | + UNIT_ASSERT_EQUAL_C(statusCode, HTTP_OK, statusCode << ": " << response); |
| 1613 | + return response; |
| 1614 | + } |
| 1615 | + |
| 1616 | + Y_UNIT_TEST(ExecuteQueryDoesntExecuteSchemeOperationsInsideTransation) { |
| 1617 | + TPortManager tp; |
| 1618 | + ui16 port = tp.GetPort(2134); |
| 1619 | + ui16 grpcPort = tp.GetPort(2135); |
| 1620 | + ui16 monPort = tp.GetPort(8765); |
| 1621 | + auto settings = TServerSettings(port); |
| 1622 | + settings.InitKikimrRunConfig() |
| 1623 | + .SetNodeCount(1) |
| 1624 | + .SetUseRealThreads(true) |
| 1625 | + .SetDomainName("Root") |
| 1626 | + .SetMonitoringPortOffset(monPort, true); |
| 1627 | + |
| 1628 | + TServer server(settings); |
| 1629 | + server.EnableGRpc(grpcPort); |
| 1630 | + TClient client(settings); |
| 1631 | + client.InitRootScheme(); |
| 1632 | + |
| 1633 | + TTestActorRuntime& runtime = *server.GetRuntime(); |
| 1634 | + runtime.SetLogPriority(NKikimrServices::TICKET_PARSER, NLog::PRI_TRACE); |
| 1635 | + |
| 1636 | + TKeepAliveHttpClient httpClient("localhost", monPort); |
| 1637 | + |
| 1638 | + //Scheme operations cannot be executed inside transaction |
| 1639 | + TString response = PostQuery(httpClient, "CREATE TABLE `/Root/Test` (Key Uint64, Value String, PRIMARY KEY (Key));", "execute-query", "serializable-read-write"); |
| 1640 | + { |
| 1641 | + NJson::TJsonReaderConfig jsonCfg; |
| 1642 | + NJson::TJsonValue json; |
| 1643 | + NJson::ReadJsonTree(response, &jsonCfg, &json, /* throwOnError = */ true); |
| 1644 | + UNIT_ASSERT_EQUAL_C(json["status"].GetString(), "PRECONDITION_FAILED", response); |
| 1645 | + } |
| 1646 | + } |
| 1647 | + |
| 1648 | + Y_UNIT_TEST(UseTransactionWhenExecuteDataActionQuery) { |
| 1649 | + TPortManager tp; |
| 1650 | + ui16 port = tp.GetPort(2134); |
| 1651 | + ui16 grpcPort = tp.GetPort(2135); |
| 1652 | + ui16 monPort = tp.GetPort(8765); |
| 1653 | + auto settings = TServerSettings(port); |
| 1654 | + settings.InitKikimrRunConfig() |
| 1655 | + .SetNodeCount(1) |
| 1656 | + .SetUseRealThreads(true) |
| 1657 | + .SetDomainName("Root") |
| 1658 | + .SetMonitoringPortOffset(monPort, true); |
| 1659 | + |
| 1660 | + TServer server(settings); |
| 1661 | + server.EnableGRpc(grpcPort); |
| 1662 | + TClient client(settings); |
| 1663 | + client.InitRootScheme(); |
| 1664 | + |
| 1665 | + TTestActorRuntime& runtime = *server.GetRuntime(); |
| 1666 | + runtime.SetLogPriority(NKikimrServices::TICKET_PARSER, NLog::PRI_TRACE); |
| 1667 | + |
| 1668 | + TKeepAliveHttpClient httpClient("localhost", monPort); |
| 1669 | + |
| 1670 | + PostQuery(httpClient, "CREATE TABLE `/Root/Test` (Key Uint64, Value String, PRIMARY KEY (Key));", "execute-query"); |
| 1671 | + PostQuery(httpClient, "INSERT INTO `/Root/Test` (Key, Value) VALUES (1, 'testvalue');", "execute-query"); |
| 1672 | + TString response = PostQuery(httpClient, "SELECT * FROM `/Root/Test`;", "execute-data"); |
| 1673 | + { |
| 1674 | + NJson::TJsonReaderConfig jsonCfg; |
| 1675 | + NJson::TJsonValue json; |
| 1676 | + NJson::ReadJsonTree(response, &jsonCfg, &json, /* throwOnError = */ true); |
| 1677 | + auto resultSets = json["result"].GetArray(); |
| 1678 | + UNIT_ASSERT_EQUAL_C(1, resultSets.size(), response); |
| 1679 | + } |
| 1680 | + } |
| 1681 | + |
1596 | 1682 | Y_UNIT_TEST(FloatPointJsonQuery) {
|
1597 | 1683 | TPortManager tp;
|
1598 | 1684 | ui16 port = tp.GetPort(2134);
|
|
0 commit comments