#include "squid.h"
#include "MemBuf.h"
+#include "SwapDir.h"
#include "store_rebuild.h"
+#if HAVE_STRING_H
+#include <string.h>
+#endif
#define STUB_API "stub_store_rebuild.cc"
#include "tests/STUB.h"
void storeRebuildProgress(int sd_index, int total, int sofar) STUB
-void storeRebuildComplete(StoreRebuildData *dc) STUB_NOP
-bool storeRebuildLoadEntry(int, int, MemBuf&, StoreRebuildData&)
-{
- return false;
-}
bool storeRebuildKeepEntry(const StoreEntry &tmpe, const cache_key *key, StoreRebuildData &counts) STUB_RETVAL(false)
bool storeRebuildParseEntry(MemBuf &, StoreEntry &, cache_key *, StoreRebuildData &, uint64_t) STUB_RETVAL(false)
+
+void storeRebuildComplete(StoreRebuildData *)
+{
+ --StoreController::store_dirs_rebuilding;
+}
+
+bool
+storeRebuildLoadEntry(int fd, int diskIndex, MemBuf &buf, StoreRebuildData &)
+{
+ if (fd < 0)
+ return false;
+
+ assert(buf.hasSpace()); // caller must allocate
+ // this stub simulates reading an empty entry
+ memset(buf.space(), 0, buf.spaceSize());
+ buf.appended(buf.spaceSize());
+ return true;
+}
*/
/* nothing left to rebuild */
- CPPUNIT_ASSERT_EQUAL(1, StoreController::store_dirs_rebuilding);
+ CPPUNIT_ASSERT_EQUAL(0, StoreController::store_dirs_rebuilding);
+}
+
+static const char *
+storeId(const int i)
+{
+ static char buf[64];
+ snprintf(buf, sizeof(buf), "dummy url %i", i);
+ buf[sizeof(buf) - 1] = '\0';
+ return buf;
}
StoreEntry *
{
RequestFlags flags;
flags.cachable = true;
- char url[64];
- snprintf(url, sizeof(url), "dummy url %i", i);
- url[sizeof(url) - 1] = '\0';
StoreEntry *const pe =
- storeCreateEntry(url, "dummy log url", flags, Http::METHOD_GET);
+ storeCreateEntry(storeId(i), "dummy log url", flags, Http::METHOD_GET);
HttpReply *const rep = const_cast<HttpReply *>(pe->getReply());
rep->setHeaders(Http::scOkay, "dummy test object", "x-squid-internal/test", 0, -1, squid_curtime + 100000);
StoreEntry *
testRock::getEntry(const int i)
{
- StoreEntry *const pe = createEntry(i);
- return store->get(reinterpret_cast<const cache_key *>(pe->key));
+ return storeGetPublic(storeId(i), Http::METHOD_GET);
}
void
CPPUNIT_ASSERT_EQUAL(SWAPOUT_DONE, pe->swap_status);
- pe->unlock("testRock::testRockSwapOut");
+ pe->unlock("testRock::testRockSwapOut priming");
}
CPPUNIT_ASSERT_EQUAL((uint64_t)5, store->currentCount());
loop.run();
CPPUNIT_ASSERT_EQUAL(SWAPOUT_DONE, pe->swap_status);
+
+ pe->unlock("testRock::testRockSwapOut e#4");
}
// try to swap out entry to a used locked slot
StockEventLoop loop;
loop.run();
+
+ pe->unlock("testRock::testRockSwapOut e#5.1");
+ pe2->unlock("testRock::testRockSwapOut e#5.2");
+
+ // pe2 has the same public key as pe so it marks old pe for release
+ // here, we add another entry #5 into the now-available slot
+ StoreEntry *const pe3 = addEntry(5);
+ CPPUNIT_ASSERT_EQUAL(SWAPOUT_WRITING, pe3->swap_status);
+ CPPUNIT_ASSERT_EQUAL(0, pe3->swap_dirn);
+ CPPUNIT_ASSERT(pe3->swap_filen >= 0);
+ loop.run();
+ CPPUNIT_ASSERT_EQUAL(SWAPOUT_DONE, pe3->swap_status);
+ pe3->unlock("testRock::testRockSwapOut e#5.3");
}
CPPUNIT_ASSERT_EQUAL((uint64_t)6, store->currentCount());
- // try to get and unlink entries
+ // try to get and release all entries
for (int i = 0; i < 6; ++i) {
StoreEntry *const pe = getEntry(i);
CPPUNIT_ASSERT(pe != NULL);
- pe->unlink();
+ pe->release(); // destroys pe
StoreEntry *const pe2 = getEntry(i);
CPPUNIT_ASSERT_EQUAL(static_cast<StoreEntry *>(NULL), pe2);