@@ -25,26 +25,24 @@ func TestMapReduceSimple(t *testing.T) {
25
25
ctx := context .Background ()
26
26
opts := []Option {UseTreeBitWidth (5 )}
27
27
cs := & readCounterStore {cbor .NewCborStore (newMockBlocks ()), 0 }
28
- begn , err := NewNode (cs , opts ... )
29
- require .NoError (t , err )
30
28
31
- golden := make (map [string ]string )
32
29
N := 50000
33
- for range N {
34
- k := randKey ()
35
- v := randValue ()
36
- golden [k ] = string ([]byte (* v ))
37
- begn .Set (ctx , k , v )
38
- }
39
-
40
- reLoadNode := func (node * Node ) * Node {
41
- c , err := node .Write (ctx )
30
+ var rootCid cid.Cid
31
+ golden := make (map [string ]string )
32
+ {
33
+ begn , err := NewNode (cs , opts ... )
42
34
require .NoError (t , err )
43
- res , err := LoadNode (ctx , cs , c , opts ... )
35
+
36
+ for range N {
37
+ k := randKey ()
38
+ v := randValue ()
39
+ golden [k ] = string ([]byte (* v ))
40
+ begn .Set (ctx , k , v )
41
+ }
42
+
43
+ rootCid , err = begn .Write (ctx )
44
44
require .NoError (t , err )
45
- return res
46
45
}
47
- begn = reLoadNode (begn )
48
46
49
47
type kv struct {
50
48
k string
@@ -70,14 +68,13 @@ func TestMapReduceSimple(t *testing.T) {
70
68
require .NoError (t , err )
71
69
72
70
cs .readCount = 0
73
- res , err := cmr .MapReduce (ctx , begn )
71
+ res , err := cmr .MapReduce (ctx , cs , rootCid , opts ... )
74
72
require .NoError (t , err )
75
73
require .Equal (t , len (golden ), len (res ))
76
74
t .Logf ("fresh readCount: %d" , cs .readCount )
77
75
78
- begn = reLoadNode (begn )
79
76
cs .readCount = 0
80
- res , err = cmr .MapReduce (ctx , begn )
77
+ res , err = cmr .MapReduce (ctx , cs , rootCid , opts ... )
81
78
require .NoError (t , err )
82
79
t .Logf ("fresh re-readCount: %d" , cs .readCount )
83
80
require .Less (t , cs .readCount , 200 )
@@ -94,39 +91,42 @@ func TestMapReduceSimple(t *testing.T) {
94
91
verifyConsistency (res )
95
92
96
93
{
94
+ begn , err := LoadNode (ctx , cs , rootCid , opts ... )
95
+ require .NoError (t , err )
97
96
// add new key
98
97
k := randKey ()
99
98
v := randValue ()
100
99
golden [k ] = string ([]byte (* v ))
101
100
begn .Set (ctx , k , v )
102
101
103
- begn = reLoadNode (begn )
102
+ rootCid , err = begn .Write (ctx )
103
+ require .NoError (t , err )
104
104
}
105
105
106
106
cs .readCount = 0
107
- res , err = cmr .MapReduce (ctx , begn )
107
+ res , err = cmr .MapReduce (ctx , cs , rootCid , opts ... )
108
108
require .NoError (t , err )
109
109
verifyConsistency (res )
110
110
t .Logf ("new key readCount: %d" , cs .readCount )
111
111
require .Less (t , cs .readCount , 200 )
112
112
113
- begn = reLoadNode (begn )
114
113
cs .readCount = 0
115
- res , err = cmr .MapReduce (ctx , begn )
114
+ res , err = cmr .MapReduce (ctx , cs , rootCid , opts ... )
116
115
require .NoError (t , err )
117
116
verifyConsistency (res )
118
117
t .Logf ("repeat readCount: %d" , cs .readCount )
119
118
require .Less (t , cs .readCount , 200 )
120
119
121
- begn = reLoadNode (begn )
122
120
cs .readCount = 0
123
- res , err = cmr .MapReduce (ctx , begn )
121
+ res , err = cmr .MapReduce (ctx , cs , rootCid , opts ... )
124
122
require .NoError (t , err )
125
123
verifyConsistency (res )
126
124
t .Logf ("repeat readCount: %d" , cs .readCount )
127
125
require .Less (t , cs .readCount , 200 )
128
126
129
127
{
128
+ begn , err := LoadNode (ctx , cs , rootCid , opts ... )
129
+ require .NoError (t , err )
130
130
// add two new keys
131
131
k := randKey ()
132
132
v := randValue ()
@@ -137,11 +137,12 @@ func TestMapReduceSimple(t *testing.T) {
137
137
golden [k ] = string ([]byte (* v ))
138
138
begn .Set (ctx , k , v )
139
139
140
- begn = reLoadNode (begn )
140
+ rootCid , err = begn .Write (ctx )
141
+ require .NoError (t , err )
141
142
}
142
143
143
144
cs .readCount = 0
144
- res , err = cmr .MapReduce (ctx , begn )
145
+ res , err = cmr .MapReduce (ctx , cs , rootCid , opts ... )
145
146
require .NoError (t , err )
146
147
verifyConsistency (res )
147
148
t .Logf ("new two keys readCount: %d" , cs .readCount )
0 commit comments