vitess.io/vitess@v0.16.2/go/vt/vttablet/tabletmanager/vreplication/json_docs_test.go (about) 1 /* 2 Copyright 2020 The Vitess Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package vreplication 18 19 import ( 20 "fmt" 21 ) 22 23 var jsonSingleDoc = ` 24 { 25 "_id": "5f882c85c74593afb7895a16", 26 "index": 0, 27 "guid": "452caaef-49a9-4483-b875-2440b90d079b", 28 "isActive": true, 29 "balance": "$2,636.61", 30 "picture": "http://placehold.it/32x32", 31 "age": 36, 32 "id2": 1234567890, 33 "eyeColor": "green", 34 "name": "Stephens Paul", 35 "gender": "male", 36 "company": "QUONATA", 37 "email": "stephenspaul@quonata.com", 38 "phone": "+1 (826) 542-2203", 39 "address": "986 Erasmus Street, Tibbie, West Virginia, 3037", 40 "registered": "2020-08-06T08:10:25 -02:00", 41 "longUnsignedInt": 18446744073709551615 42 } 43 ` 44 45 type largeDocCollectionType string 46 47 const ( 48 largeJSONArrayCollection largeDocCollectionType = "array" 49 largeJSONObjectCollection largeDocCollectionType = "object" 50 ) 51 52 func repeatJSON(jsonDoc string, times int, typ largeDocCollectionType) string { 53 var jsonDocs string 54 switch typ { 55 case largeJSONArrayCollection: 56 jsonDocs = "[" 57 for times > 0 { 58 times-- 59 jsonDocs += jsonSingleDoc 60 if times != 0 { 61 jsonDocs += "," 62 } 63 } 64 jsonDocs += "]" 65 case largeJSONObjectCollection: 66 jsonDocs = "{" 67 for times > 0 { 68 times-- 69 jsonDocs += fmt.Sprintf("\"%d\": %s", times, jsonSingleDoc) 70 if times != 0 { 71 jsonDocs += "," 72 } 73 } 74 jsonDocs += "}" 75 76 } 77 return jsonDocs 78 } 79 80 var jsonMultipleDocs = ` 81 [ 82 { 83 "_id": "5f882c85c74593afb7895a16", 84 "index": 0, 85 "guid": "452caaef-49a9-4483-b875-2440b90d079b", 86 "isActive": true, 87 "balance": "$2,636.61", 88 "picture": "http://placehold.it/32x32", 89 "age": 36, 90 "eyeColor": "green", 91 "name": "Stephens Paul", 92 "gender": "male", 93 "company": "QUONATA", 94 "email": "stephenspaul@quonata.com", 95 "phone": "+1 (826) 542-2203", 96 "address": "986 Erasmus Street, Tibbie, West Virginia, 3037", 97 "about": "Reprehenderit nisi in consequat cupidatat aliqua duis. Esse consequat sit exercitation velit in nulla. Anim culpa commodo labore id veniam elit cillum dolore sunt aliquip. Anim ex ea enim non sunt tempor. Enim duis mollit culpa officia reprehenderit aliqua anim proident laboris consectetur eiusmod.\r\n", 98 "registered": "2020-08-06T08:10:25 -02:00", 99 "latitude": -31.013461, 100 "longitude": 136.055816, 101 "tags": [ 102 "Unicode 木元木元木元木元木元木元木元木元木元木元木元木元木元木元木元木元木元木元木元木元木元木元 Text", 103 "nisi", 104 "tempor", 105 "dolor", 106 "in", 107 "ut", 108 "culpa", 109 "adipisicing" 110 ], 111 "friends": [ 112 { 113 "id": 0, 114 "name": "Bessie Mclean" 115 }, 116 { 117 "id": 1, 118 "name": "Sharon Salazar" 119 }, 120 { 121 "id": 2, 122 "name": "Ortega Vazquez" 123 } 124 ], 125 "greeting": "Hello, Stephens Paul! You have 9 unread messages.", 126 "favoriteFruit": "strawberry" 127 }, 128 { 129 "_id": "5f882c85a0da2ca490afc52b", 130 "index": 1, 131 "guid": "23da3a18-54fb-484b-b921-1122c3693811", 132 "isActive": false, 133 "balance": "$1,500.22", 134 "picture": "http://placehold.it/32x32", 135 "age": 25, 136 "eyeColor": "brown", 137 "name": "Bradley Hinton", 138 "gender": "male", 139 "company": "AFFLUEX", 140 "email": "bradleyhinton@affluex.com", 141 "phone": "+1 (909) 576-3260", 142 "address": "527 Dictum Court, Crumpler, District Of Columbia, 6169", 143 "about": "Aliqua nulla sunt eiusmod cupidatat do nisi anim elit non ut mollit ex. Eu enim duis proident mollit anim exercitation ut aute. Et reprehenderit laboris dolor laboris ex ullamco consectetur consectetur qui veniam laborum. Magna nisi aute consequat cillum duis id dolor voluptate nulla nulla. Aliquip veniam velit commodo sunt duis ex. Sit deserunt est minim labore aliqua veniam anim elit do adipisicing sit in pariatur. Officia ut anim officia exercitation cupidatat cupidatat dolore incididunt incididunt.\r\n", 144 "registered": "2019-07-21T11:02:42 -02:00", 145 "latitude": 72.516111, 146 "longitude": 96.063721, 147 "tags": [ 148 "ullamco", 149 "ut", 150 "magna", 151 "velit", 152 "et", 153 "labore", 154 "nostrud" 155 ], 156 "friends": [ 157 { 158 "id": 0, 159 "name": "Golden Figueroa" 160 }, 161 { 162 "id": 1, 163 "name": "Brandy Farmer" 164 }, 165 { 166 "id": 2, 167 "name": "Rosalind Blevins" 168 } 169 ], 170 "greeting": "Hello, Bradley Hinton! You have 10 unread messages.", 171 "favoriteFruit": "strawberry" 172 }, 173 { 174 "_id": "5f882c8520a784500e49119e", 175 "index": 2, 176 "guid": "fdbab820-8330-4f26-9ff8-12bd46c91d86", 177 "isActive": false, 178 "balance": "$3,385.42", 179 "picture": "http://placehold.it/32x32", 180 "age": 32, 181 "eyeColor": "blue", 182 "name": "Kirsten Erickson", 183 "gender": "female", 184 "company": "KINDALOO", 185 "email": "kirstenerickson@kindaloo.com", 186 "phone": "+1 (872) 521-3868", 187 "address": "196 Madison Street, Woodruff, Virgin Islands, 5496", 188 "about": "Et sunt sunt deserunt ad do irure do amet elit cillum id commodo. Quis voluptate excepteur id ea. Sunt enim id irure reprehenderit mollit nostrud ea qui non culpa aute.\r\n", 189 "registered": "2015-02-22T06:41:54 -01:00", 190 "latitude": 80.290313, 191 "longitude": 53.088018, 192 "tags": [ 193 "cupidatat", 194 "aliquip", 195 "anim", 196 "aliqua", 197 "elit", 198 "commodo", 199 "aliquip" 200 ], 201 "friends": [ 202 { 203 "id": 0, 204 "name": "Castaneda Schwartz" 205 }, 206 { 207 "id": 1, 208 "name": "Gracie Rodriquez" 209 }, 210 { 211 "id": 2, 212 "name": "Isabel Miles" 213 } 214 ], 215 "greeting": "Hello, Kirsten Erickson! You have 2 unread messages.", 216 "favoriteFruit": "apple" 217 }, 218 { 219 "_id": "5f882c852eac82920fe459da", 220 "index": 3, 221 "guid": "e45c2807-2d5f-45e7-a2f9-3b61b9953c64", 222 "isActive": true, 223 "balance": "$1,785.04", 224 "picture": "http://placehold.it/32x32", 225 "age": 22, 226 "eyeColor": "brown", 227 "name": "Bertha Guthrie", 228 "gender": "female", 229 "company": "ISOSTREAM", 230 "email": "berthaguthrie@isostream.com", 231 "phone": "+1 (988) 409-3274", 232 "address": "392 Elmwood Avenue, Venice, Texas, 2787", 233 "about": "Cupidatat do et irure sunt dolore ullamco ullamco fugiat excepteur qui. Ut nostrud in laborum nisi. Exercitation deserunt enim exercitation eiusmod eu ea ullamco commodo do pariatur. Incididunt veniam ad anim et reprehenderit tempor irure commodo reprehenderit esse cupidatat.\r\n", 234 "registered": "2019-04-14T01:30:41 -02:00", 235 "latitude": 62.215237, 236 "longitude": -139.310675, 237 "tags": [ 238 "non", 239 "eiusmod", 240 "culpa", 241 "voluptate", 242 "sint", 243 "labore", 244 "labore" 245 ], 246 "friends": [ 247 { 248 "id": 0, 249 "name": "Oneal Ray" 250 }, 251 { 252 "id": 1, 253 "name": "Mckenzie Wiley" 254 }, 255 { 256 "id": 2, 257 "name": "Patsy Hood" 258 } 259 ], 260 "greeting": "Hello, Bertha Guthrie! You have 4 unread messages.", 261 "favoriteFruit": "apple" 262 }, 263 { 264 "_id": "5f882c8584ae9d7e9946216b", 265 "index": 4, 266 "guid": "e339c4d9-29ac-43ea-ad83-88a357ee0292", 267 "isActive": false, 268 "balance": "$3,598.44", 269 "picture": "http://placehold.it/32x32", 270 "age": 31, 271 "eyeColor": "brown", 272 "name": "Brooks Gallagher", 273 "gender": "male", 274 "company": "BESTO", 275 "email": "brooksgallagher@besto.com", 276 "phone": "+1 (887) 444-3408", 277 "address": "652 Winthrop Street, Foscoe, Utah, 1225", 278 "about": "Dolor laborum laborum pariatur velit ut aliqua. Non voluptate ipsum do consectetur labore dolore incididunt veniam. Elit cillum ullamco ea officia aliqua excepteur deserunt. Ex aute voluptate consectetur ut magna Lorem dolor aliquip elit sit excepteur quis. Esse consectetur veniam consectetur sit voluptate excepteur.\r\n", 279 "registered": "2020-04-03T09:26:11 -02:00", 280 "latitude": -42.312109, 281 "longitude": 78.139406, 282 "tags": [ 283 "esse", 284 "do", 285 "dolor", 286 "ut", 287 "culpa", 288 "quis", 289 "sint" 290 ], 291 "friends": [ 292 { 293 "id": 0, 294 "name": "Blankenship Rosario" 295 }, 296 { 297 "id": 1, 298 "name": "Deborah Herman" 299 }, 300 { 301 "id": 2, 302 "name": "Frieda Hill" 303 } 304 ], 305 "greeting": "Hello, Brooks Gallagher! You have 3 unread messages.", 306 "favoriteFruit": "apple" 307 }, 308 { 309 "_id": "5f882c85686d444c49efbe23", 310 "index": 5, 311 "guid": "a53afb9c-0c3c-406b-90d2-130d455e2679", 312 "isActive": true, 313 "balance": "$1,084.59", 314 "picture": "http://placehold.it/32x32", 315 "age": 26, 316 "eyeColor": "green", 317 "name": "Cash Steele", 318 "gender": "male", 319 "company": "ZOMBOID", 320 "email": "cashsteele@zomboid.com", 321 "phone": "+1 (851) 482-3446", 322 "address": "272 Evergreen Avenue, Hoagland, Arizona, 1110", 323 "about": "Incididunt cillum consectetur incididunt labore ex laborum culpa sunt et qui voluptate. Et ea reprehenderit ex amet minim nulla et aliqua dolor veniam fugiat officia laborum non. Aliquip magna id sunt cillum voluptate. Ullamco do ad aliqua dolore esse aliquip velit nisi. Ex tempor voluptate dolor adipisicing dolor laborum duis non ea esse sunt. Ut dolore aliquip voluptate ad nisi minim ullamco est. Aliqua est laboris consequat officia sint proident mollit mollit nisi ut non tempor nisi mollit.\r\n", 324 "registered": "2019-07-31T07:48:15 -02:00", 325 "latitude": -66.786323, 326 "longitude": -172.051939, 327 "tags": [ 328 "ea", 329 "eiusmod", 330 "aute", 331 "id", 332 "proident", 333 "ea", 334 "ut" 335 ], 336 "friends": [ 337 { 338 "id": 0, 339 "name": "Ford Williamson" 340 }, 341 { 342 "id": 1, 343 "name": "Compton Boyd" 344 }, 345 { 346 "id": 2, 347 "name": "Snyder Warner" 348 } 349 ], 350 "greeting": "Hello, Cash Steele! You have 2 unread messages.", 351 "favoriteFruit": "strawberry" 352 } 353 ] 354 ` 355 356 // handcrafted test (based on an actual user failure) to isolate error with inline type handling 357 var singleLargeObjectTemplate = ` 358 { 359 "user": { 360 "id": 1234567890, 361 "type": 1, 362 "login": "isaac", 363 "created_at": { 364 "seconds": 1618443705 365 } 366 }, 367 "repository": { 368 "id": 1234567890, 369 "name": "gravitational theory", 370 "created_at": { 371 "seconds": 1234567890 372 }, 373 "updated_at": { 374 "seconds": 1234567890 375 }, 376 "visibility": 1, 377 "description": "%s" 378 }, 379 "numberOfLaws": 3, 380 "user2": { 381 "id": 1234567890, 382 "type": 1, 383 "login": "isaac", 384 "created_at": { 385 "seconds": 1234567890 386 }, 387 "challenge": "falling-apples", 388 "response": "eureka" 389 } 390 } 391 `