| … | … | @@ -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/rocks/RocksStorage.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(ROCKS_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(ROCKS_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(ROCKS_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(ROCKS_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 | } |
| … | … | @@ -117,8 +117,8 @@ void BasicDeleteUTest::test_duplicates(void) |
| 117 | 117 | store->store_atom(li); |
| 118 | 118 | store->barrier(); |
| 119 | 119 | |
| 120 | // Verify the atomspace size | |
| 121 | TS_ASSERT_EQUALS(as->get_size(), 4); | |
| 120 | // Verify the atomspace size: 2 concepts + 1 link + 1 storage node + 1 *-open-* | |
| 121 | TS_ASSERT_EQUALS(as->get_size(), 5); | |
| 122 | 122 | |
| 123 | 123 | // Remove the link. Since the link has duplicate atoms |
| 124 | 124 | // in it, this can cause trouble, depending on how the |
| … | … | @@ -30,6 +30,7 @@ |
| 30 | 30 | #include <opencog/atoms/base/Link.h> |
| 31 | 31 | #include <opencog/atoms/base/Node.h> |
| 32 | 32 | #include <opencog/atoms/value/FloatValue.h> |
| 33 | #include <opencog/atoms/value/VoidValue.h> | |
| 33 | 34 | #include <opencog/atomspace/AtomSpace.h> |
| 34 | 35 | #include <opencog/persist/rocks-types/atom_types.h> |
| 35 | 36 | #include <opencog/persist/rocks/RocksStorage.h> |
| … | … | @@ -41,7 +42,7 @@ using namespace opencog; |
| 41 | 42 | class LargeFlatUTest : public CxxTest::TestSuite |
| 42 | 43 | { |
| 43 | 44 | private: |
| 44 | AtomSpace *_as; | |
| 45 | AtomSpacePtr _as; | |
| 45 | 46 | |
| 46 | 47 | // 75000 * 7 == half-a-million atoms |
| 47 | 48 | // 19000 * 7 == 133K atoms |
| … | … | @@ -104,12 +105,12 @@ LargeFlatUTest::~LargeFlatUTest() |
| 104 | 105 | */ |
| 105 | 106 | void LargeFlatUTest::setUp(void) |
| 106 | 107 | { |
| 107 | _as = new AtomSpace(); | |
| 108 | _as = createAtomSpace(); | |
| 108 | 109 | } |
| 109 | 110 | |
| 110 | 111 | void LargeFlatUTest::tearDown(void) |
| 111 | 112 | { |
| 112 | delete _as; | |
| 113 | _as = nullptr; | |
| 113 | 114 | kill_data(); |
| 114 | 115 | } |
| 115 | 116 | |
| … | … | @@ -342,16 +343,16 @@ int LargeFlatUTest::filler_up(AtomSpace *space) |
| 342 | 343 | while (idx < (NCOPIES-20)) |
| 343 | 344 | { |
| 344 | 345 | std::string lbl = std::to_string(idx); |
| 345 | add_to_space(idx++, _as, "AA-aa-wow " + lbl); | |
| 346 | add_to_space(idx++, _as, "BB-bb-wow " + lbl); | |
| 347 | add_to_space(idx++, _as, "CC-cc-wow " + lbl); | |
| 348 | add_to_space(idx++, _as, "DD-dd-wow " + lbl); | |
| 349 | add_to_space(idx++, _as, "EE-ee-wow " + lbl); | |
| 346 | add_to_space(idx++, _as.get(), "AA-aa-wow " + lbl); | |
| 347 | add_to_space(idx++, _as.get(), "BB-bb-wow " + lbl); | |
| 348 | add_to_space(idx++, _as.get(), "CC-cc-wow " + lbl); | |
| 349 | add_to_space(idx++, _as.get(), "DD-dd-wow " + lbl); | |
| 350 | add_to_space(idx++, _as.get(), "EE-ee-wow " + lbl); | |
| 350 | 351 | |
| 351 | 352 | /* Make sure UTF-8 works fine. */ |
| 352 | add_to_space(idx++, _as, "Попытка выбраться вызвала слабый стон " + lbl); | |
| 353 | add_to_space(idx++, _as, "はにがうりだそうであってるのかはち " + lbl); | |
| 354 | add_to_space(idx++, _as, "係拉丁字母" + lbl); | |
| 353 | add_to_space(idx++, _as.get(), "Попытка выбраться вызвала слабый стон " + lbl); | |
| 354 | add_to_space(idx++, _as.get(), "はにがうりだそうであってるのかはち " + lbl); | |
| 355 | add_to_space(idx++, _as.get(), "係拉丁字母" + lbl); | |
| 355 | 356 | } |
| 356 | 357 | return idx; |
| 357 | 358 | } |
| … | … | @@ -364,16 +365,16 @@ void LargeFlatUTest::test_atomspace(void) |
| 364 | 365 | |
| 365 | 366 | Handle hsn = _as->add_node(ROCKS_STORAGE_NODE, "rocks:///tmp/cog-rocks-large-flat-utest"); |
| 366 | 367 | StorageNodePtr store = StorageNodeCast(hsn); |
| 367 | store->open(); | |
| 368 | store->setValue(_as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 368 | 369 | TS_ASSERT(store->connected()) |
| 369 | 370 | |
| 370 | 371 | /* Create a large number of atoms */ |
| 371 | int idx = filler_up(_as); | |
| 372 | int idx = filler_up(_as.get()); | |
| 372 | 373 | |
| 373 | 374 | /* Verify that the atoms were added */ |
| 374 | 375 | int i; |
| 375 | 376 | for (i=0; i<idx; i++) |
| 376 | check_space(i, _as, "verify-add"); | |
| 377 | check_space(i, _as.get(), "verify-add"); | |
| 377 | 378 | |
| 378 | 379 | /* Push all atoms out to the SQL DB */ |
| 379 | 380 | store->store_atomspace(); |
| … | … | @@ -389,14 +390,14 @@ void LargeFlatUTest::test_atomspace(void) |
| 389 | 390 | /* The clear above nuked the storage, so restart */ |
| 390 | 391 | hsn = _as->add_node(ROCKS_STORAGE_NODE, "rocks:///tmp/cog-rocks-large-flat-utest"); |
| 391 | 392 | store = StorageNodeCast(hsn); |
| 392 | store->open(); | |
| 393 | store->setValue(_as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 393 | 394 | TS_ASSERT(store->connected()) |
| 394 | 395 | |
| 395 | 396 | /* Verify that the atoms can still be fetched from storage. */ |
| 396 | 397 | for (i=0; i<idx; i++) { |
| 397 | 398 | fetch_space(i, store); |
| 398 | 399 | store->barrier(); |
| 399 | check_space(i, _as, "verify-fetch"); | |
| 400 | check_space(i, _as.get(), "verify-fetch"); | |
| 400 | 401 | } |
| 401 | 402 | |
| 402 | 403 | /* Do it again, for good luck. */ |
| … | … | @@ -406,14 +407,14 @@ void LargeFlatUTest::test_atomspace(void) |
| 406 | 407 | /* The clear above nuked the storage, so restart */ |
| 407 | 408 | hsn = _as->add_node(ROCKS_STORAGE_NODE, "rocks:///tmp/cog-rocks-large-flat-utest"); |
| 408 | 409 | store = StorageNodeCast(hsn); |
| 409 | store->open(); | |
| 410 | store->setValue(_as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 410 | 411 | TS_ASSERT(store->connected()) |
| 411 | 412 | |
| 412 | 413 | /* Verify that the atoms can still be fetched from storage. */ |
| 413 | 414 | for (i=0; i<idx; i++) { |
| 414 | 415 | fetch_space(i, store); |
| 415 | 416 | store->barrier(); |
| 416 | check_space(i, _as, "ver-again"); | |
| 417 | check_space(i, _as.get(), "ver-again"); | |
| 417 | 418 | } |
| 418 | 419 | |
| 419 | 420 | /* Kill data for good */ |
| … | … | @@ -422,7 +423,7 @@ void LargeFlatUTest::test_atomspace(void) |
| 422 | 423 | |
| 423 | 424 | /* Verify that the atoms are no longer being found. */ |
| 424 | 425 | for (i=0; i<idx; i++) |
| 425 | check_empty(i, _as); | |
| 426 | check_empty(i, _as.get()); | |
| 426 | 427 | |
| 427 | 428 | logger().debug("END TEST: %s", __FUNCTION__); |
| 428 | 429 | } |
| … | … | @@ -33,6 +33,7 @@ |
| 33 | 33 | #include <opencog/atoms/base/Node.h> |
| 34 | 34 | #include <opencog/atomspace/AtomSpace.h> |
| 35 | 35 | #include <opencog/atoms/value/FloatValue.h> |
| 36 | #include <opencog/atoms/value/VoidValue.h> | |
| 36 | 37 | #include <opencog/persist/rocks-types/atom_types.h> |
| 37 | 38 | #include <opencog/persist/rocks/RocksStorage.h> |
| 38 | 39 | |
| … | … | @@ -43,7 +44,7 @@ using namespace opencog; |
| 43 | 44 | class LargeZipfUTest : public CxxTest::TestSuite |
| 44 | 45 | { |
| 45 | 46 | private: |
| 46 | AtomSpace *_as; | |
| 47 | AtomSpacePtr _as; | |
| 47 | 48 | |
| 48 | 49 | #define NWORDS 35000 |
| 49 | 50 | Handle hword[NWORDS]; |
| … | … | @@ -92,12 +93,12 @@ LargeZipfUTest::~LargeZipfUTest() |
| 92 | 93 | */ |
| 93 | 94 | void LargeZipfUTest::setUp(void) |
| 94 | 95 | { |
| 95 | _as = new AtomSpace(); | |
| 96 | _as = createAtomSpace(); | |
| 96 | 97 | } |
| 97 | 98 | |
| 98 | 99 | void LargeZipfUTest::tearDown(void) |
| 99 | 100 | { |
| 100 | delete _as; | |
| 101 | _as = nullptr; | |
| 101 | 102 | kill_data(); |
| 102 | 103 | } |
| 103 | 104 | |
| … | … | @@ -289,14 +290,14 @@ void LargeZipfUTest::test_atomspace(void) |
| 289 | 290 | |
| 290 | 291 | Handle hsn = _as->add_node(ROCKS_STORAGE_NODE, "rocks:///tmp/cog-rocks-large-zipf-utest"); |
| 291 | 292 | StorageNodePtr store = StorageNodeCast(hsn); |
| 292 | store->open(); | |
| 293 | store->setValue(_as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 293 | 294 | TS_ASSERT(store->connected()) |
| 294 | 295 | |
| 295 | 296 | /* Create a large number of atoms */ |
| 296 | filler_up(_as); | |
| 297 | filler_up(_as.get()); | |
| 297 | 298 | |
| 298 | 299 | /* Verify that the atoms were added */ |
| 299 | check_space(_as, "verify-add"); | |
| 300 | check_space(_as.get(), "verify-add"); | |
| 300 | 301 | |
| 301 | 302 | /* Push all atoms out to the SQL DB */ |
| 302 | 303 | store->store_atomspace(); |
| … | … | @@ -312,13 +313,13 @@ void LargeZipfUTest::test_atomspace(void) |
| 312 | 313 | /* The clear above nuked the storage, so restart */ |
| 313 | 314 | hsn = _as->add_node(ROCKS_STORAGE_NODE, "rocks:///tmp/cog-rocks-large-zipf-utest"); |
| 314 | 315 | store = StorageNodeCast(hsn); |
| 315 | store->open(); | |
| 316 | store->setValue(_as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 316 | 317 | TS_ASSERT(store->connected()) |
| 317 | 318 | |
| 318 | 319 | /* Verify that the atoms can still be fetched from storage. */ |
| 319 | fetch_space(_as, store); | |
| 320 | fetch_space(_as.get(), store); | |
| 320 | 321 | store->barrier(); |
| 321 | check_space(_as, "verify-fetch"); | |
| 322 | check_space(_as.get(), "verify-fetch"); | |
| 322 | 323 | |
| 323 | 324 | /* Do it again, for good luck. */ |
| 324 | 325 | _as->clear(); |
| … | … | @@ -327,20 +328,20 @@ void LargeZipfUTest::test_atomspace(void) |
| 327 | 328 | /* The clear above nuked the storage, so restart */ |
| 328 | 329 | hsn = _as->add_node(ROCKS_STORAGE_NODE, "rocks:///tmp/cog-rocks-large-zipf-utest"); |
| 329 | 330 | store = StorageNodeCast(hsn); |
| 330 | store->open(); | |
| 331 | store->setValue(_as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 331 | 332 | TS_ASSERT(store->connected()) |
| 332 | 333 | |
| 333 | 334 | /* Verify that the atoms can still be fetched from storage. */ |
| 334 | fetch_space(_as, store); | |
| 335 | fetch_space(_as.get(), store); | |
| 335 | 336 | store->barrier(); |
| 336 | check_space(_as, "ver-again"); | |
| 337 | check_space(_as.get(), "ver-again"); | |
| 337 | 338 | |
| 338 | 339 | /* Kill data for good */ |
| 339 | 340 | _as->clear(); |
| 340 | 341 | TSM_ASSERT("Non-empty atomspace", 0 == _as->get_size()); |
| 341 | 342 | |
| 342 | 343 | /* Verify that the atoms are no longer being found. */ |
| 343 | check_empty(_as); | |
| 344 | check_empty(_as.get()); | |
| 344 | 345 | |
| 345 | 346 | logger().debug("END TEST: %s", __FUNCTION__); |
| 346 | 347 | } |
| … | … | @@ -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 | |
| 39 | 40 | #include <opencog/persist/api/StorageNode.h> |
| … | … | @@ -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 | |
| … | … | @@ -150,7 +151,7 @@ void MultiDeleteUTest::test_add_delete(void) |
| 150 | 151 | Handle hsn = as->add_node(ROCKS_STORAGE_NODE, std::string(uri)); |
| 151 | 152 | store = StorageNodeCast(hsn); |
| 152 | 153 | |
| 153 | store->open(); | |
| 154 | store->setValue(as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 154 | 155 | TS_ASSERT(store->connected()) |
| 155 | 156 | |
| 156 | 157 | // Clear out left-over junk, just in case. |
| … | … | @@ -170,17 +171,17 @@ void MultiDeleteUTest::test_add_delete(void) |
| 170 | 171 | printf("Post-update AtomSpace size=%lu\n", as->get_size()); |
| 171 | 172 | // printf("AtomSpace contents =\n%s\n", as->to_string().c_str()); |
| 172 | 173 | |
| 173 | // Verify the local AtomSpace size. Should be 34: | |
| 174 | // The StorageNode itself, the (Concept "aaaa") and | |
| 174 | // Verify the local AtomSpace size. Should be 35: | |
| 175 | // The StorageNode itself, the (Concept "aaaa"), *-open-* predicate, and | |
| 175 | 176 | // 16 Concept and Lists from thread-id modulo 16 |
| 176 | 177 | // Note: *-IsKeyFlag-* is NOT added by store_atom, only by load operations |
| 177 | TS_ASSERT_EQUALS(as->get_size(), 2 + 2*(n_threads+6)); | |
| 178 | TS_ASSERT_EQUALS(as->get_size(), 3 + 2*(n_threads+6)); | |
| 178 | 179 | |
| 179 | 180 | // Verify the DB contents: pull everything from the DB, |
| 180 | 181 | // back to here. Do this "independently", by closing and |
| 181 | 182 | // reopening; this forces the Storagenode through assorted |
| 182 | 183 | // flush and close code, potentially exposing bugs. |
| 183 | store->close(); | |
| 184 | store->setValue(as->add_node(PREDICATE_NODE, "*-close-*"), createVoidValue()); | |
| 184 | 185 | |
| 185 | 186 | HandleSeq hs; |
| 186 | 187 | as->get_handles_by_type(hs, CONCEPT_NODE); |
| … | … | @@ -188,21 +189,22 @@ void MultiDeleteUTest::test_add_delete(void) |
| 188 | 189 | as->extract_atom(h, true); |
| 189 | 190 | hs.clear(); |
| 190 | 191 | printf("AtomSpace contents =\n%s\n", as->to_string().c_str()); |
| 191 | TS_ASSERT_EQUALS(as->get_size(), 1); | |
| 192 | // Storage node + *-open-* + *-close-* | |
| 193 | TS_ASSERT_EQUALS(as->get_size(), 3); | |
| 192 | 194 | |
| 193 | store->open(); | |
| 195 | store->setValue(as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 194 | 196 | TS_ASSERT(store->connected()) |
| 195 | 197 | |
| 196 | 198 | store->load_atomspace(); |
| 197 | 199 | printf("Final AtomSpace size=%lu\n", as->get_size()); |
| 198 | 200 | |
| 199 | // Size should be 20: the 18 from before plus | |
| 200 | // (Predicate "*-TruthValueKey-*") and (Predicate "*-IsKeyFlag-*") | |
| 201 | // Size should be 21: the 18 from before plus | |
| 202 | // (Predicate "*-TruthValueKey-*"), (Predicate "*-IsKeyFlag-*"), and *-open-* | |
| 201 | 203 | // Well, actually, there is no guarantee that the removes will |
| 202 | 204 | // happen after the stores. Best we can do is check lower and |
| 203 | // upper bounds of 20 and 36: | |
| 204 | size_t min_size = 4 + n_threads + 6; | |
| 205 | size_t max_size = 4 + 2*(n_threads + 6); | |
| 205 | // upper bounds of 21 and 37: | |
| 206 | size_t min_size = 5 + n_threads + 6; | |
| 207 | size_t max_size = 5 + 2*(n_threads + 6); | |
| 206 | 208 | if (as->get_size() < min_size or max_size < as->get_size()) |
| 207 | 209 | printf("Error: Bad size! AtomSpace contents =\n%s\n", |
| 208 | 210 | as->to_string().c_str()); |
| … | … | @@ -211,7 +213,7 @@ void MultiDeleteUTest::test_add_delete(void) |
| 211 | 213 | TS_ASSERT(as->get_size() <= max_size); |
| 212 | 214 | |
| 213 | 215 | store->erase(); |
| 214 | store->close(); | |
| 216 | store->setValue(as->add_node(PREDICATE_NODE, "*-close-*"), createVoidValue()); | |
| 215 | 217 | store = nullptr; |
| 216 | 218 | |
| 217 | 219 | logger().debug("END TEST: %s", __FUNCTION__); |
| … | … | @@ -38,6 +38,7 @@ |
| 38 | 38 | #include <opencog/persist/rocks/RocksStorage.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(ROCKS_STORAGE_NODE, "rocks:///tmp/cog-rocks-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->setValue(_as->add_node(PREDICATE_NODE, "*-close-*"), createVoidValue()); | |
| 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(ROCKS_STORAGE_NODE, "rocks:///tmp/cog-rocks-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(ROCKS_STORAGE_NODE, "rocks:///tmp/cog-rocks-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 | } |
| … | … | @@ -33,6 +33,7 @@ |
| 33 | 33 | #include <opencog/atomspace/AtomSpace.h> |
| 34 | 34 | #include <opencog/atoms/value/FloatValue.h> |
| 35 | 35 | #include <opencog/atoms/value/LinkValue.h> |
| 36 | #include <opencog/atoms/value/VoidValue.h> | |
| 36 | 37 | #include <opencog/persist/rocks-types/atom_types.h> |
| 37 | 38 | #include <opencog/persist/rocks/RocksStorage.h> |
| 38 | 39 | |
| … | … | @@ -126,7 +127,7 @@ void QueryPersistUTest::setup_data(void) |
| 126 | 127 | |
| 127 | 128 | Handle hsn = _as->add_node(ROCKS_STORAGE_NODE, std::string(uri)); |
| 128 | 129 | StorageNodePtr store = StorageNodeCast(hsn); |
| 129 | store->open(); | |
| 130 | store->setValue(_as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 130 | 131 | TS_ASSERT(store->connected()) |
| 131 | 132 | |
| 132 | 133 | /* Populate the Storage with stuff that we will later query. */ |
| … | … | @@ -173,7 +174,7 @@ void QueryPersistUTest::test_meet(void) |
| 173 | 174 | _as = createAtomSpace(); |
| 174 | 175 | Handle hsn = _as->add_node(ROCKS_STORAGE_NODE, std::string(uri)); |
| 175 | 176 | StorageNodePtr store = StorageNodeCast(hsn); |
| 176 | store->open(); | |
| 177 | store->setValue(_as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 177 | 178 | TS_ASSERT(store->connected()) |
| 178 | 179 | |
| 179 | 180 | // Create a query to find all things that have wheels. |
| … | … | @@ -234,7 +235,7 @@ void QueryPersistUTest::test_join(void) |
| 234 | 235 | _as = createAtomSpace(); |
| 235 | 236 | Handle hsn = _as->add_node(ROCKS_STORAGE_NODE, std::string(uri)); |
| 236 | 237 | StorageNodePtr store = StorageNodeCast(hsn); |
| 237 | store->open(); | |
| 238 | store->setValue(_as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 238 | 239 | TS_ASSERT(store->connected()) |
| 239 | 240 | |
| 240 | 241 | // Create a join to find all vehicles. |
| … | … | @@ -32,6 +32,7 @@ |
| 32 | 32 | |
| 33 | 33 | #include <opencog/atoms/base/Atom.h> |
| 34 | 34 | #include <opencog/atoms/value/FloatValue.h> |
| 35 | #include <opencog/atoms/value/VoidValue.h> | |
| 35 | 36 | #include <opencog/atomspace/AtomSpace.h> |
| 36 | 37 | #include <opencog/guile/SchemeEval.h> |
| 37 | 38 | |
| … | … | @@ -242,7 +243,7 @@ void ThreadCountUTest::harness(int n_loops, const char* cmd) |
| 242 | 243 | hsn = as->add_node(ROCKS_STORAGE_NODE, std::string(uri)); |
| 243 | 244 | store = StorageNodeCast(hsn); |
| 244 | 245 | |
| 245 | store->open(); | |
| 246 | store->setValue(as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 246 | 247 | TS_ASSERT(store->connected()) |
| 247 | 248 | |
| 248 | 249 | store->load_atomspace(); |
| … | … | @@ -252,7 +253,7 @@ void ThreadCountUTest::harness(int n_loops, const char* cmd) |
| 252 | 253 | check(n_threads * n_loops, relo.c_str()); |
| 253 | 254 | |
| 254 | 255 | store->erase(); |
| 255 | store->close(); | |
| 256 | store->setValue(as->add_node(PREDICATE_NODE, "*-close-*"), createVoidValue()); | |
| 256 | 257 | store = nullptr; |
| 257 | 258 | } |
| 258 | 259 |