-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_test.go
73 lines (60 loc) · 1.93 KB
/
main_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
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"reflect"
"testing"
IO "github.com/geolffreym/rolling-sync/fileio"
Sync "github.com/geolffreym/rolling-sync/sync"
)
func TestIntegration(t *testing.T) {
blockSize := 1 << 4 // 16 bytes
io := IO.New(blockSize)
sync := Sync.New(blockSize)
// Memory performance improvement using bufio.Reader
v1, err := io.Open("mock.txt")
if err != nil {
t.Fatal("Expected to be able to read the original file")
}
// Fill signature in memory
sig := sync.BuildSigTable(v1)
// Write signatures
// Simulation step for signatures write and read
// Simulate split operation for signatures
IO.WriteSignature("signature.bin", sig)
// Sometime later :)
// Expected receive same signature from original written file
signaturesFromFile, _ := IO.ReadSignature("signature.bin")
if !reflect.DeepEqual(sig, signaturesFromFile) {
t.Errorf("Expected written signatures equal to out signatures")
}
v2, err := io.Open("mockV2.txt")
if err != nil {
t.Fatal("Expected to be able to read the V2 file")
}
// Match in block 2 the change "added"
// V1 "i am here guys how are you doing this is a small test for chunk split and rolling hash"
// V2 "i am here guys how are you doingadded this is a small test for chunk split and rolling hash"
delta := sync.Delta(signaturesFromFile, v2)
if string(delta[2].Lit) != "added" {
t.Fatal("Expected match change from original in V2 file")
}
}
func BenchmarkDelta(b *testing.B) {
b.StopTimer() // We are not analyzing io/declarations/etc
blockSize := 1 << 4 // 16 bytes
io := IO.New(blockSize)
sync := Sync.New(blockSize)
// Memory performance improvement using bufio.Reader
v1, err := io.Open("mock.txt")
if err != nil {
panic("Fail opening mock.txt")
}
v2, err := io.Open("mockV2.txt")
if err != nil {
panic("Fail opening mockV2.txt")
}
b.StartTimer() // Start timer here to evaluate delta
for i := 0; i <= b.N; i++ {
sig := sync.BuildSigTable(v1)
sync.Delta(sig, v2)
}
}