Page Speed Optimization Libraries  1.11.33.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
test_rewrite_driver_factory.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011 Google Inc.
3  *
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
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 
18 
19 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_TEST_REWRITE_DRIVER_FACTORY_H_
20 #define NET_INSTAWEB_REWRITER_PUBLIC_TEST_REWRITE_DRIVER_FACTORY_H_
21 
22 #include <vector>
23 
25 #include "net/instaweb/util/public/property_cache.h"
26 #include "pagespeed/kernel/base/basictypes.h"
27 #include "pagespeed/kernel/base/scoped_ptr.h"
28 #include "pagespeed/kernel/base/statistics.h"
29 #include "pagespeed/kernel/base/string.h"
30 #include "pagespeed/kernel/base/string_util.h"
31 #include "pagespeed/kernel/util/simple_stats.h"
32 
33 namespace net_instaweb {
34 
35 class CachePropertyStore;
36 class CountingUrlAsyncFetcher;
37 class DelayCache;
38 class FileSystem;
39 class Hasher;
40 class HtmlFilter;
41 class LRUCache;
42 class MemFileSystem;
43 class MessageHandler;
44 class MockHasher;
45 class MockMessageHandler;
46 class MockScheduler;
47 class MockTimer;
48 class MockTimeCache;
49 class MockUrlFetcher;
50 class NamedLockManager;
51 class NonceGenerator;
52 class ProcessContext;
53 class RateControllingUrlAsyncFetcher;
54 class ServerContext;
55 class RewriteDriver;
56 class RewriteFilter;
57 class RewriteOptions;
58 class Scheduler;
59 class TestDistributedFetcher;
60 class ThreadsafeCache;
61 class Timer;
62 class UrlAsyncFetcher;
63 class UrlNamer;
64 class WaitUrlAsyncFetcher;
65 
69  public:
70  static const int64 kStartTimeMs;
71  static const char kUrlNamerScheme[];
72 
76  static const int kMaxFetchGlobalQueueSize = 500;
77  static const int kFetchesPerHostOutgoingRequestThreshold = 100;
78  static const int kFetchesPerHostQueuedRequestThreshold = 500;
79 
81  public:
83  virtual ~CreateFilterCallback();
84  virtual HtmlFilter* Done(RewriteDriver* driver) = 0;
85 
86  private:
87 
88  };
89 
91  public:
93  virtual ~CreateRewriterCallback();
94  virtual RewriteFilter* Done(RewriteDriver* driver) = 0;
95 
96  private:
97 
98  };
99 
101  public:
104  virtual void Done(RewriteDriver* driver) = 0;
105 
106  private:
107 
108  };
109 
110  TestRewriteDriverFactory(const ProcessContext& process_context,
111  const StringPiece& temp_dir,
112  MockUrlFetcher* mock_fetcher,
113  TestDistributedFetcher* test_distributed_fetcher);
114  virtual ~TestRewriteDriverFactory();
115 
116  static void InitStats(Statistics* statistics);
117 
118  DelayCache* delay_cache() { return delay_cache_; }
119  LRUCache* lru_cache() { return lru_cache_.get(); }
120  MockTimer* mock_timer() { return mock_timer_; }
121  MockHasher* mock_hasher() { return mock_hasher_; }
122  MemFileSystem* mem_file_system() { return mem_file_system_; }
123  MockUrlFetcher* mock_url_async_fetcher() {
124  return mock_url_fetcher_;
125  }
126  WaitUrlAsyncFetcher* wait_url_async_fetcher() {
127  return wait_url_async_fetcher_.get();
128  }
129  CountingUrlAsyncFetcher* counting_url_async_fetcher() {
130  return counting_url_async_fetcher_.get();
131  }
132  CountingUrlAsyncFetcher* counting_distributed_async_fetcher() {
133  return counting_distributed_async_fetcher_;
134  }
135  MockTimeCache* mock_time_cache() { return mock_time_cache_.get(); }
136 
137  void SetupWaitFetcher();
138  void CallFetcherCallbacksForDriver(RewriteDriver* driver);
139  MockMessageHandler* mock_message_handler() { return mock_message_handler_; }
140  MockScheduler* mock_scheduler() { return mock_scheduler_; }
141  bool use_test_url_namer() const { return use_test_url_namer_; }
142  void SetUseTestUrlNamer(bool x);
143 
146  filter_callback_vector_.push_back(callback);
147  }
148 
149  void ClearFilterCallbackVector() {
150  filter_callback_vector_.clear();
151  }
152 
155  rewriter_callback_vector_.push_back(callback);
156  }
157 
158  void ClearRewriterCallbackVector() {
159  rewriter_callback_vector_.clear();
160  }
161 
163  virtual bool UseBeaconResultsInFilters() const {
164  return use_beacon_results_in_filters_;
165  }
166 
167  void set_use_beacon_results_in_filters(bool b) {
168  use_beacon_results_in_filters_ = b;
169  }
170 
174  platform_config_vector_.push_back(callback);
175  }
176 
177  void ClearPlatformSpecificConfigurationCallback() {
178  platform_config_vector_.clear();
179  }
180 
182  virtual RewriteOptions* NewRewriteOptions();
183 
185  virtual ServerContext* NewServerContext();
186 
187  virtual ServerContext* NewDecodingServerContext();
188 
189  virtual bool IsDebugClient(const GoogleString& ip) const {
190  return ip == "127.0.0.1";
191  }
192 
197  add_platform_specific_decoding_passes_ = value;
198  }
199 
200  bool add_platform_specific_decoding_passes() const {
201  return add_platform_specific_decoding_passes_;
202  }
203 
206 
208  void AdvanceTimeMs(int64 delta_ms);
209 
211  const PropertyCache::Cohort* SetupCohort(
212  PropertyCache* cache, const GoogleString& cohort_name);
213 
214  CachePropertyStore* cache_property_store() {
215  return cache_property_store_;
216  }
217 
218  protected:
219  virtual Hasher* NewHasher();
220  virtual MessageHandler* DefaultHtmlParseMessageHandler();
221  virtual MessageHandler* DefaultMessageHandler();
222  virtual UrlAsyncFetcher* DefaultAsyncUrlFetcher();
223  virtual UrlAsyncFetcher* DefaultDistributedUrlFetcher();
224  virtual FileSystem* DefaultFileSystem();
225  virtual NonceGenerator* DefaultNonceGenerator();
226  virtual Timer* DefaultTimer();
227  virtual void SetupCaches(ServerContext* server_context);
228  virtual UrlNamer* DefaultUrlNamer();
229  virtual Scheduler* CreateScheduler();
230  virtual void AddPlatformSpecificDecodingPasses(RewriteDriver* driver);
231  virtual void AddPlatformSpecificRewritePasses(RewriteDriver* driver);
232  virtual void ApplyPlatformSpecificConfiguration(RewriteDriver* driver);
233  virtual NamedLockManager* DefaultLockManager();
234 
235  private:
236  MockTimer* mock_timer_;
237  MockScheduler* mock_scheduler_;
238  DelayCache* delay_cache_;
239  scoped_ptr<ThreadsafeCache> threadsafe_cache_;
240  scoped_ptr<LRUCache> lru_cache_;
241  MockUrlFetcher* mock_url_fetcher_;
242  TestDistributedFetcher* test_distributed_fetcher_;
243  scoped_ptr<CountingUrlAsyncFetcher> counting_url_async_fetcher_;
244  RateControllingUrlAsyncFetcher* rate_controlling_url_async_fetcher_;
245  CountingUrlAsyncFetcher* counting_distributed_async_fetcher_;
246  scoped_ptr<WaitUrlAsyncFetcher> wait_url_async_fetcher_;
247  scoped_ptr<MockTimeCache> mock_time_cache_;
248  MemFileSystem* mem_file_system_;
249  MockHasher* mock_hasher_;
250  SimpleStats simple_stats_;
251  MockMessageHandler* mock_message_handler_;
252  MockMessageHandler* mock_html_message_handler_;
253  bool use_beacon_results_in_filters_;
254  bool use_test_url_namer_;
255  bool add_platform_specific_decoding_passes_;
256  std::vector<CreateFilterCallback*> filter_callback_vector_;
257  std::vector<CreateRewriterCallback*> rewriter_callback_vector_;
258  std::vector<PlatformSpecificConfigurationCallback*> platform_config_vector_;
259  CachePropertyStore* cache_property_store_;
260 };
261 
262 }
263 
264 #endif
Definition: test_rewrite_driver_factory.h:68
virtual ServerContext * NewServerContext()
Note that this enables html proxying.
static const char kUrlNamerScheme[]
Env.var URL_NAMER_SCHEME.
Definition: test_rewrite_driver_factory.h:71
virtual void ApplyPlatformSpecificConfiguration(RewriteDriver *driver)
virtual void SetupCaches(ServerContext *server_context)
void RebuildDecodingDriverForTests(ServerContext *server_context)
For use in tests.
virtual bool IsDebugClient(const GoogleString &ip) const
Base method that returns true if the given ip is a debug ip.
Definition: test_rewrite_driver_factory.h:189
Definition: test_rewrite_driver_factory.h:80
Definition: test_rewrite_driver_factory.h:90
virtual Scheduler * CreateScheduler()
void AddPlatformSpecificConfigurationCallback(PlatformSpecificConfigurationCallback *callback)
Does NOT take ownership of the callback.
Definition: test_rewrite_driver_factory.h:172
virtual NamedLockManager * DefaultLockManager()
void set_add_platform_specific_decoding_passes(bool value)
Definition: test_rewrite_driver_factory.h:196
virtual void AddPlatformSpecificDecodingPasses(RewriteDriver *driver)
Definition: test_distributed_fetcher.h:37
static const int64 kStartTimeMs
Arbitrary time to start MockTimer.
Definition: test_rewrite_driver_factory.h:70
virtual bool UseBeaconResultsInFilters() const
By default this is false, but can be reset.
Definition: test_rewrite_driver_factory.h:163
virtual void AddPlatformSpecificRewritePasses(RewriteDriver *driver)
Definition: rewrite_filter.h:35
Definition: mock_url_fetcher.h:41
void AddCreateRewriterCallback(CreateRewriterCallback *callback)
Does NOT take ownership of the callback.
Definition: test_rewrite_driver_factory.h:154
Definition: rewrite_driver.h:98
Definition: process_context.h:35
static const int kMaxFetchGlobalQueueSize
Definition: test_rewrite_driver_factory.h:76
Statistics * statistics()
Definition: rewrite_driver_factory.h:250
virtual ServerContext * NewDecodingServerContext()
virtual RewriteOptions * NewRewriteOptions()
Note that this disables ajax rewriting by default.
virtual UrlAsyncFetcher * DefaultAsyncUrlFetcher()
const PropertyCache::Cohort * SetupCohort(PropertyCache *cache, const GoogleString &cohort_name)
Sets up the cohort in the PropertyCache provided.
void AdvanceTimeMs(int64 delta_ms)
Advances the mock scheduler by delta_ms.
void AddCreateFilterCallback(CreateFilterCallback *callback)
Does NOT take ownership of the callback.
Definition: test_rewrite_driver_factory.h:145
Definition: rewrite_driver_factory.h:70