View Javadoc
1   /*
2    * Copyright (C) 2015 eXo Platform SAS.
3    *
4    * This is free software; you can redistribute it and/or modify it
5    * under the terms of the GNU Lesser General Public License as
6    * published by the Free Software Foundation; either version 2.1 of
7    * the License, or (at your option) any later version.
8    *
9    * This software is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   * Lesser General Public License for more details.
13   *
14   * You should have received a copy of the GNU Lesser General Public
15   * License along with this software; if not, write to the Free
16   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
17   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
18   */
19  
20  package org.exoplatform.wiki.jpa.mock;
21  
22  import org.exoplatform.commons.search.index.IndexingService;
23  
24  import java.util.HashMap;
25  import java.util.Map;
26  
27  /**
28   * @author <a href="mailto:tuyennt@exoplatform.com">Tuyen Nguyen The</a>.
29   */
30  public class MockIndexingService implements IndexingService {
31  
32    private Map<String, Integer> count = new HashMap<>();
33  
34    @Override
35    public void init(String s) {
36      increaseCount("init");
37    }
38  
39    @Override
40    public void index(String s, String s1) {
41      increaseCount("index");
42    }
43  
44    @Override
45    public void reindex(String s, String s1) {
46      increaseCount("reindex");
47    }
48  
49    @Override
50    public void unindex(String s, String s1) {
51      increaseCount("unindex");
52    }
53  
54    @Override
55    public void reindexAll(String s) {
56      increaseCount("reindexAll");
57    }
58  
59    @Override
60    public void unindexAll(String s) {
61      increaseCount("unindexAll");
62    }
63  
64    @Override
65    public void clearQueue() {
66      increaseCount("clearQueue");
67    }
68  
69    @Override
70    public void clearQueue(String entityType) {
71      increaseCount("clearQueueByEntityType");
72    }
73  
74    private synchronized void increaseCount(String name) {
75      Integer v = count.get(name);
76      if (v == null) {
77        v = 0;
78      } else {
79        v ++;
80      }
81      count.put(name, v);
82    }
83  
84    public int getCount(String name) {
85      Integer v = count.get(name);
86      if (v != null) {
87        return v.intValue();
88      } else {
89        return 0;
90      }
91    }
92  }