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