LONGBOW_TEST_CASE(Local, _getLeastUsedFromLRU)
{
    AthenaLRUContentStore *impl = _createLRUContentStore();

    CCNxName *name1 = ccnxName_CreateFromURI("lci:/first/entry");
    CCNxContentObject *contentObject1 = ccnxContentObject_CreateWithDataPayload(name1, NULL);

    CCNxName *name2 = ccnxName_CreateFromURI("lci:/second/entry");
    CCNxContentObject *contentObject2 = ccnxContentObject_CreateWithDataPayload(name2, NULL);

    CCNxName *name3 = ccnxName_CreateFromURI("lci:/third/entry");
    CCNxContentObject *contentObject3 = ccnxContentObject_CreateWithDataPayload(name3, NULL);

    bool status = _athenaLRUContentStore_PutContentObject(impl, contentObject1);
    assertTrue(status, "Exepected to insert content");

    status = _athenaLRUContentStore_PutContentObject(impl, contentObject2);
    assertTrue(status, "Exepected to insert content");

    status = _athenaLRUContentStore_PutContentObject(impl, contentObject3);
    assertTrue(status, "Exepected to insert content");

    athenaLRUContentStore_Display(impl, 2);

    _AthenaLRUContentStoreEntry *entry1 = _getLeastUsedFromLRU(impl);
    assertTrue(ccnxContentObject_Equals(entry1->contentObject, contentObject1), "Expected to retrieve contentObject1");
    _athenaLRUContentStore_PurgeContentStoreEntry(impl, entry1);

    _AthenaLRUContentStoreEntry *entry2 = _getLeastUsedFromLRU(impl);
    assertTrue(ccnxContentObject_Equals(entry2->contentObject, contentObject2), "Expected to retrieve contentObject1");
    _athenaLRUContentStore_PurgeContentStoreEntry(impl, entry2);

    _AthenaLRUContentStoreEntry *entry3 = _getLeastUsedFromLRU(impl);
    assertTrue(ccnxContentObject_Equals(entry3->contentObject, contentObject3), "Expected to retrieve contentObject1");
    _athenaLRUContentStore_PurgeContentStoreEntry(impl, entry3);

    ccnxContentObject_Release(&contentObject1);
    ccnxContentObject_Release(&contentObject2);
    ccnxContentObject_Release(&contentObject3);
    ccnxName_Release(&name1);
    ccnxName_Release(&name2);
    ccnxName_Release(&name3);

    _athenaLRUContentStore_Release((AthenaContentStoreImplementation *) &impl);
}
示例#2
0
static bool
_makeRoomInStore(AthenaLRUContentStore *impl, size_t sizeNeeded)
{
    bool result = false;

    if (sizeNeeded > impl->maxSizeInBytes) {
        return false; // not possible.
    }

    uint64_t nowInMillis = parcClock_GetTime(impl->wallClock);

    // Evict expired items until we have enough room, or don't have any expired items.
    while (sizeNeeded > (impl->maxSizeInBytes - impl->currentSizeInBytes)) {
        _AthenaLRUContentStoreEntry *entry = _getEarliestExpiryTime(impl);
        if (entry == NULL) {
            break;
        }
        if (nowInMillis > entry->expiryTime) {
            _athenaLRUContentStore_PurgeContentStoreEntry(impl, entry);
        } else {
            break;
        }
    }

    // Evict items past their recommended cache time until we have enough room, or don't have any items.
    while (sizeNeeded > (impl->maxSizeInBytes - impl->currentSizeInBytes)) {
        _AthenaLRUContentStoreEntry *entry = _getEarliestRecommendedCacheTime(impl);
        if (entry == NULL) {
            break;
        }
        if (nowInMillis > entry->recommendedCacheTime) {
            _athenaLRUContentStore_PurgeContentStoreEntry(impl, entry);
        } else {
            break;
        }
    }

    while (sizeNeeded > (impl->maxSizeInBytes - impl->currentSizeInBytes)) {
        _AthenaLRUContentStoreEntry *entry = _getLeastUsedFromLRU(impl);
        if (entry == NULL) {
            break;
        }
        _athenaLRUContentStore_PurgeContentStoreEntry(impl, entry);
    }

    if (impl->maxSizeInBytes - impl->currentSizeInBytes > sizeNeeded) {
        return true;
    }

    return result;
}