@@ -269,7 +269,6 @@ Y_UNIT_TEST_SUITE(Viewer) {
269269
270270 auto sample = nodes[0 ];
271271 nodes.clear ();
272-
273272 for (int nodeId = 0 ; nodeId < nodesTotal; nodeId++) {
274273 sample.NodeId = nodeId;
275274 nodes.emplace_back (sample);
@@ -1107,50 +1106,83 @@ Y_UNIT_TEST_SUITE(Viewer) {
11071106 }
11081107
11091108 void ChangeBSGroupStateResponse (TEvWhiteboard::TEvBSGroupStateResponse::TPtr* ev) {
1109+ ui64 nodeId = (*ev)->Cookie ;
11101110 auto & pbRecord = (*ev)->Get ()->Record ;
1111- // pbRecord.clear_bsgroupstateinfo();
1112- // auto state = pbRecord.add_bsgroupstateinfo();
1113- Cerr << pbRecord.ShortDebugString () << Endl;
1111+
1112+ pbRecord.clear_bsgroupstateinfo ();
1113+
1114+ for (ui64 groupId = 1 ; groupId <= 9 ; groupId++) {
1115+ if (groupId == nodeId) {
1116+ continue ;
1117+ }
1118+ auto state = pbRecord.add_bsgroupstateinfo ();
1119+ state->set_groupid (groupId);
1120+ state->set_storagepoolname (" /Root:test" );
1121+ state->set_nodeid (nodeId);
1122+ for (int k = 1 ; k <= 8 ; k++) {
1123+ auto vdisk = groupId * 8 + k;
1124+ auto vdiskId = state->add_vdiskids ();
1125+ vdiskId->set_groupid (groupId);
1126+ vdiskId->set_groupgeneration (1 );
1127+ vdiskId->set_vdisk (vdisk);
1128+ }
1129+ }
11141130 }
11151131
11161132 void ChangePDiskStateResponse (TEvWhiteboard::TEvPDiskStateResponse::TPtr* ev) {
11171133 auto & pbRecord = (*ev)->Get ()->Record ;
1118- // pbRecord.clear_pdiskstateinfo();
1119- // auto state = pbRecord.add_pdiskstateinfo();
1120- Cerr << pbRecord.ShortDebugString () << Endl;
1134+ pbRecord.clear_pdiskstateinfo ();
1135+ for (int k = 0 ; k < 2 ; k++) {
1136+ auto state = pbRecord.add_pdiskstateinfo ();
1137+ state->set_pdiskid (k);
1138+ }
11211139 }
11221140
11231141
11241142 void ChangeVDiskStateOn9NodeResponse (NNodeWhiteboard::TEvWhiteboard::TEvVDiskStateResponse::TPtr* ev) {
11251143 ui64 nodeId = (*ev)->Cookie ;
11261144 auto & pbRecord = (*ev)->Get ()->Record ;
11271145
1128- auto sample = pbRecord.vdiskstateinfo (0 );
11291146 pbRecord.clear_vdiskstateinfo ();
11301147
1131- for (int k = 1 ; k <= 8 ; k++) {
1132- auto groupId = (nodeId + k) % 9 ;
1133- ui32 pdisk = k <= 4 ? 0 : 1 ;
1148+ for (int k = 0 ; k < 8 ; k++) {
1149+ auto groupId = (nodeId + k) % 9 + 1 ;
1150+ auto vdisk = groupId * 8 + k + 1 ;
1151+ ui32 pdisk = k / 4 ;
11341152 ui32 slotid = k % 4 ;
1135- auto vdisk = 0 ;
11361153 auto state = pbRecord.add_vdiskstateinfo ();
1137- state->CopyFrom (sample);
11381154 state->set_pdiskid (pdisk);
11391155 state->set_vdiskslotid (slotid);
1140- state->mutable_vdiskid ()->set_vdisk (vdisk++);
11411156 state->mutable_vdiskid ()->set_groupid (groupId);
1157+ state->mutable_vdiskid ()->set_groupgeneration (1 );
1158+ state->mutable_vdiskid ()->set_vdisk (vdisk++);
11421159 state->set_vdiskstate (NKikimrWhiteboard::EVDiskState::OK);
11431160 state->set_nodeid (nodeId);
11441161 }
11451162 }
11461163
1147- void JsonStorage9NodesListingTest () {
1164+ void AddGroupsInControllerSelectGroupsResult (TEvBlobStorage::TEvControllerSelectGroupsResult::TPtr* ev, int groupCount) {
1165+ auto & pbRecord = (*ev)->Get ()->Record ;
1166+ auto pbMatchGroups = pbRecord.mutable_matchinggroups (0 );
1167+
1168+ auto sample = pbMatchGroups->groups (0 );
1169+ pbMatchGroups->ClearGroups ();
1170+
1171+ for (int groupId = 1 ; groupId <= groupCount; groupId++) {
1172+ auto group = pbMatchGroups->add_groups ();
1173+ group->CopyFrom (sample);
1174+ group->set_groupid (groupId++);
1175+ group->set_storagepoolname (" /Root:test" );
1176+ }
1177+ };
1178+
1179+ void JsonStorage9Nodes9GroupsListingTest (TString version, bool groupFilter, bool nodeFilter, bool pdiskFilter, ui32 expectedFoundGroups, ui32 expectedTotalGroups) {
11481180 TPortManager tp;
11491181 ui16 port = tp.GetPort (2134 );
11501182 ui16 grpcPort = tp.GetPort (2135 );
11511183 auto settings = TServerSettings (port);
11521184 settings.InitKikimrRunConfig ()
1153- .SetNodeCount (1 )
1185+ .SetNodeCount (9 )
11541186 .SetUseRealThreads (false )
11551187 .SetDomainName (" Root" );
11561188 TServer server (settings);
@@ -1163,41 +1195,49 @@ Y_UNIT_TEST_SUITE(Viewer) {
11631195
11641196 THttpRequest httpReq (HTTP_METHOD_GET);
11651197 httpReq.CgiParameters .emplace (" with" , " all" );
1166- httpReq.CgiParameters .emplace (" version" , " v2" );
1167- // httpReq.CgiParameters.emplace("node_id", "1");
1198+ httpReq.CgiParameters .emplace (" version" , version);
1199+ if (groupFilter) {
1200+ httpReq.CgiParameters .emplace (" group_id" , " 1" );
1201+ }
1202+ if (nodeFilter) {
1203+ httpReq.CgiParameters .emplace (" node_id" , " 1" );
1204+ }
1205+ if (pdiskFilter) {
1206+ httpReq.CgiParameters .emplace (" pdisk_id" , " 0" );
1207+ }
11681208 auto page = MakeHolder<TMonPage>(" viewer" , " title" );
11691209 TMonService2HttpRequest monReq (nullptr , &httpReq, nullptr , page.Get (), " /json/storage" , nullptr );
11701210 auto request = MakeHolder<NMon::TEvHttpInfo>(monReq);
11711211
11721212 auto observerFunc = [&](TAutoPtr<IEventHandle>& ev) {
11731213 Y_UNUSED (ev);
11741214 switch (ev->GetTypeRewrite ()) {
1175- case TEvInterconnect::EvNodesInfo: {
1176- auto *x = reinterpret_cast <TEvInterconnect::TEvNodesInfo::TPtr*>(&ev);
1177- Cerr << " aaaa EvNodesInfo 1" << Endl;
1178- ChangeListNodes (x, 9 );
1179- Cerr << " aaaa EvNodesInfo 2" << Endl;
1215+ case NConsole::TEvConsole::EvListTenantsResponse: {
1216+ auto *x = reinterpret_cast <NConsole::TEvConsole::TEvListTenantsResponse::TPtr*>(&ev);
1217+ Ydb::Cms::ListDatabasesResult listTenantsResult;
1218+ (*x)->Get ()->Record .GetResponse ().operation ().result ().UnpackTo (&listTenantsResult);
1219+ listTenantsResult.Addpaths (" /Root" );
1220+ (*x)->Get ()->Record .MutableResponse ()->mutable_operation ()->mutable_result ()->PackFrom (listTenantsResult);
11801221 break ;
11811222 }
11821223 case TEvWhiteboard::EvBSGroupStateResponse: {
11831224 auto *x = reinterpret_cast <TEvWhiteboard::TEvBSGroupStateResponse::TPtr*>(&ev);
1184- Cerr << " aaaa EvBSGroupStateResponse 1" << Endl;
11851225 ChangeBSGroupStateResponse (x);
1186- Cerr << " aaaa EvBSGroupStateResponse 2" << Endl;
11871226 break ;
11881227 }
11891228 case TEvWhiteboard::EvVDiskStateResponse: {
11901229 auto *x = reinterpret_cast <TEvWhiteboard::TEvVDiskStateResponse::TPtr*>(&ev);
1191- Cerr << " aaaa EvVDiskStateResponse 1" << Endl;
11921230 ChangeVDiskStateOn9NodeResponse (x);
1193- Cerr << " aaaa EvVDiskStateResponse 2" << Endl;
11941231 break ;
11951232 }
11961233 case TEvWhiteboard::EvPDiskStateResponse: {
11971234 auto *x = reinterpret_cast <TEvWhiteboard::TEvPDiskStateResponse::TPtr*>(&ev);
1198- Cerr << " aaaa EvPDiskStateResponse 1" << Endl;
11991235 ChangePDiskStateResponse (x);
1200- Cerr << " aaaa EvPDiskStateResponse 2" << Endl;
1236+ break ;
1237+ }
1238+ case TEvBlobStorage::EvControllerSelectGroupsResult: {
1239+ auto *x = reinterpret_cast <TEvBlobStorage::TEvControllerSelectGroupsResult::TPtr*>(&ev);
1240+ AddGroupsInControllerSelectGroupsResult (x, 9 );
12011241 break ;
12021242 }
12031243 }
@@ -1211,18 +1251,47 @@ Y_UNIT_TEST_SUITE(Viewer) {
12111251
12121252 size_t pos = result->Answer .find (' {' );
12131253 TString jsonResult = result->Answer .substr (pos);
1214- Cerr << " json result: " << jsonResult << Endl;
12151254 NJson::TJsonValue json;
12161255 try {
12171256 NJson::ReadJsonTree (jsonResult, &json, true );
12181257 }
12191258 catch (yexception ex) {
12201259 Ctest << ex.what () << Endl;
12211260 }
1222- // UNIT_ASSERT_VALUES_EQUAL(json.GetMap().contains("StorageGroups"), isExpectingGroup);
1261+
1262+ UNIT_ASSERT_VALUES_EQUAL (json.GetMap ().at (" FoundGroups" ), ToString (expectedFoundGroups));
1263+ UNIT_ASSERT_VALUES_EQUAL (json.GetMap ().at (" TotalGroups" ), ToString (expectedTotalGroups));
1264+ }
1265+
1266+ Y_UNIT_TEST (JsonStorageListingV1) {
1267+ JsonStorage9Nodes9GroupsListingTest (" v1" , false , false , false , 9 , 9 );
1268+ }
1269+
1270+ Y_UNIT_TEST (JsonStorageListingV2) {
1271+ JsonStorage9Nodes9GroupsListingTest (" v2" , false , false , false , 9 , 9 );
1272+ }
1273+
1274+ Y_UNIT_TEST (JsonStorageListingV1GroupIdFilter) {
1275+ JsonStorage9Nodes9GroupsListingTest (" v1" , true , false , false , 1 , 9 );
1276+ }
1277+
1278+ Y_UNIT_TEST (JsonStorageListingV2GroupIdFilter) {
1279+ JsonStorage9Nodes9GroupsListingTest (" v2" , true , false , false , 1 , 9 );
1280+ }
1281+
1282+ Y_UNIT_TEST (JsonStorageListingV1NodeIdFilter) {
1283+ JsonStorage9Nodes9GroupsListingTest (" v1" , false , true , false , 8 , 8 );
1284+ }
1285+
1286+ Y_UNIT_TEST (JsonStorageListingV2NodeIdFilter) {
1287+ JsonStorage9Nodes9GroupsListingTest (" v2" , false , true , false , 8 , 8 );
1288+ }
1289+
1290+ Y_UNIT_TEST (JsonStorageListingV1PDiskIdFilter) {
1291+ JsonStorage9Nodes9GroupsListingTest (" v1" , false , true , true , 4 , 8 );
12231292 }
12241293
1225- Y_UNIT_TEST (JsonStorage9NodesListingV1NodeIdFilter ) {
1226- JsonStorage9NodesListingTest ( );
1294+ Y_UNIT_TEST (JsonStorageListingV2PDiskIdFilter ) {
1295+ JsonStorage9Nodes9GroupsListingTest ( " v2 " , false , true , true , 4 , 8 );
12271296 }
12281297}
0 commit comments