-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlow_level_test.go
113 lines (91 loc) · 2.76 KB
/
low_level_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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package billyfs
import (
"fmt"
"github.com/apple/foundationdb/bindings/go/src/fdb"
)
type example struct {
pageSize int
dataInDb []byte
offset int
dataToWrite []byte
error error
wasRead bool
keyPresentedOnRead fdb.KeyConvertible
w *write
}
func (e *example) Set(convertible fdb.KeyConvertible, value []byte) {
e.w.Set(convertible, value)
}
func (example) Key() fdb.Key {
return []byte{0xDE, 0xAD}
}
func (e example) Op() writeOp {
return writeOp{e.dataToWrite, nil, e.offset, e.pageSize}
}
type write struct {
key fdb.KeyConvertible
written []byte
}
func (w *write) Set(convertible fdb.KeyConvertible, value []byte) {
w.key = convertible
w.written = value
}
type exactGetter struct {
data []byte
toReturn error
}
func (e exactGetter) Get() ([]byte, error) {
return e.data, e.toReturn
}
func (e *example) Get(convertible fdb.KeyConvertible) FutureGetter {
e.keyPresentedOnRead = convertible
e.wasRead = true
return &exactGetter{e.dataInDb, e.error}
}
func NewExample(pageSize int, dbSlice []byte, offset int, writeSlice []byte, errorToReturn error) example {
return example{pageSize: pageSize, dataInDb: dbSlice, offset: offset, dataToWrite: writeSlice, keyPresentedOnRead: nil, error: errorToReturn, w: &write{}}
}
func ExampleWriteBlock() {
//another option is to run 2 bit operations, 1 zeroing bits for writing,
// 2nd setting bits to be written
// partial write is funky!
// expand & combine
// A merge
// ----- <- pageSize
// -- <- data
// -- <- op.what
// B merge
// ----- <- pageSize
// ----- <- data
// ---- <- op.what
// C
// ----- <- pageSize
// ----- <- data
// -- <- op.what --> trim?
// D
// ----- <- pageSize
// ----- <- data
// -- <- op.what --> trim 2 & combine
// E
// ----- <- pageSize
// ---- <- data
// -- <- op.what --> trim 2 & combine
// ^ op.offset
examples := []example{
NewExample(3, []byte{0x00, 0x01, 0x02}, 0, []byte{0x03, 0x04, 0x05}, nil),
NewExample(3, []byte{0x00, 0x01, 0x02}, 0, []byte{0x04, 0x05}, nil),
NewExample(3, []byte{0x00, 0x01, 0x02}, 1, []byte{0x04, 0x05}, nil),
NewExample(3, []byte{0x00, 0x01, 0x02}, 1, []byte{0x05}, nil),
NewExample(3, []byte{0x00, 0x01, 0x02}, 1, []byte{0x05, 0x06, 0x07}, nil),
}
for i := range examples {
num, err := WriteBlock(&examples[i], &examples[i], examples[i].Key(), examples[i].Op())
fmt.Printf("%v,%v,R:%v,%v,W:%v\n", num, err, examples[i].wasRead, examples[i].keyPresentedOnRead, examples[i].w)
}
// Output:
// 3,<nil>,R:false,<nil>,W:&{[222 173] [3 4 5]}
// 2,<nil>,R:true,\xde\xad,W:&{[222 173] [4 5]}
// 2,<nil>,R:true,\xde\xad,W:&{[222 173] [0 4 5]}
// 1,<nil>,R:true,\xde\xad,W:&{[222 173] [0 5]}
// 0,error_wrong_write_size Size:3 Want:4,R:false,<nil>,W:&{<nil> []}
}