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 15// +build bigtest 16 17// An integration test for PDML using a relatively large database. 18 19package spanner 20 21import ( 22 "context" 23 "fmt" 24 "testing" 25) 26 27func TestIntegration_BigPDML(t *testing.T) { 28 const nRows int = 1e4 29 30 ctx := context.Background() 31 client, _, cleanup := prepareIntegrationTest(ctx, t, singerDBStatements) 32 defer cleanup() 33 34 columns := []string{"SingerId", "FirstName", "LastName"} 35 36 // Populate the Singers table with random data. 37 const rowsPerApply = 1000 38 for i := 0; i < nRows; i += rowsPerApply { 39 var muts []*Mutation 40 for j := 0; j < rowsPerApply; j++ { 41 id := i + j 42 row := []interface{}{id, fmt.Sprintf("FirstName%d", id), fmt.Sprintf("LastName%d", id)} 43 muts = append(muts, Insert("Singers", columns, row)) 44 } 45 if _, err := client.Apply(ctx, muts); err != nil { 46 t.Fatal(err) 47 } 48 } 49 50 // Run a PDML statement. 51 count, err := client.PartitionedUpdate(ctx, Statement{ 52 SQL: `UPDATE Singers SET Singers.FirstName = "changed" WHERE Singers.SingerId != -1`, 53 }) 54 if err != nil { 55 t.Fatal(err) 56 } 57 if want := int64(nRows); count != want { 58 t.Errorf("got %d, want %d", count, want) 59 } 60} 61