| … | … | @@ -31,7 +31,7 @@ |
| 31 | 31 | #include <opencog/atoms/base/Link.h> |
| 32 | 32 | #include <opencog/atoms/base/Node.h> |
| 33 | 33 | #include <opencog/atoms/value/FloatValue.h> |
| 34 | #include <opencog/atoms/value/FloatValue.h> | |
| 34 | #include <opencog/atoms/value/VoidValue.h> | |
| 35 | 35 | #include <opencog/atomspace/AtomSpace.h> |
| 36 | 36 | #include <opencog/persist/rocks-types/atom_types.h> |
| 37 | 37 | #include <opencog/persist/monospace/MonoStorage.h> |
| … | … | @@ -43,7 +43,7 @@ using namespace opencog; |
| 43 | 43 | class AlphaEquivUTest : public CxxTest::TestSuite |
| 44 | 44 | { |
| 45 | 45 | private: |
| 46 | AtomSpace* _as; | |
| 46 | AtomSpacePtr _as; | |
| 47 | 47 | std::string uri; |
| 48 | 48 | |
| 49 | 49 | public: |
| … | … | @@ -123,11 +123,11 @@ void AlphaEquivUTest::setup_data(void) |
| 123 | 123 | { |
| 124 | 124 | kill_data(); |
| 125 | 125 | |
| 126 | _as = new AtomSpace(); | |
| 126 | _as = createAtomSpace(); | |
| 127 | 127 | |
| 128 | 128 | Handle hsn = _as->add_node(MONO_STORAGE_NODE, std::string(uri)); |
| 129 | 129 | StorageNodePtr store = StorageNodeCast(hsn); |
| 130 | store->open(); | |
| 130 | store->setValue(_as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 131 | 131 | TS_ASSERT(store->connected()) |
| 132 | 132 | |
| 133 | 133 | /* Populate the Storage with stuff that we will later query. */ |
| … | … | @@ -140,7 +140,7 @@ void AlphaEquivUTest::setup_data(void) |
| 140 | 140 | store->store_atomspace(); |
| 141 | 141 | store->barrier(); |
| 142 | 142 | |
| 143 | delete _as; | |
| 143 | _as = nullptr; | |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | // ============================================================ |
| … | … | @@ -152,10 +152,10 @@ void AlphaEquivUTest::test_fetch(void) |
| 152 | 152 | |
| 153 | 153 | setup_data(); |
| 154 | 154 | |
| 155 | _as = new AtomSpace(); | |
| 155 | _as = createAtomSpace(); | |
| 156 | 156 | Handle hsn = _as->add_node(MONO_STORAGE_NODE, std::string(uri)); |
| 157 | 157 | StorageNodePtr store = StorageNodeCast(hsn); |
| 158 | store->open(); | |
| 158 | store->setValue(_as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 159 | 159 | TS_ASSERT(store->connected()) |
| 160 | 160 | |
| 161 | 161 | // Fetch an alpha-equivalent lambda link. |
| … | … | @@ -183,7 +183,7 @@ void AlphaEquivUTest::test_fetch(void) |
| 183 | 183 | FloatValuePtr fvp = FloatValueCast(fu); |
| 184 | 184 | TSM_ASSERT_EQUALS("Expecting three floats", fvp->size(), 3); |
| 185 | 185 | |
| 186 | delete _as; | |
| 186 | _as = nullptr; | |
| 187 | 187 | |
| 188 | 188 | logger().info("END TEST: %s", __FUNCTION__); |
| 189 | 189 | } |
| … | … | @@ -197,15 +197,15 @@ void AlphaEquivUTest::test_remove(void) |
| 197 | 197 | |
| 198 | 198 | setup_data(); |
| 199 | 199 | |
| 200 | _as = new AtomSpace(); | |
| 200 | _as = createAtomSpace(); | |
| 201 | 201 | Handle hsn = _as->add_node(MONO_STORAGE_NODE, std::string(uri)); |
| 202 | 202 | StorageNodePtr store = StorageNodeCast(hsn); |
| 203 | store->open(); | |
| 203 | store->setValue(_as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 204 | 204 | TS_ASSERT(store->connected()) |
| 205 | 205 | |
| 206 | 206 | // Remove the alpha-equivalent lambda link. |
| 207 | 207 | Handle ly = al(LAMBDA_LINK, an(VARIABLE, "Y"), an(CONCEPT, "A")); |
| 208 | store->remove_atom(_as, ly); | |
| 208 | store->remove_atom(_as.get(), ly); | |
| 209 | 209 | store->barrier(); |
| 210 | 210 | ly = Handle::UNDEFINED; |
| 211 | 211 | |
| … | … | @@ -221,7 +221,7 @@ void AlphaEquivUTest::test_remove(void) |
| 221 | 221 | ValuePtr fu = lx->getValue(an(PREDICATE, "foo")); |
| 222 | 222 | TSM_ASSERT("Expecting null value", nullptr == fu); |
| 223 | 223 | |
| 224 | delete _as; | |
| 224 | _as = nullptr; | |
| 225 | 225 | |
| 226 | 226 | logger().info("END TEST: %s", __FUNCTION__); |
| 227 | 227 | } |
| … | … | @@ -235,15 +235,15 @@ void AlphaEquivUTest::test_recursive_remove(void) |
| 235 | 235 | |
| 236 | 236 | setup_data(); |
| 237 | 237 | |
| 238 | _as = new AtomSpace(); | |
| 238 | _as = createAtomSpace(); | |
| 239 | 239 | Handle hsn = _as->add_node(MONO_STORAGE_NODE, std::string(uri)); |
| 240 | 240 | StorageNodePtr store = StorageNodeCast(hsn); |
| 241 | store->open(); | |
| 241 | store->setValue(_as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 242 | 242 | TS_ASSERT(store->connected()) |
| 243 | 243 | |
| 244 | 244 | // Recursive remove Concept "A". |
| 245 | 245 | Handle ca = an(CONCEPT, "A"); |
| 246 | store->remove_atom(_as, ca, true); | |
| 246 | store->remove_atom(_as.get(), ca, true); | |
| 247 | 247 | store->barrier(); |
| 248 | 248 | |
| 249 | 249 | // What happens if we look for the original? |
| … | … | @@ -258,7 +258,7 @@ void AlphaEquivUTest::test_recursive_remove(void) |
| 258 | 258 | ValuePtr fu = lx->getValue(an(PREDICATE, "foo")); |
| 259 | 259 | TSM_ASSERT("Expecting null value", nullptr == fu); |
| 260 | 260 | |
| 261 | delete _as; | |
| 261 | _as = nullptr; | |
| 262 | 262 | |
| 263 | 263 | logger().info("END TEST: %s", __FUNCTION__); |
| 264 | 264 | } |
| … | … | @@ -33,6 +33,7 @@ |
| 33 | 33 | #include <opencog/atoms/base/Link.h> |
| 34 | 34 | #include <opencog/atoms/base/Node.h> |
| 35 | 35 | #include <opencog/atoms/value/FloatValue.h> |
| 36 | #include <opencog/atoms/value/VoidValue.h> | |
| 36 | 37 | #include <opencog/atomspace/AtomSpace.h> |
| 37 | 38 | #include <opencog/persist/rocks-types/atom_types.h> |
| 38 | 39 | #include <opencog/persist/monospace/MonoStorage.h> |
| … | … | @@ -44,7 +45,7 @@ using namespace opencog; |
| 44 | 45 | class DeleteUTest : public CxxTest::TestSuite |
| 45 | 46 | { |
| 46 | 47 | private: |
| 47 | AtomSpace* _as; | |
| 48 | AtomSpacePtr _as; | |
| 48 | 49 | std::string uri; |
| 49 | 50 | |
| 50 | 51 | NodePtr n1[10]; |
| … | … | @@ -113,12 +114,12 @@ DeleteUTest:: DeleteUTest(void) |
| 113 | 114 | */ |
| 114 | 115 | void DeleteUTest::setUp(void) |
| 115 | 116 | { |
| 116 | _as = new AtomSpace(); | |
| 117 | _as = createAtomSpace(); | |
| 117 | 118 | } |
| 118 | 119 | |
| 119 | 120 | void DeleteUTest::tearDown(void) |
| 120 | 121 | { |
| 121 | delete _as; | |
| 122 | _as = nullptr; | |
| 122 | 123 | } |
| 123 | 124 | |
| 124 | 125 | // ============================================================ |
| … | … | @@ -390,11 +391,11 @@ void DeleteUTest::extract_links(int idx, AtomSpace *as) |
| 390 | 391 | // the AtomSpace) |
| 391 | 392 | void DeleteUTest::delete_links(int idx, StorageNodePtr store) |
| 392 | 393 | { |
| 393 | store->remove_atom(_as, hl3[idx]); | |
| 394 | store->remove_atom(_as.get(), hl3[idx]); | |
| 394 | 395 | store->barrier(); |
| 395 | store->remove_atom(_as, hl2[idx]); | |
| 396 | store->remove_atom(_as.get(), hl2[idx]); | |
| 396 | 397 | store->barrier(); |
| 397 | store->remove_atom(_as, hl[idx]); | |
| 398 | store->remove_atom(_as.get(), hl[idx]); | |
| 398 | 399 | store->barrier(); |
| 399 | 400 | |
| 400 | 401 | _as->extract_atom(hl3[idx]); |
| … | … | @@ -412,7 +413,7 @@ void DeleteUTest::extract_nodes(int idx, AtomSpace *as) |
| 412 | 413 | // This should delete all the links and one node from storage. |
| 413 | 414 | void DeleteUTest::delete_nodes(int idx, StorageNodePtr store) |
| 414 | 415 | { |
| 415 | store->remove_atom(_as, h3[idx], true); | |
| 416 | store->remove_atom(_as.get(), h3[idx], true); | |
| 416 | 417 | store->barrier(); |
| 417 | 418 | _as->extract_atom(h3[idx], true); |
| 418 | 419 | } |
| … | … | @@ -425,33 +426,34 @@ void DeleteUTest::test_remove(void) |
| 425 | 426 | |
| 426 | 427 | Handle hsn = _as->add_node(MONO_STORAGE_NODE, std::string(uri)); |
| 427 | 428 | StorageNodePtr store = StorageNodeCast(hsn); |
| 428 | store->open(); | |
| 429 | store->setValue(_as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 429 | 430 | TS_ASSERT(store->connected()) |
| 430 | 431 | |
| 431 | 432 | int idx = 0; |
| 432 | add_to_space(idx++, _as, "AA-aa-wow "); | |
| 433 | add_to_space(idx++, _as, "BB-bb-wow "); | |
| 434 | add_to_space(idx++, _as, "CC-cc-wow "); | |
| 435 | add_to_space(idx++, _as, "DD-dd-wow "); | |
| 436 | add_to_space(idx++, _as, "EE-ee-wow "); | |
| 433 | add_to_space(idx++, _as.get(), "AA-aa-wow "); | |
| 434 | add_to_space(idx++, _as.get(), "BB-bb-wow "); | |
| 435 | add_to_space(idx++, _as.get(), "CC-cc-wow "); | |
| 436 | add_to_space(idx++, _as.get(), "DD-dd-wow "); | |
| 437 | add_to_space(idx++, _as.get(), "EE-ee-wow "); | |
| 437 | 438 | |
| 438 | 439 | /* Make sure UTF-8 works fine. */ |
| 439 | add_to_space(idx++, _as, "Попытка выбраться вызвала слабый стон "); | |
| 440 | add_to_space(idx++, _as, "はにがうりだそうであってるのかはち "); | |
| 441 | add_to_space(idx++, _as, "係拉丁字母"); | |
| 440 | add_to_space(idx++, _as.get(), "Попытка выбраться вызвала слабый стон "); | |
| 441 | add_to_space(idx++, _as.get(), "はにがうりだそうであってるのかはち "); | |
| 442 | add_to_space(idx++, _as.get(), "係拉丁字母"); | |
| 442 | 443 | |
| 443 | 444 | /* Verify that the atoms were added */ |
| 444 | 445 | int i; |
| 445 | 446 | for (i=0; i<idx; i++) |
| 446 | check_space(i, _as, "verify-add"); | |
| 447 | check_space(i, _as.get(), "verify-add"); | |
| 447 | 448 | |
| 448 | 449 | /* Push all atoms out to storage */ |
| 449 | 450 | store->store_atomspace(); |
| 450 | 451 | |
| 451 | 452 | // *-IsKeyFlag-* is not added until after store_atomspace |
| 452 | printf("Initial Atomspace size=%lu expect=%d\n", _as->get_size(), 7*idx+1); | |
| 453 | // +1 for (Predicate "*-open-*") | |
| 454 | printf("Initial Atomspace size=%lu expect=%d\n", _as->get_size(), 7*idx+2); | |
| 453 | 455 | TSM_ASSERT("Initial unexpected atomspace size", |
| 454 | ((unsigned)(7*idx+1)) == _as->get_size()); | |
| 456 | ((unsigned)(7*idx+2)) == _as->get_size()); | |
| 455 | 457 | /* Delete some atoms with non-empty incoming sets. |
| 456 | 458 | * This should result in their being removed from the atomspace, |
| 457 | 459 | * but NOT fom the backend! |
| … | … | @@ -459,16 +461,17 @@ void DeleteUTest::test_remove(void) |
| 459 | 461 | store->barrier(); |
| 460 | 462 | |
| 461 | 463 | for (i=0; i<idx; i++) |
| 462 | extract_links(i, _as); | |
| 464 | extract_links(i, _as.get()); | |
| 463 | 465 | |
| 464 | 466 | // *-IsKeyFlag-* is not added until after fetch |
| 465 | printf("Atomspace size=%lu expect=%d\n", _as->get_size(), 4*idx+1); | |
| 466 | TSM_ASSERT("Post-extract unexpected atomspace size", ((unsigned)(4*idx+1)) == _as->get_size()); | |
| 467 | // +1 for (Predicate "*-open-*") | |
| 468 | printf("Atomspace size=%lu expect=%d\n", _as->get_size(), 4*idx+2); | |
| 469 | TSM_ASSERT("Post-extract unexpected atomspace size", ((unsigned)(4*idx+2)) == _as->get_size()); | |
| 467 | 470 | |
| 468 | 471 | /* Verify that the atoms can still be fetched from storage. */ |
| 469 | 472 | for (i=0; i<idx; i++) { |
| 470 | 473 | fetch_space(i, store); |
| 471 | check_space(i, _as, "verify-fetch"); | |
| 474 | check_space(i, _as.get(), "verify-fetch"); | |
| 472 | 475 | } |
| 473 | 476 | |
| 474 | 477 | /* This time, kill them in the backend too. */ |
| … | … | @@ -476,20 +479,22 @@ void DeleteUTest::test_remove(void) |
| 476 | 479 | delete_links(i, store); |
| 477 | 480 | |
| 478 | 481 | // +2 for *-TruthValueKey-* and *-IsKeyFlag-* |
| 479 | printf("Post-remove size=%lu expect=%d\n", _as->get_size(), 4*idx+3); | |
| 482 | // +1 for (Predicate "*-open-*") | |
| 483 | printf("Post-remove size=%lu expect=%d\n", _as->get_size(), 4*idx+4); | |
| 480 | 484 | TSM_ASSERT("Post-remove unexpected atomspace size", |
| 481 | ((unsigned)(4*idx+3)) == _as->get_size()); | |
| 485 | ((unsigned)(4*idx+4)) == _as->get_size()); | |
| 482 | 486 | |
| 483 | 487 | /* Verify that the atoms are really gone from storage. */ |
| 484 | 488 | for (i=0; i<idx; i++) { |
| 485 | 489 | fetch_space(i, store); |
| 486 | check_remove(i, _as, "verify-gone"); | |
| 490 | check_remove(i, _as.get(), "verify-gone"); | |
| 487 | 491 | } |
| 488 | 492 | |
| 489 | 493 | // +2 for *-TruthValueKey-* and *-IsKeyFlag-* |
| 490 | printf("Post-referesh size=%lu expect=%d\n", _as->get_size(), 7*idx+3); | |
| 494 | // +1 for (Predicate "*-open-*") | |
| 495 | printf("Post-referesh size=%lu expect=%d\n", _as->get_size(), 7*idx+4); | |
| 491 | 496 | TSM_ASSERT("Post-refetch unexpected atomspace size", |
| 492 | ((unsigned)(7*idx+3)) == _as->get_size()); | |
| 497 | ((unsigned)(7*idx+4)) == _as->get_size()); | |
| 493 | 498 | |
| 494 | 499 | /* Kill data for good */ |
| 495 | 500 | _as->clear(); |
| … | … | @@ -497,7 +502,7 @@ void DeleteUTest::test_remove(void) |
| 497 | 502 | |
| 498 | 503 | /* Verify that the atoms are no longer being found. */ |
| 499 | 504 | for (i=0; i<idx; i++) |
| 500 | check_empty(i, _as); | |
| 505 | check_empty(i, _as.get()); | |
| 501 | 506 | |
| 502 | 507 | logger().debug("END TEST: %s", __FUNCTION__); |
| 503 | 508 | } |
| … | … | @@ -510,26 +515,26 @@ void DeleteUTest::test_recurse(void) |
| 510 | 515 | |
| 511 | 516 | Handle hsn = _as->add_node(MONO_STORAGE_NODE, std::string(uri)); |
| 512 | 517 | StorageNodePtr store = StorageNodeCast(hsn); |
| 513 | store->open(); | |
| 518 | store->setValue(_as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 514 | 519 | |
| 515 | 520 | TS_ASSERT(store->connected()) |
| 516 | 521 | |
| 517 | 522 | int idx = 0; |
| 518 | add_to_space(idx++, _as, "AA-aa-wow "); | |
| 519 | add_to_space(idx++, _as, "BB-bb-wow "); | |
| 520 | add_to_space(idx++, _as, "CC-cc-wow "); | |
| 521 | add_to_space(idx++, _as, "DD-dd-wow "); | |
| 522 | add_to_space(idx++, _as, "EE-ee-wow "); | |
| 523 | add_to_space(idx++, _as.get(), "AA-aa-wow "); | |
| 524 | add_to_space(idx++, _as.get(), "BB-bb-wow "); | |
| 525 | add_to_space(idx++, _as.get(), "CC-cc-wow "); | |
| 526 | add_to_space(idx++, _as.get(), "DD-dd-wow "); | |
| 527 | add_to_space(idx++, _as.get(), "EE-ee-wow "); | |
| 523 | 528 | |
| 524 | 529 | /* Make sure UTF-8 works fine. */ |
| 525 | add_to_space(idx++, _as, "Попытка выбраться вызвала слабый стон "); | |
| 526 | add_to_space(idx++, _as, "はにがうりだそうであってるのかはち "); | |
| 527 | add_to_space(idx++, _as, "係拉丁字母"); | |
| 530 | add_to_space(idx++, _as.get(), "Попытка выбраться вызвала слабый стон "); | |
| 531 | add_to_space(idx++, _as.get(), "はにがうりだそうであってるのかはち "); | |
| 532 | add_to_space(idx++, _as.get(), "係拉丁字母"); | |
| 528 | 533 | |
| 529 | 534 | /* Verify that the atoms were added */ |
| 530 | 535 | int i; |
| 531 | 536 | for (i=0; i<idx; i++) |
| 532 | check_space(i, _as, "verify-add"); | |
| 537 | check_space(i, _as.get(), "verify-add"); | |
| 533 | 538 | |
| 534 | 539 | /* Push all atoms out to the SQL DB */ |
| 535 | 540 | store->store_atomspace(); |
| … | … | @@ -542,10 +547,11 @@ void DeleteUTest::test_recurse(void) |
| 542 | 547 | |
| 543 | 548 | int zap = 4; |
| 544 | 549 | for (i=0; i<zap; i++) |
| 545 | extract_nodes(i, _as); | |
| 550 | extract_nodes(i, _as.get()); | |
| 546 | 551 | |
| 547 | 552 | // *-IsKeyFlag-* is not added until after fetch |
| 548 | size_t expsz = 7*(idx-zap) + 3*zap + 1; | |
| 553 | // +1 for (Predicate "*-open-*") | |
| 554 | size_t expsz = 7*(idx-zap) + 3*zap + 2; | |
| 549 | 555 | printf("Atomspace size=%lu expect=%lu\n", |
| 550 | 556 | _as->get_size(), expsz); |
| 551 | 557 | TSM_ASSERT("Unexpected atomspace size", expsz == _as->get_size()); |
| … | … | @@ -553,7 +559,7 @@ void DeleteUTest::test_recurse(void) |
| 553 | 559 | /* Verify that the atoms can still be fetched from storage. */ |
| 554 | 560 | for (i=0; i<idx; i++) { |
| 555 | 561 | fetch_space(i, store); |
| 556 | check_space(i, _as, "verify-fetch"); | |
| 562 | check_space(i, _as.get(), "verify-fetch"); | |
| 557 | 563 | } |
| 558 | 564 | |
| 559 | 565 | /* This time, kill them in the backend too. */ |
| … | … | @@ -573,19 +579,20 @@ void DeleteUTest::test_recurse(void) |
| 573 | 579 | } |
| 574 | 580 | |
| 575 | 581 | // +2 for *-TruthValueKey-* and *-IsKeyFlag-* |
| 582 | // +1 for (Predicate "*-open-*") | |
| 576 | 583 | printf("Post-refetch size=%lu expect=%d\n", |
| 577 | _as->get_size(), 7*idx+3); | |
| 584 | _as->get_size(), 7*idx+4); | |
| 578 | 585 | TSM_ASSERT("Unexpected atomspace size", |
| 579 | ((unsigned) 7*idx+3) == _as->get_size()); | |
| 586 | ((unsigned) 7*idx+4) == _as->get_size()); | |
| 580 | 587 | |
| 581 | 588 | /* Check that the removed atoms really got zapped. */ |
| 582 | 589 | for (i=0; i<zap; i++) { |
| 583 | check_remove(i, _as, "verify-zapped"); | |
| 590 | check_remove(i, _as.get(), "verify-zapped"); | |
| 584 | 591 | } |
| 585 | 592 | |
| 586 | 593 | /* However, others should still be there. */ |
| 587 | 594 | for (i=zap; i<idx; i++) { |
| 588 | check_space(i, _as, "verify-zap"); | |
| 595 | check_space(i, _as.get(), "verify-zap"); | |
| 589 | 596 | } |
| 590 | 597 | |
| 591 | 598 | /* Kill data for good */ |
| … | … | @@ -594,7 +601,7 @@ void DeleteUTest::test_recurse(void) |
| 594 | 601 | |
| 595 | 602 | /* Verify that the atoms are no longer being found. */ |
| 596 | 603 | for (i=0; i<idx; i++) |
| 597 | check_empty(i, _as); | |
| 604 | check_empty(i, _as.get()); | |
| 598 | 605 | |
| 599 | 606 | logger().debug("END TEST: %s", __FUNCTION__); |
| 600 | 607 | } |
| … | … | @@ -34,6 +34,7 @@ |
| 34 | 34 | #include <opencog/atoms/atom_types/atom_types.h> |
| 35 | 35 | #include <opencog/atoms/value/FloatValue.h> |
| 36 | 36 | #include <opencog/atoms/value/LinkValue.h> |
| 37 | #include <opencog/atoms/value/VoidValue.h> | |
| 37 | 38 | #include <opencog/atomspace/AtomSpace.h> |
| 38 | 39 | #include <opencog/persist/rocks-types/atom_types.h> |
| 39 | 40 | |
| … | … | @@ -127,7 +128,7 @@ void MultiDeleteUTest::worker(int thread_id) |
| 127 | 128 | if (nullptr == li) continue; |
| 128 | 129 | |
| 129 | 130 | // Remove the link. |
| 130 | store->remove_atom(as, li); | |
| 131 | store->remove_atom(as.get(), li); | |
| 131 | 132 | } |
| 132 | 133 | } |
| 133 | 134 | |
| … | … | @@ -151,7 +152,7 @@ void MultiDeleteUTest::test_add_delete(void) |
| 151 | 152 | Handle hsn = as->add_node(MONO_STORAGE_NODE, std::string(uri)); |
| 152 | 153 | store = StorageNodeCast(hsn); |
| 153 | 154 | |
| 154 | store->open(); | |
| 155 | store->setValue(as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 155 | 156 | TS_ASSERT(store->connected()) |
| 156 | 157 | |
| 157 | 158 | // Clear out left-over junk, just in case. |
| … | … | @@ -174,13 +175,14 @@ void MultiDeleteUTest::test_add_delete(void) |
| 174 | 175 | // Verify the local AtomSpace size. Should be 34: |
| 175 | 176 | // The StorageNode itself, the (Concept "aaaa") and |
| 176 | 177 | // 16 Concept and Lists from thread-id modulo 16 |
| 177 | TS_ASSERT_EQUALS(as->get_size(), 2 + 2*(n_threads+6)); | |
| 178 | // +1 for (Predicate "*-open-*") | |
| 179 | TS_ASSERT_EQUALS(as->get_size(), 3 + 2*(n_threads+6)); | |
| 178 | 180 | |
| 179 | 181 | // Verify the DB contents: pull everything from the DB, |
| 180 | 182 | // back to here. Do this "independently", by closing and |
| 181 | 183 | // reopening; this forces the Storagenode through assorted |
| 182 | 184 | // flush and close code, potentially exposing bugs. |
| 183 | store->close(); | |
| 185 | store->setValue(as->add_node(PREDICATE_NODE, "*-close-*"), createVoidValue()); | |
| 184 | 186 | |
| 185 | 187 | HandleSeq hs; |
| 186 | 188 | as->get_handles_by_type(hs, CONCEPT_NODE); |
| … | … | @@ -188,9 +190,10 @@ void MultiDeleteUTest::test_add_delete(void) |
| 188 | 190 | as->extract_atom(h, true); |
| 189 | 191 | hs.clear(); |
| 190 | 192 | printf("AtomSpace contents =\n%s\n", as->to_string().c_str()); |
| 191 | TS_ASSERT_EQUALS(as->get_size(), 1); | |
| 193 | // +1 for (Predicate "*-open-*"), +1 for (Predicate "*-close-*") | |
| 194 | TS_ASSERT_EQUALS(as->get_size(), 3); | |
| 192 | 195 | |
| 193 | store->open(); | |
| 196 | store->setValue(as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 194 | 197 | TS_ASSERT(store->connected()) |
| 195 | 198 | |
| 196 | 199 | store->load_atomspace(); |
| … | … | @@ -198,7 +201,8 @@ void MultiDeleteUTest::test_add_delete(void) |
| 198 | 201 | |
| 199 | 202 | // Size should be 19: the 18 from before plus that annoying |
| 200 | 203 | // (Predicate "*-TruthValueKey-*") |
| 201 | size_t expected_size = 3 + n_threads + 6; | |
| 204 | // +1 for (Predicate "*-open-*"), +1 for (Predicate "*-close-*") | |
| 205 | size_t expected_size = 5 + n_threads + 6; | |
| 202 | 206 | if (as->get_size() != expected_size) |
| 203 | 207 | printf("Error: Bad size! AtomSpace contents =\n%s\n", |
| 204 | 208 | as->to_string().c_str()); |
| … | … | @@ -206,8 +210,8 @@ void MultiDeleteUTest::test_add_delete(void) |
| 206 | 210 | TS_ASSERT_EQUALS(as->get_size(), expected_size); |
| 207 | 211 | |
| 208 | 212 | store->erase(); |
| 209 | store->close(); | |
| 210 | 213 | store = nullptr; |
| 214 | as = nullptr; | |
| 211 | 215 | |
| 212 | 216 | logger().debug("END TEST: %s", __FUNCTION__); |
| 213 | 217 | } |
| … | … | @@ -38,6 +38,7 @@ |
| 38 | 38 | #include <opencog/persist/monospace/MonoStorage.h> |
| 39 | 39 | |
| 40 | 40 | #include <opencog/atoms/value/FloatValue.h> |
| 41 | #include <opencog/atoms/value/VoidValue.h> | |
| 41 | 42 | |
| 42 | 43 | #include <opencog/util/Logger.h> |
| 43 | 44 | |
| … | … | @@ -46,7 +47,7 @@ using namespace opencog; |
| 46 | 47 | class MultiPersistUTest : public CxxTest::TestSuite |
| 47 | 48 | { |
| 48 | 49 | private: |
| 49 | AtomSpace *_as; | |
| 50 | AtomSpacePtr _as; | |
| 50 | 51 | StorageNodePtr store; |
| 51 | 52 | |
| 52 | 53 | #define NTHREADS 6 |
| … | … | @@ -127,18 +128,18 @@ MultiPersistUTest:: MultiPersistUTest(void) |
| 127 | 128 | */ |
| 128 | 129 | void MultiPersistUTest::setUp(void) |
| 129 | 130 | { |
| 130 | _as = new AtomSpace(); | |
| 131 | _as = createAtomSpace(); | |
| 131 | 132 | |
| 132 | 133 | Handle hsn = _as->add_node(MONO_STORAGE_NODE, "monospace:///tmp/cog-mono-multi-persist-utest"); |
| 133 | 134 | store = StorageNodeCast(hsn); |
| 134 | store->open(); | |
| 135 | store->setValue(_as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 135 | 136 | TS_ASSERT(store->connected()) |
| 136 | 137 | } |
| 137 | 138 | |
| 138 | 139 | void MultiPersistUTest::tearDown(void) |
| 139 | 140 | { |
| 140 | store->close(); | |
| 141 | delete _as; | |
| 141 | store.reset(); | |
| 142 | _as = nullptr; | |
| 142 | 143 | } |
| 143 | 144 | |
| 144 | 145 | // ============================================================ |
| … | … | @@ -384,20 +385,20 @@ void MultiPersistUTest::threaded_add(int thread_id) |
| 384 | 385 | int idx = 0; |
| 385 | 386 | int off = NHACK*thread_id; |
| 386 | 387 | |
| 387 | add_to_space(off + idx++, _as, store, "AA-aa-wow "); | |
| 388 | add_to_space(off + idx++, _as, store, "BB-bb-wow "); | |
| 389 | add_to_space(off + idx++, _as, store, "CC-cc-wow "); | |
| 390 | add_to_space(off + idx++, _as, store, "DD-dd-wow "); | |
| 391 | add_to_space(off + idx++, _as, store, "EE-ee-wow "); | |
| 388 | add_to_space(off + idx++, _as.get(), store, "AA-aa-wow "); | |
| 389 | add_to_space(off + idx++, _as.get(), store, "BB-bb-wow "); | |
| 390 | add_to_space(off + idx++, _as.get(), store, "CC-cc-wow "); | |
| 391 | add_to_space(off + idx++, _as.get(), store, "DD-dd-wow "); | |
| 392 | add_to_space(off + idx++, _as.get(), store, "EE-ee-wow "); | |
| 392 | 393 | |
| 393 | 394 | /* Make sure UTF-8 works fine. */ |
| 394 | add_to_space(off + idx++, _as, store, "Попытка выбраться вызвала слабый стон "); | |
| 395 | add_to_space(off + idx++, _as, store, "はにがうりだそうであってるのかはち "); | |
| 396 | add_to_space(off + idx++, _as, store, "係拉丁字母"); | |
| 395 | add_to_space(off + idx++, _as.get(), store, "Попытка выбраться вызвала слабый стон "); | |
| 396 | add_to_space(off + idx++, _as.get(), store, "はにがうりだそうであってるのかはち "); | |
| 397 | add_to_space(off + idx++, _as.get(), store, "係拉丁字母"); | |
| 397 | 398 | |
| 398 | 399 | /* Verify that the atoms were added */ |
| 399 | 400 | for (int i=0; i<idx; i++) |
| 400 | check_space(off+i, _as, "verify-add"); | |
| 401 | check_space(off+i, _as.get(), "verify-add"); | |
| 401 | 402 | } |
| 402 | 403 | |
| 403 | 404 | // ============================================================ |
| … | … | @@ -431,7 +432,7 @@ void MultiPersistUTest::test_atomspace(void) |
| 431 | 432 | /* The clear above nuked the storage, so restart */ |
| 432 | 433 | Handle hsn = _as->add_node(MONO_STORAGE_NODE, "monospace:///tmp/cog-mono-multi-persist-utest"); |
| 433 | 434 | store = StorageNodeCast(hsn); |
| 434 | store->open(); | |
| 435 | store->setValue(_as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 435 | 436 | TS_ASSERT(store->connected()) |
| 436 | 437 | |
| 437 | 438 | int i, off; |
| … | … | @@ -440,7 +441,7 @@ void MultiPersistUTest::test_atomspace(void) |
| 440 | 441 | for (off=0; off<n_threads; off++) |
| 441 | 442 | for (i=0; i<NATS; i++) { |
| 442 | 443 | fetch_space(NHACK*off+i, store); |
| 443 | check_space(NHACK*off+i, _as, "verify-fetch-idx=" + std::to_string(i)); | |
| 444 | check_space(NHACK*off+i, _as.get(), "verify-fetch-idx=" + std::to_string(i)); | |
| 444 | 445 | } |
| 445 | 446 | |
| 446 | 447 | /* Do it again, for good luck. */ |
| … | … | @@ -450,14 +451,14 @@ void MultiPersistUTest::test_atomspace(void) |
| 450 | 451 | /* The clear above nuked the storage, so restart */ |
| 451 | 452 | hsn = _as->add_node(MONO_STORAGE_NODE, "monospace:///tmp/cog-mono-multi-persist-utest"); |
| 452 | 453 | store = StorageNodeCast(hsn); |
| 453 | store->open(); | |
| 454 | store->setValue(_as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 454 | 455 | TS_ASSERT(store->connected()) |
| 455 | 456 | |
| 456 | 457 | /* Verify that the atoms can still be fetched from storage. */ |
| 457 | 458 | for (off=0; off<n_threads; off++) |
| 458 | 459 | for (i=0; i<NATS; i++) { |
| 459 | 460 | fetch_space(NHACK*off+i, store); |
| 460 | check_space(NHACK*off+i, _as, "verify-again"); | |
| 461 | check_space(NHACK*off+i, _as.get(), "verify-again"); | |
| 461 | 462 | } |
| 462 | 463 | |
| 463 | 464 | /* Kill data for good */ |
| … | … | @@ -467,7 +468,7 @@ void MultiPersistUTest::test_atomspace(void) |
| 467 | 468 | /* Verify that the atoms are no longer being found. */ |
| 468 | 469 | for (off=0; off<n_threads; off++) |
| 469 | 470 | for (i=0; i<NATS; i++) |
| 470 | check_empty(NHACK*off+i, _as); | |
| 471 | check_empty(NHACK*off+i, _as.get()); | |
| 471 | 472 | |
| 472 | 473 | logger().debug("END TEST: %s", __FUNCTION__); |
| 473 | 474 | } |