Search in sources :

Example 1 with PutKeyValueCommand

use of org.infinispan.commands.write.PutKeyValueCommand in project hibernate-orm by hibernate.

the class AbstractRegionAccessStrategyTest method expectRemotePutFromLoad.

private CountDownLatch expectRemotePutFromLoad(AdvancedCache localCache, AdvancedCache remoteCache) {
    CountDownLatch putFromLoadLatch;
    if (!isUsingInvalidation()) {
        putFromLoadLatch = new CountDownLatch(1);
        // The command may fail to replicate if it can't acquire lock locally
        ExpectingInterceptor.Condition remoteCondition = ExpectingInterceptor.get(remoteCache).when((ctx, cmd) -> !ctx.isOriginLocal() && cmd instanceof PutKeyValueCommand);
        ExpectingInterceptor.Condition localCondition = ExpectingInterceptor.get(localCache).whenFails((ctx, cmd) -> ctx.isOriginLocal() && cmd instanceof PutKeyValueCommand);
        remoteCondition.run(() -> {
            localCondition.cancel();
            putFromLoadLatch.countDown();
        });
        localCondition.run(() -> {
            remoteCondition.cancel();
            putFromLoadLatch.countDown();
        });
        // just for case the test fails and does not remove the interceptor itself
        cleanup.add(() -> ExpectingInterceptor.cleanup(localCache, remoteCache));
    } else {
        putFromLoadLatch = new CountDownLatch(0);
    }
    return putFromLoadLatch;
}
Also used : ExpectingInterceptor(org.hibernate.test.cache.infinispan.util.ExpectingInterceptor) CountDownLatch(java.util.concurrent.CountDownLatch) PutKeyValueCommand(org.infinispan.commands.write.PutKeyValueCommand)

Example 2 with PutKeyValueCommand

use of org.infinispan.commands.write.PutKeyValueCommand in project hibernate-orm by hibernate.

the class AbstractRegionAccessStrategyTest method expectPutWithValue.

protected CountDownLatch expectPutWithValue(Predicate<Object> valuePredicate) {
    if (!isUsingInvalidation() && accessType != AccessType.NONSTRICT_READ_WRITE) {
        CountDownLatch latch = new CountDownLatch(1);
        ExpectingInterceptor.get(remoteRegion.getCache()).when((ctx, cmd) -> cmd instanceof PutKeyValueCommand && valuePredicate.test(((PutKeyValueCommand) cmd).getValue())).countDown(latch);
        cleanup.add(() -> ExpectingInterceptor.cleanup(remoteRegion.getCache()));
        return latch;
    } else {
        return new CountDownLatch(0);
    }
}
Also used : Arrays(java.util.Arrays) Connection(java.sql.Connection) BatchModeJtaPlatform(org.hibernate.test.cache.infinispan.util.BatchModeJtaPlatform) Cache(org.infinispan.Cache) Transaction(org.hibernate.Transaction) AdvancedCache(org.infinispan.AdvancedCache) After(org.junit.After) Mockito.doAnswer(org.mockito.Mockito.doAnswer) CacheDataDescriptionImpl(org.hibernate.cache.internal.CacheDataDescriptionImpl) TestingUtil(org.infinispan.test.TestingUtil) AccessType(org.hibernate.cache.spi.access.AccessType) Predicate(java.util.function.Predicate) TombstoneUpdate(org.hibernate.cache.infinispan.util.TombstoneUpdate) JdbcResourceTransactionAccess(org.hibernate.resource.transaction.backend.jdbc.spi.JdbcResourceTransactionAccess) TestSynchronization(org.hibernate.test.cache.infinispan.util.TestSynchronization) Matchers.any(org.mockito.Matchers.any) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) SoftLock(org.hibernate.cache.spi.access.SoftLock) JdbcSessionOwner(org.hibernate.resource.jdbc.spi.JdbcSessionOwner) AfterClassOnce(org.hibernate.testing.AfterClassOnce) FutureUpdate(org.hibernate.cache.infinispan.util.FutureUpdate) PutKeyValueCommand(org.infinispan.commands.write.PutKeyValueCommand) TransactionImpl(org.hibernate.engine.transaction.internal.TransactionImpl) PutFromLoadValidator(org.hibernate.cache.infinispan.access.PutFromLoadValidator) SharedSessionContractImplementor(org.hibernate.engine.spi.SharedSessionContractImplementor) Mockito.mock(org.mockito.Mockito.mock) JdbcConnectionAccess(org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess) TestResourceTracker(org.infinispan.test.fwk.TestResourceTracker) Logger(org.jboss.logging.Logger) TransactionCoordinator(org.hibernate.resource.transaction.spi.TransactionCoordinator) Session(org.hibernate.Session) Caches(org.hibernate.cache.infinispan.util.Caches) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Mockito.spy(org.mockito.Mockito.spy) ArrayList(java.util.ArrayList) RegionAccessStrategy(org.hibernate.cache.spi.access.RegionAccessStrategy) SQLException(java.sql.SQLException) TestTimeService(org.hibernate.test.cache.infinispan.util.TestTimeService) RollbackException(javax.transaction.RollbackException) TransactionCoordinatorOwner(org.hibernate.resource.transaction.spi.TransactionCoordinatorOwner) ExpectingInterceptor(org.hibernate.test.cache.infinispan.util.ExpectingInterceptor) ComparableComparator(org.hibernate.internal.util.compare.ComparableComparator) BatchModeTransactionCoordinator(org.hibernate.test.cache.infinispan.util.BatchModeTransactionCoordinator) JdbcResourceTransactionMock(org.hibernate.test.cache.infinispan.util.JdbcResourceTransactionMock) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) AssertionFailedError(junit.framework.AssertionFailedError) JdbcServices(org.hibernate.engine.jdbc.spi.JdbcServices) JdbcSessionContext(org.hibernate.resource.jdbc.spi.JdbcSessionContext) TestInfinispanRegionFactory(org.hibernate.test.cache.infinispan.util.TestInfinispanRegionFactory) Mockito.when(org.mockito.Mockito.when) BaseRegion(org.hibernate.cache.infinispan.impl.BaseRegion) ServiceRegistry(org.hibernate.service.ServiceRegistry) TimeUnit(java.util.concurrent.TimeUnit) CacheDataDescription(org.hibernate.cache.spi.CacheDataDescription) InvalidateCommand(org.infinispan.commands.write.InvalidateCommand) Assert.assertNull(org.junit.Assert.assertNull) SystemException(javax.transaction.SystemException) JdbcResourceLocalTransactionCoordinatorBuilderImpl(org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorBuilderImpl) SqlExceptionHelper(org.hibernate.engine.jdbc.spi.SqlExceptionHelper) BeforeClassOnce(org.hibernate.testing.BeforeClassOnce) Assert.assertEquals(org.junit.Assert.assertEquals) CountDownLatch(java.util.concurrent.CountDownLatch) PutKeyValueCommand(org.infinispan.commands.write.PutKeyValueCommand)

Example 3 with PutKeyValueCommand

use of org.infinispan.commands.write.PutKeyValueCommand in project hibernate-orm by hibernate.

the class AbstractFunctionalTest method expectPutWithValue.

protected CountDownLatch expectPutWithValue(AdvancedCache cache, Predicate<Object> valuePredicate, int numUpdates) {
    if (!cacheMode.isInvalidation() && accessType != AccessType.NONSTRICT_READ_WRITE) {
        CountDownLatch latch = new CountDownLatch(numUpdates);
        ExpectingInterceptor.get(cache).when((ctx, cmd) -> cmd instanceof PutKeyValueCommand && valuePredicate.test(((PutKeyValueCommand) cmd).getValue())).countDown(latch);
        cleanup.add(() -> ExpectingInterceptor.cleanup(cache));
        return latch;
    } else {
        return new CountDownLatch(0);
    }
}
Also used : Property(org.hibernate.mapping.Property) AvailableSettings(org.hibernate.cfg.AvailableSettings) TxUtil(org.hibernate.test.cache.infinispan.util.TxUtil) RootClass(org.hibernate.mapping.RootClass) RunWith(org.junit.runner.RunWith) Session(org.hibernate.Session) JtaPlatformImpl(org.hibernate.test.cache.infinispan.tm.JtaPlatformImpl) Metadata(org.hibernate.boot.Metadata) ArrayList(java.util.ArrayList) XaConnectionProvider(org.hibernate.test.cache.infinispan.tm.XaConnectionProvider) AdvancedCache(org.infinispan.AdvancedCache) RegionFactory(org.hibernate.cache.spi.RegionFactory) PersistentClass(org.hibernate.mapping.PersistentClass) Map(java.util.Map) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) After(org.junit.After) JtaTransactionCoordinatorBuilderImpl(org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl) ExpectingInterceptor(org.hibernate.test.cache.infinispan.util.ExpectingInterceptor) AccessType(org.hibernate.cache.spi.access.AccessType) Environment(org.hibernate.cfg.Environment) ClassRule(org.junit.ClassRule) Parameterized(org.junit.runners.Parameterized) SimpleCacheKeysFactory(org.hibernate.cache.internal.SimpleCacheKeysFactory) CustomParameterized(org.hibernate.testing.junit4.CustomParameterized) BaseNonConfigCoreFunctionalTestCase(org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase) Predicate(java.util.function.Predicate) SimpleValue(org.hibernate.mapping.SimpleValue) Column(org.hibernate.mapping.Column) TombstoneUpdate(org.hibernate.cache.infinispan.util.TombstoneUpdate) JtaPlatform(org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform) TestInfinispanRegionFactory(org.hibernate.test.cache.infinispan.util.TestInfinispanRegionFactory) TransactionCoordinatorBuilder(org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) CacheMode(org.infinispan.configuration.cache.CacheMode) FutureUpdate(org.hibernate.cache.infinispan.util.FutureUpdate) JdbcResourceLocalTransactionCoordinatorBuilderImpl(org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorBuilderImpl) PutKeyValueCommand(org.infinispan.commands.write.PutKeyValueCommand) BeforeClassOnce(org.hibernate.testing.BeforeClassOnce) ConnectionProvider(org.hibernate.engine.jdbc.connections.spi.ConnectionProvider) InfinispanTestingSetup(org.hibernate.test.cache.infinispan.util.InfinispanTestingSetup) CountDownLatch(java.util.concurrent.CountDownLatch) PutKeyValueCommand(org.infinispan.commands.write.PutKeyValueCommand)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)3 ExpectingInterceptor (org.hibernate.test.cache.infinispan.util.ExpectingInterceptor)3 PutKeyValueCommand (org.infinispan.commands.write.PutKeyValueCommand)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Predicate (java.util.function.Predicate)2 Session (org.hibernate.Session)2 FutureUpdate (org.hibernate.cache.infinispan.util.FutureUpdate)2 TombstoneUpdate (org.hibernate.cache.infinispan.util.TombstoneUpdate)2 AccessType (org.hibernate.cache.spi.access.AccessType)2 JdbcResourceLocalTransactionCoordinatorBuilderImpl (org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorBuilderImpl)2 TestInfinispanRegionFactory (org.hibernate.test.cache.infinispan.util.TestInfinispanRegionFactory)2 BeforeClassOnce (org.hibernate.testing.BeforeClassOnce)2 AdvancedCache (org.infinispan.AdvancedCache)2 After (org.junit.After)2 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 Arrays (java.util.Arrays)1 Map (java.util.Map)1 TimeUnit (java.util.concurrent.TimeUnit)1