Best K6 code snippet using k6.New
merge_test.go
Source:merge_test.go
...49 rng committed.Range50 records []testValueRecord51}52func createIter(tr []testRange) committed.Iterator {53 iter := testutil.NewFakeIterator()54 for _, rng := range tr {55 addRange := rng.rng56 iter.AddRange(&addRange)57 for _, record := range rng.records {58 iter.AddValueRecords(&graveler.ValueRecord{59 Key: graveler.Key(record.key),60 Value: &graveler.Value{61 Identity: []byte(record.identity),62 Data: nil,63 },64 })65 }66 }67 return iter68}69func Test_merge(t *testing.T) {70 tests := map[string]struct {71 baseRange []testRange72 sourceRange []testRange73 destRange []testRange74 expectedActions []writeAction75 conflictExpectedIdx *int76 expectedErr error77 }{78 "dest range added before": {79 baseRange: []testRange{{80 rng: committed.Range{ID: "base:k3-k6", MinKey: committed.Key("k3"), MaxKey: committed.Key("k6"), Count: 2, EstimatedSize: 1234},81 records: nil,82 }},83 sourceRange: []testRange{{84 rng: committed.Range{ID: "base:k3-k6", MinKey: committed.Key("k3"), MaxKey: committed.Key("k6"), Count: 2, EstimatedSize: 1234},85 records: nil,86 }},87 destRange: []testRange{88 {rng: committed.Range{ID: "dest:k1-k2", MinKey: committed.Key("k1"), MaxKey: committed.Key("k2"), Count: 2, EstimatedSize: 1234}},89 {rng: committed.Range{ID: "base:k3-k6", MinKey: committed.Key("k3"), MaxKey: committed.Key("k6"), Count: 2, EstimatedSize: 1234}},90 },91 conflictExpectedIdx: nil,92 expectedActions: []writeAction{93 {94 action: actionTypeWriteRange,95 rng: committed.Range{ID: "dest:k1-k2", MinKey: committed.Key("k1"), MaxKey: committed.Key("k2"), Count: 2, EstimatedSize: 1234},96 },97 {98 action: actionTypeWriteRange,99 rng: committed.Range{ID: "base:k3-k6", MinKey: committed.Key("k3"), MaxKey: committed.Key("k6"), Count: 2, EstimatedSize: 1234},100 },101 },102 expectedErr: nil,103 },104 "source range added before": {105 baseRange: []testRange{106 {rng: committed.Range{ID: "base:k3-k6", MinKey: committed.Key("k3"), MaxKey: committed.Key("k6"), Count: 2, EstimatedSize: 1024}},107 },108 sourceRange: []testRange{109 {rng: committed.Range{ID: "source:k1-k2", MinKey: committed.Key("k1"), MaxKey: committed.Key("k2"), Count: 2, EstimatedSize: 1024}},110 {rng: committed.Range{ID: "base:k3-k6", MinKey: committed.Key("k3"), MaxKey: committed.Key("k6"), Count: 2, EstimatedSize: 1024}},111 },112 destRange: []testRange{113 {rng: committed.Range{ID: "base:k3-k6", MinKey: committed.Key("k3"), MaxKey: committed.Key("k6"), Count: 2, EstimatedSize: 1024}},114 },115 conflictExpectedIdx: nil,116 expectedActions: []writeAction{117 {118 action: actionTypeWriteRange,119 rng: committed.Range{ID: "source:k1-k2", MinKey: committed.Key("k1"), MaxKey: committed.Key("k2"), Count: 2, EstimatedSize: 1024},120 },121 {122 action: actionTypeWriteRange,123 rng: committed.Range{ID: "base:k3-k6", MinKey: committed.Key("k3"), MaxKey: committed.Key("k6"), Count: 2, EstimatedSize: 1024},124 },125 },126 },127 "source range removed before": {128 baseRange: []testRange{129 {rng: committed.Range{ID: "base:k1-k2", MinKey: committed.Key("k1"), MaxKey: committed.Key("k2"), Count: 2, EstimatedSize: 1024}},130 {rng: committed.Range{ID: "base:k3-k6", MinKey: committed.Key("k3"), MaxKey: committed.Key("k6"), Count: 2, EstimatedSize: 1024}},131 },132 sourceRange: []testRange{133 {rng: committed.Range{ID: "base:k3-k6", MinKey: committed.Key("k3"), MaxKey: committed.Key("k6"), Count: 2, EstimatedSize: 1024}},134 },135 destRange: []testRange{136 {rng: committed.Range{ID: "base:k1-k2", MinKey: committed.Key("k1"), MaxKey: committed.Key("k2"), Count: 2, EstimatedSize: 1024}},137 {rng: committed.Range{ID: "base:k3-k6", MinKey: committed.Key("k3"), MaxKey: committed.Key("k6"), Count: 2, EstimatedSize: 1024}},138 },139 conflictExpectedIdx: nil,140 expectedActions: []writeAction{141 {142 action: actionTypeWriteRange,143 rng: committed.Range{ID: "base:k3-k6", MinKey: committed.Key("k3"), MaxKey: committed.Key("k6"), Count: 2, EstimatedSize: 1024},144 },145 },146 },147 "source range inner change": {148 baseRange: []testRange{149 {rng: committed.Range{ID: "base:k1-k3", MinKey: committed.Key("k1"), MaxKey: committed.Key("k3"), EstimatedSize: 1024}, records: []testValueRecord{150 {"k1", "base:k1"}, {"k3", "base:k3"},151 }},152 },153 sourceRange: []testRange{154 {rng: committed.Range{ID: "source:k1-k3", MinKey: committed.Key("k1"), MaxKey: committed.Key("k3"), EstimatedSize: 1024}, records: []testValueRecord{155 {"k1", "base:k1"}, {"k2", "source:k2"}, {"k3", "source:k3"},156 }},157 },158 destRange: []testRange{159 {rng: committed.Range{ID: "base:k1-k3", MinKey: committed.Key("k1"), MaxKey: committed.Key("k3"), EstimatedSize: 1024}, records: []testValueRecord{160 {"k1", "base:k1"},161 {"k3", "base:k3"},162 }},163 },164 conflictExpectedIdx: nil,165 expectedActions: []writeAction{166 {167 action: actionTypeWriteRange,168 rng: committed.Range{ID: "source:k1-k3", MinKey: committed.Key("k1"), MaxKey: committed.Key("k3"), EstimatedSize: 1024},169 },170 },171 },172 "dest range inner change": {173 baseRange: []testRange{174 {rng: committed.Range{ID: "base:k1-k3", MinKey: committed.Key("k1"), MaxKey: committed.Key("k3"), EstimatedSize: 1024}, records: []testValueRecord{175 {"k1", "base:k1"},176 {"k3", "base:k3"},177 }},178 },179 sourceRange: []testRange{180 {rng: committed.Range{ID: "base:k1-k3", MinKey: committed.Key("k1"), MaxKey: committed.Key("k3"), EstimatedSize: 1024}, records: []testValueRecord{181 {"k1", "base:k1"},182 {"k3", "base:k3"},183 }},184 },185 destRange: []testRange{186 {rng: committed.Range{ID: "dest:k1-k3", MinKey: committed.Key("k1"), MaxKey: committed.Key("k3"), EstimatedSize: 1024}, records: []testValueRecord{187 {"k1", "base:k1"},188 {"k2", "dest:k2"},189 {"k3", "dest:k3"},190 }},191 },192 conflictExpectedIdx: nil,193 expectedActions: []writeAction{194 {195 action: actionTypeWriteRange,196 rng: committed.Range{ID: "dest:k1-k3", MinKey: committed.Key("k1"), MaxKey: committed.Key("k3"), EstimatedSize: 1024},197 },198 },199 expectedErr: nil,200 },201 "source range append after": {202 baseRange: []testRange{203 {rng: committed.Range{ID: "base:k1-k3", MinKey: committed.Key("k1"), MaxKey: committed.Key("k3"), Count: 2, EstimatedSize: 1024}, records: []testValueRecord{204 {"k1", "base:k1"},205 {"k3", "base:k3"},206 }},207 },208 sourceRange: []testRange{209 {rng: committed.Range{ID: "source:k1-k5", MinKey: committed.Key("k1"), MaxKey: committed.Key("k5"), Count: 4, EstimatedSize: 1024}, records: []testValueRecord{210 {"k1", "base:k1"},211 {"k3", "base:k3"},212 {"k4", "source:k4"},213 {"k5", "source:k5"},214 }},215 },216 destRange: []testRange{217 {rng: committed.Range{ID: "base:k1-k3", MinKey: committed.Key("k1"), MaxKey: committed.Key("k3"), Count: 2, EstimatedSize: 1024}, records: []testValueRecord{218 {"k1", "base:k1"},219 {"k3", "base:k3"},220 }},221 },222 conflictExpectedIdx: nil,223 expectedActions: []writeAction{224 {225 action: actionTypeWriteRecord,226 key: "k1",227 identity: "base:k1",228 },229 {230 action: actionTypeWriteRecord,231 key: "k3",232 identity: "base:k3",233 },234 {235 action: actionTypeWriteRecord,236 key: "k4",237 identity: "source:k4",238 },239 {240 action: actionTypeWriteRecord,241 key: "k5",242 identity: "source:k5",243 },244 },245 },246 "source range append and remove after": {247 baseRange: []testRange{248 {rng: committed.Range{ID: "base:k1-k3", MinKey: committed.Key("k1"), MaxKey: committed.Key("k3")}, records: []testValueRecord{249 {"k1", "base:k1"}, {"k3", "base:k3"},250 }},251 {rng: committed.Range{ID: "base:k4-k6", MinKey: committed.Key("k4"), MaxKey: committed.Key("k6")}, records: []testValueRecord{252 {"k4", "base:k4"}, {"k6", "base:k6"}},253 }},254 sourceRange: []testRange{255 {rng: committed.Range{ID: "source:k1-k5", MinKey: committed.Key("k1"), MaxKey: committed.Key("k5")}, records: []testValueRecord{256 {"k1", "base:k1"}, {"k2", "source:k2"}, {"k3", "base:k3"}, {"k4", "base:k4"}, {"k5", "source:k5"},257 }},258 },259 destRange: []testRange{260 {rng: committed.Range{ID: "base:k1-k3", MinKey: committed.Key("k1"), MaxKey: committed.Key("k3")}, records: []testValueRecord{261 {"k1", "base:k1"}, {"k3", "base:k3"},262 }},263 {rng: committed.Range{ID: "base:k4-k6", MinKey: committed.Key("k4"), MaxKey: committed.Key("k6")}, records: []testValueRecord{264 {"k4", "base:k4"}, {"k6", "base:k6"}},265 }},266 conflictExpectedIdx: nil,267 expectedActions: []writeAction{268 {269 action: actionTypeWriteRecord,270 key: "k1",271 identity: "base:k1",272 },273 {274 action: actionTypeWriteRecord,275 key: "k2",276 identity: "source:k2",277 },278 {279 action: actionTypeWriteRecord,280 key: "k3",281 identity: "base:k3",282 },283 {284 action: actionTypeWriteRecord,285 key: "k4",286 identity: "base:k4",287 },288 {289 action: actionTypeWriteRecord,290 key: "k5",291 identity: "source:k5",292 },293 },294 expectedErr: nil,295 },296 "source range - overlapping ranges": {297 baseRange: []testRange{298 {rng: committed.Range{ID: "base:k1-k6", MinKey: committed.Key("k1"), MaxKey: committed.Key("k6"), Count: 4, EstimatedSize: 4444}, records: []testValueRecord{299 {"k1", "base:k1"}, {"k3", "base:k3"}, {"k5", "base:k5"}, {"k6", "base:k6"},300 }},301 },302 sourceRange: []testRange{303 {rng: committed.Range{ID: "source:k1-k10", MinKey: committed.Key("k1"), MaxKey: committed.Key("k10"), Count: 6, EstimatedSize: 66666}, records: []testValueRecord{304 {"k1", "base:k1"}, {"k3", "base:k3"}, {"k4", "source:k4"}, {"k5", "base:k5"}, {"k6", "base:k6"}, {"k10", "source:k10"},305 }},306 },307 destRange: []testRange{308 {rng: committed.Range{ID: "base:k1-k6", MinKey: committed.Key("k1"), MaxKey: committed.Key("k6"), Count: 4, EstimatedSize: 4444}, records: []testValueRecord{309 {"k1", "base:k1"}, {"k3", "base:k3"}, {"k5", "base:k5"}, {"k6", "base:k6"},310 }},311 },312 conflictExpectedIdx: nil,313 expectedActions: []writeAction{314 {action: actionTypeWriteRecord, key: "k1", identity: "base:k1"},315 {action: actionTypeWriteRecord, key: "k3", identity: "base:k3"},316 {action: actionTypeWriteRecord, key: "k4", identity: "source:k4"},317 {action: actionTypeWriteRecord, key: "k5", identity: "base:k5"},318 {action: actionTypeWriteRecord, key: "k6", identity: "base:k6"},319 {action: actionTypeWriteRecord, key: "k10", identity: "source:k10"},320 },321 },322 "dest range - overlapping ranges": {323 baseRange: []testRange{324 {rng: committed.Range{ID: "base:k1-k6", MinKey: committed.Key("k1"), MaxKey: committed.Key("k6"), Count: 4, EstimatedSize: 4444}, records: []testValueRecord{325 {"k1", "base:k1"}, {"k3", "base:k3"}, {"k5", "base:k5"}, {"k6", "base:k6"},326 }},327 },328 sourceRange: []testRange{329 {rng: committed.Range{ID: "base:k1-k6", MinKey: committed.Key("k1"), MaxKey: committed.Key("k6"), Count: 4, EstimatedSize: 4444}, records: []testValueRecord{330 {"k1", "base:k1"}, {"k3", "base:k3"}, {"k5", "base:k5"}, {"k6", "base:k6"},331 }},332 },333 destRange: []testRange{334 {rng: committed.Range{ID: "dest:k1-k10", MinKey: committed.Key("k1"), MaxKey: committed.Key("k10"), Count: 6, EstimatedSize: 66666}, records: []testValueRecord{335 {"k1", "base:k1"}, {"k3", "base:k3"}, {"k4", "dest:k4"}, {"k5", "base:k5"}, {"k6", "base:k6"}, {"k10", "dest:k10"},336 }},337 },338 conflictExpectedIdx: nil,339 expectedActions: []writeAction{340 {action: actionTypeWriteRecord, key: "k1", identity: "base:k1"},341 {action: actionTypeWriteRecord, key: "k3", identity: "base:k3"},342 {action: actionTypeWriteRecord, key: "k4", identity: "dest:k4"},343 {action: actionTypeWriteRecord, key: "k5", identity: "base:k5"},344 {action: actionTypeWriteRecord, key: "k6", identity: "base:k6"},345 {action: actionTypeWriteRecord, key: "k10", identity: "dest:k10"},346 },347 expectedErr: nil,348 },349 "source - remove at end of range": {350 baseRange: []testRange{351 {rng: committed.Range{ID: "base:k1-k6", MinKey: committed.Key("k1"), MaxKey: committed.Key("k6"), Count: 4, EstimatedSize: 4444}, records: []testValueRecord{352 {"k1", "base:k1"}, {"k3", "base:k3"}, {"k5", "base:k5"}, {"k6", "base:k6"},353 }},354 },355 sourceRange: []testRange{356 {rng: committed.Range{ID: "base:k1-k6", MinKey: committed.Key("k1"), MaxKey: committed.Key("k6"), Count: 4, EstimatedSize: 4444}, records: []testValueRecord{357 {"k1", "base:k1"}, {"k3", "base:k3"}, {"k5", "base:k5"}, {"k6", "base:k6"},358 }},359 },360 destRange: []testRange{361 {rng: committed.Range{ID: "dest:k1-k10", MinKey: committed.Key("k1"), MaxKey: committed.Key("k10"), Count: 6, EstimatedSize: 66666}, records: []testValueRecord{362 {"k1", "base:k1"}, {"k3", "base:k3"}, {"k4", "dest:k4"}, {"k5", "base:k5"}, {"k6", "base:k6"}, {"k10", "dest:k10"},363 }},364 },365 conflictExpectedIdx: nil,366 expectedActions: []writeAction{367 {action: actionTypeWriteRecord, key: "k1", identity: "base:k1"},368 {action: actionTypeWriteRecord, key: "k3", identity: "base:k3"},369 {action: actionTypeWriteRecord, key: "k4", identity: "dest:k4"},370 {action: actionTypeWriteRecord, key: "k5", identity: "base:k5"},371 {action: actionTypeWriteRecord, key: "k6", identity: "base:k6"},372 {action: actionTypeWriteRecord, key: "k10", identity: "dest:k10"},373 },374 expectedErr: nil,375 },376 "both added key to range": {377 baseRange: []testRange{378 {rng: committed.Range{ID: "base:k1-k6", MinKey: committed.Key("k1"), MaxKey: committed.Key("k6")}, records: []testValueRecord{379 {"k1", "base:k1"},380 {"k6", "base:k6"},381 }},382 },383 sourceRange: []testRange{384 {rng: committed.Range{ID: "source:k1-k6", MinKey: committed.Key("k1"), MaxKey: committed.Key("k6")}, records: []testValueRecord{385 {"k1", "base:k1"},386 {"k2", "source:k2"},387 {"k6", "base:k6"},388 }},389 },390 destRange: []testRange{391 {rng: committed.Range{ID: "dest:k1-k6", MinKey: committed.Key("k1"), MaxKey: committed.Key("k6")}, records: []testValueRecord{392 {"k1", "base:k1"},393 {"k3", "dest:k3"},394 {"k6", "base:k6"},395 }},396 },397 conflictExpectedIdx: nil,398 expectedActions: []writeAction{399 {400 action: actionTypeWriteRecord,401 key: "k1",402 identity: "base:k1",403 },404 {405 action: actionTypeWriteRecord,406 key: "k2",407 identity: "source:k2",408 },409 {410 action: actionTypeWriteRecord,411 key: "k3",412 identity: "dest:k3",413 },414 {415 action: actionTypeWriteRecord,416 key: "k6",417 identity: "base:k6",418 },419 },420 },421 "source range removed": {422 baseRange: []testRange{423 {rng: committed.Range{ID: "base:k1-k2", MinKey: committed.Key("k1"), MaxKey: committed.Key("k2"), Count: 2, EstimatedSize: 1234}},424 {rng: committed.Range{ID: "base:k3-k6", MinKey: committed.Key("k3"), MaxKey: committed.Key("k6"), Count: 2, EstimatedSize: 1234}},425 },426 sourceRange: []testRange{{427 rng: committed.Range{ID: "base:k3-k6", MinKey: committed.Key("k3"), MaxKey: committed.Key("k6"), Count: 2, EstimatedSize: 1234},428 records: nil,429 }},430 destRange: []testRange{431 {rng: committed.Range{ID: "base:k1-k2", MinKey: committed.Key("k1"), MaxKey: committed.Key("k2"), Count: 2, EstimatedSize: 1234}},432 {rng: committed.Range{ID: "base:k3-k6", MinKey: committed.Key("k3"), MaxKey: committed.Key("k6"), Count: 2, EstimatedSize: 1234}},433 },434 conflictExpectedIdx: nil,435 expectedActions: []writeAction{436 {437 action: actionTypeWriteRange,438 rng: committed.Range{ID: "base:k3-k6", MinKey: committed.Key("k3"), MaxKey: committed.Key("k6"), Count: 2, EstimatedSize: 1234},439 },440 },441 expectedErr: nil,442 },443 "dest range removed": {444 baseRange: []testRange{445 {rng: committed.Range{ID: "base:k1-k2", MinKey: committed.Key("k1"), MaxKey: committed.Key("k2"), Count: 2, EstimatedSize: 1234}},446 {rng: committed.Range{ID: "base:k3-k6", MinKey: committed.Key("k3"), MaxKey: committed.Key("k6"), Count: 2, EstimatedSize: 1234}},447 },448 sourceRange: []testRange{449 {rng: committed.Range{ID: "base:k1-k2", MinKey: committed.Key("k1"), MaxKey: committed.Key("k2"), Count: 2, EstimatedSize: 1234}},450 {rng: committed.Range{ID: "base:k3-k6", MinKey: committed.Key("k3"), MaxKey: committed.Key("k6"), Count: 2, EstimatedSize: 1234}},451 },452 destRange: []testRange{453 {rng: committed.Range{ID: "base:k3-k6", MinKey: committed.Key("k3"), MaxKey: committed.Key("k6"), Count: 2, EstimatedSize: 1234}},454 },455 conflictExpectedIdx: nil,456 expectedActions: []writeAction{457 {458 action: actionTypeWriteRange,459 rng: committed.Range{ID: "base:k3-k6", MinKey: committed.Key("k3"), MaxKey: committed.Key("k6"), Count: 2, EstimatedSize: 1234},460 },461 },462 expectedErr: nil,463 },464 "source key removed from range - same bounds": {465 baseRange: []testRange{466 {rng: committed.Range{ID: "base:k1-k2", MinKey: committed.Key("k1"), MaxKey: committed.Key("k2"), Count: 2, EstimatedSize: 1234}},467 {rng: committed.Range{ID: "base:k3-k6", MinKey: committed.Key("k3"), MaxKey: committed.Key("k6"), Count: 4, EstimatedSize: 1234},468 records: []testValueRecord{469 {"k3", "base:k3"}, {"k4", "base:k4"}, {"k5", "base:k5"}, {"k6", "base:k6"},470 },471 },472 },473 sourceRange: []testRange{474 {rng: committed.Range{ID: "base:k1-k2", MinKey: committed.Key("k1"), MaxKey: committed.Key("k2"), Count: 2, EstimatedSize: 1234}},475 {rng: committed.Range{ID: "source:k3-k6", MinKey: committed.Key("k3"), MaxKey: committed.Key("k6"), Count: 2, EstimatedSize: 1234},476 records: []testValueRecord{477 {"k3", "base:k3"}, {"k6", "base:k6"},478 },479 },480 },481 destRange: []testRange{482 {rng: committed.Range{ID: "base:k1-k2", MinKey: committed.Key("k1"), MaxKey: committed.Key("k2"), Count: 2, EstimatedSize: 1234}},483 {rng: committed.Range{ID: "base:k3-k6", MinKey: committed.Key("k3"), MaxKey: committed.Key("k6"), Count: 4, EstimatedSize: 1234},484 records: []testValueRecord{485 {"k3", "base:k3"}, {"k4", "base:k4"}, {"k5", "base:k5"}, {"k6", "base:k6"},486 },487 },488 },489 conflictExpectedIdx: nil,490 expectedActions: []writeAction{491 {action: actionTypeWriteRange, rng: committed.Range{ID: "base:k1-k2", MinKey: committed.Key("k1"), MaxKey: committed.Key("k2"), Count: 2, EstimatedSize: 1234}},492 {action: actionTypeWriteRange, rng: committed.Range{ID: "source:k3-k6", MinKey: committed.Key("k3"), MaxKey: committed.Key("k6"), Count: 2, EstimatedSize: 1234}},493 },494 },495 "source key removed from range": {496 baseRange: []testRange{497 {rng: committed.Range{ID: "base:k1-k2", MinKey: committed.Key("k1"), MaxKey: committed.Key("k2"), Count: 2, EstimatedSize: 1234}},498 {rng: committed.Range{ID: "base:k3-k6", MinKey: committed.Key("k3"), MaxKey: committed.Key("k6"), Count: 4, EstimatedSize: 1234},499 records: []testValueRecord{500 {"k3", "base:k3"}, {"k4", "base:k4"}, {"k5", "base:k5"}, {"k6", "base:k6"},501 },502 },503 },504 sourceRange: []testRange{505 {rng: committed.Range{ID: "base:k1-k2", MinKey: committed.Key("k1"), MaxKey: committed.Key("k2"), Count: 2, EstimatedSize: 1234}},506 {rng: committed.Range{ID: "source:k3-k5", MinKey: committed.Key("k3"), MaxKey: committed.Key("k5"), Count: 2, EstimatedSize: 1234},507 records: []testValueRecord{508 {"k3", "base:k3"}, {"k5", "base:k5"},509 },510 },511 },512 destRange: []testRange{513 {rng: committed.Range{ID: "base:k1-k2", MinKey: committed.Key("k1"), MaxKey: committed.Key("k2"), Count: 2, EstimatedSize: 1234}},514 {rng: committed.Range{ID: "base:k3-k6", MinKey: committed.Key("k3"), MaxKey: committed.Key("k6"), Count: 4, EstimatedSize: 1234},515 records: []testValueRecord{516 {"k3", "base:k3"}, {"k4", "base:k4"}, {"k5", "base:k5"}, {"k6", "base:k6"},517 },518 },519 },520 conflictExpectedIdx: nil,521 expectedActions: []writeAction{522 {action: actionTypeWriteRange, rng: committed.Range{ID: "base:k1-k2", MinKey: committed.Key("k1"), MaxKey: committed.Key("k2"), Count: 2, EstimatedSize: 1234}},523 {action: actionTypeWriteRecord, key: "k3", identity: "base:k3"},524 {action: actionTypeWriteRecord, key: "k5", identity: "base:k5"},525 },526 },527 "dest key removed from range": {528 baseRange: []testRange{529 {rng: committed.Range{ID: "base:k1-k2", MinKey: committed.Key("k1"), MaxKey: committed.Key("k2"), Count: 2, EstimatedSize: 1234}},530 {rng: committed.Range{ID: "base:k3-k6", MinKey: committed.Key("k3"), MaxKey: committed.Key("k6"), Count: 4, EstimatedSize: 1234},531 records: []testValueRecord{532 {"k3", "base:k3"}, {"k4", "base:k4"}, {"k5", "base:k5"}, {"k6", "base:k6"},533 },534 },535 },536 sourceRange: []testRange{537 {rng: committed.Range{ID: "base:k1-k2", MinKey: committed.Key("k1"), MaxKey: committed.Key("k2"), Count: 2, EstimatedSize: 1234}},538 {rng: committed.Range{ID: "base:k3-k6", MinKey: committed.Key("k3"), MaxKey: committed.Key("k6"), Count: 4, EstimatedSize: 1234},539 records: []testValueRecord{540 {"k3", "base:k3"}, {"k4", "base:k4"}, {"k5", "base:k5"}, {"k6", "base:k6"},541 },542 },543 },544 destRange: []testRange{545 {rng: committed.Range{ID: "base:k1-k2", MinKey: committed.Key("k1"), MaxKey: committed.Key("k2"), Count: 2, EstimatedSize: 1234}},546 {rng: committed.Range{ID: "dest:k3-k6", MinKey: committed.Key("k3"), MaxKey: committed.Key("k6"), Count: 2, EstimatedSize: 1234},547 records: []testValueRecord{548 {"k3", "base:k3"}, {"k6", "base:k6"},549 },550 },551 },552 conflictExpectedIdx: nil,553 expectedActions: []writeAction{554 {action: actionTypeWriteRange, rng: committed.Range{ID: "base:k1-k2", MinKey: committed.Key("k1"), MaxKey: committed.Key("k2"), Count: 2, EstimatedSize: 1234}},555 {action: actionTypeWriteRange, rng: committed.Range{ID: "dest:k3-k6", MinKey: committed.Key("k3"), MaxKey: committed.Key("k6"), Count: 2, EstimatedSize: 1234}},556 },557 expectedErr: nil,558 },559 "empty source and base": {560 baseRange: []testRange{},561 sourceRange: []testRange{},562 destRange: []testRange{563 {rng: committed.Range{ID: "dest:k1-k2", MinKey: committed.Key("k1"), MaxKey: committed.Key("k2"), Count: 2, EstimatedSize: 1234}},564 {rng: committed.Range{ID: "base:k3-k6", MinKey: committed.Key("k3"), MaxKey: committed.Key("k6"), Count: 2, EstimatedSize: 1234}},565 },566 conflictExpectedIdx: nil,567 expectedActions: []writeAction{568 {569 action: actionTypeWriteRange,570 rng: committed.Range{ID: "dest:k1-k2", MinKey: committed.Key("k1"), MaxKey: committed.Key("k2"), Count: 2, EstimatedSize: 1234},571 },572 {573 action: actionTypeWriteRange,574 rng: committed.Range{ID: "base:k3-k6", MinKey: committed.Key("k3"), MaxKey: committed.Key("k6"), Count: 2, EstimatedSize: 1234},575 },576 },577 expectedErr: nil,578 },579 "dest removed range and added range after source removed range edges": {580 baseRange: []testRange{581 {rng: committed.Range{ID: "base:k1-k5", MinKey: committed.Key("k1"), MaxKey: committed.Key("k5"), Count: 5, EstimatedSize: 1234},582 records: []testValueRecord{583 {"k1", "base:k1"}, {"k2", "base:k2"}, {"k3", "base:k3"}, {"k4", "base:k4"},584 {"k5", "base:k5"},585 },586 },587 },588 sourceRange: []testRange{589 {rng: committed.Range{ID: "source:k3-k4", MinKey: committed.Key("k3"), MaxKey: committed.Key("k4"), Count: 2, EstimatedSize: 1234},590 records: []testValueRecord{591 {"k3", "base:k3"}, {"k4", "base:k4"},592 },593 },594 },595 destRange: []testRange{596 {rng: committed.Range{ID: "dest:k6-k7", MinKey: committed.Key("k6"), MaxKey: committed.Key("k7"), Count: 2, EstimatedSize: 1234},597 records: []testValueRecord{598 {"k6", "dest:k6"}, {"k7", "dest:k7"},599 },600 },601 },602 conflictExpectedIdx: nil,603 expectedActions: []writeAction{604 {action: actionTypeWriteRecord, key: "k6", identity: "dest:k6"},605 {action: actionTypeWriteRecord, key: "k7", identity: "dest:k7"},606 },607 expectedErr: nil,608 },609 "source and dest change same range conflict": {610 baseRange: []testRange{611 {rng: committed.Range{ID: "base:k1-k5", MinKey: committed.Key("k1"), MaxKey: committed.Key("k5"), Count: 5, EstimatedSize: 1234},612 records: []testValueRecord{613 {"k1", "base:k1"}, {"k2", "base:k2"}, {"k3", "base:k3"}, {"k4", "base:k4"},614 {"k5", "base:k5"},615 },616 },617 },618 sourceRange: []testRange{619 {rng: committed.Range{ID: "source:k3-k4", MinKey: committed.Key("k3"), MaxKey: committed.Key("k4"), Count: 2, EstimatedSize: 1234},620 records: []testValueRecord{621 {"k3", "base:k3"}, {"k4", "source:k4"},622 },623 },624 },625 destRange: []testRange{626 {rng: committed.Range{ID: "dest:k6-k7", MinKey: committed.Key("k6"), MaxKey: committed.Key("k7"), Count: 2, EstimatedSize: 1234},627 records: []testValueRecord{628 {"k6", "dest:k6"}, {"k7", "dest:k7"},629 },630 },631 },632 conflictExpectedIdx: nil,633 expectedActions: []writeAction{},634 expectedErr: graveler.ErrConflictFound,635 },636 "no changes": {637 baseRange: []testRange{638 {rng: committed.Range{ID: "base:k3-k4", MinKey: committed.Key("k3"), MaxKey: committed.Key("k4"), Count: 2, EstimatedSize: 1234},639 records: []testValueRecord{640 {"k3", "base:k3"}, {"k4", "base:k4"},641 },642 },643 },644 sourceRange: []testRange{645 {rng: committed.Range{ID: "base:k3-k4", MinKey: committed.Key("k3"), MaxKey: committed.Key("k4"), Count: 2, EstimatedSize: 1234},646 records: []testValueRecord{647 {"k3", "base:k3"}, {"k4", "base:k4"},648 },649 },650 },651 destRange: []testRange{652 {rng: committed.Range{ID: "base:k3-k4", MinKey: committed.Key("k3"), MaxKey: committed.Key("k4"), Count: 2, EstimatedSize: 1234},653 records: []testValueRecord{654 {"k3", "base:k3"}, {"k4", "base:k4"},655 },656 },657 },658 conflictExpectedIdx: nil,659 expectedActions: []writeAction{660 {661 action: actionTypeWriteRange,662 rng: committed.Range{ID: "base:k3-k4", MinKey: committed.Key("k3"), MaxKey: committed.Key("k4"), Count: 2, EstimatedSize: 1234},663 },664 },665 expectedErr: nil,666 },667 "source and dest changed record identity": {668 baseRange: []testRange{669 {670 rng: committed.Range{ID: "base:b-c", MinKey: committed.Key("b"), MaxKey: committed.Key("c"), Count: 2, EstimatedSize: 1024},671 records: []testValueRecord{{key: "b", identity: "b"}, {key: "c", identity: "c"}},672 },673 {674 rng: committed.Range{ID: "base:d-e", MinKey: committed.Key("d"), MaxKey: committed.Key("e"), Count: 2, EstimatedSize: 1024},675 records: []testValueRecord{{key: "d", identity: "d"}, {key: "e", identity: "e"}},676 },677 },678 sourceRange: []testRange{679 {680 rng: committed.Range{ID: "source:a-d", MinKey: committed.Key("a"), MaxKey: committed.Key("d"), Count: 2, EstimatedSize: 1024},681 records: []testValueRecord{{key: "a", identity: "a"}, {key: "b", identity: "b"}, {key: "d", identity: "d"}},682 },683 {684 rng: committed.Range{ID: "source:e", MinKey: committed.Key("e"), MaxKey: committed.Key("e"), Count: 2, EstimatedSize: 1024},685 records: []testValueRecord{{key: "e", identity: "e1"}},686 },687 },688 destRange: []testRange{689 {690 rng: committed.Range{ID: "base:b-c", MinKey: committed.Key("b"), MaxKey: committed.Key("c"), Count: 2, EstimatedSize: 1024},691 records: []testValueRecord{{key: "b", identity: "b"}, {key: "c", identity: "c"}},692 },693 {694 rng: committed.Range{ID: "dest:d-e", MinKey: committed.Key("d"), MaxKey: committed.Key("e"), Count: 2, EstimatedSize: 1024},695 records: []testValueRecord{{key: "d", identity: "d1"}, {key: "e", identity: "e"}},696 },697 },698 conflictExpectedIdx: nil,699 expectedActions: []writeAction{700 {701 action: actionTypeWriteRecord,702 key: "a",703 identity: "a",704 },705 {706 action: actionTypeWriteRecord,707 key: "b",708 identity: "b",709 },710 {711 action: actionTypeWriteRecord,712 key: "d",713 identity: "d1",714 },715 {716 action: actionTypeWriteRecord,717 key: "e",718 identity: "e1",719 },720 },721 expectedErr: nil,722 },723 "dest removed all source added": {724 baseRange: []testRange{725 {726 rng: committed.Range{ID: "base:a-d", MinKey: committed.Key("a"), MaxKey: committed.Key("d"), Count: 2, EstimatedSize: 1024},727 records: []testValueRecord{{key: "a", identity: "a"}, {key: "d", identity: "d"}},728 },729 },730 sourceRange: []testRange{731 {732 rng: committed.Range{ID: "source:a-d", MinKey: committed.Key("a"), MaxKey: committed.Key("d"), Count: 4, EstimatedSize: 1024},733 records: []testValueRecord{{key: "a", identity: "a"}, {key: "b", identity: "b"}, {key: "c", identity: "c"}, {key: "d", identity: "d"}},734 },735 },736 destRange: []testRange{},737 conflictExpectedIdx: nil,738 expectedActions: []writeAction{739 {740 action: actionTypeWriteRecord,741 key: "b",742 identity: "b",743 },744 {745 action: actionTypeWriteRecord,746 key: "c",747 identity: "c",748 },749 },750 expectedErr: nil,751 },752 "same identity different key": {753 baseRange: []testRange{754 {755 rng: committed.Range{ID: "base:a-d", MinKey: committed.Key("a"), MaxKey: committed.Key("d"), Count: 2, EstimatedSize: 1024},756 records: []testValueRecord{{key: "a", identity: "a"}, {key: "d", identity: "d"}},757 },758 },759 sourceRange: []testRange{760 {761 rng: committed.Range{ID: "source:a-d", MinKey: committed.Key("a"), MaxKey: committed.Key("d"), Count: 4, EstimatedSize: 1024},762 records: []testValueRecord{{key: "a", identity: "a"}, {key: "a1", identity: "a"}, {key: "c", identity: "c"}},763 },764 },765 destRange: []testRange{766 {767 rng: committed.Range{ID: "dest:a-d", MinKey: committed.Key("a"), MaxKey: committed.Key("d"), Count: 2, EstimatedSize: 1024},768 records: []testValueRecord{{key: "a", identity: "a"}, {key: "d", identity: "d"}},769 },770 },771 conflictExpectedIdx: nil,772 expectedActions: []writeAction{773 {774 action: actionTypeWriteRecord,775 key: "a",776 identity: "a",777 },778 {779 action: actionTypeWriteRecord,780 key: "a1",781 identity: "a",782 },783 {784 action: actionTypeWriteRecord,785 key: "c",786 identity: "c",787 },788 },789 expectedErr: nil,790 },791 "dest removed all source range before base": {792 baseRange: []testRange{793 {794 rng: committed.Range{ID: "base:c-d", MinKey: committed.Key("c"), MaxKey: committed.Key("d"), Count: 2, EstimatedSize: 1024},795 records: []testValueRecord{{key: "c", identity: "c"}, {key: "d", identity: "d"}},796 },797 },798 sourceRange: []testRange{799 {800 rng: committed.Range{ID: "source:a-b", MinKey: committed.Key("a"), MaxKey: committed.Key("b"), Count: 2, EstimatedSize: 1024},801 records: []testValueRecord{{key: "a", identity: "a"}, {key: "b", identity: "b"}},802 },803 },804 destRange: []testRange{},805 conflictExpectedIdx: nil,806 expectedActions: []writeAction{807 {808 action: actionTypeWriteRange,809 rng: committed.Range{ID: "source:a-b", MinKey: committed.Key("a"), MaxKey: committed.Key("b"), Count: 2, EstimatedSize: 1024},810 },811 },812 expectedErr: nil,813 },814 "dest removed all same key different identity": {815 baseRange: []testRange{816 {817 rng: committed.Range{ID: "base:a-b", MinKey: committed.Key("a"), MaxKey: committed.Key("b"), Count: 2, EstimatedSize: 1024},818 records: []testValueRecord{{key: "a", identity: "a"}, {key: "b", identity: "b"}},819 },820 },821 sourceRange: []testRange{822 {823 rng: committed.Range{ID: "source:a-b", MinKey: committed.Key("a"), MaxKey: committed.Key("b"), Count: 2, EstimatedSize: 1024},824 records: []testValueRecord{{key: "a", identity: "a1"}, {key: "b", identity: "b"}},825 },826 },827 destRange: []testRange{},828 conflictExpectedIdx: nil,829 expectedActions: []writeAction{},830 expectedErr: graveler.ErrConflictFound,831 },832 "dest removed all different key different identity": {833 baseRange: []testRange{834 {835 rng: committed.Range{ID: "base:a-b", MinKey: committed.Key("a"), MaxKey: committed.Key("b"), Count: 2, EstimatedSize: 1024},836 records: []testValueRecord{{key: "a", identity: "a"}, {key: "a2", identity: "a2"}, {key: "b", identity: "b"}},837 },838 },839 sourceRange: []testRange{840 {841 rng: committed.Range{ID: "source:a-b", MinKey: committed.Key("a"), MaxKey: committed.Key("b"), Count: 2, EstimatedSize: 1024},842 records: []testValueRecord{{key: "a", identity: "a"}, {key: "a1", identity: "a1"}, {key: "b", identity: "b"}},843 },844 },845 destRange: []testRange{},846 conflictExpectedIdx: nil,847 expectedActions: []writeAction{848 {849 action: actionTypeWriteRecord,850 key: "a1",851 identity: "a1",852 },853 },854 expectedErr: nil,855 },856 "dest removed all base and source same identity": {857 baseRange: []testRange{858 {859 rng: committed.Range{ID: "base:a-b", MinKey: committed.Key("a"), MaxKey: committed.Key("b"), Count: 2, EstimatedSize: 1024},860 records: []testValueRecord{{key: "a", identity: "a"}, {key: "b", identity: "b"}},861 },862 {863 rng: committed.Range{ID: "base:d-f", MinKey: committed.Key("d"), MaxKey: committed.Key("f"), Count: 2, EstimatedSize: 1024},864 records: []testValueRecord{{key: "d", identity: "d"}, {key: "f", identity: "f"}},865 },866 },867 sourceRange: []testRange{868 {869 rng: committed.Range{ID: "base:a-b", MinKey: committed.Key("a"), MaxKey: committed.Key("b"), Count: 2, EstimatedSize: 1024},870 records: []testValueRecord{{key: "a", identity: "a"}, {key: "b", identity: "b"}},871 },872 {873 rng: committed.Range{ID: "source:c-e", MinKey: committed.Key("c"), MaxKey: committed.Key("e"), Count: 2, EstimatedSize: 1024},874 records: []testValueRecord{{key: "c", identity: "c"}, {key: "e", identity: "e"}},875 },876 },877 destRange: []testRange{},878 conflictExpectedIdx: nil,879 expectedActions: []writeAction{880 {881 action: actionTypeWriteRecord,882 key: "c",883 identity: "c",884 },885 {886 action: actionTypeWriteRecord,887 key: "e",888 identity: "e",889 },890 },891 expectedErr: nil,892 },893 "dest range before source": {894 baseRange: []testRange{895 {896 rng: committed.Range{ID: "base:a-b", MinKey: committed.Key("a"), MaxKey: committed.Key("b"), Count: 2, EstimatedSize: 1024},897 records: []testValueRecord{{key: "a", identity: "a"}, {key: "b", identity: "b"}},898 },899 },900 sourceRange: []testRange{901 {902 rng: committed.Range{ID: "source:c-d", MinKey: committed.Key("c"), MaxKey: committed.Key("d"), Count: 2, EstimatedSize: 1024},903 records: []testValueRecord{{key: "c", identity: "c"}, {key: "d", identity: "d"}},904 },905 },906 destRange: []testRange{907 {908 rng: committed.Range{ID: "dest:a-b", MinKey: committed.Key("a"), MaxKey: committed.Key("b"), Count: 2, EstimatedSize: 1024},909 records: []testValueRecord{{key: "a", identity: "a1"}, {key: "b", identity: "b"}},910 },911 },912 conflictExpectedIdx: nil,913 expectedActions: []writeAction{},914 expectedErr: graveler.ErrConflictFound,915 },916 "source key before dest range": {917 baseRange: []testRange{918 {919 rng: committed.Range{ID: "base:a-d", MinKey: committed.Key("a"), MaxKey: committed.Key("d"), Count: 2, EstimatedSize: 1024},920 records: []testValueRecord{{key: "a", identity: "a"}, {key: "b", identity: "b"}, {key: "c", identity: "c"}, {key: "d", identity: "d"}},921 },922 },923 sourceRange: []testRange{924 {925 rng: committed.Range{ID: "source:a-d", MinKey: committed.Key("a"), MaxKey: committed.Key("d"), Count: 2, EstimatedSize: 1024},926 records: []testValueRecord{{key: "a", identity: "a"}, {key: "b", identity: "b"}, {key: "c", identity: "c"}, {key: "d", identity: "d"}},927 },928 },929 destRange: []testRange{930 {931 rng: committed.Range{ID: "dest:b-c", MinKey: committed.Key("b"), MaxKey: committed.Key("c"), Count: 2, EstimatedSize: 1024},932 records: []testValueRecord{{key: "b", identity: "b"}, {key: "c", identity: "c"}},933 },934 {935 rng: committed.Range{ID: "dest:e-f", MinKey: committed.Key("e"), MaxKey: committed.Key("f"), Count: 2, EstimatedSize: 1024},936 records: []testValueRecord{{key: "e", identity: "e"}, {key: "f", identity: "f"}},937 },938 },939 conflictExpectedIdx: nil,940 expectedActions: []writeAction{941 {942 action: actionTypeWriteRecord,943 key: "b",944 identity: "b",945 },946 {947 action: actionTypeWriteRecord,948 key: "c",949 identity: "c",950 },951 {952 action: actionTypeWriteRange,953 rng: committed.Range{ID: "dest:e-f", MinKey: committed.Key("e"), MaxKey: committed.Key("f"), Count: 2, EstimatedSize: 1024},954 },955 },956 expectedErr: nil,957 },958 "dest key before source range": {959 baseRange: []testRange{960 {961 rng: committed.Range{ID: "base:a-d", MinKey: committed.Key("a"), MaxKey: committed.Key("d"), Count: 2, EstimatedSize: 1024},962 records: []testValueRecord{{key: "a", identity: "a"}, {key: "b", identity: "b"}, {key: "c", identity: "c"}, {key: "d", identity: "d"}},963 },964 },965 sourceRange: []testRange{966 {967 rng: committed.Range{ID: "source:b-c", MinKey: committed.Key("b"), MaxKey: committed.Key("c"), Count: 2, EstimatedSize: 1024},968 records: []testValueRecord{{key: "b", identity: "b"}, {key: "c", identity: "c"}},969 },970 {971 rng: committed.Range{ID: "source:e-f", MinKey: committed.Key("e"), MaxKey: committed.Key("f"), Count: 2, EstimatedSize: 1024},972 records: []testValueRecord{{key: "e", identity: "e"}, {key: "f", identity: "f"}},973 },974 },975 destRange: []testRange{976 {977 rng: committed.Range{ID: "dest:a-d", MinKey: committed.Key("a"), MaxKey: committed.Key("d"), Count: 2, EstimatedSize: 1024},978 records: []testValueRecord{{key: "a", identity: "a"}, {key: "b", identity: "b"}, {key: "c", identity: "c"}, {key: "d", identity: "d"}},979 },980 },981 conflictExpectedIdx: nil,982 expectedActions: []writeAction{983 {984 action: actionTypeWriteRecord,985 key: "b",986 identity: "b",987 },988 {989 action: actionTypeWriteRecord,990 key: "c",991 identity: "c",992 },993 {994 action: actionTypeWriteRange,995 rng: committed.Range{ID: "source:e-f", MinKey: committed.Key("e"), MaxKey: committed.Key("f"), Count: 2, EstimatedSize: 1024},996 },997 },998 expectedErr: nil,999 },1000 "dest range before source key": {1001 baseRange: []testRange{1002 {1003 rng: committed.Range{ID: "base:c-c", MinKey: committed.Key("c"), MaxKey: committed.Key("c"), Count: 2, EstimatedSize: 1024},1004 records: []testValueRecord{{key: "c", identity: "c"}},1005 },1006 },1007 sourceRange: []testRange{1008 {1009 rng: committed.Range{ID: "source:a-d", MinKey: committed.Key("a"), MaxKey: committed.Key("d"), Count: 2, EstimatedSize: 1024},1010 records: []testValueRecord{{key: "a", identity: "a"}, {key: "d", identity: "d"}},1011 },1012 },1013 destRange: []testRange{1014 {1015 rng: committed.Range{ID: "dest:a-a", MinKey: committed.Key("a"), MaxKey: committed.Key("a"), Count: 2, EstimatedSize: 1024},1016 records: []testValueRecord{{key: "a", identity: "a"}},1017 },1018 {1019 rng: committed.Range{ID: "dest:b-b", MinKey: committed.Key("b"), MaxKey: committed.Key("b"), Count: 2, EstimatedSize: 1024},1020 records: []testValueRecord{{key: "b", identity: "b"}},1021 },1022 {1023 rng: committed.Range{ID: "base:c-c", MinKey: committed.Key("c"), MaxKey: committed.Key("c"), Count: 2, EstimatedSize: 1024},1024 records: []testValueRecord{{key: "c", identity: "c"}},1025 },1026 },1027 conflictExpectedIdx: nil,1028 expectedActions: []writeAction{1029 {1030 action: actionTypeWriteRecord,1031 key: "a",1032 identity: "a",1033 },1034 {1035 action: actionTypeWriteRange,1036 rng: committed.Range{ID: "dest:b-b", MinKey: committed.Key("b"), MaxKey: committed.Key("b"), Count: 2, EstimatedSize: 1024},1037 },1038 {1039 action: actionTypeWriteRecord,1040 key: "d",1041 identity: "d",1042 },1043 },1044 expectedErr: nil,1045 },1046 "source range before dest key": {1047 baseRange: []testRange{1048 {1049 rng: committed.Range{ID: "base:c-c", MinKey: committed.Key("c"), MaxKey: committed.Key("c"), Count: 2, EstimatedSize: 1024},1050 records: []testValueRecord{{key: "c", identity: "c"}},1051 },1052 },1053 sourceRange: []testRange{1054 {1055 rng: committed.Range{ID: "source:a-a", MinKey: committed.Key("a"), MaxKey: committed.Key("a"), Count: 2, EstimatedSize: 1024},1056 records: []testValueRecord{{key: "a", identity: "a"}},1057 },1058 {1059 rng: committed.Range{ID: "source:b-b", MinKey: committed.Key("b"), MaxKey: committed.Key("b"), Count: 2, EstimatedSize: 1024},1060 records: []testValueRecord{{key: "b", identity: "b"}},1061 },1062 {1063 rng: committed.Range{ID: "base:c-c", MinKey: committed.Key("c"), MaxKey: committed.Key("c"), Count: 2, EstimatedSize: 1024},1064 records: []testValueRecord{{key: "c", identity: "c"}},1065 },1066 },1067 destRange: []testRange{1068 {1069 rng: committed.Range{ID: "dest:a-d", MinKey: committed.Key("a"), MaxKey: committed.Key("d"), Count: 2, EstimatedSize: 1024},1070 records: []testValueRecord{{key: "a", identity: "a"}, {key: "d", identity: "d"}},1071 },1072 },1073 conflictExpectedIdx: nil,1074 expectedActions: []writeAction{1075 {1076 action: actionTypeWriteRecord,1077 key: "a",1078 identity: "a",1079 },1080 {1081 action: actionTypeWriteRange,1082 rng: committed.Range{ID: "source:b-b", MinKey: committed.Key("b"), MaxKey: committed.Key("b"), Count: 2, EstimatedSize: 1024},1083 },1084 {1085 action: actionTypeWriteRecord,1086 key: "d",1087 identity: "d",1088 },1089 },1090 expectedErr: nil,1091 },1092 }1093 for name, tst := range tests {1094 t.Run(name, func(t *testing.T) {1095 ctrl := gomock.NewController(t)1096 defer ctrl.Finish()1097 ctx := context.Background()1098 writer := mock.NewMockMetaRangeWriter(ctrl)1099 for _, action := range tst.expectedActions {1100 switch action.action {1101 case actionTypeWriteRecord:1102 writer.EXPECT().WriteRecord(newRecordMatcher(action.key, action.identity))1103 case actionTypeWriteRange:1104 writer.EXPECT().WriteRange(gomock.Eq(action.rng))1105 }1106 }1107 metaRangeManager := mock.NewMockMetaRangeManager(ctrl)1108 metaRangeManager.EXPECT().NewWriter(gomock.Any(), gomock.Any(), gomock.Any()).Return(writer)1109 sourceKey := graveler.MetaRangeID("source")1110 destKey := graveler.MetaRangeID("dest")1111 baseKey := graveler.MetaRangeID("base")1112 metaRangeManager.EXPECT().NewMetaRangeIterator(gomock.Any(), gomock.Any(), baseKey).Return(createIter(tst.baseRange), nil)1113 metaRangeManager.EXPECT().NewMetaRangeIterator(gomock.Any(), gomock.Any(), sourceKey).Return(createIter(tst.sourceRange), nil)1114 metaRangeManager.EXPECT().NewMetaRangeIterator(gomock.Any(), gomock.Any(), destKey).Return(createIter(tst.destRange), nil)1115 writer.EXPECT().Abort()1116 metaRangeId := graveler.MetaRangeID("merge")1117 writer.EXPECT().Close().Return(&metaRangeId, nil).AnyTimes()1118 committedManager := committed.NewCommittedManager(metaRangeManager)1119 _, err := committedManager.Merge(ctx, "ns", "dest", "source", "base")1120 if err != tst.expectedErr {1121 t.Fatal(err)1122 }1123 })1124 }1125}1126func TestMergeCancelContext(t *testing.T) {1127 ctrl := gomock.NewController(t)1128 defer ctrl.Finish()1129 t.Run("source", func(t *testing.T) {1130 base := testutil.NewFakeIterator().1131 AddRange(&committed.Range{ID: "one", MinKey: committed.Key("b"), MaxKey: committed.Key("b"), Count: 1}).1132 AddValueRecords(makeV("b", "dest:b"))1133 source := testutil.NewFakeIterator()1134 destination := testutil.NewFakeIterator().1135 AddRange(&committed.Range{ID: "one", MinKey: committed.Key("b"), MaxKey: committed.Key("b"), Count: 1}).1136 AddValueRecords(makeV("b", "dest:b"))1137 writer := mock.NewMockMetaRangeWriter(ctrl)1138 ctx, cancel := context.WithCancel(context.Background())1139 cancel()1140 err := committed.Merge(ctx, writer, base, source, destination)1141 assert.True(t, errors.Is(err, context.Canceled), "context canceled error")1142 })1143 t.Run("destination", func(t *testing.T) {1144 base := testutil.NewFakeIterator().1145 AddRange(&committed.Range{ID: "one", MinKey: committed.Key("a"), MaxKey: committed.Key("cz"), Count: 2}).1146 AddValueRecords(makeV("a", "base:a"), makeV("c", "base:c"))1147 source := testutil.NewFakeIterator().1148 AddRange(&committed.Range{ID: "one", MinKey: committed.Key("a"), MaxKey: committed.Key("cz"), Count: 2}).1149 AddValueRecords(makeV("a", "base:a"), makeV("c", "base:c"))1150 destination := testutil.NewFakeIterator()1151 writer := mock.NewMockMetaRangeWriter(ctrl)1152 ctx, cancel := context.WithCancel(context.Background())1153 cancel()1154 err := committed.Merge(ctx, writer, base, source, destination)1155 assert.True(t, errors.Is(err, context.Canceled), "context canceled error")1156 })1157 t.Run("source_and_destination", func(t *testing.T) {1158 base := testutil.NewFakeIterator().1159 AddRange(&committed.Range{ID: "one", MinKey: committed.Key("a"), MaxKey: committed.Key("cz"), Count: 3}).1160 AddValueRecords(makeV("a", "base:a"), makeV("c", "base:c"))1161 source := testutil.NewFakeIterator().1162 AddRange(&committed.Range{ID: "two", MinKey: committed.Key("e"), MaxKey: committed.Key("f"), Count: 2}).1163 AddValueRecords(makeV("e", "source:e"), makeV("f", "source:f"))1164 destination := testutil.NewFakeIterator().1165 AddRange(&committed.Range{ID: "three", MinKey: committed.Key("b"), MaxKey: committed.Key("b"), Count: 1}).1166 AddValueRecords(makeV("b", "dest:b"))1167 writer := mock.NewMockMetaRangeWriter(ctrl)1168 ctx, cancel := context.WithCancel(context.Background())1169 cancel()1170 err := committed.Merge(ctx, writer, base, source, destination)1171 assert.True(t, errors.Is(err, context.Canceled), "context canceled error")1172 })1173 t.Run("base", func(t *testing.T) {1174 base := testutil.NewFakeIterator()1175 source := testutil.NewFakeIterator().1176 AddRange(&committed.Range{ID: "two", MinKey: committed.Key("e"), MaxKey: committed.Key("f"), Count: 2}).1177 AddValueRecords(makeV("e", "source:e"), makeV("f", "source:f"))1178 destination := testutil.NewFakeIterator().1179 AddRange(&committed.Range{ID: "one", MinKey: committed.Key("b"), MaxKey: committed.Key("b"), Count: 1}).1180 AddValueRecords(makeV("b", "dest:b"))1181 writer := mock.NewMockMetaRangeWriter(ctrl)1182 ctx, cancel := context.WithCancel(context.Background())1183 cancel()1184 err := committed.Merge(ctx, writer, base, source, destination)1185 assert.True(t, errors.Is(err, context.Canceled), "context canceled error")1186 })1187}...
outputs.go
Source:outputs.go
...37// TODO: move this to an output sub-module after we get rid of the old collectors?38func getAllOutputConstructors() (map[string]func(output.Params) (output.Output, error), error) {39 // Start with the built-in outputs40 result := map[string]func(output.Params) (output.Output, error){41 "json": json.New,42 "cloud": cloud.New,43 "influxdb": influxdb.New,44 "kafka": func(params output.Params) (output.Output, error) {45 return nil, errors.New("the kafka output was deprecated in k6 v0.32.0 and removed in k6 v0.34.0, " +46 "please use the new xk6 kafka output extension instead - https://github.com/k6io/xk6-output-kafka")47 },48 "statsd": statsd.New,49 "datadog": func(params output.Params) (output.Output, error) {50 return nil, errors.New("the datadog output was deprecated in k6 v0.32.0 and removed in k6 v0.34.0, " +51 "please use the statsd output with env. variable K6_STATSD_ENABLE_TAGS=true instead")52 },53 "csv": csv.New,54 }55 exts := output.GetExtensions()56 for k, v := range exts {57 if _, ok := result[k]; ok {58 return nil, fmt.Errorf("invalid output extension %s, built-in output with the same type already exists", k)59 }60 result[k] = v61 }62 return result, nil63}64func getPossibleIDList(constrs map[string]func(output.Params) (output.Output, error)) string {65 res := make([]string, 0, len(constrs))66 for k := range constrs {67 if k == "kafka" || k == "datadog" {68 continue69 }70 res = append(res, k)71 }72 sort.Strings(res)73 return strings.Join(res, ", ")74}75func createOutputs(76 outputFullArguments []string, src *loader.SourceData, conf Config, rtOpts lib.RuntimeOptions,77 executionPlan []lib.ExecutionStep, osEnvironment map[string]string, logger logrus.FieldLogger,78) ([]output.Output, error) {79 outputConstructors, err := getAllOutputConstructors()80 if err != nil {81 return nil, err82 }83 baseParams := output.Params{84 ScriptPath: src.URL,85 Logger: logger,86 Environment: osEnvironment,87 StdOut: stdout,88 StdErr: stderr,89 FS: afero.NewOsFs(),90 ScriptOptions: conf.Options,91 RuntimeOptions: rtOpts,92 ExecutionPlan: executionPlan,93 }94 result := make([]output.Output, 0, len(outputFullArguments))95 for _, outputFullArg := range outputFullArguments {96 outputType, outputArg := parseOutputArgument(outputFullArg)97 outputConstructor, ok := outputConstructors[outputType]98 if !ok {99 return nil, fmt.Errorf(100 "invalid output type '%s', available types are: %s",101 outputType, getPossibleIDList(outputConstructors),102 )103 }...
modules.go
Source:modules.go
...53 }54 modules[name] = mod55}56// HasModuleInstancePerVU should be implemented by all native Golang modules that57// would require per-VU state. k6 will call their NewModuleInstancePerVU() methods58// every time a VU imports the module and use its result as the returned object.59type HasModuleInstancePerVU interface {60 NewModuleInstancePerVU() interface{}61}62// checks that modules implement HasModuleInstancePerVU63// this is done here as otherwise there will be a loop if the module imports this package64var _ HasModuleInstancePerVU = http.New()65// GetJSModules returns a map of all js modules66func GetJSModules() map[string]interface{} {67 result := map[string]interface{}{68 "k6": k6.New(),69 "k6/crypto": crypto.New(),70 "k6/crypto/x509": x509.New(),71 "k6/data": data.New(),72 "k6/encoding": encoding.New(),73 "k6/net/grpc": grpc.New(),74 "k6/html": html.New(),75 "k6/http": http.New(),76 "k6/metrics": metrics.New(),77 "k6/ws": ws.New(),78 }79 mx.Lock()80 defer mx.Unlock()81 for name, module := range modules {82 result[name] = module83 }84 return result85}...
New
Using AI Code Generation
1import (2func main() {3 k6 := lib.New()4 bundle := &loader.SourceData{5 Data: []byte(`6 import http from "k6/http";7 export default function() {8 }9 }10 _, err := k6.Load(bundle)11 if err != nil {12 panic(err)13 }14 config := executor.NewConstantArrivalRateConfig("shared-iterations", 1, 1, 0)15 executor, err := executor.NewConstantArrivalRate(config)16 if err != nil {17 panic(err)18 }19 config = statsd.NewConfig()20 statsdCollector, err := statsd.New(config)21 if err != nil {22 panic(err)23 }24 config = json.NewConfig()25 jsonCollector, err := json.New(config)26 if err != nil {27 panic(err)28 }29 config = cloud.NewConfig()30 cloudCollector, err := cloud.New(config)31 if err != nil {32 panic(err)33 }34 config = influxdb.NewConfig()35 influxdbCollector, err := influxdb.New(config)36 if err != nil {37 panic(err)38 }39 config = pb.NewConfig()40 pbCollector, err := pb.New(config)
New
Using AI Code Generation
1import (2func main() {3 fmt.Println("Hello, playground")4 k6.New()5}6import (7func main() {8 fmt.Println("Hello, playground")9 k6.New()10}11import (12func main() {13 fmt.Println("Hello, playground")14 k6.New()15}16import (17func main() {18 fmt.Println("Hello, playground")19 k6.New()20}21import (22func main() {23 fmt.Println("Hello, playground")24 k6.New()25}26import (27func main() {28 fmt.Println("Hello, playground")29 k6.New()30}31import (32func main() {33 fmt.Println("Hello, playground")34 k6.New()35}36import (37func main() {38 fmt.Println("Hello, playground")39 k6.New()40}41import (42func main() {43 fmt.Println("Hello, playground")44 k6.New()45}
New
Using AI Code Generation
1import (2func main() {3 k := k6.New("k6")4 fmt.Println(k)5}6import (7func main() {8 k := k6.New("k6")9 fmt.Println(k)10}11import (12func main() {13 k := k6.New("k6")14 fmt.Println(k)15}16import (17func main() {18 k := k6.New("k6")19 fmt.Println(k)20}21import (22func main() {23 k := k6.New("k6")24 fmt.Println(k)25}26import (27func main() {28 k := k6.New("k6")29 fmt.Println(k)30}31import (32func main() {33 k := k6.New("k6")34 fmt.Println(k)35}36import (37func main() {38 k := k6.New("k6")39 fmt.Println(k)40}41import (42func main() {43 k := k6.New("k6")44 fmt.Println(k)45}46import (47func main() {48 k := k6.New("k6")49 fmt.Println(k)50}51import (52func main() {53 k := k6.New("k6")54 fmt.Println(k)55}
New
Using AI Code Generation
1import (2func main() {3 vm := otto.New()4 vm.Run(`5 var k6 = {6 New: function(options) {7 return options;8 }9 };10 value, err := vm.Call("k6.New", nil, map[string]interface{}{11 })12 if err != nil {13 panic(err)14 }15 result, err := value.Export()16 if err != nil {17 panic(err)18 }19 fmt.Println(result)20}21import (22func main() {23 vm := otto.New()24 vm.Run(`25 var k6 = {26 New: function(options) {27 return options;28 }29 };30 value, err := vm.Call("k6.New", nil, map[string]interface{}{31 })32 if err != nil {33 panic(err)34 }35 result, err := value.Export()36 if err != nil {37 panic(err)38 }39 fmt.Println(result)40 vm = otto.New()
New
Using AI Code Generation
1import (2func main() {3 fmt.Println("main")4 k := k6.New()5 k.SayHello()6}7import (8func main() {9 fmt.Println("main")10 k := k6.New()11 k.SayHello()12}13Your name to display (optional):14Your name to display (optional):15import (16type k6 struct {17}18func New() *k6 {19 return &k6{name: "k6"}20}
New
Using AI Code Generation
1import (2type k6 struct {3}4func (k *k6) New() {5 fmt.Println("New method of k6 class")6}7func main() {8}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!