| … | … | @@ -1,9 +1,43 @@ |
| 1 | 1 | #include <opencog/atomspace/AtomSpace.h> |
| 2 | #include <opencog/atoms/atom_types/atom_types.h> | |
| 2 | 3 | #include <opencog/atoms/value/FloatValue.h> |
| 3 | 4 | #include <opencog/atoms/value/VoidValue.h> |
| 4 | 5 | #include <opencog/atoms/atom_types/atom_names.h> |
| 5 | 6 | #include <opencog/cogserver/atoms/CogServerNode.h> |
| 6 | 7 | #include <opencog/cogserver/types/atom_types.h> |
| 8 | #include <opencog/persist/api/StorageNode.h> | |
| 9 | ||
| 10 | using namespace opencog; | |
| 11 | ||
| 12 | // Selectively clear test data from the remote atomspace without | |
| 13 | // removing the CogServerNode itself. This replaces kill_data() which | |
| 14 | // would destroy the CogServerNode and cause segfaults. | |
| 15 | inline void kill_data(StorageNode* store, AtomSpace* asp) | |
| 16 | { | |
| 17 | // Load all nodes from remote storage | |
| 18 | store->fetch_all_atoms_of_type(NODE, asp); | |
| 19 | store->barrier(); | |
| 20 | ||
| 21 | HandleSeq nodes; | |
| 22 | asp->get_handles_by_type(nodes, NODE, true); | |
| 23 | for (const Handle& h : nodes) | |
| 24 | { | |
| 25 | Type t = h->get_type(); | |
| 26 | // Keep the CogServerNode | |
| 27 | if (t == COG_SERVER_NODE) continue; | |
| 28 | // Keep infrastructure PredicateNodes (those starting with "*-") | |
| 29 | #if 0 | |
| 30 | if (t == PREDICATE_NODE) | |
| 31 | { | |
| 32 | const std::string& name = h->get_name(); | |
| 33 | if (name.size() > 2 && name[0] == '*' && name[1] == '-') | |
| 34 | continue; | |
| 35 | } | |
| 36 | #endif | |
| 37 | store->remove_atom(asp, h, true); | |
| 38 | } | |
| 39 | store->barrier(); | |
| 40 | } | |
| 7 | 41 | |
| 8 | 42 | #define DECLARE_TEST_COGSERVER \ |
| 9 | 43 | AtomSpacePtr _test_asp; \ |
| … | … | @@ -108,8 +108,8 @@ void AlphaEquivUTest::kill_data(void) |
| 108 | 108 | exit(1); |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | // Trash the contents of the database. | |
| 112 | astore->kill_data(); | |
| 111 | // Selectively clear test data (preserves CogServerNode) | |
| 112 | ::kill_data(astore, _test_asp.get()); | |
| 113 | 113 | |
| 114 | 114 | // Destructor also logs out of database |
| 115 | 115 | delete astore; |
| … | … | @@ -217,7 +217,7 @@ void BasicSaveUTest::single_atom_save_restore(std::string id) |
| 217 | 217 | atomCompare(l, hl, "Single link save-restore"); |
| 218 | 218 | printf("Done fetching single link\n"); |
| 219 | 219 | |
| 220 | store->kill_data(); | |
| 220 | kill_data(store, _test_asp.get()); | |
| 221 | 221 | delete store; |
| 222 | 222 | } |
| 223 | 223 | |
| … | … | @@ -353,7 +353,7 @@ void BasicSaveUTest::test_fresh_atom(void) |
| 353 | 353 | if (he) printf("Got %s\n", he->to_string().c_str()); |
| 354 | 354 | atomCompare(le, he, "Empty Fresh"); |
| 355 | 355 | |
| 356 | store->kill_data(); | |
| 356 | kill_data(store, _test_asp.get()); | |
| 357 | 357 | delete store; |
| 358 | 358 | |
| 359 | 359 | logger().debug("END TEST: %s", __FUNCTION__); |
| … | … | @@ -417,7 +417,7 @@ void BasicSaveUTest::test_table() |
| 417 | 417 | check_table(idx++, as2, "ddd "); |
| 418 | 418 | check_table(idx++, as2, "eee "); |
| 419 | 419 | |
| 420 | store->kill_data(); | |
| 420 | kill_data(store, _test_asp.get()); | |
| 421 | 421 | delete store; |
| 422 | 422 | |
| 423 | 423 | logger().debug("END TEST: %s", __FUNCTION__); |
| … | … | @@ -127,8 +127,8 @@ void LargeFlatUTest::kill_data(void) |
| 127 | 127 | exit(1); |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | // Trash the contents of the database. | |
| 131 | astore->kill_data(); | |
| 130 | // Selectively clear test data (preserves CogServerNode) | |
| 131 | ::kill_data(astore, _test_asp.get()); | |
| 132 | 132 | |
| 133 | 133 | // Destructor also logs out |
| 134 | 134 | delete astore; |
| … | … | @@ -115,8 +115,8 @@ void LargeZipfUTest::kill_data(void) |
| 115 | 115 | exit(1); |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | // Trash the contents of the database. | |
| 119 | astore->kill_data(); | |
| 118 | // Selectively clear test data (preserves CogServerNode) | |
| 119 | ::kill_data(astore, _test_asp.get()); | |
| 120 | 120 | |
| 121 | 121 | // Destructor also logs out |
| 122 | 122 | delete astore; |
| … | … | @@ -158,7 +158,7 @@ void SimpleMultiDeleteUTest::test_add_delete(void) |
| 158 | 158 | TS_ASSERT(store->connected()) |
| 159 | 159 | |
| 160 | 160 | // Clear out left-over junk, just in case. |
| 161 | store->erase(); | |
| 161 | ::kill_data(store.get(), _test_asp.get()); | |
| 162 | 162 | |
| 163 | 163 | printf("Start creating %d threads\n", n_threads); |
| 164 | 164 | |
| … | … | @@ -201,14 +201,15 @@ void SimpleMultiDeleteUTest::test_add_delete(void) |
| 201 | 201 | |
| 202 | 202 | // Size should be 20: the 18 from before plus |
| 203 | 203 | // (Predicate "*-TruthValueKey-*") and (Predicate "*-IsKeyFlag-*") |
| 204 | size_t expected_size = 4 + 6 + n_threads; | |
| 204 | // Plus 9 more from CogServerNode gorp | |
| 205 | size_t expected_size = 9 + 4 + 6 + n_threads; | |
| 205 | 206 | if (as->get_size() != expected_size) |
| 206 | 207 | printf("Error: Bad size! AtomSpace contents =\n%s\n", |
| 207 | 208 | as->to_string().c_str()); |
| 208 | 209 | |
| 209 | 210 | TS_ASSERT_EQUALS(as->get_size(), expected_size); |
| 210 | 211 | |
| 211 | store->erase(); | |
| 212 | ::kill_data(store.get(), _test_asp.get()); | |
| 212 | 213 | store->close(); |
| 213 | 214 | store = nullptr; |
| 214 | 215 |
| … | … | @@ -104,8 +104,8 @@ void SimpleQueryPersistUTest::kill_data(void) |
| 104 | 104 | astore->open(); |
| 105 | 105 | TS_ASSERT(astore->connected()) |
| 106 | 106 | |
| 107 | // Trash the contents of the database. | |
| 108 | astore->kill_data(); | |
| 107 | // Selectively clear test data (preserves CogServerNode) | |
| 108 | ::kill_data(astore, _test_asp.get()); | |
| 109 | 109 | |
| 110 | 110 | // Destructor also logs out of database |
| 111 | 111 | delete astore; |
| … | … | @@ -277,7 +277,7 @@ void SimpleValueSaveUTest::test_load_by_type() |
| 277 | 277 | TS_ASSERT(store->connected()) |
| 278 | 278 | |
| 279 | 279 | // Clear out left-over junk, just in case. |
| 280 | store->erase(); | |
| 280 | ::kill_data(store.get(), _test_asp.get()); | |
| 281 | 281 | |
| 282 | 282 | Handle key = as->add_node(PREDICATE_NODE, "some pred key"); |
| 283 | 283 | Handle af = as->add_node(CONCEPT_NODE, "float node"); |
| … | … | @@ -108,8 +108,8 @@ void AlphaEquivUTest::kill_data(void) |
| 108 | 108 | exit(1); |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | // Trash the contents of the database. | |
| 112 | astore->kill_data(); | |
| 111 | // Selectively clear test data (preserves CogServerNode) | |
| 112 | ::kill_data(astore, _test_asp.get()); | |
| 113 | 113 | |
| 114 | 114 | // Destructor also logs out of database |
| 115 | 115 | delete astore; |
| … | … | @@ -106,7 +106,7 @@ void BasicDeleteUTest::test_duplicates(void) |
| 106 | 106 | TS_ASSERT(store->connected()) |
| 107 | 107 | |
| 108 | 108 | // Clear out left-over junk, just in case. |
| 109 | store->erase(); | |
| 109 | ::kill_data(store.get(), _test_asp.get()); | |
| 110 | 110 | |
| 111 | 111 | Handle ha(as->add_node(CONCEPT_NODE, "a")); |
| 112 | 112 | Handle hb(as->add_node(CONCEPT_NODE, "b")); |
| … | … | @@ -132,7 +132,7 @@ void BasicDeleteUTest::test_duplicates(void) |
| 132 | 132 | // +1 for *-IsKeyFlag-* |
| 133 | 133 | TS_ASSERT_EQUALS(as->get_size(), 5); |
| 134 | 134 | |
| 135 | store->erase(); | |
| 135 | ::kill_data(store.get(), _test_asp.get()); | |
| 136 | 136 | store->close(); |
| 137 | 137 | |
| 138 | 138 | logger().debug("END TEST: %s", __FUNCTION__); |
| … | … | @@ -153,7 +153,7 @@ void BasicDeleteUTest::test_recursive(void) |
| 153 | 153 | TS_ASSERT(store->connected()) |
| 154 | 154 | |
| 155 | 155 | // Clear out left-over junk, just in case. |
| 156 | store->erase(); | |
| 156 | ::kill_data(store.get(), _test_asp.get()); | |
| 157 | 157 | |
| 158 | 158 | Handle ha(as->add_node(CONCEPT_NODE, "a")); |
| 159 | 159 | Handle hb(as->add_node(CONCEPT_NODE, "b")); |
| … | … | @@ -258,7 +258,7 @@ void BasicDeleteUTest::test_recursive(void) |
| 258 | 258 | TS_ASSERT_EQUALS(as->get_size(), 4); |
| 259 | 259 | |
| 260 | 260 | // -------------------------------------- |
| 261 | store->erase(); | |
| 261 | ::kill_data(store.get(), _test_asp.get()); | |
| 262 | 262 | store->close(); |
| 263 | 263 | |
| 264 | 264 | logger().debug("END TEST: %s", __FUNCTION__); |
| … | … | @@ -280,7 +280,7 @@ void BasicDeleteUTest::test_key_deletion(void) |
| 280 | 280 | TS_ASSERT(store->connected()) |
| 281 | 281 | |
| 282 | 282 | // Clear out left-over junk, just in case. |
| 283 | store->erase(); | |
| 283 | ::kill_data(store.get(), _test_asp.get()); | |
| 284 | 284 | |
| 285 | 285 | Handle ha(as->add_node(CONCEPT_NODE, "a")); |
| 286 | 286 | Handle ka(as->add_node(PREDICATE_NODE, "key-a")); |
| … | … | @@ -363,7 +363,7 @@ void BasicDeleteUTest::test_key_deletion(void) |
| 363 | 363 | printf("key=%s\n", k->get_name().c_str()); |
| 364 | 364 | TS_ASSERT_EQUALS(hs.size(), 3); |
| 365 | 365 | |
| 366 | store->erase(); | |
| 366 | ::kill_data(store.get(), _test_asp.get()); | |
| 367 | 367 | store->close(); |
| 368 | 368 | |
| 369 | 369 | logger().debug("END TEST: %s", __FUNCTION__); |
| … | … | @@ -387,7 +387,7 @@ void BasicDeleteUTest::test_key_corruption(void) |
| 387 | 387 | TS_ASSERT(store->connected()) |
| 388 | 388 | |
| 389 | 389 | // Clear out left-over junk, just in case. |
| 390 | store->erase(); | |
| 390 | ::kill_data(store.get(), _test_asp.get()); | |
| 391 | 391 | |
| 392 | 392 | Handle hb(as->add_node(CONCEPT_NODE, "b")); |
| 393 | 393 | Handle hx(as->add_node(CONCEPT_NODE, "x")); |
| … | … | @@ -497,7 +497,7 @@ void BasicDeleteUTest::test_key_corruption(void) |
| 497 | 497 | } |
| 498 | 498 | TS_ASSERT_EQUALS(hs.size(), 2); |
| 499 | 499 | |
| 500 | store->erase(); | |
| 500 | ::kill_data(store.get(), _test_asp.get()); | |
| 501 | 501 | store->close(); |
| 502 | 502 | |
| 503 | 503 | logger().debug("END TEST: %s", __FUNCTION__); |
| … | … | @@ -220,7 +220,7 @@ void BasicSaveUTest::single_atom_save_restore(std::string id) |
| 220 | 220 | atomCompare(l, hl, "Single link save-restore"); |
| 221 | 221 | printf("Done fetching single link\n"); |
| 222 | 222 | |
| 223 | store->kill_data(); | |
| 223 | kill_data(store, _test_asp.get()); | |
| 224 | 224 | store->close(); |
| 225 | 225 | delete store; |
| 226 | 226 | } |
| … | … | @@ -358,7 +358,7 @@ void BasicSaveUTest::test_fresh_atom(void) |
| 358 | 358 | if (he) printf("Got %s\n", he->to_string().c_str()); |
| 359 | 359 | atomCompare(le, he, "Empty Fresh"); |
| 360 | 360 | |
| 361 | store->kill_data(); | |
| 361 | kill_data(store, _test_asp.get()); | |
| 362 | 362 | store->close(); |
| 363 | 363 | delete store; |
| 364 | 364 | |
| … | … | @@ -426,7 +426,7 @@ void BasicSaveUTest::test_table() |
| 426 | 426 | check_table(idx++, table2, "ddd "); |
| 427 | 427 | check_table(idx++, table2, "eee "); |
| 428 | 428 | |
| 429 | store->kill_data(); | |
| 429 | kill_data(store, _test_asp.get()); | |
| 430 | 430 | store->close(); |
| 431 | 431 | delete store; |
| 432 | 432 |
| … | … | @@ -127,8 +127,8 @@ void LargeFlatUTest::kill_data(void) |
| 127 | 127 | exit(1); |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | // Trash the contents of the database. | |
| 131 | astore->kill_data(); | |
| 130 | // Selectively clear test data (preserves CogServerNode) | |
| 131 | ::kill_data(astore, _test_asp.get()); | |
| 132 | 132 | |
| 133 | 133 | // Destructor also logs out |
| 134 | 134 | delete astore; |
| … | … | @@ -116,8 +116,8 @@ void LargeZipfUTest::kill_data(void) |
| 116 | 116 | exit(1); |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | // Trash the contents of the database. | |
| 120 | astore->kill_data(); | |
| 119 | // Selectively clear test data (preserves CogServerNode) | |
| 120 | ::kill_data(astore, _test_asp.get()); | |
| 121 | 121 | |
| 122 | 122 | // Destructor also logs out |
| 123 | 123 | delete astore; |
| … | … | @@ -156,7 +156,7 @@ void MultiDeleteUTest::test_add_delete(void) |
| 156 | 156 | TS_ASSERT(store->connected()) |
| 157 | 157 | |
| 158 | 158 | // Clear out left-over junk, just in case. |
| 159 | store->erase(); | |
| 159 | ::kill_data(store.get(), _test_asp.get()); | |
| 160 | 160 | |
| 161 | 161 | printf("Start creating %d threads\n", n_threads); |
| 162 | 162 | |
| … | … | @@ -199,11 +199,12 @@ void MultiDeleteUTest::test_add_delete(void) |
| 199 | 199 | |
| 200 | 200 | // Size should be 20: the 18 from before plus that annoying |
| 201 | 201 | // (Predicate "*-TruthValueKey-*") And also *-IsKeyFlag-* |
| 202 | // And 9 more from CogServerNode gorp | |
| 202 | 203 | // Well, actually, there is no guarantee that the removes will |
| 203 | 204 | // happen after the stores. Best we can do is check lower and |
| 204 | 205 | // upper bounds of 20 and 36: |
| 205 | size_t min_size = 4 + n_threads + 6; | |
| 206 | size_t max_size = 4 + 2*(n_threads + 6); | |
| 206 | size_t min_size = 9 + 4 + n_threads + 6; | |
| 207 | size_t max_size = 9 + 4 + 2*(n_threads + 6); | |
| 207 | 208 | if (as->get_size() < min_size or max_size < as->get_size()) |
| 208 | 209 | printf("Error: Bad size! AtomSpace contents =\n%s\n", |
| 209 | 210 | as->to_string().c_str()); |
| … | … | @@ -211,7 +212,7 @@ void MultiDeleteUTest::test_add_delete(void) |
| 211 | 212 | TS_ASSERT(as->get_size() >= min_size); |
| 212 | 213 | TS_ASSERT(as->get_size() <= max_size); |
| 213 | 214 | |
| 214 | store->erase(); | |
| 215 | ::kill_data(store.get(), _test_asp.get()); | |
| 215 | 216 | store->close(); |
| 216 | 217 | store = nullptr; |
| 217 | 218 |
| … | … | @@ -104,8 +104,8 @@ void QueryPersistUTest::kill_data(void) |
| 104 | 104 | astore->open(); |
| 105 | 105 | TS_ASSERT(astore->connected()) |
| 106 | 106 | |
| 107 | // Trash the contents of the database. | |
| 108 | astore->kill_data(); | |
| 107 | // Selectively clear test data (preserves CogServerNode) | |
| 108 | ::kill_data(astore, _test_asp.get()); | |
| 109 | 109 | astore->barrier(); |
| 110 | 110 | astore->close(); |
| 111 | 111 |
| … | … | @@ -260,7 +260,7 @@ void ValueSaveUTest::test_save_restore(bool fkey) |
| 260 | 260 | |
| 261 | 261 | check_one(pvl2, fkey); |
| 262 | 262 | |
| 263 | store->erase(); | |
| 263 | ::kill_data(store.get(), _test_asp.get()); | |
| 264 | 264 | as = nullptr; |
| 265 | 265 | |
| 266 | 266 | logger().info("END TEST: %s", __FUNCTION__); |
| … | … | @@ -282,7 +282,7 @@ void ValueSaveUTest::test_load_by_type() |
| 282 | 282 | TS_ASSERT(store->connected()) |
| 283 | 283 | |
| 284 | 284 | // Clear out left-over junk, just in case. |
| 285 | store->erase(); | |
| 285 | ::kill_data(store.get(), _test_asp.get()); | |
| 286 | 286 | |
| 287 | 287 | Handle key = as->add_node(PREDICATE_NODE, "some pred key"); |
| 288 | 288 | Handle af = as->add_node(CONCEPT_NODE, "float node"); |