You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ObjectCacheTest.java 1.6KB

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