|
1 |
| -/* |
| 1 | +/* |
2 | 2 | * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
|
3 | 3 | *
|
4 | 4 | * This program is free software; you can redistribute it and/or modify
|
@@ -490,3 +490,92 @@ TEST_F(Bugs, crud_move)
|
490 | 490 |
|
491 | 491 |
|
492 | 492 | }
|
| 493 | + |
| 494 | +TEST_F(Bugs, not_accumulate) |
| 495 | +{ |
| 496 | + SKIP_IF_NO_XPLUGIN; |
| 497 | + |
| 498 | + auto sch = get_sess().createSchema("test",true); |
| 499 | + auto coll = sch.createCollection("c1",true); |
| 500 | + auto tbl = sch.getCollectionAsTable("c1"); |
| 501 | + |
| 502 | + coll.remove("true").execute(); |
| 503 | + |
| 504 | + coll.add("{ \"_id\": \"myuuid-1\", \"name\": \"foo\", \"age\": 7 }", |
| 505 | + "{ \"name\": \"buz\", \"age\": 17 }", |
| 506 | + "{ \"name\": \"bar\", \"age\": 3 }", |
| 507 | + "{ \"name\": \"baz\", \"age\": 3 }" |
| 508 | + ).execute(); |
| 509 | + |
| 510 | + |
| 511 | + //FIND |
| 512 | + |
| 513 | + auto find = coll.find(); |
| 514 | + find.fields("notfound"); |
| 515 | + find.fields("name as name", "age as age"); |
| 516 | + find.groupBy("notfound"); |
| 517 | + find.groupBy("age","name"); |
| 518 | + find.sort("notfound"); |
| 519 | + find.sort("age ASC"); |
| 520 | + |
| 521 | + auto doc = find.execute().fetchOne(); |
| 522 | + EXPECT_EQ(3, doc["age"].get<int>()); |
| 523 | + EXPECT_EQ(string("bar"), doc["name"].get<string>()); |
| 524 | + |
| 525 | + |
| 526 | + // MODIFY |
| 527 | + |
| 528 | + auto modify = coll.modify("true"); |
| 529 | + modify.set("food", expr("[]")); |
| 530 | + modify.arrayAppend("food", "milk"); |
| 531 | + modify.arrayAppend("food", "soup"); |
| 532 | + modify.arrayAppend("food", "potatoes"); |
| 533 | + modify.sort("notfound"); |
| 534 | + modify.sort("age ASC"); |
| 535 | + modify.limit(2); |
| 536 | + //only age=3 will be modified |
| 537 | + modify.execute(); |
| 538 | + |
| 539 | + auto check_changes = coll.find().sort("age ASC").execute(); |
| 540 | + EXPECT_TRUE(check_changes.fetchOne().hasField("food")); |
| 541 | + EXPECT_TRUE(check_changes.fetchOne().hasField("food")); |
| 542 | + EXPECT_FALSE(check_changes.fetchOne().hasField("food")); |
| 543 | + EXPECT_FALSE(check_changes.fetchOne().hasField("food")); |
| 544 | + |
| 545 | + //REMOVE |
| 546 | + |
| 547 | + auto remove = coll.remove("true"); |
| 548 | + remove.sort("name DESC"); |
| 549 | + remove.sort("age ASC"); |
| 550 | + remove.limit(2); |
| 551 | + //only age=3 will be removed |
| 552 | + remove.execute(); |
| 553 | + |
| 554 | + check_changes = coll.find().execute(); |
| 555 | + for(auto doc : check_changes) |
| 556 | + { |
| 557 | + EXPECT_NE(3, doc["age"].get<int>()); |
| 558 | + } |
| 559 | + |
| 560 | + // TABLE |
| 561 | + auto select = tbl.select("doc->$.age"); |
| 562 | + select.orderBy("notfound ASC"); |
| 563 | + select.orderBy("doc->$.age ASC"); |
| 564 | + select.groupBy("notfound"); |
| 565 | + select.groupBy("doc->$.age"); |
| 566 | + |
| 567 | + select.lockExclusive(); |
| 568 | + EXPECT_EQ(2, select.execute().count()); |
| 569 | + |
| 570 | + auto update = tbl.update(); |
| 571 | + update.set("doc->$.age",1); |
| 572 | + update.where("doc->$.age > 7"); |
| 573 | + update.orderBy("notfound ASC"); |
| 574 | + update.orderBy("doc->$.age ASC"); |
| 575 | + EXPECT_EQ(1, update.execute().getAffectedItemsCount()); |
| 576 | + |
| 577 | + auto tbl_remove = tbl.remove(); |
| 578 | + tbl_remove.orderBy("notfound ASC"); |
| 579 | + tbl_remove.orderBy("doc->$.age ASC"); |
| 580 | + EXPECT_EQ(2, tbl_remove.execute().getAffectedItemsCount()); |
| 581 | +} |
0 commit comments