1 /***
2 * Copyright 2003-2010 Terracotta, 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
17 package net.sf.ehcache;
18
19 import org.junit.Test;
20 import net.sf.ehcache.store.MemoryStoreEvictionPolicy;
21
22 import static org.junit.Assert.assertEquals;
23
24 public class AutoVersioningElementTest {
25
26 @Test
27 public void testVersioningCanRevertToOldBehavior() {
28 System.setProperty("net.sf.ehcache.element.version.auto", "true");
29 try {
30 CacheManager cacheManager = CacheManager.getInstance();
31 cacheManager.addCache(new Cache("mltest", 50,
32 MemoryStoreEvictionPolicy.LRU, true, null, true, 0, 0, false, 120, null, null, 0, 2, false));
33 Cache cache = cacheManager.getCache("mltest");
34
35 Element a = new Element("a key", "a value", 1L);
36 cache.put(a);
37 Element aAfter = cache.get("a key");
38 assertEquals(1L, aAfter.getVersion());
39
40 Element b = new Element("a key", "a value");
41 cache.put(b);
42 Element bAfter = cache.get("a key");
43 assertEquals(bAfter.getLastUpdateTime(), bAfter.getVersion());
44
45 Element c = new Element("a key", "a value", 3L);
46 cache.put(c);
47 Element cAfter = cache.get("a key");
48 assertEquals(cAfter.getLastUpdateTime(), cAfter.getVersion());
49 } finally {
50 System.getProperties().remove("net.sf.ehcache.element.version.auto");
51 }
52 }
53 }