ddl_budget_test.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. package storage
  2. import (
  3. "errors"
  4. "strings"
  5. "testing"
  6. )
  7. // The DDL commit publishes one storage transaction, so the rewrite budget must
  8. // reject an oversized table before the batch is encoded. The boundary is
  9. // inclusive: exactly the store's operation ceiling is still sendable.
  10. func TestDDLBatchBudgetRejectsOversizedRewrite(t *testing.T) {
  11. budget := &ddlBatchBudget{}
  12. if err := budget.reserve("t", maxOperations, 0); err != nil {
  13. t.Fatalf("reserve at the operation ceiling = %v, want nil", err)
  14. }
  15. err := budget.reserve("t", 1, 0)
  16. var limit *ddlBatchLimitError
  17. if !errors.As(err, &limit) {
  18. t.Fatalf("reserve past the operation ceiling = %v, want *ddlBatchLimitError", err)
  19. }
  20. if !strings.Contains(limit.Error(), "storage batch limit") {
  21. t.Fatalf("limit error message = %q, want the storage batch limit named", limit.Error())
  22. }
  23. if limit.Table != "t" {
  24. t.Fatalf("limit error table = %q, want t", limit.Table)
  25. }
  26. bytes := &ddlBatchBudget{}
  27. if err := bytes.reserve("t", 1, maxTransactionSize); err != nil {
  28. t.Fatalf("reserve at the byte ceiling = %v, want nil", err)
  29. }
  30. if err := bytes.reserve("t", 1, 1); !errors.As(err, &limit) {
  31. t.Fatalf("reserve past the byte ceiling = %v, want *ddlBatchLimitError", err)
  32. }
  33. }