summaryrefslogtreecommitdiffstats
path: root/cpp/sca/modules/cache/diskcache-test.cpp
diff options
context:
space:
mode:
authorjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2009-11-16 06:01:30 +0000
committerjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2009-11-16 06:01:30 +0000
commit4109b6c23b5169463bd493347dddb1ab58aa0860 (patch)
tree9aeee1019d6e7e1b9d92b33e12aadf8811fcebce /cpp/sca/modules/cache/diskcache-test.cpp
parentec5f59dac8d5eca3504ec5fe205dcb7d8fd382a6 (diff)
Added SCDL parsing functions. Refactored cache support with disk-cached functions that can be used to cache SCDL files. Minor makefile updates to get build and ctags working on Ubuntu 9.10.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@880599 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r--cpp/sca/modules/cache/diskcache-test.cpp (renamed from cpp/sca/modules/cache/cache-test.cpp)40
1 files changed, 31 insertions, 9 deletions
diff --git a/cpp/sca/modules/cache/cache-test.cpp b/cpp/sca/modules/cache/diskcache-test.cpp
index 776ac72363..3b21de7b9e 100644
--- a/cpp/sca/modules/cache/cache-test.cpp
+++ b/cpp/sca/modules/cache/diskcache-test.cpp
@@ -20,28 +20,50 @@
/* $Rev$ $Date$ */
/**
- * Test Memcached access functions.
+ * Test cache functions.
*/
#include <assert.h>
+#include <sys/time.h>
+#include <time.h>
#include <iostream>
#include <string>
+#include <fstream>
+#include "slist.hpp"
#include "cache.hpp"
namespace tuscany {
namespace cache {
+const std::string fileRead(const std::string path) {
+ std::ifstream is(path);
+ return car(streamList(is));
+}
+
bool testCache() {
- Cache cache;
- addServer("localhost", 11311, cache);
+ const std::string p("tmp/test.txt");
+ const lambda<std::string(std::string)> fr(fileRead);
+ const lambda<time_t(std::string)> ft(latestFileTime);
+
+ const cached<std::string> c(curry(fr, p), curry(ft, p));
+
+ {
+ std::ofstream os(p);
+ os << "initial";
+ os.close();
+ assert(std::string(latest(c)) == std::string("initial"));
+ }
- assert(hasValue(post("a", "AAA", cache)));
- assert(get("a", cache) == value(std::string("AAA")));
- assert(hasValue(put("a", "aaa", cache)));
- assert(get("a", cache) == value(std::string("aaa")));
- assert(hasValue(del("a", cache)));
- assert(!hasValue(get("a", cache)));
+ usleep(1000000);
+ {
+ std::ofstream os(p);
+ os << "updated";
+ os.close();
+ assert(latest(c) != c);
+ assert(std::string(latest(c)) == std::string("updated"));
+ assert(latest(c) == latest(c));
+ }
return true;
}