@@ -26,6 +26,7 @@ import (
26
26
"sync"
27
27
"testing"
28
28
29
+ "github.com/pingcap/tidb/br/pkg/storage"
29
30
"github.com/pingcap/tidb/pkg/domain/infosync"
30
31
"github.com/pingcap/tidb/pkg/executor/internal/exec"
31
32
"github.com/pingcap/tidb/pkg/infoschema"
@@ -190,16 +191,18 @@ func TestCapturePath(t *testing.T) {
190
191
ctx := context .TODO ()
191
192
tempCtx := fillCtxWithTiProxyAddr (ctx , ports )
192
193
suite := newTrafficTestSuite (t , 10 )
193
- exec := suite .build (ctx , "traffic capture to 's3://bucket/tmp' duration='1s'" )
194
+ prefix , suffix := "s3://bucket/tmp" , "access-key=minioadmin&secret-access-key=minioadmin&endpoint=http://minio:8000&force-path-style=true"
195
+ exec := suite .build (ctx , fmt .Sprintf ("traffic capture to '%s?%s' duration='1s'" , prefix , suffix ))
194
196
require .NoError (t , exec .Next (tempCtx , nil ))
195
197
196
198
paths := make ([]string , 0 , tiproxyNum )
197
199
expectedPaths := make ([]string , 0 , tiproxyNum )
198
200
for i := 0 ; i < tiproxyNum ; i ++ {
199
201
httpHandler := handlers [i ]
200
202
output := httpHandler .getForm ().Get ("output" )
201
- require .True (t , strings .HasPrefix (output , "s3://bucket/tmp/" ), output )
202
- paths = append (paths , output [len ("s3://bucket/tmp/" ):])
203
+ require .True (t , strings .HasPrefix (output , prefix ), output )
204
+ require .True (t , strings .HasSuffix (output , suffix ), output )
205
+ paths = append (paths , output [len (prefix )+ 1 :len (output )- len (suffix )- 1 ])
203
206
expectedPaths = append (expectedPaths , fmt .Sprintf ("tiproxy-%d" , i ))
204
207
}
205
208
sort .Strings (paths )
@@ -236,40 +239,47 @@ func TestReplayPath(t *testing.T) {
236
239
formPaths : []string {},
237
240
},
238
241
{
239
- paths : []string {"tiproxy-0" },
242
+ paths : []string {"tiproxy-0/meta" , "tiproxy-0/traffic-1.log" , "tiproxy-0/traffic-2.log " },
240
243
formPaths : []string {"tiproxy-0" },
241
244
warn : "tiproxy instances number (2) is greater than input paths number (1)" ,
242
245
},
243
246
{
244
- paths : []string {"tiproxy-0" , "tiproxy-1" },
247
+ paths : []string {"tiproxy-0/meta " , "tiproxy-1/meta" , "tiproxy-2 " },
245
248
formPaths : []string {"tiproxy-0" , "tiproxy-1" },
246
249
},
247
250
{
248
- paths : []string {"tiproxy-0" , "tiproxy-1" , "tiproxy-2" },
251
+ paths : []string {"tiproxy-0/meta" , "tiproxy-0/traffic-1.log" , "tiproxy-1/meta" , "tiproxy-1/traffic-1.log" },
252
+ formPaths : []string {"tiproxy-0" , "tiproxy-1" },
253
+ },
254
+ {
255
+ paths : []string {"tiproxy-0/meta" , "tiproxy-1/meta" , "tiproxy-2/meta" },
249
256
formPaths : []string {},
250
257
err : "tiproxy instances number (2) is less than input paths number (3)" ,
251
258
},
252
259
}
253
260
ctx := context .TODO ()
261
+ store := & mockExternalStorage {}
254
262
ctx = fillCtxWithTiProxyAddr (ctx , ports )
263
+ ctx = context .WithValue (ctx , trafficStoreKey , store )
264
+ prefix , suffix := "s3://bucket/tmp" , "access-key=minioadmin&secret-access-key=minioadmin&endpoint=http://minio:8000&force-path-style=true"
255
265
for i , test := range tests {
256
- tempCtx := context . WithValue ( ctx , trafficPathKey , test .paths )
266
+ store . paths = test .paths
257
267
suite := newTrafficTestSuite (t , 10 )
258
- exec := suite .build (ctx , "traffic replay from 's3://bucket/tmp ' user='root'" )
268
+ exec := suite .build (ctx , fmt . Sprintf ( "traffic replay from '%s?%s ' user='root'" , prefix , suffix ) )
259
269
for j := 0 ; j < tiproxyNum ; j ++ {
260
270
handlers [j ].reset ()
261
271
}
262
- err := exec .Next (tempCtx , nil )
272
+ err := exec .Next (ctx , nil )
263
273
if test .err != "" {
264
- require .ErrorContains (t , err , test .err )
274
+ require .ErrorContains (t , err , test .err , "case %d" , i )
265
275
} else {
266
- require .NoError (t , err )
276
+ require .NoError (t , err , "case %d" , i )
267
277
warnings := suite .stmtCtx ().GetWarnings ()
268
278
if test .warn != "" {
269
- require .Len (t , warnings , 1 )
270
- require .ErrorContains (t , warnings [0 ].Err , test .warn )
279
+ require .Len (t , warnings , 1 , "case %d" , i )
280
+ require .ErrorContains (t , warnings [0 ].Err , test .warn , "case %d" , i )
271
281
} else {
272
- require .Len (t , warnings , 0 )
282
+ require .Len (t , warnings , 0 , "case %d" , i )
273
283
}
274
284
}
275
285
@@ -278,14 +288,15 @@ func TestReplayPath(t *testing.T) {
278
288
httpHandler := handlers [j ]
279
289
if httpHandler .getMethod () != "" {
280
290
form := httpHandler .getForm ()
281
- require .NotEmpty (t , form )
291
+ require .NotEmpty (t , form , "case %d" , i )
282
292
input := form .Get ("input" )
283
- require .True (t , strings .HasPrefix (input , "s3://bucket/tmp/" ), input )
284
- formPaths = append (formPaths , input [len ("s3://bucket/tmp/" ):])
293
+ require .True (t , strings .HasPrefix (input , prefix ), input )
294
+ require .True (t , strings .HasSuffix (input , suffix ), input )
295
+ formPaths = append (formPaths , input [len (prefix )+ 1 :len (input )- len (suffix )- 1 ])
285
296
}
286
297
}
287
298
sort .Strings (formPaths )
288
- require .Equal (t , test .formPaths , formPaths , "case %d" , i )
299
+ require .Equal (t , test .formPaths , formPaths , "case %d" , i , "case %d" , i )
289
300
}
290
301
}
291
302
@@ -579,3 +590,19 @@ type mockPrivManager struct {
579
590
func (m * mockPrivManager ) RequestDynamicVerification (activeRoles []* auth.RoleIdentity , privName string , grantable bool ) bool {
580
591
return m .Called (activeRoles , privName , grantable ).Bool (0 )
581
592
}
593
+
594
+ var _ storage.ExternalStorage = (* mockExternalStorage )(nil )
595
+
596
+ type mockExternalStorage struct {
597
+ storage.ExternalStorage
598
+ paths []string
599
+ }
600
+
601
+ func (s * mockExternalStorage ) WalkDir (ctx context.Context , _ * storage.WalkOption , fn func (string , int64 ) error ) error {
602
+ for _ , path := range s .paths {
603
+ if err := fn (path , 0 ); err != nil {
604
+ return err
605
+ }
606
+ }
607
+ return nil
608
+ }
0 commit comments