Skip to content

Commit b859388

Browse files
committed
fixing test failures after merge
1 parent 09e5bfe commit b859388

File tree

8 files changed

+97
-106
lines changed

8 files changed

+97
-106
lines changed

hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/AbstractGeneralDataRegionTestCase.java

Lines changed: 75 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,22 @@ public abstract class AbstractGeneralDataRegionTestCase extends AbstractRegionIm
5757
protected static final String VALUE2 = "value2";
5858

5959
protected Configuration createConfiguration() {
60-
return CacheTestUtil.buildConfiguration( "test", InfinispanRegionFactory.class, false, true );
60+
return CacheTestUtil.buildConfiguration(
61+
"test",
62+
org.hibernate.test.cache.infinispan.functional.SingleNodeTestCase.TestInfinispanRegionFactory.class,
63+
false,
64+
true
65+
);
6166
}
6267

6368
@Override
6469
protected void putInRegion(Region region, Object key, Object value) {
65-
((GeneralDataRegion) region).put( key, value );
70+
( (GeneralDataRegion) region ).put( key, value );
6671
}
6772

6873
@Override
6974
protected void removeFromRegion(Region region, Object key) {
70-
((GeneralDataRegion) region).evict( key );
75+
( (GeneralDataRegion) region ).evict( key );
7176
}
7277

7378
@Test
@@ -77,63 +82,71 @@ public void testEvict() throws Exception {
7782

7883
private void evictOrRemoveTest() throws Exception {
7984
Configuration cfg = createConfiguration();
80-
InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(
81-
new StandardServiceRegistryBuilder().applySettings( cfg.getProperties() ).build(),
82-
cfg,
83-
getCacheTestSupport()
84-
);
85-
boolean invalidation = false;
86-
87-
// Sleep a bit to avoid concurrent FLUSH problem
88-
avoidConcurrentFlush();
89-
90-
GeneralDataRegion localRegion = (GeneralDataRegion) createRegion(
91-
regionFactory,
92-
getStandardRegionName( REGION_PREFIX ), cfg.getProperties(), null
93-
);
94-
95-
cfg = createConfiguration();
96-
regionFactory = CacheTestUtil.startRegionFactory(
97-
new StandardServiceRegistryBuilder().applySettings( cfg.getProperties() ).build(),
98-
cfg,
99-
getCacheTestSupport()
100-
);
101-
102-
GeneralDataRegion remoteRegion = (GeneralDataRegion) createRegion(
103-
regionFactory,
104-
getStandardRegionName( REGION_PREFIX ),
105-
cfg.getProperties(),
106-
null
107-
);
108-
109-
assertNull( "local is clean", localRegion.get( KEY ) );
110-
assertNull( "remote is clean", remoteRegion.get( KEY ) );
111-
112-
regionPut(localRegion);
113-
assertEquals( VALUE1, localRegion.get( KEY ) );
114-
115-
// allow async propagation
116-
sleep( 250 );
117-
Object expected = invalidation ? null : VALUE1;
118-
assertEquals( expected, remoteRegion.get( KEY ) );
119-
120-
regionEvict(localRegion);
121-
122-
// allow async propagation
123-
sleep( 250 );
124-
assertEquals( null, localRegion.get( KEY ) );
125-
assertEquals( null, remoteRegion.get( KEY ) );
85+
InfinispanRegionFactory regionFactory = null;
86+
InfinispanRegionFactory remoteRegionFactory = null;
87+
try {
88+
regionFactory = CacheTestUtil.startRegionFactory(
89+
new StandardServiceRegistryBuilder().applySettings( cfg.getProperties() ).build(),
90+
cfg,
91+
getCacheTestSupport()
92+
);
93+
boolean invalidation = false;
94+
95+
// Sleep a bit to avoid concurrent FLUSH problem
96+
avoidConcurrentFlush();
97+
98+
GeneralDataRegion localRegion = (GeneralDataRegion) createRegion(
99+
regionFactory,
100+
getStandardRegionName( REGION_PREFIX ), cfg.getProperties(), null
101+
);
102+
103+
cfg = createConfiguration();
104+
remoteRegionFactory = CacheTestUtil.startRegionFactory(
105+
new StandardServiceRegistryBuilder().applySettings( cfg.getProperties() ).build(),
106+
cfg,
107+
getCacheTestSupport()
108+
);
109+
110+
GeneralDataRegion remoteRegion = (GeneralDataRegion) createRegion(
111+
remoteRegionFactory,
112+
getStandardRegionName( REGION_PREFIX ),
113+
cfg.getProperties(),
114+
null
115+
);
116+
117+
assertNull( "local is clean", localRegion.get( KEY ) );
118+
assertNull( "remote is clean", remoteRegion.get( KEY ) );
119+
120+
regionPut( localRegion );
121+
assertEquals( VALUE1, localRegion.get( KEY ) );
122+
123+
// allow async propagation
124+
sleep( 250 );
125+
Object expected = invalidation ? null : VALUE1;
126+
assertEquals( expected, remoteRegion.get( KEY ) );
127+
128+
regionEvict( localRegion );
129+
130+
// allow async propagation
131+
sleep( 250 );
132+
assertEquals( null, localRegion.get( KEY ) );
133+
assertEquals( null, remoteRegion.get( KEY ) );
134+
}
135+
finally {
136+
CacheTestUtil.stopRegionFactory( regionFactory, getCacheTestSupport() );
137+
CacheTestUtil.stopRegionFactory( remoteRegionFactory, getCacheTestSupport() );
138+
}
126139
}
127140

128-
protected void regionEvict(GeneralDataRegion region) throws Exception {
129-
region.evict(KEY);
130-
}
141+
protected void regionEvict(GeneralDataRegion region) throws Exception {
142+
region.evict( KEY );
143+
}
131144

132-
protected void regionPut(GeneralDataRegion region) throws Exception {
133-
region.put(KEY, VALUE1);
134-
}
145+
protected void regionPut(GeneralDataRegion region) throws Exception {
146+
region.put( KEY, VALUE1 );
147+
}
135148

136-
protected abstract String getStandardRegionName(String regionPrefix);
149+
protected abstract String getStandardRegionName(String regionPrefix);
137150

138151
/**
139152
* Test method for {@link QueryResultsRegion#evictAll()}.
@@ -170,7 +183,7 @@ private void evictOrRemoveAllTest(String configName) throws Exception {
170183
cfg,
171184
getCacheTestSupport()
172185
);
173-
AdvancedCache remoteCache = getInfinispanCache( regionFactory );
186+
AdvancedCache remoteCache = getInfinispanCache( regionFactory );
174187

175188
// Sleep a bit to avoid concurrent FLUSH problem
176189
avoidConcurrentFlush();
@@ -191,14 +204,14 @@ private void evictOrRemoveAllTest(String configName) throws Exception {
191204
assertNull( "local is clean", localRegion.get( KEY ) );
192205
assertNull( "remote is clean", remoteRegion.get( KEY ) );
193206

194-
regionPut(localRegion);
195-
assertEquals( VALUE1, localRegion.get( KEY ) );
207+
regionPut( localRegion );
208+
assertEquals( VALUE1, localRegion.get( KEY ) );
196209

197210
// Allow async propagation
198211
sleep( 250 );
199212

200-
regionPut(remoteRegion);
201-
assertEquals( VALUE1, remoteRegion.get( KEY ) );
213+
regionPut( remoteRegion );
214+
assertEquals( VALUE1, remoteRegion.get( KEY ) );
202215

203216
// Allow async propagation
204217
sleep( 250 );
@@ -225,7 +238,7 @@ protected void rollback() {
225238
try {
226239
BatchModeTransactionManager.getInstance().rollback();
227240
}
228-
catch (Exception e) {
241+
catch ( Exception e ) {
229242
log.error( e.getMessage(), e );
230243
}
231244
}

hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/NodeEnvironment.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class NodeEnvironment {
5050

5151
private Map<String, EntityRegionImpl> entityRegionMap;
5252
private Map<String, CollectionRegionImpl> collectionRegionMap;
53-
private SessionFactoryImplementor sessionFactory;
53+
private SessionFactoryImplementor sessionFactory;
5454
public NodeEnvironment(Configuration configuration) {
5555
this.configuration = configuration;
5656
}
@@ -113,7 +113,6 @@ public void prepare() throws Exception {
113113
.applySettings(configuration.getProperties())
114114
.build();
115115
sessionFactory = (SessionFactoryImplementor)configuration.buildSessionFactory( serviceRegistry );
116-
// regionFactory = CacheTestUtil.startRegionFactory(serviceRegistry, configuration);
117116
regionFactory = (InfinispanRegionFactory)sessionFactory.getServiceRegistry().getService( RegionFactory.class );
118117
}
119118

@@ -142,11 +141,6 @@ public void release() throws Exception {
142141
}
143142
} finally {
144143
try {
145-
// if (regionFactory != null) {
146-
// // Currently the RegionFactory is shutdown by its registration
147-
// // with the CacheTestSetup from CacheTestUtil when built
148-
// regionFactory.stop();
149-
// }
150144
if(sessionFactory!=null){
151145
sessionFactory.close();
152146
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public void prepareResources() throws Exception {
123123

124124
protected static Configuration createConfiguration(String configName) {
125125
Configuration cfg = CacheTestUtil.buildConfiguration(
126-
REGION_PREFIX, InfinispanRegionFactory.class, true, false
126+
REGION_PREFIX, org.hibernate.test.cache.infinispan.functional.SingleNodeTestCase.TestInfinispanRegionFactory.class, true, false
127127
);
128128
cfg.setProperty( InfinispanRegionFactory.ENTITY_CACHE_RESOURCE_PROP, configName );
129129
return cfg;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ protected void waitForClusterToForm(Cache... caches) {
123123
protected static Configuration createConfiguration(String configName) {
124124
Configuration cfg = CacheTestUtil.buildConfiguration(
125125
REGION_PREFIX,
126-
InfinispanRegionFactory.class,
126+
org.hibernate.test.cache.infinispan.functional.SingleNodeTestCase.TestInfinispanRegionFactory.class,
127127
true,
128128
false
129129
);

hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/DualNodeTestCase.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ protected void standardConfigure(Configuration cfg) {
136136
cfg.setProperty( Environment.TRANSACTION_STRATEGY, getTransactionFactoryClass().getName() );
137137
cfg.setProperty( Environment.CACHE_REGION_FACTORY, getCacheRegionFactory().getName() );
138138
cfg.setProperty( Environment.USE_QUERY_CACHE, String.valueOf( getUseQueryCache() ) );
139+
cfg.setProperty( USE_NEW_METADATA_MAPPINGS, "false" );
139140
}
140141

141142
public class SecondNodeEnvironment {
@@ -173,13 +174,15 @@ public void shutDown() {
173174
if ( sessionFactory != null ) {
174175
try {
175176
sessionFactory.close();
177+
sessionFactory = null;
176178
}
177179
catch (Exception ignore) {
178180
}
179181
}
180182
if ( serviceRegistry != null ) {
181183
try {
182184
serviceRegistry.destroy();
185+
serviceRegistry = null;
183186
}
184187
catch (Exception ignore) {
185188
}

hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/NaturalIdInvalidationTestCase.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ public class NaturalIdInvalidationTestCase extends DualNodeTestCase {
4444
private static final long SLEEP_TIME = 50l;
4545
private static final Integer CUSTOMER_ID = new Integer( 1 );
4646
private static int test = 0;
47-
47+
@Override
48+
public String[] getMappings() {
49+
return new String[]{};
50+
}
4851
@Override
4952
protected Class<?>[] getAnnotatedClasses() {
5053
return new Class[] {

hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/query/QueryRegionImplTestCase.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,11 @@ protected AdvancedCache getInfinispanCache(InfinispanRegionFactory regionFactory
106106

107107
@Override
108108
protected Configuration createConfiguration() {
109-
return CacheTestUtil.buildCustomQueryCacheConfiguration( "test", "replicated-query" );
109+
Configuration cfg = super.createConfiguration();
110+
cfg.setProperty(InfinispanRegionFactory.QUERY_CACHE_RESOURCE_PROP, "replicated-query");
111+
112+
// return CacheTestUtil.buildCustomQueryCacheConfiguration( "test", "replicated-query" );
113+
return cfg;
110114
}
111115

112116
private void putDoesNotBlockGetTest() throws Exception {

hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/util/CacheTestUtil.java

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -57,34 +57,6 @@ public static Configuration buildConfiguration(String regionPrefix,
5757
return cfg;
5858
}
5959

60-
public static Configuration buildCustomQueryCacheConfiguration(String regionPrefix, String queryCacheName) {
61-
Configuration cfg = buildConfiguration(regionPrefix, InfinispanRegionFactory.class, true, true);
62-
cfg.setProperty(InfinispanRegionFactory.QUERY_CACHE_RESOURCE_PROP, queryCacheName);
63-
return cfg;
64-
}
65-
66-
public static InfinispanRegionFactory startRegionFactory(ServiceRegistry reg,
67-
Configuration cfg){
68-
try {
69-
Settings settings = cfg.buildSettings(reg);
70-
Properties properties = cfg.getProperties();
71-
72-
String factoryType = cfg.getProperty(Environment.CACHE_REGION_FACTORY);
73-
Class clazz = Thread.currentThread()
74-
.getContextClassLoader().loadClass(factoryType);
75-
InfinispanRegionFactory regionFactory;
76-
if (clazz == InfinispanRegionFactory.class) {
77-
regionFactory = new SingleNodeTestCase.TestInfinispanRegionFactory();
78-
} else {
79-
regionFactory = (InfinispanRegionFactory) clazz.newInstance();
80-
}
81-
regionFactory.start(settings, properties);
82-
return regionFactory;
83-
} catch (Exception e) {
84-
throw new RuntimeException(e);
85-
}
86-
}
87-
8860
public static InfinispanRegionFactory startRegionFactory(ServiceRegistry serviceRegistry,
8961
Configuration cfg, CacheTestSupport testSupport) {
9062
SessionFactoryImplementor sessionFactory =(SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry );
@@ -93,12 +65,14 @@ public static InfinispanRegionFactory startRegionFactory(ServiceRegistry service
9365
return factory;
9466
}
9567

96-
public static void stopRegionFactory(InfinispanRegionFactory factory,
97-
CacheTestSupport testSupport) {
98-
testSupport.unregisterFactory(factory).close();
99-
}
68+
public static void stopRegionFactory(InfinispanRegionFactory factory,
69+
CacheTestSupport testSupport) {
70+
if ( factory != null ) {
71+
testSupport.unregisterFactory( factory ).close();
72+
}
73+
}
10074

101-
/**
75+
/**
10276
* Prevent instantiation.
10377
*/
10478
private CacheTestUtil() {

0 commit comments

Comments
 (0)