Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
shared_mem_cache_test_base.h
Go to the documentation of this file.
1 // Copyright 2011 Google Inc.
16 
17 #ifndef PAGESPEED_KERNEL_SHAREDMEM_SHARED_MEM_CACHE_TEST_BASE_H_
18 #define PAGESPEED_KERNEL_SHAREDMEM_SHARED_MEM_CACHE_TEST_BASE_H_
19 
34 
35 namespace net_instaweb {
36 
37 class SharedMemCacheDump;
38 class ThreadSystem;
39 
41  protected:
42  typedef void (SharedMemCacheTestBase::*TestMethod)();
43  static const int kBlockSize = 512;
44 
45  explicit SharedMemCacheTestBase(SharedMemTestEnv* test_env);
46 
47  virtual void TearDown();
48 
49  virtual SharedMemCache<kBlockSize>* Cache() { return cache_.get(); }
50  virtual void SanityCheck();
51 
52  void TestBasic();
53  void TestReinsert();
54  void TestReplacement();
55  void TestReaderWriter();
56  void TestConflict();
57  void TestEvict();
58  void TestSnapshot();
59  void TestRegisterSnapshotFileCache();
60  void TestCheckpointAndRestore();
61 
62  void ResetCache();
63 
64  private:
65  bool CreateChild(TestMethod method);
66 
67  void CheckDumpsEqual(const SharedMemCacheDump& a,
68  const SharedMemCacheDump& b,
69  const char* test_label);
70 
71  SharedMemCache<kBlockSize>* MakeCache();
72  void CheckDelete(const char* key);
73  void TestReaderWriterChild();
74 
76  scoped_ptr<AbstractSharedMem> shmem_runtime_;
78  MD5Hasher hasher_;
79  scoped_ptr<ThreadSystem> thread_system_;
80  MockMessageHandler handler_;
81  MockTimer timer_;
82 
83  GoogleString large_;
84  GoogleString gigantic_;
85 
86  bool sanity_checks_enabled_;
87 
88 
89 };
90 
92  public:
94  ThreadSystem* thread_system,
95  Timer* timer,
96  MessageHandler* handler) {
97  filesystem_.reset(new MemFileSystem(thread_system, timer));
98  worker_.reset(new SlowWorker("slow worker", thread_system));
99  stats_.reset(new SimpleStats(thread_system));
100  FileCache::InitStats(stats_.get());
101  hasher_.reset(new MD5Hasher());
102  file_cache_.reset(new FileCache(
103  path, filesystem_.get(), thread_system, worker_.get(),
104  new FileCache::CachePolicy(timer, hasher_.get(),
105  20*60*1000,
106  10*1024*1024,
107  1024*1024),
108  stats_.get(), handler));
109  }
111 
112  FileCache* file_cache() {
113  return file_cache_.get();
114  }
115  MemFileSystem* filesystem() {
116  return filesystem_.get();
117  }
118 
119  private:
120  scoped_ptr<MemFileSystem> filesystem_;
121  scoped_ptr<SlowWorker> worker_;
122  scoped_ptr<SimpleStats> stats_;
123  scoped_ptr<MD5Hasher> hasher_;
124  scoped_ptr<FileCache> file_cache_;
125 };
126 
127 template<typename ConcreteTestEnv>
129  public:
131  : SharedMemCacheTestBase(new ConcreteTestEnv) {
132  }
133 };
134 
135 TYPED_TEST_CASE_P(SharedMemCacheTestTemplate);
136 
137 TYPED_TEST_P(SharedMemCacheTestTemplate, TestBasic) {
138  SharedMemCacheTestBase::TestBasic();
139 }
140 
141 TYPED_TEST_P(SharedMemCacheTestTemplate, TestReinsert) {
142  SharedMemCacheTestBase::TestReinsert();
143 }
144 
145 TYPED_TEST_P(SharedMemCacheTestTemplate, TestReplacement) {
146  SharedMemCacheTestBase::TestReplacement();
147 }
148 
149 TYPED_TEST_P(SharedMemCacheTestTemplate, TestReaderWriter) {
150  SharedMemCacheTestBase::TestReaderWriter();
151 }
152 
153 TYPED_TEST_P(SharedMemCacheTestTemplate, TestConflict) {
154  SharedMemCacheTestBase::TestConflict();
155 }
156 
157 TYPED_TEST_P(SharedMemCacheTestTemplate, TestEvict) {
158  SharedMemCacheTestBase::TestEvict();
159 }
160 
161 TYPED_TEST_P(SharedMemCacheTestTemplate, TestSnapshot) {
162  SharedMemCacheTestBase::TestSnapshot();
163 }
164 
165 TYPED_TEST_P(SharedMemCacheTestTemplate, TestRegisterSnapshotFileCache) {
166  SharedMemCacheTestBase::TestRegisterSnapshotFileCache();
167 }
168 
169 TYPED_TEST_P(SharedMemCacheTestTemplate, TestCheckpointAndRestore) {
170  SharedMemCacheTestBase::TestCheckpointAndRestore();
171 }
172 
173 REGISTER_TYPED_TEST_CASE_P(SharedMemCacheTestTemplate, TestBasic, TestReinsert,
174  TestReplacement, TestReaderWriter, TestConflict,
175  TestEvict, TestSnapshot,
176  TestRegisterSnapshotFileCache,
177  TestCheckpointAndRestore);
178 
179 }
180 
181 #endif
Definition: mock_timer.h:33
Definition: md5_hasher.h:28
Definition: mock_message_handler.h:39
Definition: shared_mem_cache_test_base.h:40
Definition: scoped_ptr.h:30
Simple name/value pair statistics implementation.
Definition: simple_stats.h:55
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
Definition: file_cache.h:44
FileCacheTestWrapper(const GoogleString &path, ThreadSystem *thread_system, Timer *timer, MessageHandler *handler)
Definition: shared_mem_cache_test_base.h:93
Definition: shared_mem_cache_test_base.h:91
Definition: thread_system.h:40
Abstract interface for a cache.
Definition: shared_mem_cache.h:46
Definition: message_handler.h:39
Definition: mem_file_system.h:48
Definition: shared_mem_test_base.h:33
Definition: cache_test_base.h:39
Simple C++ implementation of file cache.
Definition: file_cache.h:42
Timer interface, made virtual so it can be mocked for tests.
Definition: timer.h:27
See file comment.
Definition: slow_worker.h:35
Definition: shared_mem_cache_test_base.h:128