Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HHH-12417 - default strategy based on registrations with StrategySele…
…ctor ConnectionProviderInitiator and tests
- Loading branch information
Showing
7 changed files
with
172 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
hibernate-core/src/test/java/org/hibernate/test/cache/SingleRegisteredProviderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html | ||
*/ | ||
package org.hibernate.test.cache; | ||
|
||
import java.util.Collection; | ||
|
||
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; | ||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder; | ||
import org.hibernate.boot.registry.selector.spi.StrategySelector; | ||
import org.hibernate.cache.internal.EnabledCaching; | ||
import org.hibernate.cache.spi.RegionFactory; | ||
import org.hibernate.cfg.AvailableSettings; | ||
import org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl; | ||
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; | ||
|
||
import org.hibernate.testing.cache.CachingRegionFactory; | ||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; | ||
import org.junit.Test; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.CoreMatchers.instanceOf; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
/** | ||
* @author Steve Ebersole | ||
*/ | ||
public class SingleRegisteredProviderTest extends BaseNonConfigCoreFunctionalTestCase { | ||
@Override | ||
protected void configureStandardServiceRegistryBuilder(StandardServiceRegistryBuilder ssrb) { | ||
super.configureStandardServiceRegistryBuilder( ssrb ); | ||
|
||
ssrb.applySetting( AvailableSettings.USE_SECOND_LEVEL_CACHE, "false" ); | ||
ssrb.applySetting( AvailableSettings.CACHE_REGION_PREFIX, "" ); | ||
ssrb.applySetting( AvailableSettings.CACHE_REGION_FACTORY, "" ); | ||
|
||
ssrb.applySetting( AvailableSettings.CONNECTION_PROVIDER, "" ); | ||
} | ||
|
||
@Override | ||
protected void configureBootstrapServiceRegistryBuilder(BootstrapServiceRegistryBuilder bsrb) { | ||
super.configureBootstrapServiceRegistryBuilder( bsrb ); | ||
bsrb.applyStrategySelector( ConnectionProvider.class, "testing", DriverManagerConnectionProviderImpl.class ); | ||
} | ||
|
||
@Test | ||
public void testCachingExpectations() { | ||
final Collection<Class<? extends RegionFactory>> implementors = sessionFactory().getServiceRegistry() | ||
.getService( StrategySelector.class ) | ||
.getRegisteredStrategyImplementors( RegionFactory.class ); | ||
|
||
assertThat( implementors.size(), equalTo( 1 ) ); | ||
assertThat( sessionFactory().getSessionFactoryOptions().isSecondLevelCacheEnabled(), equalTo( true ) ); | ||
assertThat( sessionFactory().getCache(), instanceOf( EnabledCaching.class ) ); | ||
assertThat( sessionFactory().getCache().getRegionFactory(), instanceOf( CachingRegionFactory.class ) ); | ||
assertThat( implementors.iterator().next(), equalTo( CachingRegionFactory.class ) ); | ||
} | ||
|
||
@Test | ||
public void testConnectionsExpectations() { | ||
final Collection<Class<? extends ConnectionProvider>> implementors = sessionFactory().getServiceRegistry() | ||
.getService( StrategySelector.class ) | ||
.getRegisteredStrategyImplementors( ConnectionProvider.class ); | ||
|
||
assertThat( implementors.size(), equalTo( 1 ) ); | ||
|
||
final ConnectionProvider configuredProvider = sessionFactory().getServiceRegistry().getService( ConnectionProvider.class ); | ||
|
||
assertThat( configuredProvider, instanceOf( DriverManagerConnectionProviderImpl.class ) ); | ||
assertThat( implementors.iterator().next(), equalTo( DriverManagerConnectionProviderImpl.class ) ); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...e-testing/src/main/java/org/hibernate/testing/cache/StrategyRegistrationProviderImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html | ||
*/ | ||
package org.hibernate.testing.cache; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import org.hibernate.boot.registry.selector.SimpleStrategyRegistrationImpl; | ||
import org.hibernate.boot.registry.selector.StrategyRegistration; | ||
import org.hibernate.boot.registry.selector.StrategyRegistrationProvider; | ||
import org.hibernate.cache.spi.RegionFactory; | ||
|
||
/** | ||
* Makes the JCache RegionFactory available to the Hibernate | ||
* {@link org.hibernate.boot.registry.selector.spi.StrategySelector} service | ||
* under a number of keys. Prefer to use | ||
* | ||
* @author Steve Ebersole | ||
*/ | ||
public class StrategyRegistrationProviderImpl implements StrategyRegistrationProvider { | ||
@Override | ||
@SuppressWarnings("unchecked") | ||
public Iterable<StrategyRegistration> getStrategyRegistrations() { | ||
return Collections.singletonList( | ||
new SimpleStrategyRegistrationImpl( | ||
RegionFactory.class, | ||
CachingRegionFactory.class, | ||
"testing", | ||
CachingRegionFactory.class.getName() | ||
) | ||
); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...urces/META-INF/services/org.hibernate.boot.registry.selector.StrategyRegistrationProvider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# | ||
# Hibernate, Relational Persistence for Idiomatic Java | ||
# | ||
# License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
# See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html | ||
|
||
org.hibernate.testing.cache.StrategyRegistrationProviderImpl |