Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions ydb/core/persqueue/partition_scale_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void TPartitionScaleManager::UpdateDatabasePath(const TString& dbPath) {
}

TString TPartitionScaleManager::GetRangeMid(const TString& from, const TString& to) {
if (from > to) {
if (from > to && to.size() != 0) {
return "";
}

Expand All @@ -133,7 +133,6 @@ TString TPartitionScaleManager::GetRangeMid(const TString& from, const TString&
if (result == from) {
result += static_cast<unsigned char>(127);
}

return result;
}

Expand Down
54 changes: 52 additions & 2 deletions ydb/core/persqueue/ut/autoscaling_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <ydb/public/sdk/cpp/client/ydb_topic/ut/ut_utils/topic_sdk_test_setup.h>

#include <library/cpp/testing/unittest/registar.h>
#include <ydb/core/persqueue/partition_scale_manager.h>
#include <ydb/core/tx/schemeshard/ut_helpers/helpers.h>
#include <ydb/core/tx/schemeshard/ut_helpers/test_env.h>

Expand Down Expand Up @@ -499,7 +500,7 @@ Y_UNIT_TEST_SUITE(TopicAutoscaling) {
UNIT_ASSERT_VALUES_EQUAL_C(NYdb::EStatus::BAD_REQUEST, status.GetStatus(), "The consumer cannot commit an offset for inactive, read-to-the-end partitions.");
}

Y_UNIT_TEST(CreateAlterDescribe) {
Y_UNIT_TEST(ControlPlane_CreateAlterDescribe) {
auto autoscalingTestTopic = "autoscalit-topic";
TTopicSdkTestSetup setup = CreateSetup();
TTopicClient client = setup.MakeClient();
Expand Down Expand Up @@ -589,12 +590,61 @@ Y_UNIT_TEST_SUITE(TopicAutoscaling) {
client.CreateTopic(TEST_TOPIC, createSettings).Wait();

auto msg = TString("a", 1_MB);

auto writeSession = CreateWriteSession(client, "producer-1", 0);
UNIT_ASSERT(writeSession->Write(Msg(msg, 1)));
UNIT_ASSERT(writeSession->Write(Msg(msg, 2)));
Sleep(TDuration::Seconds(5));
Sleep(TDuration::Seconds(10));
auto describe = client.DescribeTopic(TEST_TOPIC).GetValueSync();
UNIT_ASSERT_EQUAL(describe.GetTopicDescription().GetPartitions().size(), 3);

auto writeSession2 = CreateWriteSession(client, "producer-1", 1);
UNIT_ASSERT(writeSession2->Write(Msg(msg, 3)));
Sleep(TDuration::Seconds(10));
auto describe2 = client.DescribeTopic(TEST_TOPIC).GetValueSync();
UNIT_ASSERT_EQUAL(describe2.GetTopicDescription().GetPartitions().size(), 5);
}

Y_UNIT_TEST(MidOfRange) {
TString a = "a";
TString b = "c";
auto res = NKikimr::NPQ::TPartitionScaleManager::GetRangeMid(a,b);

b = "b";
res = NKikimr::NPQ::TPartitionScaleManager::GetRangeMid(a,b);
UNIT_ASSERT(a < res);
UNIT_ASSERT(b > res);

a = {};
b = "b";
res = NKikimr::NPQ::TPartitionScaleManager::GetRangeMid(a,b);
UNIT_ASSERT(a < res);
UNIT_ASSERT(b > res);

a = "a";
b = {};
res = NKikimr::NPQ::TPartitionScaleManager::GetRangeMid(a,b);
Cerr << "\n SAVDBG " << res << "\n";
UNIT_ASSERT(a < res);
UNIT_ASSERT(b != res);

a = "aa";
b = {};
res = NKikimr::NPQ::TPartitionScaleManager::GetRangeMid(a,b);
UNIT_ASSERT(a < res);
UNIT_ASSERT(b != res);

a = "aaa";
b = "b";
res = NKikimr::NPQ::TPartitionScaleManager::GetRangeMid(a,b);
UNIT_ASSERT(a < res);
UNIT_ASSERT(b > res);

a = "aaa";
b = "aab";
res = NKikimr::NPQ::TPartitionScaleManager::GetRangeMid(a,b);
UNIT_ASSERT(a < res);
UNIT_ASSERT(b > res);
}
}

Expand Down