File path: /hibernate-distribution-3.3.2.GA/project/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/AbstractEntityCacheFunctionalTestCase.java | File path: /hibernate-distribution-3.3.2.GA/project/testing/src/main/java/org/hibernate/test/cache/BaseCacheProviderTestCase.java | |||
Method name: void testStaleWritesLeaveCacheConsistent()
|
Method name: void testStaleWritesLeaveCacheConsistent()
|
|||
Number of AST nodes: 30 | Number of AST nodes: 30 | |||
1 | Session s = openSession();↵ | 1 | Session s = openSession();↵ | |
2 | Transaction txn = s.beginTransaction();↵ | 2 | Transaction txn = s.beginTransaction();↵ | |
3 | VersionedItem item = new VersionedItem();↵ | 3 | VersionedItem item = new VersionedItem();↵ | |
4 | item.setName("steve");↵ | 4 | item.setName( "steve" );↵ | |
5 | item.setDescription("steve's item");↵ | 5 | item.setDescription( "steve's item" );↵ | |
6 | s.save(item);↵ | 6 | s.save( item );↵ | |
7 | txn.commit();↵ | 7 | txn.commit();↵ | |
8 | s.close();↵ | 8 | s.close();↵ | |
9 | Long initialVersion = item.getVersion();↵ | 9 | Long initialVersion = item.getVersion();↵ | |
10 | // manually revert the version property↵ | 10 | // manually revert the version property↵ | |
11 | item.setVersion(new Long(item.getVersion().longValue() - 1));↵ | 11 | item.setVersion( new Long( item.getVersion().longValue() - 1 ) );↵ | |
12 | try {↵ | |||
13 | ↵ | 12 | try {↵ | |
14 | s = openSession();↵ | 13 | s = openSession();↵ | |
15 | txn = s.beginTransaction();↵ | 14 | txn = s.beginTransaction();↵ | |
16 | s.update(item);↵ | 15 | s.update( item );↵ | |
17 | txn.commit();↵ | 16 | txn.commit();↵ | |
18 | s.close();↵ | |||
19 | ↵ | 17 | s.close();↵ | |
20 | fail("expected stale write to fail");↵ | 18 | fail( "expected stale write to fail" );↵ | |
21 | } ↵ | 19 | }↵ | |
22 | catch (Throwable expected) {↵ | 20 | catch( Throwable expected ) {↵ | |
23 | // expected behavior here↵ | 21 | // expected behavior here↵ | |
24 | if (txn != null) {↵ | 22 | if ( txn != null ) {↵ | |
25 | try {↵ | |||
26 | txn.rollback();↵ | |||
27 | } ↵ | 23 | try {↵ | |
24 | txn.rollback();↵ | |||
25 | }↵ | |||
28 | catch (Throwable ignore) {↵ | 26 | catch( Throwable ignore ) {↵ | |
29 | }↵ | |||
30 | }↵ | |||
31 | } finally {↵ | |||
32 | ↵ | 27 | }↵ | |
28 | }↵ | |||
29 | }↵ | |||
30 | finally {↵ | |||
33 | if (s != null && s.isOpen()) {↵ | 31 | if ( s != null && s.isOpen() ) {↵ | |
34 | try {↵ | |||
35 | s.close();↵ | |||
36 | } ↵ | 32 | try {↵ | |
33 | s.close();↵ | |||
34 | }↵ | |||
37 | catch (Throwable ignore) {↵ | 35 | catch( Throwable ignore ) {↵ | |
38 | }↵ | |||
39 | }↵ | |||
40 | }↵ | |||
41 | ↵ | 36 | }↵ | |
37 | }↵ | |||
38 | }↵ | |||
42 | // check the version value in the cache...↵ | 39 | // check the version value in the cache...↵ | |
43 | SecondLevelCacheStatistics slcs = sfi().getStatistics()↵ | 40 | SecondLevelCacheStatistics slcs = sfi().getStatistics()↵ | |
44 | .getSecondLevelCacheStatistics(↵ | 41 | .getSecondLevelCacheStatistics(↵ | |
45 | getPrefixedRegionName(VersionedItem.class.getName()));↵ | 42 | VersionedItem.class.getName() );↵ | |
46 | Object entry = slcs.getEntries().get(item.getId());↵ | 43 | Object entry = slcs.getEntries().get( item.getId() );↵ | |
47 | Long cachedVersionValue;↵ | 44 | Long cachedVersionValue;↵ | |
48 | if (entry instanceof ReadWriteCache.Lock) {↵ | 45 | if ( entry instanceof ReadWriteCache.Lock ) {↵ | |
49 | // FIXME don't know what to test here↵ | 46 | //FIXME don't know what to test here↵ | |
50 | cachedVersionValue = new Long(((ReadWriteCache.Lock) entry).getUnlockTimestamp());↵ | 47 | cachedVersionValue = new Long( ( (ReadWriteCache.Lock) entry).getUnlockTimestamp() );↵ | |
51 | } else {↵ | |||
52 | ↵ | 48 | }↵ | |
49 | else {↵ | |||
53 | cachedVersionValue = (Long) ((Map) entry).get("_version");↵ | 50 | cachedVersionValue = ( Long ) ( (Map) entry ).get( "_version" );↵ | |
54 | assertEquals(initialVersion.longValue(), cachedVersionValue.longValue());↵ | 51 | assertEquals( initialVersion.longValue(), cachedVersionValue.longValue() );↵ | |
55 | }↵ | |||
56 | ↵ | 52 | }↵ | |
57 | // cleanup↵ | 53 | // cleanup↵ | |
58 | s = openSession();↵ | 54 | s = openSession();↵ | |
59 | txn = s.beginTransaction();↵ | 55 | txn = s.beginTransaction();↵ | |
60 | item = (VersionedItem) s.load(VersionedItem.class, item.getId());↵ | 56 | item = ( VersionedItem ) s.load( VersionedItem.class, item.getId() );↵ | |
61 | s.delete(item);↵ | 57 | s.delete( item );↵ | |
62 | txn.commit();↵ | 58 | txn.commit();↵ | |
63 | s.close(); | 59 | s.close(); | |
See real code fragment | See real code fragment |
Number of common nesting structure subtrees | 1 |
Number of refactorable cases | 0 |
Number of non-refactorable cases | 1 |
Time elapsed for finding largest common nesting structure subtrees (ms) | 1.7 |
Clones location | Clones are in different classes having the same super class |
Number of node comparisons | 228 |
Number of mapped statements | 27 |
Number of unmapped statements in the first code fragment | 3 |
Number of unmapped statements in the second code fragment | 3 |
Time elapsed for statement mapping (ms) | 65.3 |
Clone type | Type 2 |
ID | Statement | ID | Statement | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | Session s = openSession(); | 1 | Session s = openSession(); | ||||||||||||||||
2 | Transaction txn = s.beginTransaction(); | 2 | Transaction txn = s.beginTransaction(); | ||||||||||||||||
| 3 | VersionedItem item = new VersionedItem(); | |||||||||||||||||
3 | VersionedItem item = new VersionedItem(); | | |||||||||||||||||
4 | item.setName("steve"); |
| 4 | item.setName("steve"); | |||||||||||||||
5 | item.setDescription("steve's item"); |
| 5 | item.setDescription("steve's item"); | |||||||||||||||
6 | s.save(item); |
| 6 | s.save(item); | |||||||||||||||
7 | txn.commit(); | 7 | txn.commit(); | ||||||||||||||||
8 | s.close(); | 8 | s.close(); | ||||||||||||||||
9 | Long initialVersion = item.getVersion(); |
| 9 | Long initialVersion = item.getVersion(); | |||||||||||||||
10 | item.setVersion(new Long(item.getVersion().longValue() - 1)); |
| 10 | item.setVersion(new Long(item.getVersion().longValue() - 1)); | |||||||||||||||
11 | try | 11 | try | ||||||||||||||||
12 | s = openSession(); | 12 | s = openSession(); | ||||||||||||||||
13 | txn = s.beginTransaction(); | 13 | txn = s.beginTransaction(); | ||||||||||||||||
14 | s.update(item); |
| 14 | s.update(item); | |||||||||||||||
15 | txn.commit(); | 15 | txn.commit(); | ||||||||||||||||
16 | s.close(); | 16 | s.close(); | ||||||||||||||||
17 | fail("expected stale write to fail"); | 17 | fail("expected stale write to fail"); | ||||||||||||||||
| 18 | SecondLevelCacheStatistics slcs = sfi().getStatistics().getSecondLevelCacheStatistics(VersionedItem.class.getName()); | |||||||||||||||||
18 | SecondLevelCacheStatistics slcs = sfi().getStatistics().getSecondLevelCacheStatistics(getPrefixedRegionName(VersionedItem.class.getName())); | | |||||||||||||||||
19 | Object entry = slcs.getEntries().get(item.getId()); |
| 19 | Object entry = slcs.getEntries().get(item.getId()); | |||||||||||||||
20 | Long cachedVersionValue; | 20 | Long cachedVersionValue; | ||||||||||||||||
21 | if (entry instanceof ReadWriteCache.Lock) | 21 | if (entry instanceof ReadWriteCache.Lock) | ||||||||||||||||
22 | cachedVersionValue = new Long(((ReadWriteCache.Lock)entry).getUnlockTimestamp()); | 22 | cachedVersionValue = new Long(((ReadWriteCache.Lock)entry).getUnlockTimestamp()); | ||||||||||||||||
else | else | ||||||||||||||||||
23 | cachedVersionValue = (Long)((Map)entry).get("_version"); | 23 | cachedVersionValue = (Long)((Map)entry).get("_version"); | ||||||||||||||||
24 | assertEquals(initialVersion.longValue(), cachedVersionValue.longValue()); | 24 | assertEquals(initialVersion.longValue(), cachedVersionValue.longValue()); | ||||||||||||||||
25 | s = openSession(); | 25 | s = openSession(); | ||||||||||||||||
26 | txn = s.beginTransaction(); | 26 | txn = s.beginTransaction(); | ||||||||||||||||
|
| 27 | item = (VersionedItem)s.load(VersionedItem.class, item.getId()); | ||||||||||||||||
27 | item = (VersionedItem)s.load(VersionedItem.class, item.getId()); |
| | ||||||||||||||||
28 | s.delete(item); |
| 28 | s.delete(item); | |||||||||||||||
29 | txn.commit(); | 29 | txn.commit(); | ||||||||||||||||
30 | s.close(); | 30 | s.close(); |
Row | Violation |
---|---|
1 | Type org.hibernate.test.cache.jbc2.functional.VersionedItem of variable item does not match with type org.hibernate.test.cache.VersionedItem of variable item |
2 | Type org.hibernate.test.cache.jbc2.functional.VersionedItem of variable item does not match with type org.hibernate.test.cache.VersionedItem of variable item |
3 | Type org.hibernate.test.cache.jbc2.functional.VersionedItem of variable item does not match with type org.hibernate.test.cache.VersionedItem of variable item |
4 | Type org.hibernate.test.cache.jbc2.functional.VersionedItem of variable item does not match with type org.hibernate.test.cache.VersionedItem of variable item |
5 | Type org.hibernate.test.cache.jbc2.functional.VersionedItem of variable item does not match with type org.hibernate.test.cache.VersionedItem of variable item |
6 | Type org.hibernate.test.cache.jbc2.functional.VersionedItem of variable item does not match with type org.hibernate.test.cache.VersionedItem of variable item |
7 | Type org.hibernate.test.cache.jbc2.functional.VersionedItem of variable item does not match with type org.hibernate.test.cache.VersionedItem of variable item |
8 | Type org.hibernate.test.cache.jbc2.functional.VersionedItem of variable item does not match with type org.hibernate.test.cache.VersionedItem of variable item |
9 | Unmatched statement item=(VersionedItem)s.load(VersionedItem.class,item.getId()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
10 | Unmatched statement item=(VersionedItem)s.load(VersionedItem.class,item.getId()); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
11 | Type org.hibernate.test.cache.jbc2.functional.VersionedItem of variable item does not match with type org.hibernate.test.cache.VersionedItem of variable item |