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