(t *testing.T, query *frame.Frame, response message.Error, cfg *proxyTestConfig, testMessage string)
| 371 | } |
| 372 | |
| 373 | func testProxyRetryWithConfig(t *testing.T, query *frame.Frame, response message.Error, cfg *proxyTestConfig, testMessage string) (numNodesTried, retryCount int, responseError error) { |
| 374 | ctx, cancel := context.WithCancel(context.Background()) |
| 375 | defer cancel() |
| 376 | |
| 377 | var mu sync.Mutex |
| 378 | tried := make(map[string]int) |
| 379 | prepared := make(map[[16]byte]string) |
| 380 | |
| 381 | if cfg == nil { |
| 382 | cfg = &proxyTestConfig{} |
| 383 | } |
| 384 | |
| 385 | cfg.handlers = proxycore.MockRequestHandlers{ |
| 386 | primitive.OpCodeQuery: func(cl *proxycore.MockClient, frm *frame.Frame) message.Message { |
| 387 | if msg := cl.InterceptQuery(frm.Header, frm.Body.Message.(*message.Query)); msg != nil { |
| 388 | return msg |
| 389 | } else { |
| 390 | mu.Lock() |
| 391 | tried[cl.Local().IP]++ |
| 392 | mu.Unlock() |
| 393 | return response |
| 394 | } |
| 395 | }, |
| 396 | primitive.OpCodeExecute: func(cl *proxycore.MockClient, frm *frame.Frame) message.Message { |
| 397 | msg := frm.Body.Message.(*message.Execute) |
| 398 | mu.Lock() |
| 399 | defer mu.Unlock() |
| 400 | var id [16]byte |
| 401 | copy(id[:], msg.QueryId) |
| 402 | if _, ok := prepared[id]; !ok { |
| 403 | return &message.Unprepared{ |
| 404 | ErrorMessage: "query is not prepared", |
| 405 | Id: id[:], |
| 406 | } |
| 407 | } else { |
| 408 | tried[cl.Local().IP]++ |
| 409 | return response |
| 410 | } |
| 411 | }, |
| 412 | primitive.OpCodeBatch: func(cl *proxycore.MockClient, frm *frame.Frame) message.Message { |
| 413 | msg := frm.Body.Message.(*message.Batch) |
| 414 | mu.Lock() |
| 415 | defer mu.Unlock() |
| 416 | for _, child := range msg.Children { |
| 417 | id := child.Id |
| 418 | if id != nil { |
| 419 | var hash [16]byte |
| 420 | copy(hash[:], id) |
| 421 | if _, ok := prepared[hash]; !ok { |
| 422 | return &message.Unprepared{ |
| 423 | ErrorMessage: "query is not prepared", |
| 424 | Id: id, |
| 425 | } |
| 426 | } |
| 427 | } |
| 428 | } |
| 429 | tried[cl.Local().IP]++ |
| 430 | return response |
no test coverage detected