@@ -154,7 +154,7 @@ Y_UNIT_TEST_SUITE(TCompositeCache) {
154154 return result;
155155 }
156156
157- Y_UNIT_TEST (One_Touch ) {
157+ Y_UNIT_TEST (Touch ) {
158158 TCounterPtr counter = new NMonitoring::TCounterForPtr;
159159 TCompositeCache<TPage, TPageTraits> cache (10 , MakeHolder<TSimpleCache>(), counter);
160160
@@ -192,7 +192,7 @@ Y_UNIT_TEST_SUITE(TCompositeCache) {
192192 UNIT_ASSERT_VALUES_EQUAL (counter->Val (), cache.GetSize ());
193193 }
194194
195- Y_UNIT_TEST (One_Erase ) {
195+ Y_UNIT_TEST (Erase ) {
196196 TCounterPtr counter = new NMonitoring::TCounterForPtr;
197197 TCompositeCache<TPage, TPageTraits> cache (10 , MakeHolder<TSimpleCache>(), counter);
198198
@@ -217,7 +217,7 @@ Y_UNIT_TEST_SUITE(TCompositeCache) {
217217 UNIT_ASSERT_VALUES_EQUAL (counter->Val (), cache.GetSize ());
218218 }
219219
220- Y_UNIT_TEST (One_EvictNext ) {
220+ Y_UNIT_TEST (EvictNext ) {
221221 TCounterPtr counter = new NMonitoring::TCounterForPtr;
222222 TCompositeCache<TPage, TPageTraits> cache (10 , MakeHolder<TSimpleCache>(), counter);
223223
@@ -253,7 +253,7 @@ Y_UNIT_TEST_SUITE(TCompositeCache) {
253253 UNIT_ASSERT_VALUES_EQUAL (counter->Val (), cache.GetSize ());
254254 }
255255
256- Y_UNIT_TEST (One_UpdateLimit ) {
256+ Y_UNIT_TEST (UpdateLimit ) {
257257 TCounterPtr counter = new NMonitoring::TCounterForPtr;
258258 TCompositeCache<TPage, TPageTraits> cache (10 , MakeHolder<TSimpleCache>(), counter);
259259
@@ -327,8 +327,8 @@ Y_UNIT_TEST_SUITE(TCompositeCache) {
327327 pages.push_back (MakeHolder<TPage>(pages.size (), 1 ));
328328 UNIT_ASSERT_VALUES_EQUAL (Touch (cache, *pages.back ()), TVector<ui32>{10 });
329329 UNIT_ASSERT_VALUES_EQUAL (cache.GetSize (), 50 );
330- UNIT_ASSERT_VALUES_EQUAL (counter1->Val (), 39 );
331- UNIT_ASSERT_VALUES_EQUAL (counter2->Val (), 11 );
330+ UNIT_ASSERT_VALUES_EQUAL (counter1->Val (), 39 ); // [11 .. 49]
331+ UNIT_ASSERT_VALUES_EQUAL (counter2->Val (), 11 ); // [50, 0 .. 9]
332332
333333 pages.push_back (MakeHolder<TPage>(pages.size (), 1 ));
334334 UNIT_ASSERT_VALUES_EQUAL (Touch (cache, *pages.back ()), TVector<ui32>{21 });
@@ -409,6 +409,134 @@ Y_UNIT_TEST_SUITE(TCompositeCache) {
409409 UNIT_ASSERT_VALUES_EQUAL (cache.GetSize (), 4 );
410410 UNIT_ASSERT_VALUES_EQUAL (counter->Val (), 4 );
411411 }
412+
413+ Y_UNIT_TEST (Switch_Touch) {
414+ TCounterPtr counter1 = new NMonitoring::TCounterForPtr;
415+ TCounterPtr counter2 = new NMonitoring::TCounterForPtr;
416+ TCompositeCache<TPage, TPageTraits> cache (50 , MakeHolder<TSimpleCache>(), counter1);
417+
418+ TVector<THolder<TPage>> pages;
419+ for (ui32 pageId : xrange (50 )) {
420+ pages.push_back (MakeHolder<TPage>(pageId, 1 ));
421+ UNIT_ASSERT_VALUES_EQUAL (Touch (cache, *pages.back ()), TVector<ui32>{});
422+ }
423+
424+ UNIT_ASSERT_VALUES_EQUAL (Switch (cache, MakeHolder<TSimpleCache>(), counter2), TVector<ui32>{});
425+
426+ pages.push_back (MakeHolder<TPage>(pages.size (), 1 ));
427+ UNIT_ASSERT_VALUES_EQUAL (Touch (cache, *pages.back ()), TVector<ui32>{10 });
428+ UNIT_ASSERT_VALUES_EQUAL (cache.GetSize (), 50 );
429+ UNIT_ASSERT_VALUES_EQUAL (counter1->Val (), 39 ); // [11 .. 49]
430+ UNIT_ASSERT_VALUES_EQUAL (counter2->Val (), 11 ); // [50, 0 .. 9]
431+
432+ Touch (cache, *pages[23 ]);
433+ UNIT_ASSERT_VALUES_EQUAL (cache.GetSize (), 50 );
434+ UNIT_ASSERT_VALUES_EQUAL (counter1->Val (), 29 );
435+ UNIT_ASSERT_VALUES_EQUAL (counter2->Val (), 21 );
436+
437+ Touch (cache, *pages[7 ]);
438+ UNIT_ASSERT_VALUES_EQUAL (cache.GetSize (), 50 );
439+ UNIT_ASSERT_VALUES_EQUAL (counter1->Val (), 19 );
440+ UNIT_ASSERT_VALUES_EQUAL (counter2->Val (), 31 );
441+ }
442+
443+ Y_UNIT_TEST (Switch_Erase) {
444+ TCounterPtr counter1 = new NMonitoring::TCounterForPtr;
445+ TCounterPtr counter2 = new NMonitoring::TCounterForPtr;
446+ TCompositeCache<TPage, TPageTraits> cache (50 , MakeHolder<TSimpleCache>(), counter1);
447+
448+ TVector<THolder<TPage>> pages;
449+ for (ui32 pageId : xrange (50 )) {
450+ pages.push_back (MakeHolder<TPage>(pageId, 1 ));
451+ UNIT_ASSERT_VALUES_EQUAL (Touch (cache, *pages.back ()), TVector<ui32>{});
452+ }
453+
454+ UNIT_ASSERT_VALUES_EQUAL (Switch (cache, MakeHolder<TSimpleCache>(), counter2), TVector<ui32>{});
455+
456+ pages.push_back (MakeHolder<TPage>(pages.size (), 1 ));
457+ UNIT_ASSERT_VALUES_EQUAL (Touch (cache, *pages.back ()), TVector<ui32>{10 });
458+ UNIT_ASSERT_VALUES_EQUAL (cache.GetSize (), 50 );
459+ UNIT_ASSERT_VALUES_EQUAL (counter1->Val (), 39 ); // [11 .. 49]
460+ UNIT_ASSERT_VALUES_EQUAL (counter2->Val (), 11 ); // [50, 0 .. 9]
461+
462+ Erase (cache, *pages[23 ]);
463+ UNIT_ASSERT_VALUES_EQUAL (cache.GetSize (), 49 );
464+ UNIT_ASSERT_VALUES_EQUAL (counter1->Val (), 38 );
465+ UNIT_ASSERT_VALUES_EQUAL (counter2->Val (), 11 );
466+
467+ Erase (cache, *pages[7 ]);
468+ UNIT_ASSERT_VALUES_EQUAL (cache.GetSize (), 48 );
469+ UNIT_ASSERT_VALUES_EQUAL (counter1->Val (), 38 );
470+ UNIT_ASSERT_VALUES_EQUAL (counter2->Val (), 10 );
471+ }
472+
473+ Y_UNIT_TEST (Switch_EvictNext) {
474+ TCounterPtr counter1 = new NMonitoring::TCounterForPtr;
475+ TCounterPtr counter2 = new NMonitoring::TCounterForPtr;
476+ TCompositeCache<TPage, TPageTraits> cache (50 , MakeHolder<TSimpleCache>(), counter1);
477+
478+ TVector<THolder<TPage>> pages;
479+ for (ui32 pageId : xrange (50 )) {
480+ pages.push_back (MakeHolder<TPage>(pageId, 1 ));
481+ UNIT_ASSERT_VALUES_EQUAL (Touch (cache, *pages.back ()), TVector<ui32>{});
482+ }
483+
484+ UNIT_ASSERT_VALUES_EQUAL (Switch (cache, MakeHolder<TSimpleCache>(), counter2), TVector<ui32>{});
485+
486+ pages.push_back (MakeHolder<TPage>(pages.size (), 1 ));
487+ UNIT_ASSERT_VALUES_EQUAL (Touch (cache, *pages.back ()), TVector<ui32>{10 });
488+ UNIT_ASSERT_VALUES_EQUAL (cache.GetSize (), 50 );
489+ UNIT_ASSERT_VALUES_EQUAL (counter1->Val (), 39 ); // [11 .. 49]
490+ UNIT_ASSERT_VALUES_EQUAL (counter2->Val (), 11 ); // [50, 0 .. 9]
491+
492+ for (ui32 i : xrange (39 )) {
493+ UNIT_ASSERT_VALUES_EQUAL (EvictNext (cache), TVector<ui32>{i + 11 });
494+ }
495+ UNIT_ASSERT_VALUES_EQUAL (cache.GetSize (), 11 );
496+ UNIT_ASSERT_VALUES_EQUAL (counter1->Val (), 0 );
497+ UNIT_ASSERT_VALUES_EQUAL (counter2->Val (), 11 );
498+
499+ UNIT_ASSERT_VALUES_EQUAL (EvictNext (cache), TVector<ui32>{50 });
500+ for (ui32 i : xrange (10 )) {
501+ UNIT_ASSERT_VALUES_EQUAL (EvictNext (cache), TVector<ui32>{i});
502+ }
503+ UNIT_ASSERT_VALUES_EQUAL (cache.GetSize (), 0 );
504+ UNIT_ASSERT_VALUES_EQUAL (counter1->Val (), 0 );
505+ UNIT_ASSERT_VALUES_EQUAL (counter2->Val (), 0 );
506+ }
507+
508+ Y_UNIT_TEST (Switch_UpdateLimit) {
509+ TCounterPtr counter1 = new NMonitoring::TCounterForPtr;
510+ TCounterPtr counter2 = new NMonitoring::TCounterForPtr;
511+ TCompositeCache<TPage, TPageTraits> cache (50 , MakeHolder<TSimpleCache>(), counter1);
512+
513+ TVector<THolder<TPage>> pages;
514+ for (ui32 pageId : xrange (50 )) {
515+ pages.push_back (MakeHolder<TPage>(pageId, 1 ));
516+ UNIT_ASSERT_VALUES_EQUAL (Touch (cache, *pages.back ()), TVector<ui32>{});
517+ }
518+
519+ UNIT_ASSERT_VALUES_EQUAL (Switch (cache, MakeHolder<TSimpleCache>(), counter2), TVector<ui32>{});
520+
521+ pages.push_back (MakeHolder<TPage>(pages.size (), 1 ));
522+ UNIT_ASSERT_VALUES_EQUAL (Touch (cache, *pages.back ()), TVector<ui32>{10 });
523+ UNIT_ASSERT_VALUES_EQUAL (cache.GetSize (), 50 );
524+ UNIT_ASSERT_VALUES_EQUAL (counter1->Val (), 39 ); // [11 .. 49]
525+ UNIT_ASSERT_VALUES_EQUAL (counter2->Val (), 11 ); // [50, 0 .. 9]
526+
527+ cache.UpdateLimit (40 );
528+ UNIT_ASSERT_VALUES_EQUAL (Touch (cache, *pages[23 ]), (TVector<ui32>{21 , 22 , 24 , 25 , 26 , 27 , 28 , 29 , 30 , 31 }));
529+ UNIT_ASSERT_VALUES_EQUAL (cache.GetSize (), 40 );
530+ UNIT_ASSERT_VALUES_EQUAL (counter1->Val (), 19 ); // [32 .. 39, 23]
531+ UNIT_ASSERT_VALUES_EQUAL (counter2->Val (), 21 ); // [50, 0 .. 20]
532+
533+ cache.UpdateLimit (10 );
534+ UNIT_ASSERT_VALUES_EQUAL (Touch (cache, *pages[7 ]).size (), 30 );
535+ UNIT_ASSERT_VALUES_EQUAL (cache.GetSize (), 10 );
536+ UNIT_ASSERT_VALUES_EQUAL (counter1->Val (), 0 );
537+ UNIT_ASSERT_VALUES_EQUAL (counter2->Val (), 10 );
538+ }
539+
412540}
413541
414542}
0 commit comments