-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdedicated_parity_test.go
92 lines (70 loc) · 1.35 KB
/
dedicated_parity_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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package streammux_test
import (
"bytes"
"crypto/sha256"
"io"
"os"
"testing"
"github.com/bh107/streammux"
"github.com/bh107/streammux/pkg/util/testutil"
)
func TestDedicatedParity(t *testing.T) {
blkdevs := []io.ReadWriteCloser{
testutil.NewBlockDevice(1 << 20),
testutil.NewBlockDevice(1 << 20),
testutil.NewBlockDevice(1 << 20),
testutil.NewBlockDevice(1 << 20),
testutil.NewFaultyDevice(1<<20, 100),
}
dp := streammux.NewDedicatedParity(blkdevs[0], blkdevs[1:])
dp.Open()
data := make([]byte, 1<<22)
f, err := os.Open("/dev/urandom")
if err != nil {
t.Fatal(err)
}
n, err := f.Read(data)
if err != nil || n != len(data) {
t.Fatal(err)
}
origSha256Sum := sha256.Sum256(data)
buf := bytes.NewBuffer(data)
p := make([]byte, 1024)
for {
_, err := buf.Read(p)
if err == io.EOF {
break
}
if err != nil {
t.Fatal(err)
}
n, err := dp.Write(p)
if err != nil || n != len(p) {
t.Fatal(err, n)
}
}
// close to reset position
if err := dp.Close(); err != nil {
t.Fatal(err)
}
// reopen
dp.Open()
buf.Reset()
for {
_, err := dp.Read(p)
if err == io.EOF {
break
}
if err != nil {
t.Fatal(err)
}
_, err = buf.Write(p)
if err != nil {
t.Fatal(err)
}
}
newSha256Sum := sha256.Sum256(buf.Bytes())
if origSha256Sum != newSha256Sum {
t.Fatal("origSha256Sum != newSha256Sum")
}
}