@@ -171,6 +171,67 @@ func TestStream(t *testing.T) {
171171 require .NoError (t , db .Close ())
172172}
173173
174+ func TestStreamMaxSize (t * testing.T ) {
175+ if ! * manual {
176+ t .Skip ("Skipping test meant to be run manually." )
177+ return
178+ }
179+ // Set the maxStreamSize to 1MB for the duration of the test so that the it can use a smaller
180+ // dataset than it would otherwise need.
181+ originalMaxStreamSize := maxStreamSize
182+ maxStreamSize = 1 << 20
183+ defer func () {
184+ maxStreamSize = originalMaxStreamSize
185+ }()
186+
187+ testSize := int (1e6 )
188+ dir , err := os .MkdirTemp ("" , "badger-big-test" )
189+ require .NoError (t , err )
190+ defer removeDir (dir )
191+
192+ db , err := OpenManaged (DefaultOptions (dir ))
193+ require .NoError (t , err )
194+
195+ var count int
196+ wb := db .NewWriteBatchAt (5 )
197+ for _ , prefix := range []string {"p0" , "p1" , "p2" } {
198+ for i := 1 ; i <= testSize ; i ++ {
199+ require .NoError (t , wb .SetEntry (NewEntry (keyWithPrefix (prefix , i ), value (i ))))
200+ count ++
201+ }
202+ }
203+ require .NoError (t , wb .Flush ())
204+
205+ stream := db .NewStreamAt (math .MaxUint64 )
206+ stream .LogPrefix = "Testing"
207+ c := & collector {}
208+ stream .Send = c .Send
209+
210+ // default value
211+ require .Equal (t , stream .MaxSize , maxStreamSize )
212+
213+ // reset maxsize
214+ stream .MaxSize = 1024 * 1024 * 50
215+
216+ // Test case 1. Retrieve everything.
217+ err = stream .Orchestrate (ctxb )
218+ require .NoError (t , err )
219+ require .Equal (t , 3 * testSize , len (c .kv ), "Expected 30000. Got: %d" , len (c .kv ))
220+
221+ m := make (map [string ]int )
222+ for _ , kv := range c .kv {
223+ prefix , ki := keyToInt (kv .Key )
224+ expected := value (ki )
225+ require .Equal (t , expected , kv .Value )
226+ m [prefix ]++
227+ }
228+ require .Equal (t , 3 , len (m ))
229+ for pred , count := range m {
230+ require .Equal (t , testSize , count , "Count mismatch for pred: %s" , pred )
231+ }
232+ require .NoError (t , db .Close ())
233+ }
234+
174235func TestStreamWithThreadId (t * testing.T ) {
175236 dir , err := os .MkdirTemp ("" , "badger-test" )
176237 require .NoError (t , err )
0 commit comments