1 /*
2 Copyright 2016 Skytechnology sp. z o.o.
3
4 This file is part of LizardFS.
5
6 LizardFS is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, version 3.
9
10 LizardFS is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with LizardFS. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "common/platform.h"
20
21 #include <gtest/gtest.h>
22
23 #include "mount/readahead_adviser.h"
24
TEST(ReadaheadTests,ReadSequential)25 TEST(ReadaheadTests, ReadSequential) {
26 ReadaheadAdviser ra(1024);
27
28 int window = 0;
29 for (int i = 0; i < 32; ++i) {
30 ra.feed(i * 65536, 65536);
31 ASSERT_GE(ra.window(), window);
32 window = ra.window();
33 }
34 }
35
TEST(ReadaheadTests,ReadHoles)36 TEST(ReadaheadTests, ReadHoles) {
37 ReadaheadAdviser ra(1024);
38
39 int i = 0;
40 for (; i < 8; ++i) {
41 ra.feed(i * 65536, 65536 - 1000*i);
42 }
43 int window = ra.window();
44 for (; i < 16; ++i) {
45 ra.feed(i * 65536, 65536 - 1000*i);
46 ASSERT_LE(ra.window(), window);
47 window = ra.window();
48 }
49 }
50
TEST(ReadaheadTests,ReadOverlapping)51 TEST(ReadaheadTests, ReadOverlapping) {
52 ReadaheadAdviser ra(1024);
53
54 int i = 0;
55 for (;i < 8; ++i) {
56 ra.feed(i * 65536, 65536 + 1000*i);
57 }
58 int window = ra.window();
59 for (;i < 16; ++i) {
60 ASSERT_LE(ra.window(), window);
61 window = ra.window();
62 }
63 }
64
TEST(ReadaheadTests,ReadSequentialThenHolesThenSequential)65 TEST(ReadaheadTests, ReadSequentialThenHolesThenSequential) {
66 ReadaheadAdviser ra(1024);
67
68 int i = 0;
69 int window = 0;
70 for (; i < 16; ++i) {
71 ra.feed(i * 65536, 65536);
72 ASSERT_GE(ra.window(), window);
73 window = ra.window();
74 }
75
76 for (; i < 20; ++i) {
77 ra.feed(i * 65536, 65536 - 1000*i);
78 }
79 for (; i < 48; ++i) {
80 ra.feed(i * 65536, 65536 - 1000*i);
81 ASSERT_LE(ra.window(), window);
82 window = ra.window();
83 }
84
85 for (; i < 52; ++i) {
86 ra.feed(i * 65536, 65536);
87 }
88 for (; i < 64; ++i) {
89 ra.feed(i * 65536, 65536);
90 ASSERT_GE(ra.window(), window);
91 window = ra.window();
92 }
93 }
94