2
* Copyright 2010 Google Inc.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
16
// Author: jmarantz@google.com (Joshua Marantz)
18
// Helper class for sending concurrent traffic to a cache during unit tests.
20
#ifndef PAGESPEED_KERNEL_CACHE_CACHE_SPAMMER_H_
21
#define PAGESPEED_KERNEL_CACHE_CACHE_SPAMMER_H_
23
#include "pagespeed/kernel/base/basictypes.h"
24
#include "pagespeed/kernel/base/thread.h"
25
#include "pagespeed/kernel/base/thread_system.h"
27
namespace net_instaweb {
31
// Helper class for blasting a cache with concurrent requests. Refactored
32
// from threadsafe_cache_test.cc.
33
class CacheSpammer : public ThreadSystem::Thread {
35
virtual ~CacheSpammer();
37
// value_pattern will be used as a format string, and must have a single %d.
38
// num_threads indicates how many threads will run in parallel.
39
// num_iters indicates how many times each thread will run a big loop.
40
// num_inserts sets the number of keys inserted and looked up in the loop.
42
// num_iters will be divided down by 100 when running on valgrind.
43
static void RunTests(int num_threads, int num_iters, int num_inserts,
44
bool expecting_evictions, bool do_deletes,
45
const char* value_pattern,
46
CacheInterface* cache,
47
ThreadSystem* thread_runtime);
53
CacheSpammer(ThreadSystem* runtime,
54
ThreadSystem::ThreadFlags flags,
55
CacheInterface* cache,
56
bool expecting_evictions,
58
const char* value_pattern,
63
CacheInterface* cache_;
64
bool expecting_evictions_;
66
const char* value_pattern_;
71
DISALLOW_COPY_AND_ASSIGN(CacheSpammer);
74
} // namespace net_instaweb
76
#endif // PAGESPEED_KERNEL_CACHE_CACHE_SPAMMER_H_