(t *testing.T)
| 418 | } |
| 419 | |
| 420 | func TestTwoPhaseCommit(t *testing.T) { |
| 421 | c := twopc.NewCoordinator(twopc.NewOptions(5 * time.Second)) |
| 422 | |
| 423 | testNodeReset() |
| 424 | |
| 425 | policy = AllGood |
| 426 | res, err := c.Put(nodes, &RaftWriteBatchReq{TxID: 0, Cmds: []string{"+1", "-3", "+10"}}) |
| 427 | |
| 428 | if err != nil { |
| 429 | t.Fatalf("error occurred: %s", err.Error()) |
| 430 | } |
| 431 | |
| 432 | if res.(int64) != 8 { |
| 433 | t.Fatalf("TwoPC returns invalid result: %v", res) |
| 434 | } |
| 435 | |
| 436 | testNodeReset() |
| 437 | |
| 438 | policy = FailOnPrepare |
| 439 | res, err = c.Put(nodes, &RaftWriteBatchReq{TxID: 1, Cmds: []string{"-3", "-4", "+1"}}) |
| 440 | |
| 441 | if err == nil { |
| 442 | t.Fatal("unexpected result: returned nil while expecting an error") |
| 443 | } else { |
| 444 | t.Logf("Error occurred as expected: %s", err.Error()) |
| 445 | } |
| 446 | |
| 447 | testNodeReset() |
| 448 | |
| 449 | policy = FailOnCommit |
| 450 | res, err = c.Put(nodes, &RaftWriteBatchReq{TxID: 2, Cmds: []string{"-5", "+9", "+1"}}) |
| 451 | |
| 452 | if err == nil { |
| 453 | t.Fatal("unexpected result: returned nil while expecting an error") |
| 454 | } else { |
| 455 | t.Logf("Error occurred as expected: %s", err.Error()) |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | func TestTwoPhaseCommit_WithHooks(t *testing.T) { |
| 460 | errorBeforePrepare := false |
nothing calls this directly
no test coverage detected