You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

61 lines
1.7 KiB

  1. // Copyright 2018 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // +build bigtest
  15. // An integration test for PDML using a relatively large database.
  16. package spanner
  17. import (
  18. "context"
  19. "fmt"
  20. "testing"
  21. )
  22. func TestIntegration_BigPDML(t *testing.T) {
  23. const nRows int = 1e4
  24. ctx := context.Background()
  25. client, _, cleanup := prepareIntegrationTest(ctx, t, singerDBStatements)
  26. defer cleanup()
  27. columns := []string{"SingerId", "FirstName", "LastName"}
  28. // Populate the Singers table with random data.
  29. const rowsPerApply = 1000
  30. for i := 0; i < nRows; i += rowsPerApply {
  31. var muts []*Mutation
  32. for j := 0; j < rowsPerApply; j++ {
  33. id := i + j
  34. row := []interface{}{id, fmt.Sprintf("FirstName%d", id), fmt.Sprintf("LastName%d", id)}
  35. muts = append(muts, Insert("Singers", columns, row))
  36. }
  37. if _, err := client.Apply(ctx, muts); err != nil {
  38. t.Fatal(err)
  39. }
  40. }
  41. // Run a PDML statement.
  42. count, err := client.PartitionedUpdate(ctx, Statement{
  43. SQL: `UPDATE Singers SET Singers.FirstName = "changed" WHERE Singers.SingerId != -1`,
  44. })
  45. if err != nil {
  46. t.Fatal(err)
  47. }
  48. if want := int64(nRows); count != want {
  49. t.Errorf("got %d, want %d", count, want)
  50. }
  51. }