diff options
author | gvit <gvit@ydb.tech> | 2022-11-05 17:11:14 +0300 |
---|---|---|
committer | gvit <gvit@ydb.tech> | 2022-11-05 17:11:14 +0300 |
commit | 7259c66aae8e7b8f83ac73e140a815d6282e1168 (patch) | |
tree | c42afce2243ed500b52f0927e1b6e0ccf87858f0 | |
parent | ed11e26937c18a86271556c8a515d2c6b22195d5 (diff) | |
download | ydb-7259c66aae8e7b8f83ac73e140a815d6282e1168.tar.gz |
continue switching datashard tests to public api
-rw-r--r-- | ydb/core/tx/datashard/datashard_ut_common_kqp.h | 27 | ||||
-rw-r--r-- | ydb/core/tx/datashard/datashard_ut_followers.cpp | 66 |
2 files changed, 29 insertions, 64 deletions
diff --git a/ydb/core/tx/datashard/datashard_ut_common_kqp.h b/ydb/core/tx/datashard/datashard_ut_common_kqp.h index eb43679f662..f3713336fcb 100644 --- a/ydb/core/tx/datashard/datashard_ut_common_kqp.h +++ b/ydb/core/tx/datashard/datashard_ut_common_kqp.h @@ -95,22 +95,6 @@ namespace NKqpHelpers { return request; } - inline THolder<NKqp::TEvKqp::TEvQueryRequest> MakeSimpleStaleRoRequest( - const TString& sql, - const TString& database = {}) - { - auto request = MakeHolder<NKqp::TEvKqp::TEvQueryRequest>(); - request->Record.MutableRequest()->MutableTxControl()->mutable_begin_tx()->mutable_stale_read_only(); - request->Record.MutableRequest()->MutableTxControl()->set_commit_tx(true); - request->Record.MutableRequest()->SetAction(NKikimrKqp::QUERY_ACTION_EXECUTE); - request->Record.MutableRequest()->SetType(NKikimrKqp::QUERY_TYPE_SQL_DML); - request->Record.MutableRequest()->SetQuery(sql); - if (!database.empty()) { - request->Record.MutableRequest()->SetDatabase(database); - } - return request; - } - inline THolder<NKqp::TEvKqp::TEvQueryRequest> MakeBeginRequest( const TString& sessionId, const TString& sql, @@ -215,10 +199,11 @@ namespace NKqpHelpers { } - inline TString KqpSimpleExec(TTestActorRuntime& runtime, const TString& query, bool staleRo = false) { - TString sessionId = CreateSessionRPC(runtime); + inline TString KqpSimpleExec(TTestActorRuntime& runtime, const TString& query, bool staleRo = false, const TString& database = {}) { + TString sessionId = CreateSessionRPC(runtime, database); TString txId; - auto response = AwaitResponse(runtime, SendRequest(runtime, MakeSimpleRequestRPC(query, sessionId, txId, true /* commitTx */, staleRo))); + auto response = AwaitResponse( + runtime, SendRequest(runtime, MakeSimpleRequestRPC(query, sessionId, txId, true /* commitTx */, staleRo), database)); if (response.operation().status() != Ydb::StatusIds::SUCCESS) { return TStringBuilder() << "ERROR: " << response.operation().status(); } @@ -227,8 +212,8 @@ namespace NKqpHelpers { return FormatResult(result); } - inline TString KqpSimpleStaleRoExec(TTestActorRuntime& runtime, const TString& query) { - return KqpSimpleExec(runtime, query, true); + inline TString KqpSimpleStaleRoExec(TTestActorRuntime& runtime, const TString& query, const TString& database = {}) { + return KqpSimpleExec(runtime, query, true, database); } inline TString KqpSimpleBegin(TTestActorRuntime& runtime, TString& sessionId, TString& txId, const TString& query) { diff --git a/ydb/core/tx/datashard/datashard_ut_followers.cpp b/ydb/core/tx/datashard/datashard_ut_followers.cpp index 54f6a339946..e8173c24aae 100644 --- a/ydb/core/tx/datashard/datashard_ut_followers.cpp +++ b/ydb/core/tx/datashard/datashard_ut_followers.cpp @@ -36,16 +36,11 @@ Y_UNIT_TEST_SUITE(DataShardFollowers) { ExecSQL(server, sender, "UPSERT INTO `/Root/table-1` (key, value) VALUES (1, 1), (2, 2), (3, 3);"); { - auto ev = ExecRequest(runtime, sender, MakeSimpleStaleRoRequest("SELECT * FROM `/Root/table-1`", "/Root")); - auto& response = ev->Get()->Record.GetRef(); - UNIT_ASSERT_VALUES_EQUAL(response.GetYdbStatus(), Ydb::StatusIds::SUCCESS); - UNIT_ASSERT_VALUES_EQUAL(response.GetResponse().GetResults().size(), 1u); - TString expected = "Struct { " - "List { Struct { Optional { Uint32: 1 } } Struct { Optional { Uint32: 1 } } } " - "List { Struct { Optional { Uint32: 2 } } Struct { Optional { Uint32: 2 } } } " - "List { Struct { Optional { Uint32: 3 } } Struct { Optional { Uint32: 3 } } } " - "} Struct { Bool: false }"; - UNIT_ASSERT_VALUES_EQUAL(response.GetResponse().GetResults()[0].GetValue().ShortDebugString(), expected); + auto result = KqpSimpleStaleRoExec(runtime, "SELECT * FROM `/Root/table-1`", "/Root"); + TString expected = "{ items { uint32_value: 1 } items { uint32_value: 1 } }, " + "{ items { uint32_value: 2 } items { uint32_value: 2 } }, " + "{ items { uint32_value: 3 } items { uint32_value: 3 } }"; + UNIT_ASSERT_VALUES_EQUAL(result, expected); } auto table1state = TReadTableState(server, MakeReadTableSettings("/Root/table-1")); @@ -60,33 +55,23 @@ Y_UNIT_TEST_SUITE(DataShardFollowers) { // Make a request to make sure snapshot metadata is updated on the follower { - auto ev = ExecRequest(runtime, sender, MakeSimpleStaleRoRequest("SELECT * FROM `/Root/table-1`", "/Root")); - auto& response = ev->Get()->Record.GetRef(); - UNIT_ASSERT_VALUES_EQUAL(response.GetYdbStatus(), Ydb::StatusIds::SUCCESS); - UNIT_ASSERT_VALUES_EQUAL(response.GetResponse().GetResults().size(), 1u); - TString expected = "Struct { " - "List { Struct { Optional { Uint32: 1 } } Struct { Optional { Uint32: 1 } } } " - "List { Struct { Optional { Uint32: 2 } } Struct { Optional { Uint32: 2 } } } " - "List { Struct { Optional { Uint32: 3 } } Struct { Optional { Uint32: 3 } } } " - "} Struct { Bool: false }"; - UNIT_ASSERT_VALUES_EQUAL(response.GetResponse().GetResults()[0].GetValue().ShortDebugString(), expected); + auto result = KqpSimpleStaleRoExec(runtime, "SELECT * FROM `/Root/table-1`", "/Root"); + TString expected = "{ items { uint32_value: 1 } items { uint32_value: 1 } }, " + "{ items { uint32_value: 2 } items { uint32_value: 2 } }, " + "{ items { uint32_value: 3 } items { uint32_value: 3 } }"; + UNIT_ASSERT_VALUES_EQUAL(result, expected); } ExecSQL(server, sender, "UPSERT INTO `/Root/table-1` (key, value) VALUES (4, 4);"); // The new row should be visible on the follower { - auto ev = ExecRequest(runtime, sender, MakeSimpleStaleRoRequest("SELECT * FROM `/Root/table-1`", "/Root")); - auto& response = ev->Get()->Record.GetRef(); - UNIT_ASSERT_VALUES_EQUAL(response.GetYdbStatus(), Ydb::StatusIds::SUCCESS); - UNIT_ASSERT_VALUES_EQUAL(response.GetResponse().GetResults().size(), 1u); - TString expected = "Struct { " - "List { Struct { Optional { Uint32: 1 } } Struct { Optional { Uint32: 1 } } } " - "List { Struct { Optional { Uint32: 2 } } Struct { Optional { Uint32: 2 } } } " - "List { Struct { Optional { Uint32: 3 } } Struct { Optional { Uint32: 3 } } } " - "List { Struct { Optional { Uint32: 4 } } Struct { Optional { Uint32: 4 } } } " - "} Struct { Bool: false }"; - UNIT_ASSERT_VALUES_EQUAL(response.GetResponse().GetResults()[0].GetValue().ShortDebugString(), expected); + auto result = KqpSimpleStaleRoExec(runtime, "SELECT * FROM `/Root/table-1`", "/Root"); + TString expected = "{ items { uint32_value: 1 } items { uint32_value: 1 } }, " + "{ items { uint32_value: 2 } items { uint32_value: 2 } }, " + "{ items { uint32_value: 3 } items { uint32_value: 3 } }, " + "{ items { uint32_value: 4 } items { uint32_value: 4 } }"; + UNIT_ASSERT_VALUES_EQUAL(result, expected); } // Wait a bit more and add one more row @@ -95,18 +80,13 @@ Y_UNIT_TEST_SUITE(DataShardFollowers) { // The new row should be visible on the follower { - auto ev = ExecRequest(runtime, sender, MakeSimpleStaleRoRequest("SELECT * FROM `/Root/table-1`", "/Root")); - auto& response = ev->Get()->Record.GetRef(); - UNIT_ASSERT_VALUES_EQUAL(response.GetYdbStatus(), Ydb::StatusIds::SUCCESS); - UNIT_ASSERT_VALUES_EQUAL(response.GetResponse().GetResults().size(), 1u); - TString expected = "Struct { " - "List { Struct { Optional { Uint32: 1 } } Struct { Optional { Uint32: 1 } } } " - "List { Struct { Optional { Uint32: 2 } } Struct { Optional { Uint32: 2 } } } " - "List { Struct { Optional { Uint32: 3 } } Struct { Optional { Uint32: 3 } } } " - "List { Struct { Optional { Uint32: 4 } } Struct { Optional { Uint32: 4 } } } " - "List { Struct { Optional { Uint32: 5 } } Struct { Optional { Uint32: 5 } } } " - "} Struct { Bool: false }"; - UNIT_ASSERT_VALUES_EQUAL(response.GetResponse().GetResults()[0].GetValue().ShortDebugString(), expected); + auto result = KqpSimpleStaleRoExec(runtime, "SELECT * FROM `/Root/table-1`", "/Root"); + TString expected = "{ items { uint32_value: 1 } items { uint32_value: 1 } }, " + "{ items { uint32_value: 2 } items { uint32_value: 2 } }, " + "{ items { uint32_value: 3 } items { uint32_value: 3 } }, " + "{ items { uint32_value: 4 } items { uint32_value: 4 } }, " + "{ items { uint32_value: 5 } items { uint32_value: 5 } }"; + UNIT_ASSERT_VALUES_EQUAL(result, expected); } } |