filechunks_test.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. package filer
  2. import (
  3. "fmt"
  4. "log"
  5. "math"
  6. "math/rand"
  7. "strconv"
  8. "testing"
  9. "github.com/stretchr/testify/assert"
  10. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  11. )
  12. func TestCompactFileChunks(t *testing.T) {
  13. chunks := []*filer_pb.FileChunk{
  14. {Offset: 10, Size: 100, FileId: "abc", Mtime: 50},
  15. {Offset: 100, Size: 100, FileId: "def", Mtime: 100},
  16. {Offset: 200, Size: 100, FileId: "ghi", Mtime: 200},
  17. {Offset: 110, Size: 200, FileId: "jkl", Mtime: 300},
  18. }
  19. compacted, garbage := CompactFileChunks(nil, chunks)
  20. if len(compacted) != 3 {
  21. t.Fatalf("unexpected compacted: %d", len(compacted))
  22. }
  23. if len(garbage) != 1 {
  24. t.Fatalf("unexpected garbage: %d", len(garbage))
  25. }
  26. }
  27. func TestCompactFileChunks2(t *testing.T) {
  28. chunks := []*filer_pb.FileChunk{
  29. {Offset: 0, Size: 100, FileId: "abc", Mtime: 50},
  30. {Offset: 100, Size: 100, FileId: "def", Mtime: 100},
  31. {Offset: 200, Size: 100, FileId: "ghi", Mtime: 200},
  32. {Offset: 0, Size: 100, FileId: "abcf", Mtime: 300},
  33. {Offset: 50, Size: 100, FileId: "fhfh", Mtime: 400},
  34. {Offset: 100, Size: 100, FileId: "yuyu", Mtime: 500},
  35. }
  36. k := 3
  37. for n := 0; n < k; n++ {
  38. chunks = append(chunks, &filer_pb.FileChunk{
  39. Offset: int64(n * 100), Size: 100, FileId: fmt.Sprintf("fileId%d", n), Mtime: int64(n),
  40. })
  41. chunks = append(chunks, &filer_pb.FileChunk{
  42. Offset: int64(n * 50), Size: 100, FileId: fmt.Sprintf("fileId%d", n+k), Mtime: int64(n + k),
  43. })
  44. }
  45. compacted, garbage := CompactFileChunks(nil, chunks)
  46. if len(compacted) != 4 {
  47. t.Fatalf("unexpected compacted: %d", len(compacted))
  48. }
  49. if len(garbage) != 8 {
  50. t.Fatalf("unexpected garbage: %d", len(garbage))
  51. }
  52. }
  53. func TestRandomFileChunksCompact(t *testing.T) {
  54. data := make([]byte, 1024)
  55. var chunks []*filer_pb.FileChunk
  56. for i := 0; i < 15; i++ {
  57. start, stop := rand.Intn(len(data)), rand.Intn(len(data))
  58. if start > stop {
  59. start, stop = stop, start
  60. }
  61. if start+16 < stop {
  62. stop = start + 16
  63. }
  64. chunk := &filer_pb.FileChunk{
  65. FileId: strconv.Itoa(i),
  66. Offset: int64(start),
  67. Size: uint64(stop - start),
  68. Mtime: int64(i),
  69. Fid: &filer_pb.FileId{FileKey: uint64(i)},
  70. }
  71. chunks = append(chunks, chunk)
  72. for x := start; x < stop; x++ {
  73. data[x] = byte(i)
  74. }
  75. }
  76. visibles, _ := NonOverlappingVisibleIntervals(nil, chunks, 0, math.MaxInt64)
  77. for _, v := range visibles {
  78. for x := v.start; x < v.stop; x++ {
  79. assert.Equal(t, strconv.Itoa(int(data[x])), v.fileId)
  80. }
  81. }
  82. }
  83. func TestIntervalMerging(t *testing.T) {
  84. testcases := []struct {
  85. Chunks []*filer_pb.FileChunk
  86. Expected []*VisibleInterval
  87. }{
  88. // case 0: normal
  89. {
  90. Chunks: []*filer_pb.FileChunk{
  91. {Offset: 0, Size: 100, FileId: "abc", Mtime: 123},
  92. {Offset: 100, Size: 100, FileId: "asdf", Mtime: 134},
  93. {Offset: 200, Size: 100, FileId: "fsad", Mtime: 353},
  94. },
  95. Expected: []*VisibleInterval{
  96. {start: 0, stop: 100, fileId: "abc"},
  97. {start: 100, stop: 200, fileId: "asdf"},
  98. {start: 200, stop: 300, fileId: "fsad"},
  99. },
  100. },
  101. // case 1: updates overwrite full chunks
  102. {
  103. Chunks: []*filer_pb.FileChunk{
  104. {Offset: 0, Size: 100, FileId: "abc", Mtime: 123},
  105. {Offset: 0, Size: 200, FileId: "asdf", Mtime: 134},
  106. },
  107. Expected: []*VisibleInterval{
  108. {start: 0, stop: 200, fileId: "asdf"},
  109. },
  110. },
  111. // case 2: updates overwrite part of previous chunks
  112. {
  113. Chunks: []*filer_pb.FileChunk{
  114. {Offset: 0, Size: 100, FileId: "a", Mtime: 123},
  115. {Offset: 0, Size: 70, FileId: "b", Mtime: 134},
  116. },
  117. Expected: []*VisibleInterval{
  118. {start: 0, stop: 70, fileId: "b"},
  119. {start: 70, stop: 100, fileId: "a", chunkOffset: 70},
  120. },
  121. },
  122. // case 3: updates overwrite full chunks
  123. {
  124. Chunks: []*filer_pb.FileChunk{
  125. {Offset: 0, Size: 100, FileId: "abc", Mtime: 123},
  126. {Offset: 0, Size: 200, FileId: "asdf", Mtime: 134},
  127. {Offset: 50, Size: 250, FileId: "xxxx", Mtime: 154},
  128. },
  129. Expected: []*VisibleInterval{
  130. {start: 0, stop: 50, fileId: "asdf"},
  131. {start: 50, stop: 300, fileId: "xxxx"},
  132. },
  133. },
  134. // case 4: updates far away from prev chunks
  135. {
  136. Chunks: []*filer_pb.FileChunk{
  137. {Offset: 0, Size: 100, FileId: "abc", Mtime: 123},
  138. {Offset: 0, Size: 200, FileId: "asdf", Mtime: 134},
  139. {Offset: 250, Size: 250, FileId: "xxxx", Mtime: 154},
  140. },
  141. Expected: []*VisibleInterval{
  142. {start: 0, stop: 200, fileId: "asdf"},
  143. {start: 250, stop: 500, fileId: "xxxx"},
  144. },
  145. },
  146. // case 5: updates overwrite full chunks
  147. {
  148. Chunks: []*filer_pb.FileChunk{
  149. {Offset: 0, Size: 100, FileId: "a", Mtime: 123},
  150. {Offset: 0, Size: 200, FileId: "d", Mtime: 184},
  151. {Offset: 70, Size: 150, FileId: "c", Mtime: 143},
  152. {Offset: 80, Size: 100, FileId: "b", Mtime: 134},
  153. },
  154. Expected: []*VisibleInterval{
  155. {start: 0, stop: 200, fileId: "d"},
  156. {start: 200, stop: 220, fileId: "c", chunkOffset: 130},
  157. },
  158. },
  159. // case 6: same updates
  160. {
  161. Chunks: []*filer_pb.FileChunk{
  162. {Offset: 0, Size: 100, FileId: "abc", Fid: &filer_pb.FileId{FileKey: 1}, Mtime: 123},
  163. {Offset: 0, Size: 100, FileId: "axf", Fid: &filer_pb.FileId{FileKey: 2}, Mtime: 123},
  164. {Offset: 0, Size: 100, FileId: "xyz", Fid: &filer_pb.FileId{FileKey: 3}, Mtime: 123},
  165. },
  166. Expected: []*VisibleInterval{
  167. {start: 0, stop: 100, fileId: "xyz"},
  168. },
  169. },
  170. // case 7: real updates
  171. {
  172. Chunks: []*filer_pb.FileChunk{
  173. {Offset: 0, Size: 2097152, FileId: "7,0294cbb9892b", Mtime: 123},
  174. {Offset: 0, Size: 3145728, FileId: "3,029565bf3092", Mtime: 130},
  175. {Offset: 2097152, Size: 3145728, FileId: "6,029632f47ae2", Mtime: 140},
  176. {Offset: 5242880, Size: 3145728, FileId: "2,029734c5aa10", Mtime: 150},
  177. {Offset: 8388608, Size: 3145728, FileId: "5,02982f80de50", Mtime: 160},
  178. {Offset: 11534336, Size: 2842193, FileId: "7,0299ad723803", Mtime: 170},
  179. },
  180. Expected: []*VisibleInterval{
  181. {start: 0, stop: 2097152, fileId: "3,029565bf3092"},
  182. {start: 2097152, stop: 5242880, fileId: "6,029632f47ae2"},
  183. {start: 5242880, stop: 8388608, fileId: "2,029734c5aa10"},
  184. {start: 8388608, stop: 11534336, fileId: "5,02982f80de50"},
  185. {start: 11534336, stop: 14376529, fileId: "7,0299ad723803"},
  186. },
  187. },
  188. // case 8: real bug
  189. {
  190. Chunks: []*filer_pb.FileChunk{
  191. {Offset: 0, Size: 77824, FileId: "4,0b3df938e301", Mtime: 123},
  192. {Offset: 471040, Size: 472225 - 471040, FileId: "6,0b3e0650019c", Mtime: 130},
  193. {Offset: 77824, Size: 208896 - 77824, FileId: "4,0b3f0c7202f0", Mtime: 140},
  194. {Offset: 208896, Size: 339968 - 208896, FileId: "2,0b4031a72689", Mtime: 150},
  195. {Offset: 339968, Size: 471040 - 339968, FileId: "3,0b416a557362", Mtime: 160},
  196. },
  197. Expected: []*VisibleInterval{
  198. {start: 0, stop: 77824, fileId: "4,0b3df938e301"},
  199. {start: 77824, stop: 208896, fileId: "4,0b3f0c7202f0"},
  200. {start: 208896, stop: 339968, fileId: "2,0b4031a72689"},
  201. {start: 339968, stop: 471040, fileId: "3,0b416a557362"},
  202. {start: 471040, stop: 472225, fileId: "6,0b3e0650019c"},
  203. },
  204. },
  205. }
  206. for i, testcase := range testcases {
  207. log.Printf("++++++++++ merged test case %d ++++++++++++++++++++", i)
  208. intervals, _ := NonOverlappingVisibleIntervals(nil, testcase.Chunks, 0, math.MaxInt64)
  209. for x, interval := range intervals {
  210. log.Printf("test case %d, interval %d, start=%d, stop=%d, fileId=%s",
  211. i, x, interval.start, interval.stop, interval.fileId)
  212. }
  213. for x, interval := range intervals {
  214. if interval.start != testcase.Expected[x].start {
  215. t.Fatalf("failed on test case %d, interval %d, start %d, expect %d",
  216. i, x, interval.start, testcase.Expected[x].start)
  217. }
  218. if interval.stop != testcase.Expected[x].stop {
  219. t.Fatalf("failed on test case %d, interval %d, stop %d, expect %d",
  220. i, x, interval.stop, testcase.Expected[x].stop)
  221. }
  222. if interval.fileId != testcase.Expected[x].fileId {
  223. t.Fatalf("failed on test case %d, interval %d, chunkId %s, expect %s",
  224. i, x, interval.fileId, testcase.Expected[x].fileId)
  225. }
  226. if interval.chunkOffset != testcase.Expected[x].chunkOffset {
  227. t.Fatalf("failed on test case %d, interval %d, chunkOffset %d, expect %d",
  228. i, x, interval.chunkOffset, testcase.Expected[x].chunkOffset)
  229. }
  230. }
  231. if len(intervals) != len(testcase.Expected) {
  232. t.Fatalf("failed to compact test case %d, len %d expected %d", i, len(intervals), len(testcase.Expected))
  233. }
  234. }
  235. }
  236. func TestChunksReading(t *testing.T) {
  237. testcases := []struct {
  238. Chunks []*filer_pb.FileChunk
  239. Offset int64
  240. Size int64
  241. Expected []*ChunkView
  242. }{
  243. // case 0: normal
  244. {
  245. Chunks: []*filer_pb.FileChunk{
  246. {Offset: 0, Size: 100, FileId: "abc", Mtime: 123},
  247. {Offset: 100, Size: 100, FileId: "asdf", Mtime: 134},
  248. {Offset: 200, Size: 100, FileId: "fsad", Mtime: 353},
  249. },
  250. Offset: 0,
  251. Size: 250,
  252. Expected: []*ChunkView{
  253. {Offset: 0, Size: 100, FileId: "abc", LogicOffset: 0},
  254. {Offset: 0, Size: 100, FileId: "asdf", LogicOffset: 100},
  255. {Offset: 0, Size: 50, FileId: "fsad", LogicOffset: 200},
  256. },
  257. },
  258. // case 1: updates overwrite full chunks
  259. {
  260. Chunks: []*filer_pb.FileChunk{
  261. {Offset: 0, Size: 100, FileId: "abc", Mtime: 123},
  262. {Offset: 0, Size: 200, FileId: "asdf", Mtime: 134},
  263. },
  264. Offset: 50,
  265. Size: 100,
  266. Expected: []*ChunkView{
  267. {Offset: 50, Size: 100, FileId: "asdf", LogicOffset: 50},
  268. },
  269. },
  270. // case 2: updates overwrite part of previous chunks
  271. {
  272. Chunks: []*filer_pb.FileChunk{
  273. {Offset: 3, Size: 100, FileId: "a", Mtime: 123},
  274. {Offset: 10, Size: 50, FileId: "b", Mtime: 134},
  275. },
  276. Offset: 30,
  277. Size: 40,
  278. Expected: []*ChunkView{
  279. {Offset: 20, Size: 30, FileId: "b", LogicOffset: 30},
  280. {Offset: 57, Size: 10, FileId: "a", LogicOffset: 60},
  281. },
  282. },
  283. // case 3: updates overwrite full chunks
  284. {
  285. Chunks: []*filer_pb.FileChunk{
  286. {Offset: 0, Size: 100, FileId: "abc", Mtime: 123},
  287. {Offset: 0, Size: 200, FileId: "asdf", Mtime: 134},
  288. {Offset: 50, Size: 250, FileId: "xxxx", Mtime: 154},
  289. },
  290. Offset: 0,
  291. Size: 200,
  292. Expected: []*ChunkView{
  293. {Offset: 0, Size: 50, FileId: "asdf", LogicOffset: 0},
  294. {Offset: 0, Size: 150, FileId: "xxxx", LogicOffset: 50},
  295. },
  296. },
  297. // case 4: updates far away from prev chunks
  298. {
  299. Chunks: []*filer_pb.FileChunk{
  300. {Offset: 0, Size: 100, FileId: "abc", Mtime: 123},
  301. {Offset: 0, Size: 200, FileId: "asdf", Mtime: 134},
  302. {Offset: 250, Size: 250, FileId: "xxxx", Mtime: 154},
  303. },
  304. Offset: 0,
  305. Size: 400,
  306. Expected: []*ChunkView{
  307. {Offset: 0, Size: 200, FileId: "asdf", LogicOffset: 0},
  308. {Offset: 0, Size: 150, FileId: "xxxx", LogicOffset: 250},
  309. },
  310. },
  311. // case 5: updates overwrite full chunks
  312. {
  313. Chunks: []*filer_pb.FileChunk{
  314. {Offset: 0, Size: 100, FileId: "a", Mtime: 123},
  315. {Offset: 0, Size: 200, FileId: "c", Mtime: 184},
  316. {Offset: 70, Size: 150, FileId: "b", Mtime: 143},
  317. {Offset: 80, Size: 100, FileId: "xxxx", Mtime: 134},
  318. },
  319. Offset: 0,
  320. Size: 220,
  321. Expected: []*ChunkView{
  322. {Offset: 0, Size: 200, FileId: "c", LogicOffset: 0},
  323. {Offset: 130, Size: 20, FileId: "b", LogicOffset: 200},
  324. },
  325. },
  326. // case 6: same updates
  327. {
  328. Chunks: []*filer_pb.FileChunk{
  329. {Offset: 0, Size: 100, FileId: "abc", Fid: &filer_pb.FileId{FileKey: 1}, Mtime: 123},
  330. {Offset: 0, Size: 100, FileId: "def", Fid: &filer_pb.FileId{FileKey: 2}, Mtime: 123},
  331. {Offset: 0, Size: 100, FileId: "xyz", Fid: &filer_pb.FileId{FileKey: 3}, Mtime: 123},
  332. },
  333. Offset: 0,
  334. Size: 100,
  335. Expected: []*ChunkView{
  336. {Offset: 0, Size: 100, FileId: "xyz", LogicOffset: 0},
  337. },
  338. },
  339. // case 7: edge cases
  340. {
  341. Chunks: []*filer_pb.FileChunk{
  342. {Offset: 0, Size: 100, FileId: "abc", Mtime: 123},
  343. {Offset: 100, Size: 100, FileId: "asdf", Mtime: 134},
  344. {Offset: 200, Size: 100, FileId: "fsad", Mtime: 353},
  345. },
  346. Offset: 0,
  347. Size: 200,
  348. Expected: []*ChunkView{
  349. {Offset: 0, Size: 100, FileId: "abc", LogicOffset: 0},
  350. {Offset: 0, Size: 100, FileId: "asdf", LogicOffset: 100},
  351. },
  352. },
  353. // case 8: edge cases
  354. {
  355. Chunks: []*filer_pb.FileChunk{
  356. {Offset: 0, Size: 100, FileId: "abc", Mtime: 123},
  357. {Offset: 90, Size: 200, FileId: "asdf", Mtime: 134},
  358. {Offset: 190, Size: 300, FileId: "fsad", Mtime: 353},
  359. },
  360. Offset: 0,
  361. Size: 300,
  362. Expected: []*ChunkView{
  363. {Offset: 0, Size: 90, FileId: "abc", LogicOffset: 0},
  364. {Offset: 0, Size: 100, FileId: "asdf", LogicOffset: 90},
  365. {Offset: 0, Size: 110, FileId: "fsad", LogicOffset: 190},
  366. },
  367. },
  368. // case 9: edge cases
  369. {
  370. Chunks: []*filer_pb.FileChunk{
  371. {Offset: 0, Size: 43175947, FileId: "2,111fc2cbfac1", Mtime: 1},
  372. {Offset: 43175936, Size: 52981771 - 43175936, FileId: "2,112a36ea7f85", Mtime: 2},
  373. {Offset: 52981760, Size: 72564747 - 52981760, FileId: "4,112d5f31c5e7", Mtime: 3},
  374. {Offset: 72564736, Size: 133255179 - 72564736, FileId: "1,113245f0cdb6", Mtime: 4},
  375. {Offset: 133255168, Size: 137269259 - 133255168, FileId: "3,1141a70733b5", Mtime: 5},
  376. {Offset: 137269248, Size: 153578836 - 137269248, FileId: "1,114201d5bbdb", Mtime: 6},
  377. },
  378. Offset: 0,
  379. Size: 153578836,
  380. Expected: []*ChunkView{
  381. {Offset: 0, Size: 43175936, FileId: "2,111fc2cbfac1", LogicOffset: 0},
  382. {Offset: 0, Size: 52981760 - 43175936, FileId: "2,112a36ea7f85", LogicOffset: 43175936},
  383. {Offset: 0, Size: 72564736 - 52981760, FileId: "4,112d5f31c5e7", LogicOffset: 52981760},
  384. {Offset: 0, Size: 133255168 - 72564736, FileId: "1,113245f0cdb6", LogicOffset: 72564736},
  385. {Offset: 0, Size: 137269248 - 133255168, FileId: "3,1141a70733b5", LogicOffset: 133255168},
  386. {Offset: 0, Size: 153578836 - 137269248, FileId: "1,114201d5bbdb", LogicOffset: 137269248},
  387. },
  388. },
  389. }
  390. for i, testcase := range testcases {
  391. if i != 2 {
  392. // continue
  393. }
  394. log.Printf("++++++++++ read test case %d ++++++++++++++++++++", i)
  395. chunks := ViewFromChunks(nil, testcase.Chunks, testcase.Offset, testcase.Size)
  396. for x, chunk := range chunks {
  397. log.Printf("read case %d, chunk %d, offset=%d, size=%d, fileId=%s",
  398. i, x, chunk.Offset, chunk.Size, chunk.FileId)
  399. if chunk.Offset != testcase.Expected[x].Offset {
  400. t.Fatalf("failed on read case %d, chunk %s, Offset %d, expect %d",
  401. i, chunk.FileId, chunk.Offset, testcase.Expected[x].Offset)
  402. }
  403. if chunk.Size != testcase.Expected[x].Size {
  404. t.Fatalf("failed on read case %d, chunk %s, Size %d, expect %d",
  405. i, chunk.FileId, chunk.Size, testcase.Expected[x].Size)
  406. }
  407. if chunk.FileId != testcase.Expected[x].FileId {
  408. t.Fatalf("failed on read case %d, chunk %d, FileId %s, expect %s",
  409. i, x, chunk.FileId, testcase.Expected[x].FileId)
  410. }
  411. if chunk.LogicOffset != testcase.Expected[x].LogicOffset {
  412. t.Fatalf("failed on read case %d, chunk %d, LogicOffset %d, expect %d",
  413. i, x, chunk.LogicOffset, testcase.Expected[x].LogicOffset)
  414. }
  415. }
  416. if len(chunks) != len(testcase.Expected) {
  417. t.Fatalf("failed to read test case %d, len %d expected %d", i, len(chunks), len(testcase.Expected))
  418. }
  419. }
  420. }
  421. func BenchmarkCompactFileChunks(b *testing.B) {
  422. var chunks []*filer_pb.FileChunk
  423. k := 1024
  424. for n := 0; n < k; n++ {
  425. chunks = append(chunks, &filer_pb.FileChunk{
  426. Offset: int64(n * 100), Size: 100, FileId: fmt.Sprintf("fileId%d", n), Mtime: int64(n),
  427. })
  428. chunks = append(chunks, &filer_pb.FileChunk{
  429. Offset: int64(n * 50), Size: 100, FileId: fmt.Sprintf("fileId%d", n+k), Mtime: int64(n + k),
  430. })
  431. }
  432. for n := 0; n < b.N; n++ {
  433. CompactFileChunks(nil, chunks)
  434. }
  435. }
  436. func TestViewFromVisibleIntervals(t *testing.T) {
  437. visibles := []VisibleInterval{
  438. {
  439. start: 0,
  440. stop: 25,
  441. fileId: "fid1",
  442. },
  443. {
  444. start: 4096,
  445. stop: 8192,
  446. fileId: "fid2",
  447. },
  448. {
  449. start: 16384,
  450. stop: 18551,
  451. fileId: "fid3",
  452. },
  453. }
  454. views := ViewFromVisibleIntervals(visibles, 0, math.MaxInt32)
  455. if len(views) != len(visibles) {
  456. assert.Equal(t, len(visibles), len(views), "ViewFromVisibleIntervals error")
  457. }
  458. }
  459. func TestViewFromVisibleIntervals2(t *testing.T) {
  460. visibles := []VisibleInterval{
  461. {
  462. start: 344064,
  463. stop: 348160,
  464. fileId: "fid1",
  465. },
  466. {
  467. start: 348160,
  468. stop: 356352,
  469. fileId: "fid2",
  470. },
  471. }
  472. views := ViewFromVisibleIntervals(visibles, 0, math.MaxInt32)
  473. if len(views) != len(visibles) {
  474. assert.Equal(t, len(visibles), len(views), "ViewFromVisibleIntervals error")
  475. }
  476. }
  477. func TestViewFromVisibleIntervals3(t *testing.T) {
  478. visibles := []VisibleInterval{
  479. {
  480. start: 1000,
  481. stop: 2000,
  482. fileId: "fid1",
  483. },
  484. {
  485. start: 3000,
  486. stop: 4000,
  487. fileId: "fid2",
  488. },
  489. }
  490. views := ViewFromVisibleIntervals(visibles, 1700, 1500)
  491. if len(views) != len(visibles) {
  492. assert.Equal(t, len(visibles), len(views), "ViewFromVisibleIntervals error")
  493. }
  494. }