View Javadoc
1   package org.apache.commons.jcs.auxiliary;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.commons.jcs.engine.logging.CacheEvent;
23  import org.apache.commons.jcs.engine.logging.behavior.ICacheEvent;
24  import org.apache.commons.jcs.engine.logging.behavior.ICacheEventLogger;
25  
26  import java.util.ArrayList;
27  import java.util.List;
28  
29  /**
30   * For testing auxiliary event logging. Improve later so we can test the details. This is very
31   * crude.
32   */
33  public class MockCacheEventLogger
34      implements ICacheEventLogger
35  {
36      /** times called */
37      public int applicationEventCalls = 0;
38  
39      /** times called */
40      public int startICacheEventCalls = 0;
41  
42      /** times called */
43      public int endICacheEventCalls = 0;
44  
45      /** times called */
46      public int errorEventCalls = 0;
47  
48      /** list of messages */
49      public List<String> errorMessages = new ArrayList<String>();
50  
51      /**
52       * @param source
53       * @param eventName
54       * @param optionalDetails
55       */
56      @Override
57      public void logApplicationEvent( String source, String eventName, String optionalDetails )
58      {
59          applicationEventCalls++;
60      }
61  
62      /**
63       * @param event
64       */
65      @Override
66      public <T> void logICacheEvent( ICacheEvent<T> event )
67      {
68          endICacheEventCalls++;
69      }
70  
71      /**
72       * @param source
73       * @param eventName
74       * @param errorMessage
75       */
76      @Override
77      public void logError( String source, String eventName, String errorMessage )
78      {
79          errorEventCalls++;
80          errorMessages.add( errorMessage );
81      }
82  
83      /**
84       * @param source
85       * @param region
86       * @param eventName
87       * @param optionalDetails
88       * @param key
89       * @return ICacheEvent
90       */
91      @Override
92      public <T> ICacheEvent<T> createICacheEvent( String source, String region,
93              String eventName, String optionalDetails, T key )
94      {
95          startICacheEventCalls++;
96          return new CacheEvent<T>();
97      }
98  }