-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_locator_test.go
62 lines (53 loc) · 1.24 KB
/
file_locator_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"testing"
)
func TestFileLocator(t *testing.T) {
// Locator
l := newFileLocator()
// Filename
fileName := "test.txt"
fullNameNotExisting := "file_not_found.txt"
// Create few indices
var expectedIndices map[string]bool = make(map[string]bool, 0)
for i := 0; i < 1000; i++ {
// New shard
id := randomUuid()
idStr := uuidToString(id)
idx := newShardIndex(id)
// Add filename to every x-th index
if i%200 == 0 {
idx.Add(fileName)
expectedIndices[idStr] = true
}
// Into index
l.LoadIndex("localhost", idx.ShardId, idx)
}
// Locate file
res, scanCount, e := l._locate(nil, fileName)
panicErr(e)
if len(res) != 5 {
log.Error("File should have been located in 5 shard indices")
}
if scanCount != 1000 {
log.Error("Scan count wrong")
}
// Validate indices
for idStr, _ := range expectedIndices {
var found bool = false
for _, resIdx := range res {
if uuidToString(resIdx.ShardId) == idStr {
found = true
break
}
}
if !found {
log.Error("Not able to find shard indice in map")
}
}
// Locate non-existant file
resNonExist, _, errNonExist := l._locate(nil, fullNameNotExisting)
if resNonExist != nil || errNonExist == nil {
log.Error("Found non-existing file")
}
}