| … | … | @@ -223,12 +223,7 @@ void MonoBasicSaveUTest::single_atom_save_restore(std::string id) |
| 223 | 223 | atomCompare(l, hl, "Single link save-restore"); |
| 224 | 224 | printf("Done fetching single link\n"); |
| 225 | 225 | |
| 226 | | // Close the store and clean up database for next iteration. |
| 227 | | store->setValue(as->add_node(PREDICATE_NODE, "*-erase-*"), createVoidValue()); |
| 228 | | store->setValue(as->add_node(PREDICATE_NODE, "*-close-*"), createVoidValue()); |
| 229 | | store.reset(); |
| 230 | | hsn = Handle::UNDEFINED; |
| 231 | | as.reset(); |
| 226 | store->erase(); |
| 232 | 227 | } |
| 233 | 228 | |
| 234 | 229 | // ============================================================ |
| … | … | @@ -364,12 +359,7 @@ void MonoBasicSaveUTest::test_fresh_atom(void) |
| 364 | 359 | if (he) printf("Got %s\n", he->to_string().c_str()); |
| 365 | 360 | atomCompare(le, he, "Empty Fresh"); |
| 366 | 361 | |
| 367 | | // Close the store and clean up database for next test. |
| 368 | | store->setValue(as->add_node(PREDICATE_NODE, "*-erase-*"), createVoidValue()); |
| 369 | | store->setValue(as->add_node(PREDICATE_NODE, "*-close-*"), createVoidValue()); |
| 370 | | store.reset(); |
| 371 | | hsn = Handle::UNDEFINED; |
| 372 | | as.reset(); |
| 362 | store->erase(); |
| 373 | 363 | |
| 374 | 364 | logger().debug("END TEST: %s", __FUNCTION__); |
| 375 | 365 | } |
| … | … | @@ -378,45 +368,46 @@ void MonoBasicSaveUTest::test_table() |
| 378 | 368 | { |
| 379 | 369 | logger().debug("BEGIN TEST: %s", __FUNCTION__); |
| 380 | 370 | |
| 381 | | AtomSpacePtr as1 = createAtomSpace(); |
| 382 | | Handle hsn = as1->add_node(MONO_STORAGE_NODE, std::string(uri)); |
| 383 | | StorageNodePtr store = StorageNodeCast(hsn); |
| 384 | | store->setValue(as1->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); |
| 385 | | if (!store->connected()) |
| 371 | size_t num_stored; |
| 372 | |
| 373 | // Use scope block to ensure as1 is destroyed before as2 opens |
| 386 | 374 | { |
| 387 | | logger().debug("test_table: cannot connect to db"); |
| 388 | | return; |
| 389 | | } |
| 375 | AtomSpacePtr as1 = createAtomSpace(); |
| 376 | Handle hsn = as1->add_node(MONO_STORAGE_NODE, std::string(uri)); |
| 377 | StorageNodePtr store = StorageNodeCast(hsn); |
| 378 | store->setValue(as1->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); |
| 379 | if (!store->connected()) |
| 380 | { |
| 381 | logger().debug("test_table: cannot connect to db"); |
| 382 | return; |
| 383 | } |
| 390 | 384 | |
| 391 | | int idx = 0; |
| 392 | | add_to_table(idx++, as1.get(), "AA-aa-wow "); |
| 393 | | add_to_table(idx++, as1.get(), "BB-bb-wow "); |
| 394 | | add_to_table(idx++, as1.get(), "CC-cc-wow "); |
| 395 | | add_to_table(idx++, as1.get(), "DD-dd-wow "); |
| 396 | | add_to_table(idx++, as1.get(), "EE-ee-wow "); |
| 385 | int idx = 0; |
| 386 | add_to_table(idx++, as1.get(), "AA-aa-wow "); |
| 387 | add_to_table(idx++, as1.get(), "BB-bb-wow "); |
| 388 | add_to_table(idx++, as1.get(), "CC-cc-wow "); |
| 389 | add_to_table(idx++, as1.get(), "DD-dd-wow "); |
| 390 | add_to_table(idx++, as1.get(), "EE-ee-wow "); |
| 397 | 391 | |
| 398 | | store->store_atomspace(); |
| 399 | | // Subtract 2 for the MonoStorageNode and *-open-* PredicateNode |
| 400 | | size_t num_stored = as1->get_size() - 2; |
| 392 | store->store_atomspace(); |
| 393 | // Subtract 2 for the MonoStorageNode and *-open-* PredicateNode |
| 394 | num_stored = as1->get_size() - 2; |
| 401 | 395 | #ifdef DOPRT |
| 402 | | HandleSeq hset; |
| 403 | | as1->get_handles_by_type(hset, ATOM, true, false); |
| 404 | | for (auto h: hset) { |
| 405 | | printf("Store table has %s\n", h->to_string().c_str()); |
| 406 | | } |
| 396 | HandleSeq hset; |
| 397 | as1->get_handles_by_type(hset, ATOM, true, false); |
| 398 | for (auto h: hset) { |
| 399 | printf("Store table has %s\n", h->to_string().c_str()); |
| 400 | } |
| 407 | 401 | #endif |
| 408 | 402 | |
| 409 | | // Explicitly close the store before resetting handles. |
| 410 | | store->setValue(as1->add_node(PREDICATE_NODE, "*-close-*"), createVoidValue()); |
| 411 | | store.reset(); |
| 412 | | hsn = Handle::UNDEFINED; |
| 413 | | as1.reset(); |
| 414 | | printf("Done storing table; size=%lu\n", num_stored); |
| 403 | printf("Done storing table; size=%lu\n", num_stored); |
| 404 | } |
| 405 | // as1 goes out of scope here, storage is closed automatically |
| 415 | 406 | |
| 416 | 407 | // Reopen connection, and load the atom table. |
| 417 | 408 | AtomSpacePtr as2 = createAtomSpace(); |
| 418 | | hsn = as2->add_node(MONO_STORAGE_NODE, std::string(uri)); |
| 419 | | store = StorageNodeCast(hsn); |
| 409 | Handle hsn = as2->add_node(MONO_STORAGE_NODE, std::string(uri)); |
| 410 | StorageNodePtr store = StorageNodeCast(hsn); |
| 420 | 411 | store->setValue(as2->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); |
| 421 | 412 | TSM_ASSERT("Not connected to database", store->connected()); |
| 422 | 413 | |
| … | … | @@ -430,19 +421,14 @@ void MonoBasicSaveUTest::test_table() |
| 430 | 421 | // and (PredicateNode "*-IsKeyFlag-*") |
| 431 | 422 | TSM_ASSERT("Wrong number of atoms fetched", num_fetched == num_stored+2); |
| 432 | 423 | |
| 433 | | idx = 0; |
| 424 | int idx = 0; |
| 434 | 425 | check_table(idx++, as2.get(), "aaa "); |
| 435 | 426 | check_table(idx++, as2.get(), "bbb "); |
| 436 | 427 | check_table(idx++, as2.get(), "ccc "); |
| 437 | 428 | check_table(idx++, as2.get(), "ddd "); |
| 438 | 429 | check_table(idx++, as2.get(), "eee "); |
| 439 | 430 | |
| 440 | | // Close the store and clean up database. |
| 441 | | store->setValue(as2->add_node(PREDICATE_NODE, "*-erase-*"), createVoidValue()); |
| 442 | | store->setValue(as2->add_node(PREDICATE_NODE, "*-close-*"), createVoidValue()); |
| 443 | | store.reset(); |
| 444 | | hsn = Handle::UNDEFINED; |
| 445 | | as2.reset(); |
| 431 | store->erase(); |
| 446 | 432 | |
| 447 | 433 | logger().debug("END TEST: %s", __FUNCTION__); |
| 448 | 434 | } |