Skip to content

Commit 231c980

Browse files
Merge c3e3f95 into 0ee58bd
2 parents 0ee58bd + c3e3f95 commit 231c980

File tree

3 files changed

+93
-2
lines changed

3 files changed

+93
-2
lines changed

ydb/core/testlib/actors/test_runtime.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
namespace NActors {
1919

2020
void TTestActorRuntime::TNodeData::Stop() {
21-
TNodeDataBase::Stop();
2221
if (Mon) {
2322
Mon->Stop();
23+
GetAppData<NKikimr::TAppData>()->Mon = nullptr;
2424
}
25+
TNodeDataBase::Stop();
2526
}
2627

2728
TTestActorRuntime::TNodeData::~TNodeData() {

ydb/core/viewer/json_query.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,10 @@ class TJsonQuery : public TViewerPipeClient<TJsonQuery> {
210210
request.SetType(NKikimrKqp::QUERY_TYPE_SQL_DML);
211211
request.SetKeepSession(false);
212212
SetTransactionMode(request);
213+
if (!request.txcontrol().has_begin_tx()) {
214+
request.mutable_txcontrol()->mutable_begin_tx()->mutable_serializable_read_write();
215+
request.mutable_txcontrol()->set_commit_tx(true);
216+
}
213217
} else if (Action == "explain" || Action == "explain-ast" || Action == "explain-data") {
214218
request.SetAction(NKikimrKqp::QUERY_ACTION_EXPLAIN);
215219
request.SetType(NKikimrKqp::QUERY_TYPE_SQL_DML);

ydb/core/viewer/viewer_ut.cpp

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include <library/cpp/testing/unittest/registar.h>
1818
#include <library/cpp/testing/unittest/tests_data.h>
19+
#include <ydb/core/kqp/common/kqp.h>
1920
#include <ydb/core/testlib/test_client.h>
2021
#include <ydb/core/testlib/tenant_runtime.h>
2122
#include <ydb/public/lib/deprecated/kicli/kicli.h>
@@ -1115,6 +1116,91 @@ Y_UNIT_TEST_SUITE(Viewer) {
11151116
size_t AuthorizeTicketFails = 0;
11161117
};
11171118

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+
11181204
Y_UNIT_TEST(FloatPointJsonQuery) {
11191205
TPortManager tp;
11201206
ui16 port = tp.GetPort(2134);
@@ -1145,7 +1231,7 @@ Y_UNIT_TEST_SUITE(Viewer) {
11451231
"database": "/Root",
11461232
"action": "execute-script",
11471233
"syntax": "yql_v1",
1148-
"stats": "profile"
1234+
"stats": "none"
11491235
})json";
11501236
const TKeepAliveHttpClient::THttpCode statusCode = httpClient.DoPost("/viewer/json/query?timeout=600000&base64=false&schema=modern", requestBody, &responseStream, headers);
11511237
const TString response = responseStream.ReadAll();

0 commit comments

Comments
 (0)