|
16 | 16 |
|
17 | 17 | #include <library/cpp/testing/unittest/registar.h>
|
18 | 18 | #include <library/cpp/testing/unittest/tests_data.h>
|
| 19 | +#include <ydb/core/kqp/common/kqp.h> |
19 | 20 | #include <ydb/core/testlib/test_client.h>
|
20 | 21 | #include <ydb/core/testlib/tenant_runtime.h>
|
21 | 22 | #include <ydb/public/lib/deprecated/kicli/kicli.h>
|
@@ -1115,6 +1116,91 @@ Y_UNIT_TEST_SUITE(Viewer) {
|
1115 | 1116 | size_t AuthorizeTicketFails = 0;
|
1116 | 1117 | };
|
1117 | 1118 |
|
| 1119 | + TString PostQuery(TKeepAliveHttpClient& httpClient, TString query, TString action = "", TString transactionMode = "") { |
| 1120 | + TStringStream requestBody; |
| 1121 | + requestBody |
| 1122 | + << "{ \"query\": \"" << query << "\"," |
| 1123 | + << " \"database\": \"/Root\"," |
| 1124 | + << " \"action\": \"" << action << "\"," |
| 1125 | + << " \"syntax\": \"yql_v1\"," |
| 1126 | + << " \"transaction_mode\": \"" << transactionMode << "\"," |
| 1127 | + << " \"stats\": \"none\" }"; |
| 1128 | + TStringStream responseStream; |
| 1129 | + TKeepAliveHttpClient::THeaders headers; |
| 1130 | + headers["Content-Type"] = "application/json"; |
| 1131 | + headers["Authorization"] = "test_ydb_token"; |
| 1132 | + const TKeepAliveHttpClient::THttpCode statusCode = httpClient.DoPost("/viewer/query?timeout=600000&base64=false&schema=modern", requestBody.Str(), &responseStream, headers); |
| 1133 | + const TString response = responseStream.ReadAll(); |
| 1134 | + UNIT_ASSERT_EQUAL_C(statusCode, HTTP_OK, statusCode << ": " << response); |
| 1135 | + return response; |
| 1136 | + } |
| 1137 | + |
| 1138 | + Y_UNIT_TEST(ExecuteQueryDoesntExecuteSchemeOperationsInsideTransation) { |
| 1139 | + TPortManager tp; |
| 1140 | + ui16 port = tp.GetPort(2134); |
| 1141 | + ui16 grpcPort = tp.GetPort(2135); |
| 1142 | + ui16 monPort = tp.GetPort(8765); |
| 1143 | + auto settings = TServerSettings(port); |
| 1144 | + settings.InitKikimrRunConfig() |
| 1145 | + .SetNodeCount(1) |
| 1146 | + .SetUseRealThreads(true) |
| 1147 | + .SetDomainName("Root") |
| 1148 | + .SetMonitoringPortOffset(monPort, true); |
| 1149 | + |
| 1150 | + TServer server(settings); |
| 1151 | + server.EnableGRpc(grpcPort); |
| 1152 | + TClient client(settings); |
| 1153 | + client.InitRootScheme(); |
| 1154 | + |
| 1155 | + TTestActorRuntime& runtime = *server.GetRuntime(); |
| 1156 | + runtime.SetLogPriority(NKikimrServices::TICKET_PARSER, NLog::PRI_TRACE); |
| 1157 | + |
| 1158 | + TKeepAliveHttpClient httpClient("localhost", monPort); |
| 1159 | + |
| 1160 | + //Scheme operations cannot be executed inside transaction |
| 1161 | + TString response = PostQuery(httpClient, "CREATE TABLE `/Root/Test` (Key Uint64, Value String, PRIMARY KEY (Key));", "execute-query", "serializable-read-write"); |
| 1162 | + { |
| 1163 | + NJson::TJsonReaderConfig jsonCfg; |
| 1164 | + NJson::TJsonValue json; |
| 1165 | + NJson::ReadJsonTree(response, &jsonCfg, &json, /* throwOnError = */ true); |
| 1166 | + UNIT_ASSERT_EQUAL_C(json["status"].GetString(), "PRECONDITION_FAILED", response); |
| 1167 | + } |
| 1168 | + } |
| 1169 | + |
| 1170 | + Y_UNIT_TEST(UseTransactionWhenExecuteDataActionQuery) { |
| 1171 | + TPortManager tp; |
| 1172 | + ui16 port = tp.GetPort(2134); |
| 1173 | + ui16 grpcPort = tp.GetPort(2135); |
| 1174 | + ui16 monPort = tp.GetPort(8765); |
| 1175 | + auto settings = TServerSettings(port); |
| 1176 | + settings.InitKikimrRunConfig() |
| 1177 | + .SetNodeCount(1) |
| 1178 | + .SetUseRealThreads(true) |
| 1179 | + .SetDomainName("Root") |
| 1180 | + .SetMonitoringPortOffset(monPort, true); |
| 1181 | + |
| 1182 | + TServer server(settings); |
| 1183 | + server.EnableGRpc(grpcPort); |
| 1184 | + TClient client(settings); |
| 1185 | + client.InitRootScheme(); |
| 1186 | + |
| 1187 | + TTestActorRuntime& runtime = *server.GetRuntime(); |
| 1188 | + runtime.SetLogPriority(NKikimrServices::TICKET_PARSER, NLog::PRI_TRACE); |
| 1189 | + |
| 1190 | + TKeepAliveHttpClient httpClient("localhost", monPort); |
| 1191 | + |
| 1192 | + PostQuery(httpClient, "CREATE TABLE `/Root/Test` (Key Uint64, Value String, PRIMARY KEY (Key));", "execute-query"); |
| 1193 | + PostQuery(httpClient, "INSERT INTO `/Root/Test` (Key, Value) VALUES (1, 'testvalue');", "execute-query"); |
| 1194 | + TString response = PostQuery(httpClient, "SELECT * FROM `/Root/Test`;", "execute-data"); |
| 1195 | + { |
| 1196 | + NJson::TJsonReaderConfig jsonCfg; |
| 1197 | + NJson::TJsonValue json; |
| 1198 | + NJson::ReadJsonTree(response, &jsonCfg, &json, /* throwOnError = */ true); |
| 1199 | + auto resultSets = json["result"].GetArray(); |
| 1200 | + UNIT_ASSERT_EQUAL_C(1, resultSets.size(), response); |
| 1201 | + } |
| 1202 | + } |
| 1203 | + |
1118 | 1204 | Y_UNIT_TEST(FloatPointJsonQuery) {
|
1119 | 1205 | TPortManager tp;
|
1120 | 1206 | ui16 port = tp.GetPort(2134);
|
@@ -1145,7 +1231,7 @@ Y_UNIT_TEST_SUITE(Viewer) {
|
1145 | 1231 | "database": "/Root",
|
1146 | 1232 | "action": "execute-script",
|
1147 | 1233 | "syntax": "yql_v1",
|
1148 |
| - "stats": "profile" |
| 1234 | + "stats": "none" |
1149 | 1235 | })json";
|
1150 | 1236 | const TKeepAliveHttpClient::THttpCode statusCode = httpClient.DoPost("/viewer/json/query?timeout=600000&base64=false&schema=modern", requestBody, &responseStream, headers);
|
1151 | 1237 | const TString response = responseStream.ReadAll();
|
|
0 commit comments