Skip to content

Commit 2057bb3

Browse files
rvansagalderz
authored andcommitted
HHH-10023 Make hibernate-infinispan compiled with Infinispan 7.x but runnable with Infinispan 8.x
* workaround for ISPN-5676 * fix for ClassCastException in ClusteredTimestampsRegionImpl * minor fixes in the testsuite
1 parent 3bd3f54 commit 2057bb3

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/timestamp/ClusteredTimestampsRegionImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@ public void destroy() throws CacheException {
122122
* Brings all data from the distributed cache into our local cache.
123123
*/
124124
private void populateLocalCache() {
125-
CloseableIterable<CacheEntry<Object, Void>> iterable = Caches.keys(cache);
125+
CloseableIterable<Object> iterable = Caches.keys(cache);
126126
try {
127-
for (CacheEntry<Object, Void> entry : iterable) {
128-
get(null, entry.getKey());
127+
for (Object key : iterable) {
128+
get(null, key);
129129
}
130130
}
131131
finally {

hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/Caches.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,10 @@ public interface CollectableCloseableIterable extends CloseableIterable {
291291
}
292292

293293
public static CollectableCloseableIterable keys(AdvancedCache cache) {
294+
if (cache.getCacheConfiguration().transaction().transactionMode().isTransactional()) {
295+
// Dummy read to enlist the LocalTransaction as workaround for ISPN-5676
296+
cache.containsKey(false);
297+
}
294298
// HHH-10023: we can't use keySet()
295299
final CloseableIterable<CacheEntry<Object, Void>> entryIterable = cache
296300
.filterEntries( AcceptAllKeyValueFilter.getInstance() )

hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/collection/TransactionalExtraAPITestCase.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.hibernate.cache.spi.access.AccessType;
1414
import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy;
1515
import org.hibernate.cache.spi.access.SoftLock;
16+
import org.hibernate.engine.spi.SessionImplementor;
1617
import org.hibernate.internal.util.compare.ComparableComparator;
1718
import org.hibernate.test.cache.infinispan.AbstractNonFunctionalTestCase;
1819
import org.hibernate.test.cache.infinispan.NodeEnvironment;
@@ -25,6 +26,7 @@
2526
import org.junit.Test;
2627

2728
import static org.junit.Assert.assertNull;
29+
import static org.mockito.Mockito.mock;
2830

2931
/**
3032
* TransactionalExtraAPITestCase.
@@ -41,6 +43,7 @@ public class TransactionalExtraAPITestCase extends AbstractNonFunctionalTestCase
4143
public static final Object KEY = TestingKeyFactory.generateCollectionCacheKey( "KEY" );
4244
public static final CacheDataDescription CACHE_DATA_DESCRIPTION
4345
= new CacheDataDescriptionImpl(false, false, ComparableComparator.INSTANCE, null);
46+
private static final SessionImplementor SESSION = mock(SessionImplementor.class);
4447

4548
private NodeEnvironment environment;
4649
private static CollectionRegionAccessStrategy accessStrategy;
@@ -85,7 +88,7 @@ protected CollectionRegionAccessStrategy getCollectionAccessStrategy() {
8588

8689
@Test
8790
public void testLockItem() {
88-
assertNull( getCollectionAccessStrategy().lockItem(null, KEY, new Integer( 1 ) ) );
91+
assertNull( getCollectionAccessStrategy().lockItem(SESSION, KEY, new Integer( 1 ) ) );
8992
}
9093

9194
@Test
@@ -95,12 +98,12 @@ public void testLockRegion() {
9598

9699
@Test
97100
public void testUnlockItem() {
98-
getCollectionAccessStrategy().unlockItem(null, KEY, new MockSoftLock() );
101+
getCollectionAccessStrategy().unlockItem(SESSION, KEY, new MockSoftLock() );
99102
}
100103

101104
@Test
102105
public void testUnlockRegion() {
103-
getCollectionAccessStrategy().unlockItem(null, KEY, new MockSoftLock() );
106+
getCollectionAccessStrategy().unlockItem(SESSION, KEY, new MockSoftLock() );
104107
}
105108

106109
public static class MockSoftLock implements SoftLock {

hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/TransactionalExtraAPITestCase.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.hibernate.cache.spi.access.AccessType;
1313
import org.hibernate.cache.spi.access.EntityRegionAccessStrategy;
1414
import org.hibernate.cache.spi.access.SoftLock;
15+
import org.hibernate.engine.spi.SessionImplementor;
1516
import org.hibernate.internal.util.compare.ComparableComparator;
1617
import org.hibernate.test.cache.infinispan.AbstractNonFunctionalTestCase;
1718
import org.hibernate.test.cache.infinispan.NodeEnvironment;
@@ -25,6 +26,7 @@
2526

2627
import static org.junit.Assert.assertFalse;
2728
import static org.junit.Assert.assertNull;
29+
import static org.mockito.Mockito.mock;
2830

2931
/**
3032
* Tests for the "extra API" in EntityRegionAccessStrategy;.
@@ -47,6 +49,7 @@ public class TransactionalExtraAPITestCase extends AbstractNonFunctionalTestCase
4749
public static final String VALUE2 = "VALUE2";
4850
protected static final CacheDataDescriptionImpl CACHE_DATA_DESCRIPTION
4951
= new CacheDataDescriptionImpl(true, false, ComparableComparator.INSTANCE, null);
52+
private static final SessionImplementor SESSION = mock(SessionImplementor.class);
5053

5154
private NodeEnvironment environment;
5255
private EntityRegionAccessStrategy accessStrategy;
@@ -95,7 +98,7 @@ protected AccessType getAccessType() {
9598
@Test
9699
@SuppressWarnings( {"UnnecessaryBoxing"})
97100
public void testLockItem() {
98-
assertNull( getEntityAccessStrategy().lockItem(null, KEY, Integer.valueOf( 1 ) ) );
101+
assertNull( getEntityAccessStrategy().lockItem(SESSION, KEY, Integer.valueOf( 1 ) ) );
99102
}
100103

101104
@Test
@@ -105,20 +108,20 @@ public void testLockRegion() {
105108

106109
@Test
107110
public void testUnlockItem() {
108-
getEntityAccessStrategy().unlockItem(null, KEY, new MockSoftLock() );
111+
getEntityAccessStrategy().unlockItem(SESSION, KEY, new MockSoftLock() );
109112
}
110113

111114
@Test
112115
public void testUnlockRegion() {
113-
getEntityAccessStrategy().unlockItem(null, KEY, new MockSoftLock() );
116+
getEntityAccessStrategy().unlockItem(SESSION, KEY, new MockSoftLock() );
114117
}
115118

116119
@Test
117120
@SuppressWarnings( {"UnnecessaryBoxing"})
118121
public void testAfterInsert() {
119122
assertFalse(
120123
"afterInsert always returns false",
121-
getEntityAccessStrategy().afterInsert(null,
124+
getEntityAccessStrategy().afterInsert(SESSION,
122125
KEY,
123126
VALUE1,
124127
Integer.valueOf( 1 )
@@ -131,7 +134,7 @@ public void testAfterInsert() {
131134
public void testAfterUpdate() {
132135
assertFalse(
133136
"afterInsert always returns false",
134-
getEntityAccessStrategy().afterUpdate(null,
137+
getEntityAccessStrategy().afterUpdate(SESSION,
135138
KEY,
136139
VALUE2,
137140
Integer.valueOf( 1 ),

0 commit comments

Comments
 (0)