Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HHH-10023 Make hibernate-infinispan compiled with Infinispan 7.x but … #1045

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ public void destroy() throws CacheException {
* Brings all data from the distributed cache into our local cache.
*/
private void populateLocalCache() {
CloseableIterable<CacheEntry<Object, Void>> iterable = Caches.keys(cache);
CloseableIterable<Object> iterable = Caches.keys(cache);
try {
for (CacheEntry<Object, Void> entry : iterable) {
get(null, entry.getKey());
for (Object key : iterable) {
get(null, key);
}
}
finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ public interface CollectableCloseableIterable extends CloseableIterable {
}

public static CollectableCloseableIterable keys(AdvancedCache cache) {
if (cache.getCacheConfiguration().transaction().transactionMode().isTransactional()) {
// Dummy read to enlist the LocalTransaction as workaround for ISPN-5676
cache.containsKey(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering maybe you want to do a withFlags(CACHE_MODE_LOCAL) ? So this way if it is distributed you won't incur the remote overhead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. @rvansa I'll integrate this PR asap but can you make sure this gets addressed later on?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also this will be fixed in ISPN 7.2.5 which will render this change unneeded. But I am not for sure when that will be released.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that in all places where I use this, local cache is passed to the method. I don't think that the additional flag should be passed at this place (which is some kind of generic helper on Cache API).

}
// HHH-10023: we can't use keySet()
final CloseableIterable<CacheEntry<Object, Void>> entryIterable = cache
.filterEntries( AcceptAllKeyValueFilter.getInstance() )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.hibernate.cache.spi.access.AccessType;
import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy;
import org.hibernate.cache.spi.access.SoftLock;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.internal.util.compare.ComparableComparator;
import org.hibernate.test.cache.infinispan.AbstractNonFunctionalTestCase;
import org.hibernate.test.cache.infinispan.NodeEnvironment;
Expand All @@ -25,6 +26,7 @@
import org.junit.Test;

import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;

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

private NodeEnvironment environment;
private static CollectionRegionAccessStrategy accessStrategy;
Expand Down Expand Up @@ -85,7 +88,7 @@ protected CollectionRegionAccessStrategy getCollectionAccessStrategy() {

@Test
public void testLockItem() {
assertNull( getCollectionAccessStrategy().lockItem(null, KEY, new Integer( 1 ) ) );
assertNull( getCollectionAccessStrategy().lockItem(SESSION, KEY, new Integer( 1 ) ) );
}

@Test
Expand All @@ -95,12 +98,12 @@ public void testLockRegion() {

@Test
public void testUnlockItem() {
getCollectionAccessStrategy().unlockItem(null, KEY, new MockSoftLock() );
getCollectionAccessStrategy().unlockItem(SESSION, KEY, new MockSoftLock() );
}

@Test
public void testUnlockRegion() {
getCollectionAccessStrategy().unlockItem(null, KEY, new MockSoftLock() );
getCollectionAccessStrategy().unlockItem(SESSION, KEY, new MockSoftLock() );
}

public static class MockSoftLock implements SoftLock {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.hibernate.cache.spi.access.AccessType;
import org.hibernate.cache.spi.access.EntityRegionAccessStrategy;
import org.hibernate.cache.spi.access.SoftLock;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.internal.util.compare.ComparableComparator;
import org.hibernate.test.cache.infinispan.AbstractNonFunctionalTestCase;
import org.hibernate.test.cache.infinispan.NodeEnvironment;
Expand All @@ -25,6 +26,7 @@

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;

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

private NodeEnvironment environment;
private EntityRegionAccessStrategy accessStrategy;
Expand Down Expand Up @@ -95,7 +98,7 @@ protected AccessType getAccessType() {
@Test
@SuppressWarnings( {"UnnecessaryBoxing"})
public void testLockItem() {
assertNull( getEntityAccessStrategy().lockItem(null, KEY, Integer.valueOf( 1 ) ) );
assertNull( getEntityAccessStrategy().lockItem(SESSION, KEY, Integer.valueOf( 1 ) ) );
}

@Test
Expand All @@ -105,20 +108,20 @@ public void testLockRegion() {

@Test
public void testUnlockItem() {
getEntityAccessStrategy().unlockItem(null, KEY, new MockSoftLock() );
getEntityAccessStrategy().unlockItem(SESSION, KEY, new MockSoftLock() );
}

@Test
public void testUnlockRegion() {
getEntityAccessStrategy().unlockItem(null, KEY, new MockSoftLock() );
getEntityAccessStrategy().unlockItem(SESSION, KEY, new MockSoftLock() );
}

@Test
@SuppressWarnings( {"UnnecessaryBoxing"})
public void testAfterInsert() {
assertFalse(
"afterInsert always returns false",
getEntityAccessStrategy().afterInsert(null,
getEntityAccessStrategy().afterInsert(SESSION,
KEY,
VALUE1,
Integer.valueOf( 1 )
Expand All @@ -131,7 +134,7 @@ public void testAfterInsert() {
public void testAfterUpdate() {
assertFalse(
"afterInsert always returns false",
getEntityAccessStrategy().afterUpdate(null,
getEntityAccessStrategy().afterUpdate(SESSION,
KEY,
VALUE2,
Integer.valueOf( 1 ),
Expand Down