| … | … | @@ -33,6 +33,7 @@ |
| 33 | 33 | #include <opencog/atoms/atom_types/atom_types.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/atomspace/AtomSpace.h> |
| 37 | 38 | |
| 38 | 39 | #include <opencog/persist/api/StorageNode.h> |
| … | … | @@ -97,12 +98,12 @@ void BasicDeleteUTest::test_duplicates(void) |
| 97 | 98 | { |
| 98 | 99 | logger().debug("BEGIN TEST: %s", __FUNCTION__); |
| 99 | 100 | |
| 100 | AtomSpace* as = new AtomSpace(); | |
| 101 | AtomSpacePtr as = createAtomSpace(); | |
| 101 | 102 | |
| 102 | 103 | Handle hsn = as->add_node(ROCKS_STORAGE_NODE, std::string(uri)); |
| 103 | 104 | StorageNodePtr store = StorageNodeCast(hsn); |
| 104 | 105 | |
| 105 | store->open(); | |
| 106 | store->setValue(as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 106 | 107 | TS_ASSERT(store->connected()) |
| 107 | 108 | |
| 108 | 109 | // Clear out left-over junk, just in case. |
| … | … | @@ -122,19 +123,21 @@ void BasicDeleteUTest::test_duplicates(void) |
| 122 | 123 | // Remove the link. Since the link has duplicate atoms |
| 123 | 124 | // in it, this can cause trouble, depending on how the |
| 124 | 125 | // incoming set is managed. |
| 125 | store->remove_atom(as, li); | |
| 126 | TS_ASSERT_EQUALS(as->get_size(), 4); | |
| 127 | store->close(); | |
| 126 | store->remove_atom(as.get(), li); | |
| 127 | // +1 for *-open-* | |
| 128 | TS_ASSERT_EQUALS(as->get_size(), 5); | |
| 129 | store->setValue(as->add_node(PREDICATE_NODE, "*-close-*"), createVoidValue()); | |
| 128 | 130 | as->extract_atom(li); |
| 129 | TS_ASSERT_EQUALS(as->get_size(), 3); | |
| 130 | store->open(); | |
| 131 | // +1 for *-open-*, +1 for *-close-* | |
| 132 | TS_ASSERT_EQUALS(as->get_size(), 5); | |
| 133 | store->setValue(as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 131 | 134 | store->load_atomspace(); |
| 132 | // +1 for *-IsKeyFlag-* | |
| 133 | TS_ASSERT_EQUALS(as->get_size(), 4); | |
| 135 | // +1 for *-IsKeyFlag-*, +1 for *-open-*, +1 for *-close-* | |
| 136 | TS_ASSERT_EQUALS(as->get_size(), 6); | |
| 134 | 137 | |
| 135 | 138 | store->erase(); |
| 136 | store->close(); | |
| 137 | delete as; | |
| 139 | store->setValue(as->add_node(PREDICATE_NODE, "*-close-*"), createVoidValue()); | |
| 140 | as = nullptr; | |
| 138 | 141 | |
| 139 | 142 | logger().debug("END TEST: %s", __FUNCTION__); |
| 140 | 143 | } |
| … | … | @@ -145,12 +148,12 @@ void BasicDeleteUTest::test_recursive(void) |
| 145 | 148 | { |
| 146 | 149 | logger().debug("BEGIN TEST: %s", __FUNCTION__); |
| 147 | 150 | |
| 148 | AtomSpace* as = new AtomSpace(); | |
| 151 | AtomSpacePtr as = createAtomSpace(); | |
| 149 | 152 | |
| 150 | 153 | Handle hsn = as->add_node(ROCKS_STORAGE_NODE, std::string(uri)); |
| 151 | 154 | StorageNodePtr store = StorageNodeCast(hsn); |
| 152 | 155 | |
| 153 | store->open(); | |
| 156 | store->setValue(as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 154 | 157 | TS_ASSERT(store->connected()) |
| 155 | 158 | |
| 156 | 159 | // Clear out left-over junk, just in case. |
| … | … | @@ -171,12 +174,12 @@ void BasicDeleteUTest::test_recursive(void) |
| 171 | 174 | for (const Handle& h : hset) |
| 172 | 175 | printf("Atomspace contains: %s\n", h->to_short_string().c_str()); |
| 173 | 176 | |
| 174 | // Verify the atomspace size | |
| 175 | TS_ASSERT_EQUALS(as->get_size(), 5); | |
| 177 | // Verify the atomspace size (+1 for *-open-*) | |
| 178 | TS_ASSERT_EQUALS(as->get_size(), 6); | |
| 176 | 179 | |
| 177 | 180 | // Remove (Concept "a"). Since this appears twice, recursion |
| 178 | 181 | // will hit it twice, in strange ways, and maybe crash. |
| 179 | store->remove_atom(as, ha, true); | |
| 182 | store->remove_atom(as.get(), ha, true); | |
| 180 | 183 | |
| 181 | 184 | printf("Post-delete atomspace size=%lu\n", as->get_size()); |
| 182 | 185 | hset.clear(); |
| … | … | @@ -184,12 +187,12 @@ void BasicDeleteUTest::test_recursive(void) |
| 184 | 187 | for (const Handle& h : hset) |
| 185 | 188 | printf("Post delete: %s\n", h->to_short_string().c_str()); |
| 186 | 189 | |
| 187 | store->close(); | |
| 190 | store->setValue(as->add_node(PREDICATE_NODE, "*-close-*"), createVoidValue()); | |
| 188 | 191 | as->extract_atom(ha, true); |
| 189 | store->open(); | |
| 192 | store->setValue(as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 190 | 193 | store->load_atomspace(); |
| 191 | // +1 for *-IsKeyFlag-* | |
| 192 | TS_ASSERT_EQUALS(as->get_size(), 3); | |
| 194 | // +1 for *-IsKeyFlag-*, +1 for *-open-*, +1 for *-close-* | |
| 195 | TS_ASSERT_EQUALS(as->get_size(), 5); | |
| 193 | 196 | |
| 194 | 197 | // -------------------------------------- |
| 195 | 198 | // Do it again, but with a different order. |
| … | … | @@ -199,19 +202,19 @@ void BasicDeleteUTest::test_recursive(void) |
| 199 | 202 | |
| 200 | 203 | store->store_atom(lj); |
| 201 | 204 | store->barrier(); |
| 202 | store->close(); | |
| 203 | store->open(); | |
| 205 | store->setValue(as->add_node(PREDICATE_NODE, "*-close-*"), createVoidValue()); | |
| 206 | store->setValue(as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 204 | 207 | store->load_atomspace(); |
| 205 | // +1 for *-IsKeyFlag-* | |
| 206 | TS_ASSERT_EQUALS(as->get_size(), 6); | |
| 208 | // +1 for *-IsKeyFlag-*, +1 for *-open-*, +1 for *-close-* | |
| 209 | TS_ASSERT_EQUALS(as->get_size(), 8); | |
| 207 | 210 | |
| 208 | store->remove_atom(as, ha, true); | |
| 209 | store->close(); | |
| 211 | store->remove_atom(as.get(), ha, true); | |
| 212 | store->setValue(as->add_node(PREDICATE_NODE, "*-close-*"), createVoidValue()); | |
| 210 | 213 | as->extract_atom(ha, true); |
| 211 | store->open(); | |
| 214 | store->setValue(as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 212 | 215 | store->load_atomspace(); |
| 213 | // +1 for *-IsKeyFlag-* | |
| 214 | TS_ASSERT_EQUALS(as->get_size(), 3); | |
| 216 | // +1 for *-IsKeyFlag-*, +1 for *-open-*, +1 for *-close-* | |
| 217 | TS_ASSERT_EQUALS(as->get_size(), 5); | |
| 215 | 218 | |
| 216 | 219 | // -------------------------------------- |
| 217 | 220 | // Do it again, but with a complex order. |
| … | … | @@ -221,19 +224,19 @@ void BasicDeleteUTest::test_recursive(void) |
| 221 | 224 | |
| 222 | 225 | store->store_atom(lj); |
| 223 | 226 | store->barrier(); |
| 224 | store->close(); | |
| 225 | store->open(); | |
| 227 | store->setValue(as->add_node(PREDICATE_NODE, "*-close-*"), createVoidValue()); | |
| 228 | store->setValue(as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 226 | 229 | store->load_atomspace(); |
| 227 | // +1 for *-IsKeyFlag-* | |
| 228 | TS_ASSERT_EQUALS(as->get_size(), 6); | |
| 230 | // +1 for *-IsKeyFlag-*, +1 for *-open-*, +1 for *-close-* | |
| 231 | TS_ASSERT_EQUALS(as->get_size(), 8); | |
| 229 | 232 | |
| 230 | store->remove_atom(as, ha, true); | |
| 231 | store->close(); | |
| 233 | store->remove_atom(as.get(), ha, true); | |
| 234 | store->setValue(as->add_node(PREDICATE_NODE, "*-close-*"), createVoidValue()); | |
| 232 | 235 | as->extract_atom(ha, true); |
| 233 | store->open(); | |
| 236 | store->setValue(as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 234 | 237 | store->load_atomspace(); |
| 235 | // +1 for *-IsKeyFlag-* | |
| 236 | TS_ASSERT_EQUALS(as->get_size(), 3); | |
| 238 | // +1 for *-IsKeyFlag-*, +1 for *-open-*, +1 for *-close-* | |
| 239 | TS_ASSERT_EQUALS(as->get_size(), 5); | |
| 237 | 240 | |
| 238 | 241 | // -------------------------------------- |
| 239 | 242 | // Do it again, but more deeply. |
| … | … | @@ -244,24 +247,24 @@ void BasicDeleteUTest::test_recursive(void) |
| 244 | 247 | |
| 245 | 248 | store->store_atom(lk); |
| 246 | 249 | store->barrier(); |
| 247 | store->close(); | |
| 248 | store->open(); | |
| 250 | store->setValue(as->add_node(PREDICATE_NODE, "*-close-*"), createVoidValue()); | |
| 251 | store->setValue(as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 249 | 252 | store->load_atomspace(); |
| 250 | // +1 for *-IsKeyFlag-* | |
| 251 | TS_ASSERT_EQUALS(as->get_size(), 7); | |
| 253 | // +1 for *-IsKeyFlag-*, +1 for *-open-*, +1 for *-close-* | |
| 254 | TS_ASSERT_EQUALS(as->get_size(), 9); | |
| 252 | 255 | |
| 253 | store->remove_atom(as, ha, true); | |
| 254 | store->close(); | |
| 256 | store->remove_atom(as.get(), ha, true); | |
| 257 | store->setValue(as->add_node(PREDICATE_NODE, "*-close-*"), createVoidValue()); | |
| 255 | 258 | as->extract_atom(ha, true); |
| 256 | store->open(); | |
| 259 | store->setValue(as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 257 | 260 | store->load_atomspace(); |
| 258 | // +1 for *-IsKeyFlag-* | |
| 259 | TS_ASSERT_EQUALS(as->get_size(), 3); | |
| 261 | // +1 for *-IsKeyFlag-*, +1 for *-open-*, +1 for *-close-* | |
| 262 | TS_ASSERT_EQUALS(as->get_size(), 5); | |
| 260 | 263 | |
| 261 | 264 | // -------------------------------------- |
| 262 | 265 | store->erase(); |
| 263 | store->close(); | |
| 264 | delete as; | |
| 266 | store->setValue(as->add_node(PREDICATE_NODE, "*-close-*"), createVoidValue()); | |
| 267 | as = nullptr; | |
| 265 | 268 | |
| 266 | 269 | logger().debug("END TEST: %s", __FUNCTION__); |
| 267 | 270 | } |
| … | … | @@ -273,12 +276,12 @@ void BasicDeleteUTest::test_key_deletion(void) |
| 273 | 276 | logger().debug("BEGIN TEST: %s", __FUNCTION__); |
| 274 | 277 | |
| 275 | 278 | // Create an Atom with some keys on it. |
| 276 | AtomSpace* as = new AtomSpace(); | |
| 279 | AtomSpacePtr as = createAtomSpace(); | |
| 277 | 280 | |
| 278 | 281 | Handle hsn = as->add_node(ROCKS_STORAGE_NODE, std::string(uri)); |
| 279 | 282 | StorageNodePtr store = StorageNodeCast(hsn); |
| 280 | 283 | |
| 281 | store->open(); | |
| 284 | store->setValue(as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 282 | 285 | TS_ASSERT(store->connected()) |
| 283 | 286 | |
| 284 | 287 | // Clear out left-over junk, just in case. |
| … | … | @@ -297,8 +300,8 @@ void BasicDeleteUTest::test_key_deletion(void) |
| 297 | 300 | store->store_atom(ha); |
| 298 | 301 | store->barrier(); |
| 299 | 302 | |
| 300 | // Verify the atomspace size (+1 for *-IsKeyFlag-*) | |
| 301 | TS_ASSERT_EQUALS(as->get_size(), 6); | |
| 303 | // Verify the atomspace size (+1 for *-IsKeyFlag-*, +1 for *-open-*) | |
| 304 | TS_ASSERT_EQUALS(as->get_size(), 7); | |
| 302 | 305 | |
| 303 | 306 | // Verify that there are three keys |
| 304 | 307 | HandleSet hs = ha->getKeys(); |
| … | … | @@ -307,17 +310,17 @@ void BasicDeleteUTest::test_key_deletion(void) |
| 307 | 310 | TS_ASSERT_EQUALS(hs.size(), 3); |
| 308 | 311 | |
| 309 | 312 | // Attempt to remove one of the keys. Should fail. |
| 310 | store->remove_atom(as, kb); | |
| 313 | store->remove_atom(as.get(), kb); | |
| 311 | 314 | as->extract_atom(kb); |
| 312 | // +1 for *-IsKeyFlag-* | |
| 313 | TS_ASSERT_EQUALS(as->get_size(), 6); | |
| 315 | // +1 for *-IsKeyFlag-*, +1 for *-open-* | |
| 316 | TS_ASSERT_EQUALS(as->get_size(), 7); | |
| 314 | 317 | |
| 315 | 318 | // Verify the key was NOT deleted by loading only PredicateNodes. |
| 316 | delete as; | |
| 317 | as = new AtomSpace(); | |
| 319 | as = nullptr; | |
| 320 | as = createAtomSpace(); | |
| 318 | 321 | hsn = as->add_node(ROCKS_STORAGE_NODE, std::string(uri)); |
| 319 | 322 | store = StorageNodeCast(hsn); |
| 320 | store->open(); | |
| 323 | store->setValue(as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 321 | 324 | store->fetch_all_atoms_of_type(PREDICATE_NODE); |
| 322 | 325 | |
| 323 | 326 | // All three keys need to still be here. |
| … | … | @@ -331,24 +334,24 @@ void BasicDeleteUTest::test_key_deletion(void) |
| 331 | 334 | // without the close(). |
| 332 | 335 | |
| 333 | 336 | // We are done. |
| 334 | delete as; | |
| 337 | as = nullptr; | |
| 335 | 338 | |
| 336 | 339 | // ------------------------------------------------------- |
| 337 | 340 | // Start again, with a fresh connection. |
| 338 | 341 | // Verify that in-use keys cannot be deleted. |
| 339 | 342 | |
| 340 | as = new AtomSpace(); | |
| 343 | as = createAtomSpace(); | |
| 341 | 344 | |
| 342 | 345 | hsn = as->add_node(ROCKS_STORAGE_NODE, std::string(uri)); |
| 343 | 346 | store = StorageNodeCast(hsn); |
| 344 | 347 | |
| 345 | store->open(); | |
| 348 | store->setValue(as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 346 | 349 | TS_ASSERT(store->connected()) |
| 347 | 350 | |
| 348 | // We expect 7 atoms (+1 for *-IsKeyFlag-*) | |
| 351 | // We expect 8 atoms (+1 for *-IsKeyFlag-*, +1 for *-open-*) | |
| 349 | 352 | printf("Loading the atomspace ...\n"); |
| 350 | 353 | store->load_atomspace(); |
| 351 | TS_ASSERT_EQUALS(as->get_size(), 7); | |
| 354 | TS_ASSERT_EQUALS(as->get_size(), 8); | |
| 352 | 355 | printf("AtomSpace contents=\n%s\n", as->to_string().c_str()); |
| 353 | 356 | |
| 354 | 357 | // Verify that there are only three keys |
| … | … | @@ -364,8 +367,8 @@ void BasicDeleteUTest::test_key_deletion(void) |
| 364 | 367 | TS_ASSERT(nullptr != as->get_node(PREDICATE_NODE, "key-c")); |
| 365 | 368 | |
| 366 | 369 | store->erase(); |
| 367 | store->close(); | |
| 368 | delete as; | |
| 370 | store->setValue(as->add_node(PREDICATE_NODE, "*-close-*"), createVoidValue()); | |
| 371 | as = nullptr; | |
| 369 | 372 | |
| 370 | 373 | logger().debug("END TEST: %s", __FUNCTION__); |
| 371 | 374 | } |
| … | … | @@ -379,12 +382,12 @@ void BasicDeleteUTest::test_key_corruption(void) |
| 379 | 382 | logger().debug("BEGIN TEST: %s", __FUNCTION__); |
| 380 | 383 | |
| 381 | 384 | // Create an Atom with some keys on it. |
| 382 | AtomSpace* as = new AtomSpace(); | |
| 385 | AtomSpacePtr as = createAtomSpace(); | |
| 383 | 386 | |
| 384 | 387 | Handle hsn = as->add_node(ROCKS_STORAGE_NODE, std::string(uri)); |
| 385 | 388 | StorageNodePtr store = StorageNodeCast(hsn); |
| 386 | 389 | |
| 387 | store->open(); | |
| 390 | store->setValue(as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 388 | 391 | TS_ASSERT(store->connected()) |
| 389 | 392 | |
| 390 | 393 | // Clear out left-over junk, just in case. |
| … | … | @@ -400,14 +403,14 @@ void BasicDeleteUTest::test_key_corruption(void) |
| 400 | 403 | store->store_atom(hb); |
| 401 | 404 | store->barrier(); |
| 402 | 405 | |
| 403 | // Verify the atomspace size (+1 for *-IsKeyFlag-*) | |
| 404 | TS_ASSERT_EQUALS(as->get_size(), 5); | |
| 406 | // Verify the atomspace size (+1 for *-IsKeyFlag-*, +1 for *-open-*) | |
| 407 | TS_ASSERT_EQUALS(as->get_size(), 6); | |
| 405 | 408 | |
| 406 | 409 | // Remove the value |
| 407 | store->remove_atom(as, hx); | |
| 410 | store->remove_atom(as.get(), hx); | |
| 408 | 411 | as->extract_atom(hx); |
| 409 | // +1 for *-IsKeyFlag-* | |
| 410 | TS_ASSERT_EQUALS(as->get_size(), 4); | |
| 412 | // +1 for *-IsKeyFlag-*, +1 for *-open-* | |
| 413 | TS_ASSERT_EQUALS(as->get_size(), 5); | |
| 411 | 414 | |
| 412 | 415 | // FYI, we should call store->close() at this point, but we |
| 413 | 416 | // don't, because ... most users forget to do this too. |
| … | … | @@ -415,21 +418,21 @@ void BasicDeleteUTest::test_key_corruption(void) |
| 415 | 418 | // without the close(). |
| 416 | 419 | |
| 417 | 420 | // We are done. |
| 418 | delete as; | |
| 421 | as = nullptr; | |
| 419 | 422 | |
| 420 | 423 | // ------------------------------------------------------- |
| 421 | 424 | // Start again, with a fresh connection. |
| 422 | 425 | // Verify that the delete key is really deleted. |
| 423 | 426 | |
| 424 | as = new AtomSpace(); | |
| 427 | as = createAtomSpace(); | |
| 425 | 428 | |
| 426 | 429 | hsn = as->add_node(ROCKS_STORAGE_NODE, std::string(uri)); |
| 427 | 430 | store = StorageNodeCast(hsn); |
| 428 | 431 | |
| 429 | store->open(); | |
| 432 | store->setValue(as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 430 | 433 | TS_ASSERT(store->connected()) |
| 431 | 434 | |
| 432 | // We expect 5 atoms: b, x, key-x, *-IsKeyFlag-*, StorageNode | |
| 435 | // We expect 6 atoms: b, x, key-x, *-IsKeyFlag-*, StorageNode, *-open-* | |
| 433 | 436 | // That's because the (Concept "x") sitting in the Value |
| 434 | 437 | // was never actually deleted; thus it is restored. |
| 435 | 438 | printf("Loading the atomspace ...\n"); |
| … | … | @@ -440,9 +443,9 @@ void BasicDeleteUTest::test_key_corruption(void) |
| 440 | 443 | for (const Handle& h: hset) |
| 441 | 444 | printf("Atomspace contains h=%s\n", h->to_short_string().c_str()); |
| 442 | 445 | |
| 443 | // Size is 6 because (Concept "x") cannot be deleted. | |
| 444 | // +1 for *-IsKeyFlag-* | |
| 445 | TS_ASSERT_EQUALS(as->get_size(), 6); | |
| 446 | // Size is 7 because (Concept "x") cannot be deleted. | |
| 447 | // +1 for *-IsKeyFlag-*, +1 for *-open-* | |
| 448 | TS_ASSERT_EQUALS(as->get_size(), 7); | |
| 446 | 449 | |
| 447 | 450 | hb = as->add_node(CONCEPT_NODE, "b"); |
| 448 | 451 | hx = as->add_node(CONCEPT_NODE, "x"); |
| … | … | @@ -455,41 +458,41 @@ void BasicDeleteUTest::test_key_corruption(void) |
| 455 | 458 | store->store_atom(hb); |
| 456 | 459 | store->barrier(); |
| 457 | 460 | |
| 458 | // +1 for *-IsKeyFlag-* | |
| 459 | TS_ASSERT_EQUALS(as->get_size(), 8); | |
| 461 | // +1 for *-IsKeyFlag-*, +1 for *-open-* | |
| 462 | TS_ASSERT_EQUALS(as->get_size(), 9); | |
| 460 | 463 | |
| 461 | 464 | // Remove the value .. again |
| 462 | store->remove_atom(as, hx); | |
| 465 | store->remove_atom(as.get(), hx); | |
| 463 | 466 | as->extract_atom(hx); |
| 464 | // +1 for *-IsKeyFlag-* | |
| 465 | TS_ASSERT_EQUALS(as->get_size(), 7); | |
| 466 | store->close(); | |
| 467 | store->open(); | |
| 468 | store->load_atomspace(); | |
| 469 | // Size is 8 because (Concept "x") cannot be deleted. | |
| 470 | // +1 for *-IsKeyFlag-* | |
| 467 | // +1 for *-IsKeyFlag-*, +1 for *-open-* | |
| 471 | 468 | TS_ASSERT_EQUALS(as->get_size(), 8); |
| 469 | store->setValue(as->add_node(PREDICATE_NODE, "*-close-*"), createVoidValue()); | |
| 470 | store->setValue(as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 471 | store->load_atomspace(); | |
| 472 | // Size is 10 because (Concept "x") cannot be deleted. | |
| 473 | // +1 for *-IsKeyFlag-*, +1 for *-open-*, +1 for *-close-* | |
| 474 | TS_ASSERT_EQUALS(as->get_size(), 10); | |
| 472 | 475 | |
| 473 | 476 | // We are done. |
| 474 | store->close(); | |
| 475 | delete as; | |
| 477 | store->setValue(as->add_node(PREDICATE_NODE, "*-close-*"), createVoidValue()); | |
| 478 | as = nullptr; | |
| 476 | 479 | |
| 477 | 480 | // ------------------------------------------------------- |
| 478 | 481 | // Start again, with a fresh connection. |
| 479 | 482 | // Verify that the delete key is really deleted. |
| 480 | 483 | |
| 481 | as = new AtomSpace(); | |
| 484 | as = createAtomSpace(); | |
| 482 | 485 | |
| 483 | 486 | hsn = as->add_node(ROCKS_STORAGE_NODE, std::string(uri)); |
| 484 | 487 | store = StorageNodeCast(hsn); |
| 485 | 488 | |
| 486 | store->open(); | |
| 489 | store->setValue(as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 487 | 490 | TS_ASSERT(store->connected()) |
| 488 | 491 | |
| 489 | // We expect 8 atoms (+1 for *-IsKeyFlag-*) | |
| 492 | // We expect 9 atoms (+1 for *-IsKeyFlag-*, +1 for *-open-*) | |
| 490 | 493 | printf("Loading the atomspace ...\n"); |
| 491 | 494 | store->load_atomspace(); |
| 492 | TS_ASSERT_EQUALS(as->get_size(), 8); | |
| 495 | TS_ASSERT_EQUALS(as->get_size(), 9); | |
| 493 | 496 | |
| 494 | 497 | // Verify that there are two keys |
| 495 | 498 | hb = as->add_node(CONCEPT_NODE, "b"); |
| … | … | @@ -503,8 +506,8 @@ void BasicDeleteUTest::test_key_corruption(void) |
| 503 | 506 | TS_ASSERT_EQUALS(hs.size(), 2); |
| 504 | 507 | |
| 505 | 508 | store->erase(); |
| 506 | store->close(); | |
| 507 | delete as; | |
| 509 | store->setValue(as->add_node(PREDICATE_NODE, "*-close-*"), createVoidValue()); | |
| 510 | as = nullptr; | |
| 508 | 511 | |
| 509 | 512 | logger().debug("END TEST: %s", __FUNCTION__); |
| 510 | 513 | } |
| … | … | @@ -34,8 +34,10 @@ |
| 34 | 34 | #include <opencog/atoms/base/Node.h> |
| 35 | 35 | #include <opencog/atoms/atom_types/atom_types.h> |
| 36 | 36 | #include <opencog/atoms/value/FloatValue.h> |
| 37 | #include <opencog/atoms/value/VoidValue.h> | |
| 37 | 38 | #include <opencog/atomspace/AtomSpace.h> |
| 38 | 39 | #include <opencog/persist/rocks/RocksStorage.h> |
| 40 | #include <opencog/persist/rocks-types/atom_types.h> | |
| 39 | 41 | |
| 40 | 42 | #include <opencog/util/Logger.h> |
| 41 | 43 | |
| … | … | @@ -169,9 +171,11 @@ static void atomCompare(Handle a, Handle b, const char* where) |
| 169 | 171 | */ |
| 170 | 172 | void BasicSaveUTest::single_atom_save_restore(std::string id) |
| 171 | 173 | { |
| 172 | RocksStorageNodePtr store = createRocksStorageNode(std::string(uri)); | |
| 174 | AtomSpacePtr as = createAtomSpace(); | |
| 175 | Handle hsn = as->add_node(ROCKS_STORAGE_NODE, std::string(uri)); | |
| 176 | RocksStorageNodePtr store = RocksStorageNodeCast(hsn); | |
| 173 | 177 | logger().debug("single_atom_save_restore: create %p", store.get()); |
| 174 | store->open(); | |
| 178 | store->setValue(as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 175 | 179 | logger().debug("single_atom_save_restore: opened"); |
| 176 | 180 | if (!store->connected()) |
| 177 | 181 | { |
| … | … | @@ -234,7 +238,7 @@ void BasicSaveUTest::single_atom_save_restore(std::string id) |
| 234 | 238 | fflush(stdout); |
| 235 | 239 | |
| 236 | 240 | store->kill_data(); |
| 237 | store->close(); | |
| 241 | store->setValue(as->add_node(PREDICATE_NODE, "*-close-*"), createVoidValue()); | |
| 238 | 242 | } |
| 239 | 243 | |
| 240 | 244 | // ============================================================ |
| … | … | @@ -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/rocks/RocksStorage.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 | // ============================================================ |
| … | … | @@ -424,32 +425,33 @@ void DeleteUTest::test_remove(void) |
| 424 | 425 | |
| 425 | 426 | Handle hsn = _as->add_node(ROCKS_STORAGE_NODE, std::string(uri)); |
| 426 | 427 | StorageNodePtr store = StorageNodeCast(hsn); |
| 427 | store->open(); | |
| 428 | store->setValue(_as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 428 | 429 | TS_ASSERT(store->connected()) |
| 429 | 430 | |
| 430 | 431 | int idx = 0; |
| 431 | add_to_space(idx++, _as, "AA-aa-wow "); | |
| 432 | add_to_space(idx++, _as, "BB-bb-wow "); | |
| 433 | add_to_space(idx++, _as, "CC-cc-wow "); | |
| 434 | add_to_space(idx++, _as, "DD-dd-wow "); | |
| 435 | add_to_space(idx++, _as, "EE-ee-wow "); | |
| 432 | add_to_space(idx++, _as.get(), "AA-aa-wow "); | |
| 433 | add_to_space(idx++, _as.get(), "BB-bb-wow "); | |
| 434 | add_to_space(idx++, _as.get(), "CC-cc-wow "); | |
| 435 | add_to_space(idx++, _as.get(), "DD-dd-wow "); | |
| 436 | add_to_space(idx++, _as.get(), "EE-ee-wow "); | |
| 436 | 437 | |
| 437 | 438 | /* Make sure UTF-8 works fine. */ |
| 438 | add_to_space(idx++, _as, "Попытка выбраться вызвала слабый стон "); | |
| 439 | add_to_space(idx++, _as, "はにがうりだそうであってるのかはち "); | |
| 440 | add_to_space(idx++, _as, "係拉丁字母"); | |
| 439 | add_to_space(idx++, _as.get(), "Попытка выбраться вызвала слабый стон "); | |
| 440 | add_to_space(idx++, _as.get(), "はにがうりだそうであってるのかはち "); | |
| 441 | add_to_space(idx++, _as.get(), "係拉丁字母"); | |
| 441 | 442 | |
| 442 | 443 | /* Verify that the atoms were added */ |
| 443 | 444 | int i; |
| 444 | 445 | for (i=0; i<idx; i++) |
| 445 | check_space(i, _as, "verify-add"); | |
| 446 | check_space(i, _as.get(), "verify-add"); | |
| 446 | 447 | |
| 447 | 448 | /* Push all atoms out to storage */ |
| 448 | 449 | store->store_atomspace(); |
| 449 | 450 | |
| 450 | printf("Initial Atomspace size=%lu expect=%d\n", _as->get_size(), 7*idx+1); | |
| 451 | // +2 for *-open-* predicate and storage node | |
| 452 | printf("Initial Atomspace size=%lu expect=%d\n", _as->get_size(), 7*idx+2); | |
| 451 | 453 | TSM_ASSERT("Initial unexpected atomspace size", |
| 452 | ((unsigned)(7*idx+1)) == _as->get_size()); | |
| 454 | ((unsigned)(7*idx+2)) == _as->get_size()); | |
| 453 | 455 | /* Delete some atoms with non-empty incoming sets. |
| 454 | 456 | * This should result in their being removed from the atomspace, |
| 455 | 457 | * but NOT fom the backend! |
| … | … | @@ -457,36 +459,37 @@ void DeleteUTest::test_remove(void) |
| 457 | 459 | store->barrier(); |
| 458 | 460 | |
| 459 | 461 | for (i=0; i<idx; i++) |
| 460 | extract_links(i, _as); | |
| 462 | extract_links(i, _as.get()); | |
| 461 | 463 | |
| 462 | printf("Atomspace size=%lu expect=%d\n", _as->get_size(), 4*idx+1); | |
| 463 | TSM_ASSERT("Post-extract unexpected atomspace size", ((unsigned)(4*idx+1)) == _as->get_size()); | |
| 464 | // +2 for *-open-* predicate and storage node | |
| 465 | printf("Atomspace size=%lu expect=%d\n", _as->get_size(), 4*idx+2); | |
| 466 | TSM_ASSERT("Post-extract unexpected atomspace size", ((unsigned)(4*idx+2)) == _as->get_size()); | |
| 464 | 467 | |
| 465 | 468 | /* Verify that the atoms can still be fetched from storage. */ |
| 466 | 469 | for (i=0; i<idx; i++) { |
| 467 | 470 | fetch_space(i, store); |
| 468 | check_space(i, _as, "verify-fetch"); | |
| 471 | check_space(i, _as.get(), "verify-fetch"); | |
| 469 | 472 | } |
| 470 | 473 | |
| 471 | 474 | /* This time, kill them in the backend too. */ |
| 472 | 475 | for (i=0; i<idx; i++) |
| 473 | 476 | delete_links(i, store); |
| 474 | 477 | |
| 475 | // +2 for *-TruthValueKey-* and *-IsKeyFlag-* | |
| 476 | printf("Post-remove size=%lu expect=%d\n", _as->get_size(), 4*idx+3); | |
| 478 | // +2 for *-TruthValueKey-* and *-IsKeyFlag-*, +1 for *-open-* | |
| 479 | printf("Post-remove size=%lu expect=%d\n", _as->get_size(), 4*idx+4); | |
| 477 | 480 | TSM_ASSERT("Post-remove unexpected atomspace size", |
| 478 | ((unsigned)(4*idx+3)) == _as->get_size()); | |
| 481 | ((unsigned)(4*idx+4)) == _as->get_size()); | |
| 479 | 482 | |
| 480 | 483 | /* Verify that the atoms are really gone from storage. */ |
| 481 | 484 | for (i=0; i<idx; i++) { |
| 482 | 485 | fetch_space(i, store); |
| 483 | check_remove(i, _as, "verify-gone"); | |
| 486 | check_remove(i, _as.get(), "verify-gone"); | |
| 484 | 487 | } |
| 485 | 488 | |
| 486 | // +2 for *-TruthValueKey-* and *-IsKeyFlag-* | |
| 487 | printf("Post-referesh size=%lu expect=%d\n", _as->get_size(), 7*idx+3); | |
| 489 | // +2 for *-TruthValueKey-* and *-IsKeyFlag-*, +1 for *-open-* | |
| 490 | printf("Post-referesh size=%lu expect=%d\n", _as->get_size(), 7*idx+4); | |
| 488 | 491 | TSM_ASSERT("Post-refetch unexpected atomspace size", |
| 489 | ((unsigned)(7*idx+3)) == _as->get_size()); | |
| 492 | ((unsigned)(7*idx+4)) == _as->get_size()); | |
| 490 | 493 | |
| 491 | 494 | /* Kill data for good */ |
| 492 | 495 | _as->clear(); |
| … | … | @@ -494,7 +497,7 @@ void DeleteUTest::test_remove(void) |
| 494 | 497 | |
| 495 | 498 | /* Verify that the atoms are no longer being found. */ |
| 496 | 499 | for (i=0; i<idx; i++) |
| 497 | check_empty(i, _as); | |
| 500 | check_empty(i, _as.get()); | |
| 498 | 501 | |
| 499 | 502 | logger().debug("END TEST: %s", __FUNCTION__); |
| 500 | 503 | } |
| … | … | @@ -507,26 +510,26 @@ void DeleteUTest::test_recurse(void) |
| 507 | 510 | |
| 508 | 511 | Handle hsn = _as->add_node(ROCKS_STORAGE_NODE, std::string(uri)); |
| 509 | 512 | StorageNodePtr store = StorageNodeCast(hsn); |
| 510 | store->open(); | |
| 513 | store->setValue(_as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 511 | 514 | |
| 512 | 515 | TS_ASSERT(store->connected()) |
| 513 | 516 | |
| 514 | 517 | int idx = 0; |
| 515 | add_to_space(idx++, _as, "AA-aa-wow "); | |
| 516 | add_to_space(idx++, _as, "BB-bb-wow "); | |
| 517 | add_to_space(idx++, _as, "CC-cc-wow "); | |
| 518 | add_to_space(idx++, _as, "DD-dd-wow "); | |
| 519 | add_to_space(idx++, _as, "EE-ee-wow "); | |
| 518 | add_to_space(idx++, _as.get(), "AA-aa-wow "); | |
| 519 | add_to_space(idx++, _as.get(), "BB-bb-wow "); | |
| 520 | add_to_space(idx++, _as.get(), "CC-cc-wow "); | |
| 521 | add_to_space(idx++, _as.get(), "DD-dd-wow "); | |
| 522 | add_to_space(idx++, _as.get(), "EE-ee-wow "); | |
| 520 | 523 | |
| 521 | 524 | /* Make sure UTF-8 works fine. */ |
| 522 | add_to_space(idx++, _as, "Попытка выбраться вызвала слабый стон "); | |
| 523 | add_to_space(idx++, _as, "はにがうりだそうであってるのかはち "); | |
| 524 | add_to_space(idx++, _as, "係拉丁字母"); | |
| 525 | add_to_space(idx++, _as.get(), "Попытка выбраться вызвала слабый стон "); | |
| 526 | add_to_space(idx++, _as.get(), "はにがうりだそうであってるのかはち "); | |
| 527 | add_to_space(idx++, _as.get(), "係拉丁字母"); | |
| 525 | 528 | |
| 526 | 529 | /* Verify that the atoms were added */ |
| 527 | 530 | int i; |
| 528 | 531 | for (i=0; i<idx; i++) |
| 529 | check_space(i, _as, "verify-add"); | |
| 532 | check_space(i, _as.get(), "verify-add"); | |
| 530 | 533 | |
| 531 | 534 | /* Push all atoms out to the SQL DB */ |
| 532 | 535 | store->store_atomspace(); |
| … | … | @@ -539,9 +542,10 @@ void DeleteUTest::test_recurse(void) |
| 539 | 542 | |
| 540 | 543 | int zap = 4; |
| 541 | 544 | for (i=0; i<zap; i++) |
| 542 | extract_nodes(i, _as); | |
| 545 | extract_nodes(i, _as.get()); | |
| 543 | 546 | |
| 544 | size_t expsz = 7*(idx-zap) + 3*zap + 1; | |
| 547 | // +1 for *-open-* | |
| 548 | size_t expsz = 7*(idx-zap) + 3*zap + 2; | |
| 545 | 549 | printf("Atomspace size=%lu expect=%lu\n", |
| 546 | 550 | _as->get_size(), expsz); |
| 547 | 551 | TSM_ASSERT("Unexpected atomspace size", expsz == _as->get_size()); |
| … | … | @@ -549,14 +553,14 @@ void DeleteUTest::test_recurse(void) |
| 549 | 553 | /* Verify that the atoms can still be fetched from storage. */ |
| 550 | 554 | for (i=0; i<idx; i++) { |
| 551 | 555 | fetch_space(i, store); |
| 552 | check_space(i, _as, "verify-fetch"); | |
| 556 | check_space(i, _as.get(), "verify-fetch"); | |
| 553 | 557 | } |
| 554 | 558 | |
| 555 | 559 | /* This time, kill them in the backend too. */ |
| 556 | 560 | for (i=0; i<zap; i++) |
| 557 | 561 | delete_nodes(i, store); |
| 558 | 562 | |
| 559 | // +1 for *-IsKeyFlag-* | |
| 563 | // +1 for *-IsKeyFlag-*, expsz already has +1 for *-open-* | |
| 560 | 564 | printf("Post-remove size=%lu expect=%lu\n", |
| 561 | 565 | _as->get_size(), expsz+2); |
| 562 | 566 | TSM_ASSERT("Unexpected atomspace size", expsz+2 == _as->get_size()); |
| … | … | @@ -568,20 +572,20 @@ void DeleteUTest::test_recurse(void) |
| 568 | 572 | fetch_space(i, store); |
| 569 | 573 | } |
| 570 | 574 | |
| 571 | // +2 for *-TruthValueKey-* and *-IsKeyFlag-* | |
| 575 | // +2 for *-TruthValueKey-* and *-IsKeyFlag-*, +1 for *-open-* | |
| 572 | 576 | printf("Post-refetch size=%lu expect=%d\n", |
| 573 | _as->get_size(), 7*idx+3); | |
| 577 | _as->get_size(), 7*idx+4); | |
| 574 | 578 | TSM_ASSERT("Unexpected atomspace size", |
| 575 | ((unsigned) 7*idx+3) == _as->get_size()); | |
| 579 | ((unsigned) 7*idx+4) == _as->get_size()); | |
| 576 | 580 | |
| 577 | 581 | /* Check that the removed atoms really got zapped. */ |
| 578 | 582 | for (i=0; i<zap; i++) { |
| 579 | check_remove(i, _as, "verify-zapped"); | |
| 583 | check_remove(i, _as.get(), "verify-zapped"); | |
| 580 | 584 | } |
| 581 | 585 | |
| 582 | 586 | /* However, others should still be there. */ |
| 583 | 587 | for (i=zap; i<idx; i++) { |
| 584 | check_space(i, _as, "verify-zap"); | |
| 588 | check_space(i, _as.get(), "verify-zap"); | |
| 585 | 589 | } |
| 586 | 590 | |
| 587 | 591 | /* Kill data for good */ |
| … | … | @@ -590,7 +594,7 @@ void DeleteUTest::test_recurse(void) |
| 590 | 594 | |
| 591 | 595 | /* Verify that the atoms are no longer being found. */ |
| 592 | 596 | for (i=0; i<idx; i++) |
| 593 | check_empty(i, _as); | |
| 597 | check_empty(i, _as.get()); | |
| 594 | 598 | |
| 595 | 599 | logger().debug("END TEST: %s", __FUNCTION__); |
| 596 | 600 | } |
| … | … | @@ -32,6 +32,7 @@ |
| 32 | 32 | #include <opencog/atoms/base/Link.h> |
| 33 | 33 | #include <opencog/atoms/base/Node.h> |
| 34 | 34 | #include <opencog/atoms/value/FloatValue.h> |
| 35 | #include <opencog/atoms/value/VoidValue.h> | |
| 35 | 36 | |
| 36 | 37 | #include <opencog/atomspace/AtomSpace.h> |
| 37 | 38 | |
| … | … | @@ -45,7 +46,7 @@ using namespace opencog; |
| 45 | 46 | class PersistUTest : public CxxTest::TestSuite |
| 46 | 47 | { |
| 47 | 48 | private: |
| 48 | AtomSpace *_as; | |
| 49 | AtomSpacePtr _as; | |
| 49 | 50 | |
| 50 | 51 | NodePtr n1[10]; |
| 51 | 52 | NodePtr n2[10]; |
| … | … | @@ -100,12 +101,12 @@ PersistUTest:: PersistUTest(void) |
| 100 | 101 | */ |
| 101 | 102 | void PersistUTest::setUp(void) |
| 102 | 103 | { |
| 103 | _as = new AtomSpace(); | |
| 104 | _as = createAtomSpace(); | |
| 104 | 105 | } |
| 105 | 106 | |
| 106 | 107 | void PersistUTest::tearDown(void) |
| 107 | 108 | { |
| 108 | delete _as; | |
| 109 | _as = nullptr; | |
| 109 | 110 | } |
| 110 | 111 | |
| 111 | 112 | // ============================================================ |
| … | … | @@ -317,25 +318,25 @@ void PersistUTest::test_atomspace(void) |
| 317 | 318 | |
| 318 | 319 | Handle hsn = _as->add_node(ROCKS_STORAGE_NODE, "rocks:///tmp/cog-rocks-persist-utest"); |
| 319 | 320 | StorageNodePtr store = StorageNodeCast(hsn); |
| 320 | store->open(); | |
| 321 | store->setValue(_as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 321 | 322 | TS_ASSERT(store->connected()) |
| 322 | 323 | |
| 323 | 324 | int idx = 0; |
| 324 | add_to_space(idx++, _as, "AA-aa-wow "); | |
| 325 | add_to_space(idx++, _as, "BB-bb-wow "); | |
| 326 | add_to_space(idx++, _as, "CC-cc-wow "); | |
| 327 | add_to_space(idx++, _as, "DD-dd-wow "); | |
| 328 | add_to_space(idx++, _as, "EE-ee-wow "); | |
| 325 | add_to_space(idx++, _as.get(), "AA-aa-wow "); | |
| 326 | add_to_space(idx++, _as.get(), "BB-bb-wow "); | |
| 327 | add_to_space(idx++, _as.get(), "CC-cc-wow "); | |
| 328 | add_to_space(idx++, _as.get(), "DD-dd-wow "); | |
| 329 | add_to_space(idx++, _as.get(), "EE-ee-wow "); | |
| 329 | 330 | |
| 330 | 331 | /* Make sure UTF-8 works fine. */ |
| 331 | add_to_space(idx++, _as, "Попытка выбраться вызвала слабый стон "); | |
| 332 | add_to_space(idx++, _as, "はにがうりだそうであってるのかはち "); | |
| 333 | add_to_space(idx++, _as, "係拉丁字母"); | |
| 332 | add_to_space(idx++, _as.get(), "Попытка выбраться вызвала слабый стон "); | |
| 333 | add_to_space(idx++, _as.get(), "はにがうりだそうであってるのかはち "); | |
| 334 | add_to_space(idx++, _as.get(), "係拉丁字母"); | |
| 334 | 335 | |
| 335 | 336 | /* Verify that the atoms were added */ |
| 336 | 337 | int i; |
| 337 | 338 | for (i=0; i<idx; i++) |
| 338 | check_space(i, _as, "verify-add"); | |
| 339 | check_space(i, _as.get(), "verify-add"); | |
| 339 | 340 | |
| 340 | 341 | /* Push all atoms out to the Cogserver */ |
| 341 | 342 | store->store_atomspace(); |
| … | … | @@ -351,12 +352,12 @@ void PersistUTest::test_atomspace(void) |
| 351 | 352 | /* The above clear wiped out the storage node; recreate it. */ |
| 352 | 353 | hsn = _as->add_node(ROCKS_STORAGE_NODE, "rocks:///tmp/cog-rocks-persist-utest"); |
| 353 | 354 | store = StorageNodeCast(hsn); |
| 354 | store->open(); | |
| 355 | store->setValue(_as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 355 | 356 | |
| 356 | 357 | /* Verify that the atoms can still be fetched from storage. */ |
| 357 | 358 | for (i=0; i<idx; i++) { |
| 358 | 359 | fetch_space(i, store); |
| 359 | check_space(i, _as, "verify-fetch"); | |
| 360 | check_space(i, _as.get(), "verify-fetch"); | |
| 360 | 361 | } |
| 361 | 362 | |
| 362 | 363 | /* Do it again, for good luck. */ |
| … | … | @@ -366,12 +367,12 @@ void PersistUTest::test_atomspace(void) |
| 366 | 367 | /* The above clear wiped out the storage node; recreate it. */ |
| 367 | 368 | hsn = _as->add_node(ROCKS_STORAGE_NODE, "rocks:///tmp/cog-rocks-persist-utest"); |
| 368 | 369 | store = StorageNodeCast(hsn); |
| 369 | store->open(); | |
| 370 | store->setValue(_as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 370 | 371 | |
| 371 | 372 | /* Verify that the atoms can still be fetched from storage. */ |
| 372 | 373 | for (i=0; i<idx; i++) { |
| 373 | 374 | fetch_space(i, store); |
| 374 | check_space(i, _as, "ver-again"); | |
| 375 | check_space(i, _as.get(), "ver-again"); | |
| 375 | 376 | } |
| 376 | 377 | |
| 377 | 378 | /* Kill data for good */ |
| … | … | @@ -380,7 +381,7 @@ void PersistUTest::test_atomspace(void) |
| 380 | 381 | |
| 381 | 382 | /* Verify that the atoms are no longer being found. */ |
| 382 | 383 | for (i=0; i<idx; i++) |
| 383 | check_empty(i, _as); | |
| 384 | check_empty(i, _as.get()); | |
| 384 | 385 | |
| 385 | 386 | logger().debug("END TEST: %s", __FUNCTION__); |
| 386 | 387 | } |
| … | … | @@ -37,6 +37,7 @@ |
| 37 | 37 | #include <opencog/atoms/value/LinkValue.h> |
| 38 | 38 | #include <opencog/atoms/value/StringValue.h> |
| 39 | 39 | #include <opencog/atoms/value/FloatValue.h> |
| 40 | #include <opencog/atoms/value/VoidValue.h> | |
| 40 | 41 | |
| 41 | 42 | #include <opencog/persist/rocks-types/atom_types.h> |
| 42 | 43 | #include <opencog/persist/rocks/RocksStorage.h> |
| … | … | @@ -105,10 +106,10 @@ void ValueSaveUTest::test_single_atom_save() |
| 105 | 106 | { |
| 106 | 107 | logger().info("BEGIN TEST: %s", __FUNCTION__); |
| 107 | 108 | |
| 108 | AtomSpace* as = new AtomSpace(); | |
| 109 | AtomSpacePtr as = createAtomSpace(); | |
| 109 | 110 | Handle hsn = as->add_node(ROCKS_STORAGE_NODE, std::string(uri)); |
| 110 | 111 | StorageNodePtr store = StorageNodeCast(hsn); |
| 111 | store->open(); | |
| 112 | store->setValue(as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 112 | 113 | TS_ASSERT(store->connected()) |
| 113 | 114 | |
| 114 | 115 | Handle key = as->add_node(PREDICATE_NODE, "some pred key"); |
| … | … | @@ -154,7 +155,7 @@ void ValueSaveUTest::test_single_atom_save() |
| 154 | 155 | store->store_atom(atom); |
| 155 | 156 | store->barrier(); |
| 156 | 157 | |
| 157 | delete as; | |
| 158 | as = nullptr; | |
| 158 | 159 | |
| 159 | 160 | logger().info("END TEST: %s", __FUNCTION__); |
| 160 | 161 | } |
| … | … | @@ -172,10 +173,10 @@ void ValueSaveUTest::check_one(ValuePtr pap, bool fetchkey) |
| 172 | 173 | // ------ |
| 173 | 174 | // First, save the value |
| 174 | 175 | |
| 175 | AtomSpace* as = new AtomSpace(); | |
| 176 | AtomSpacePtr as = createAtomSpace(); | |
| 176 | 177 | Handle hsn = as->add_node(ROCKS_STORAGE_NODE, std::string(uri)); |
| 177 | 178 | StorageNodePtr store = StorageNodeCast(hsn); |
| 178 | store->open(); | |
| 179 | store->setValue(as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 179 | 180 | TS_ASSERT(store->connected()) |
| 180 | 181 | |
| 181 | 182 | Handle key = store->fetch_atom(bkey); |
| … | … | @@ -190,15 +191,15 @@ void ValueSaveUTest::check_one(ValuePtr pap, bool fetchkey) |
| 190 | 191 | printf ("Stored atom %s\n", atom->to_string().c_str()); |
| 191 | 192 | printf ("Stored vals %s\n", atom->valuesToString().c_str()); |
| 192 | 193 | |
| 193 | delete as; | |
| 194 | as = nullptr; | |
| 194 | 195 | |
| 195 | 196 | // --------------------------------- |
| 196 | 197 | // Now, fetch the value and compare. |
| 197 | 198 | |
| 198 | as = new AtomSpace(); | |
| 199 | as = createAtomSpace(); | |
| 199 | 200 | hsn = as->add_node(ROCKS_STORAGE_NODE, std::string(uri)); |
| 200 | 201 | store = StorageNodeCast(hsn); |
| 201 | store->open(); | |
| 202 | store->setValue(as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 202 | 203 | TS_ASSERT(store->connected()) |
| 203 | 204 | |
| 204 | 205 | // Storage uses a different code path if the key is not yet |
| … | … | @@ -213,17 +214,17 @@ void ValueSaveUTest::check_one(ValuePtr pap, bool fetchkey) |
| 213 | 214 | printf("Expecting %s\n", pap->to_string().c_str()); |
| 214 | 215 | TS_ASSERT(*pap == *fap); |
| 215 | 216 | |
| 216 | delete as; | |
| 217 | as = nullptr; | |
| 217 | 218 | } |
| 218 | 219 | |
| 219 | 220 | void ValueSaveUTest::test_save_restore(bool fkey) |
| 220 | 221 | { |
| 221 | 222 | logger().info("BEGIN TEST: %s", __FUNCTION__); |
| 222 | 223 | |
| 223 | AtomSpace* as = new AtomSpace(); | |
| 224 | AtomSpacePtr as = createAtomSpace(); | |
| 224 | 225 | Handle hsn = as->add_node(ROCKS_STORAGE_NODE, std::string(uri)); |
| 225 | 226 | StorageNodePtr store = StorageNodeCast(hsn); |
| 226 | store->open(); | |
| 227 | store->setValue(as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 227 | 228 | TS_ASSERT(store->connected()) |
| 228 | 229 | |
| 229 | 230 | Handle key = as->add_node(PREDICATE_NODE, "some pred key"); |
| … | … | @@ -262,7 +263,7 @@ void ValueSaveUTest::test_save_restore(bool fkey) |
| 262 | 263 | check_one(pvl2, fkey); |
| 263 | 264 | |
| 264 | 265 | store->erase(); |
| 265 | delete as; | |
| 266 | as = nullptr; | |
| 266 | 267 | |
| 267 | 268 | logger().info("END TEST: %s", __FUNCTION__); |
| 268 | 269 | } |
| … | … | @@ -276,10 +277,10 @@ void ValueSaveUTest::test_load_by_type() |
| 276 | 277 | { |
| 277 | 278 | logger().info("BEGIN TEST: %s", __FUNCTION__); |
| 278 | 279 | |
| 279 | AtomSpace* as = new AtomSpace(); | |
| 280 | AtomSpacePtr as = createAtomSpace(); | |
| 280 | 281 | Handle hsn = as->add_node(ROCKS_STORAGE_NODE, std::string(uri)); |
| 281 | 282 | StorageNodePtr store = StorageNodeCast(hsn); |
| 282 | store->open(); | |
| 283 | store->setValue(as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 283 | 284 | TS_ASSERT(store->connected()) |
| 284 | 285 | |
| 285 | 286 | // Clear out left-over junk, just in case. |
| … | … | @@ -332,15 +333,15 @@ void ValueSaveUTest::test_load_by_type() |
| 332 | 333 | store->store_atom(al); |
| 333 | 334 | store->store_atom(av); |
| 334 | 335 | store->barrier(); |
| 335 | delete as; | |
| 336 | as = nullptr; | |
| 336 | 337 | |
| 337 | 338 | // -------------------- |
| 338 | 339 | // Start it up again. |
| 339 | 340 | |
| 340 | as = new AtomSpace(); | |
| 341 | as = createAtomSpace(); | |
| 341 | 342 | hsn = as->add_node(ROCKS_STORAGE_NODE, std::string(uri)); |
| 342 | 343 | store = StorageNodeCast(hsn); |
| 343 | store->open(); | |
| 344 | store->setValue(as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 344 | 345 | TS_ASSERT(store->connected()) |
| 345 | 346 | |
| 346 | 347 | // -------------------- |
| … | … | @@ -348,11 +349,11 @@ void ValueSaveUTest::test_load_by_type() |
| 348 | 349 | store->fetch_all_atoms_of_type(CONCEPT_NODE); |
| 349 | 350 | store->barrier(); |
| 350 | 351 | |
| 351 | // Eight: 4 ConceptNodes, the PredicateNode "*-TruthValueKey-*", | |
| 352 | // Nine: 4 ConceptNodes, the PredicateNode "*-TruthValueKey-*", | |
| 352 | 353 | // PredicateNode "*-IsKeyFlag-*", PredicateNode "some pred key", |
| 353 | // and the RocksStorageNode. | |
| 354 | // the RocksStorageNode, and PredicateNode "*-open-*". | |
| 354 | 355 | printf ("fetched %lu atoms\n", as->get_size()); |
| 355 | TSM_ASSERT("Wrong number of Atoms fetched!", as->get_size() == 8); | |
| 356 | TSM_ASSERT("Wrong number of Atoms fetched!", as->get_size() == 9); | |
| 356 | 357 | |
| 357 | 358 | Handle gkey = as->add_node(PREDICATE_NODE, "some pred key"); |
| 358 | 359 | Handle gaf = as->add_node(CONCEPT_NODE, "float node"); |
| … | … | @@ -388,7 +389,7 @@ void ValueSaveUTest::test_load_by_type() |
| 388 | 389 | TS_ASSERT(*gpv == *pvv); |
| 389 | 390 | |
| 390 | 391 | // -------------------- |
| 391 | delete as; | |
| 392 | as = nullptr; | |
| 392 | 393 | |
| 393 | 394 | logger().info("END TEST: %s", __FUNCTION__); |
| 394 | 395 | } |
| … | … | @@ -404,10 +405,10 @@ void ValueSaveUTest::test_link_by_type() |
| 404 | 405 | { |
| 405 | 406 | logger().info("BEGIN TEST: %s", __FUNCTION__); |
| 406 | 407 | |
| 407 | AtomSpace* as = new AtomSpace(); | |
| 408 | AtomSpacePtr as = createAtomSpace(); | |
| 408 | 409 | Handle hsn = as->add_node(ROCKS_STORAGE_NODE, std::string(uri)); |
| 409 | 410 | StorageNodePtr store = StorageNodeCast(hsn); |
| 410 | store->open(); | |
| 411 | store->setValue(as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 411 | 412 | TS_ASSERT(store->connected()) |
| 412 | 413 | |
| 413 | 414 | Handle key = as->add_node(PREDICATE_NODE, "some pred key"); |
| … | … | @@ -486,15 +487,15 @@ void ValueSaveUTest::test_link_by_type() |
| 486 | 487 | store->store_atom(cv); |
| 487 | 488 | store->barrier(); |
| 488 | 489 | |
| 489 | delete as; | |
| 490 | as = nullptr; | |
| 490 | 491 | |
| 491 | 492 | // -------------------- |
| 492 | 493 | // Start it up again. |
| 493 | 494 | |
| 494 | as = new AtomSpace(); | |
| 495 | as = createAtomSpace(); | |
| 495 | 496 | hsn = as->add_node(ROCKS_STORAGE_NODE, std::string(uri)); |
| 496 | 497 | store = StorageNodeCast(hsn); |
| 497 | store->open(); | |
| 498 | store->setValue(as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 498 | 499 | TS_ASSERT(store->connected()) |
| 499 | 500 | |
| 500 | 501 | // -------------------- |
| … | … | @@ -510,11 +511,11 @@ void ValueSaveUTest::test_link_by_type() |
| 510 | 511 | // The B-nodes are added after the fetch. In either case, |
| 511 | 512 | // there should not be any values fetched for either A or B; |
| 512 | 513 | // only the values on the C-links should be fetched. |
| 513 | // +1 for *-IsKeyFlag-* | |
| 514 | // +1 for *-IsKeyFlag-*, +1 for *-open-* | |
| 514 | 515 | store->fetch_all_atoms_of_type(LIST_LINK); |
| 515 | 516 | store->barrier(); |
| 516 | 517 | printf ("fetched %lu atoms\n", as->get_size()); |
| 517 | TSM_ASSERT("Wrong number of Atoms fetched!", as->get_size() == 16); | |
| 518 | TSM_ASSERT("Wrong number of Atoms fetched!", as->get_size() == 17); | |
| 518 | 519 | |
| 519 | 520 | Handle gbf = as->add_node(CONCEPT_NODE, "b float node"); |
| 520 | 521 | Handle gbt = as->add_node(CONCEPT_NODE, "b string node"); |
| … | … | @@ -601,7 +602,7 @@ void ValueSaveUTest::test_link_by_type() |
| 601 | 602 | TS_ASSERT(*gpv == *pvv); |
| 602 | 603 | |
| 603 | 604 | // -------------------- |
| 604 | delete as; | |
| 605 | as = nullptr; | |
| 605 | 606 | |
| 606 | 607 | logger().info("END TEST: %s", __FUNCTION__); |
| 607 | 608 | } |
| … | … | @@ -614,10 +615,10 @@ void ValueSaveUTest::test_link_by_type_quoted() |
| 614 | 615 | { |
| 615 | 616 | logger().info("BEGIN TEST: %s", __FUNCTION__); |
| 616 | 617 | |
| 617 | AtomSpace* as = new AtomSpace(); | |
| 618 | AtomSpacePtr as = createAtomSpace(); | |
| 618 | 619 | Handle hsn = as->add_node(ROCKS_STORAGE_NODE, std::string(uri)); |
| 619 | 620 | StorageNodePtr store = StorageNodeCast(hsn); |
| 620 | store->open(); | |
| 621 | store->setValue(as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 621 | 622 | TS_ASSERT(store->connected()) |
| 622 | 623 | |
| 623 | 624 | Handle key = as->add_node(PREDICATE_NODE, "some (\"pred\"))) key"); |
| … | … | @@ -696,15 +697,15 @@ void ValueSaveUTest::test_link_by_type_quoted() |
| 696 | 697 | store->store_atom(cv); |
| 697 | 698 | store->barrier(); |
| 698 | 699 | |
| 699 | delete as; | |
| 700 | as = nullptr; | |
| 700 | 701 | |
| 701 | 702 | // -------------------- |
| 702 | 703 | // Start it up again. |
| 703 | 704 | |
| 704 | as = new AtomSpace(); | |
| 705 | as = createAtomSpace(); | |
| 705 | 706 | hsn = as->add_node(ROCKS_STORAGE_NODE, std::string(uri)); |
| 706 | 707 | store = StorageNodeCast(hsn); |
| 707 | store->open(); | |
| 708 | store->setValue(as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 708 | 709 | TS_ASSERT(store->connected()) |
| 709 | 710 | |
| 710 | 711 | // -------------------- |
| … | … | @@ -723,10 +724,10 @@ void ValueSaveUTest::test_link_by_type_quoted() |
| 723 | 724 | store->fetch_all_atoms_of_type(LIST_LINK); |
| 724 | 725 | store->barrier(); |
| 725 | 726 | |
| 726 | // We created 9 new atoms above, so expect 16 from before plus 9 | |
| 727 | // +1 for *-IsKeyFlag-* | |
| 728 | printf ("fetched %lu atoms, expecting 25\n", as->get_size()); | |
| 729 | TSM_ASSERT("Wrong number of Atoms fetched!", as->get_size() == 25); | |
| 727 | // We created 9 new atoms above, so expect 17 from before plus 9 | |
| 728 | // +1 for *-IsKeyFlag-*, +1 for *-open-* | |
| 729 | printf ("fetched %lu atoms, expecting 26\n", as->get_size()); | |
| 730 | TSM_ASSERT("Wrong number of Atoms fetched!", as->get_size() == 26); | |
| 730 | 731 | |
| 731 | 732 | Handle gbf = as->add_node(CONCEPT_NODE, "b float node"); |
| 732 | 733 | Handle gbt = as->add_node(CONCEPT_NODE, "b string node"); |
| … | … | @@ -813,7 +814,7 @@ void ValueSaveUTest::test_link_by_type_quoted() |
| 813 | 814 | TS_ASSERT(*gpv == *pvv); |
| 814 | 815 | |
| 815 | 816 | // -------------------- |
| 816 | delete as; | |
| 817 | as = nullptr; | |
| 817 | 818 | |
| 818 | 819 | logger().info("END TEST: %s", __FUNCTION__); |
| 819 | 820 | } |
| … | … | @@ -827,10 +828,10 @@ void ValueSaveUTest::test_incoming() |
| 827 | 828 | { |
| 828 | 829 | logger().info("BEGIN TEST: %s", __FUNCTION__); |
| 829 | 830 | |
| 830 | AtomSpace* as = new AtomSpace(); | |
| 831 | AtomSpacePtr as = createAtomSpace(); | |
| 831 | 832 | Handle hsn = as->add_node(ROCKS_STORAGE_NODE, std::string(uri)); |
| 832 | 833 | StorageNodePtr store = StorageNodeCast(hsn); |
| 833 | store->open(); | |
| 834 | store->setValue(as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 834 | 835 | TS_ASSERT(store->connected()) |
| 835 | 836 | |
| 836 | 837 | Handle key = as->add_node(PREDICATE_NODE, "some pred key"); |
| … | … | @@ -909,15 +910,15 @@ void ValueSaveUTest::test_incoming() |
| 909 | 910 | store->store_atom(cv); |
| 910 | 911 | store->barrier(); |
| 911 | 912 | |
| 912 | delete as; | |
| 913 | as = nullptr; | |
| 913 | 914 | |
| 914 | 915 | // -------------------- |
| 915 | 916 | // Start it up again. |
| 916 | 917 | |
| 917 | as = new AtomSpace(); | |
| 918 | as = createAtomSpace(); | |
| 918 | 919 | hsn = as->add_node(ROCKS_STORAGE_NODE, std::string(uri)); |
| 919 | 920 | store = StorageNodeCast(hsn); |
| 920 | store->open(); | |
| 921 | store->setValue(as->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue()); | |
| 921 | 922 | TS_ASSERT(store->connected()) |
| 922 | 923 | |
| 923 | 924 | // -------------------- |
| … | … | @@ -938,9 +939,9 @@ void ValueSaveUTest::test_incoming() |
| 938 | 939 | store->fetch_incoming_set(gal, false); |
| 939 | 940 | store->fetch_incoming_set(gav, false); |
| 940 | 941 | store->barrier(); |
| 941 | // +1 for *-IsKeyFlag-* | |
| 942 | // +1 for *-IsKeyFlag-*, +1 for *-open-* | |
| 942 | 943 | printf ("fetched %lu atoms\n", as->get_size()); |
| 943 | TSM_ASSERT("Wrong number of Atoms fetched!", as->get_size() == 16); | |
| 944 | TSM_ASSERT("Wrong number of Atoms fetched!", as->get_size() == 17); | |
| 944 | 945 | |
| 945 | 946 | Handle gbf = as->add_node(CONCEPT_NODE, "b float node"); |
| 946 | 947 | Handle gbt = as->add_node(CONCEPT_NODE, "b string node"); |
| … | … | @@ -1025,7 +1026,7 @@ void ValueSaveUTest::test_incoming() |
| 1025 | 1026 | TS_ASSERT(*gpv == *pvv); |
| 1026 | 1027 | |
| 1027 | 1028 | // -------------------- |
| 1028 | delete as; | |
| 1029 | as = nullptr; | |
| 1029 | 1030 | |
| 1030 | 1031 | logger().info("END TEST: %s", __FUNCTION__); |
| 1031 | 1032 | } |