commit | author | age
|
143fc9
|
1 |
/*
|
JM |
2 |
* Copyright 2011 gitblit.com.
|
|
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 |
package com.gitblit.tests;
|
|
17 |
|
7e8873
|
18 |
import static org.junit.Assert.assertEquals;
|
JM |
19 |
import static org.junit.Assert.assertFalse;
|
|
20 |
import static org.junit.Assert.assertTrue;
|
|
21 |
|
143fc9
|
22 |
import java.util.Date;
|
JM |
23 |
|
7e8873
|
24 |
import org.junit.Test;
|
143fc9
|
25 |
|
JM |
26 |
import com.gitblit.utils.ObjectCache;
|
|
27 |
|
7e8873
|
28 |
public class ObjectCacheTest {
|
143fc9
|
29 |
|
7e8873
|
30 |
@Test
|
143fc9
|
31 |
public void testCache() throws Exception {
|
JM |
32 |
ObjectCache<String> cache = new ObjectCache<String>();
|
|
33 |
cache.updateObject("test", "alpha");
|
|
34 |
Date date = cache.getDate("test");
|
|
35 |
assertTrue("cache date is not working!", cache.hasCurrent("test", date));
|
|
36 |
// The cache is time-based (msecs) so we insert this artificial sleep to
|
|
37 |
// ensure that time (msecs) advances. The ObjectCache class is suitable
|
|
38 |
// for Gitblit's needs but may not be suitable for other needs.
|
|
39 |
Thread.sleep(10);
|
|
40 |
cache.updateObject("test", "beta");
|
|
41 |
assertFalse("update cache date is not working!", cache.hasCurrent("test", date));
|
|
42 |
assertEquals("unexpected cache object", cache.getObject("test"), "beta");
|
|
43 |
assertEquals("beta", cache.remove("test"));
|
|
44 |
assertEquals(null, cache.getObject("test"));
|
|
45 |
assertEquals(null, cache.remove("test"));
|
|
46 |
}
|
|
47 |
}
|