Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
c7ed5c3d
Commit
c7ed5c3d
authored
Feb 27, 2018
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upgrade to EhCache 3.5.0
Closes gh-12256
parent
fe792790
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
355 additions
and
216 deletions
+355
-216
AbstractCacheAutoConfigurationTests.java
...oconfigure/cache/AbstractCacheAutoConfigurationTests.java
+165
-0
CacheAutoConfigurationTests.java
...boot/autoconfigure/cache/CacheAutoConfigurationTests.java
+19
-215
EhCache2CacheAutoConfigurationTests.java
...oconfigure/cache/EhCache2CacheAutoConfigurationTests.java
+93
-0
EhCache3CacheAutoConfigurationTests.java
...oconfigure/cache/EhCache3CacheAutoConfigurationTests.java
+77
-0
pom.xml
spring-boot-project/spring-boot-dependencies/pom.xml
+1
-1
No files found.
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/AbstractCacheAutoConfigurationTests.java
0 → 100644
View file @
c7ed5c3d
/*
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
autoconfigure
.
cache
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.Map
;
import
com.couchbase.client.spring.cache.CouchbaseCacheManager
;
import
com.hazelcast.spring.cache.HazelcastCacheManager
;
import
org.infinispan.spring.provider.SpringEmbeddedCacheManager
;
import
org.springframework.boot.autoconfigure.AutoConfigurations
;
import
org.springframework.boot.test.context.assertj.AssertableApplicationContext
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.boot.test.context.runner.ContextConsumer
;
import
org.springframework.cache.CacheManager
;
import
org.springframework.cache.caffeine.CaffeineCacheManager
;
import
org.springframework.cache.concurrent.ConcurrentMapCacheManager
;
import
org.springframework.cache.ehcache.EhCacheCacheManager
;
import
org.springframework.cache.support.SimpleCacheManager
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.redis.cache.RedisCacheManager
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Base class for {@link CacheAutoConfiguration} tests.
*
* @author Andy Wilkinson
*/
abstract
class
AbstractCacheAutoConfigurationTests
{
protected
final
ApplicationContextRunner
contextRunner
=
new
ApplicationContextRunner
()
.
withConfiguration
(
AutoConfigurations
.
of
(
CacheAutoConfiguration
.
class
));
protected
<
T
extends
CacheManager
>
T
getCacheManager
(
AssertableApplicationContext
loaded
,
Class
<
T
>
type
)
{
CacheManager
cacheManager
=
loaded
.
getBean
(
CacheManager
.
class
);
assertThat
(
cacheManager
).
as
(
"Wrong cache manager type"
).
isInstanceOf
(
type
);
return
type
.
cast
(
cacheManager
);
}
@SuppressWarnings
(
"rawtypes"
)
protected
ContextConsumer
<
AssertableApplicationContext
>
verifyCustomizers
(
String
...
expectedCustomizerNames
)
{
return
(
context
)
->
{
CacheManager
cacheManager
=
getCacheManager
(
context
,
CacheManager
.
class
);
List
<
String
>
expected
=
new
ArrayList
<>(
Arrays
.
asList
(
expectedCustomizerNames
));
Map
<
String
,
CacheManagerTestCustomizer
>
customizer
=
context
.
getBeansOfType
(
CacheManagerTestCustomizer
.
class
);
customizer
.
forEach
((
key
,
value
)
->
{
if
(
expected
.
contains
(
key
))
{
expected
.
remove
(
key
);
assertThat
(
value
.
cacheManager
).
isSameAs
(
cacheManager
);
}
else
{
assertThat
(
value
.
cacheManager
).
isNull
();
}
});
assertThat
(
expected
).
hasSize
(
0
);
};
}
@Configuration
static
class
CacheManagerCustomizersConfiguration
{
@Bean
public
CacheManagerCustomizer
<
CacheManager
>
allCacheManagerCustomizer
()
{
return
new
CacheManagerTestCustomizer
<
CacheManager
>()
{
};
}
@Bean
public
CacheManagerCustomizer
<
ConcurrentMapCacheManager
>
simpleCacheManagerCustomizer
()
{
return
new
CacheManagerTestCustomizer
<
ConcurrentMapCacheManager
>()
{
};
}
@Bean
public
CacheManagerCustomizer
<
SimpleCacheManager
>
genericCacheManagerCustomizer
()
{
return
new
CacheManagerTestCustomizer
<
SimpleCacheManager
>()
{
};
}
@Bean
public
CacheManagerCustomizer
<
CouchbaseCacheManager
>
couchbaseCacheManagerCustomizer
()
{
return
new
CacheManagerTestCustomizer
<
CouchbaseCacheManager
>()
{
};
}
@Bean
public
CacheManagerCustomizer
<
RedisCacheManager
>
redisCacheManagerCustomizer
()
{
return
new
CacheManagerTestCustomizer
<
RedisCacheManager
>()
{
};
}
@Bean
public
CacheManagerCustomizer
<
EhCacheCacheManager
>
ehcacheCacheManagerCustomizer
()
{
return
new
CacheManagerTestCustomizer
<
EhCacheCacheManager
>()
{
};
}
@Bean
public
CacheManagerCustomizer
<
HazelcastCacheManager
>
hazelcastCacheManagerCustomizer
()
{
return
new
CacheManagerTestCustomizer
<
HazelcastCacheManager
>()
{
};
}
@Bean
public
CacheManagerCustomizer
<
SpringEmbeddedCacheManager
>
infinispanCacheManagerCustomizer
()
{
return
new
CacheManagerTestCustomizer
<
SpringEmbeddedCacheManager
>()
{
};
}
@Bean
public
CacheManagerCustomizer
<
CaffeineCacheManager
>
caffeineCacheManagerCustomizer
()
{
return
new
CacheManagerTestCustomizer
<
CaffeineCacheManager
>()
{
};
}
}
static
abstract
class
CacheManagerTestCustomizer
<
T
extends
CacheManager
>
implements
CacheManagerCustomizer
<
T
>
{
T
cacheManager
;
@Override
public
void
customize
(
T
cacheManager
)
{
if
(
this
.
cacheManager
!=
null
)
{
throw
new
IllegalStateException
(
"Customized invoked twice"
);
}
this
.
cacheManager
=
cacheManager
;
}
}
}
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java
View file @
c7ed5c3d
This diff is collapsed.
Click to expand it.
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/EhCache2CacheAutoConfigurationTests.java
0 → 100644
View file @
c7ed5c3d
/*
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
autoconfigure
.
cache
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.boot.autoconfigure.AutoConfigurations
;
import
org.springframework.boot.autoconfigure.cache.CacheAutoConfigurationTests.DefaultCacheAndCustomizersConfiguration
;
import
org.springframework.boot.autoconfigure.cache.CacheAutoConfigurationTests.DefaultCacheConfiguration
;
import
org.springframework.boot.autoconfigure.cache.CacheAutoConfigurationTests.EhCacheCustomCacheManager
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.boot.testsupport.runner.classpath.ClassPathExclusions
;
import
org.springframework.boot.testsupport.runner.classpath.ModifiedClassPathRunner
;
import
org.springframework.cache.ehcache.EhCacheCacheManager
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link CacheAutoConfigurationTests} with EhCache 2.
*
* @author Stephane Nicoll
* @author Andy Wilkinson
*/
@RunWith
(
ModifiedClassPathRunner
.
class
)
@ClassPathExclusions
(
"ehcache-3*.jar"
)
public
class
EhCache2CacheAutoConfigurationTests
extends
AbstractCacheAutoConfigurationTests
{
private
final
ApplicationContextRunner
contextRunner
=
new
ApplicationContextRunner
()
.
withConfiguration
(
AutoConfigurations
.
of
(
CacheAutoConfiguration
.
class
));
@Test
public
void
ehCacheWithCaches
()
{
this
.
contextRunner
.
withUserConfiguration
(
DefaultCacheConfiguration
.
class
)
.
withPropertyValues
(
"spring.cache.type=ehcache"
).
run
((
context
)
->
{
EhCacheCacheManager
cacheManager
=
getCacheManager
(
context
,
EhCacheCacheManager
.
class
);
assertThat
(
cacheManager
.
getCacheNames
()).
containsOnly
(
"cacheTest1"
,
"cacheTest2"
);
assertThat
(
context
.
getBean
(
net
.
sf
.
ehcache
.
CacheManager
.
class
))
.
isEqualTo
(
cacheManager
.
getCacheManager
());
});
}
@Test
public
void
ehCacheWithCustomizers
()
{
this
.
contextRunner
.
withUserConfiguration
(
DefaultCacheAndCustomizersConfiguration
.
class
)
.
withPropertyValues
(
"spring.cache.type="
+
"ehcache"
)
.
run
(
verifyCustomizers
(
"allCacheManagerCustomizer"
,
"ehcacheCacheManagerCustomizer"
));
}
@Test
public
void
ehCacheWithConfig
()
{
this
.
contextRunner
.
withUserConfiguration
(
DefaultCacheConfiguration
.
class
)
.
withPropertyValues
(
"spring.cache.type=ehcache"
,
"spring.cache.ehcache.config=cache/ehcache-override.xml"
)
.
run
((
context
)
->
{
EhCacheCacheManager
cacheManager
=
getCacheManager
(
context
,
EhCacheCacheManager
.
class
);
assertThat
(
cacheManager
.
getCacheNames
())
.
containsOnly
(
"cacheOverrideTest1"
,
"cacheOverrideTest2"
);
});
}
@Test
public
void
ehCacheWithExistingCacheManager
()
{
this
.
contextRunner
.
withUserConfiguration
(
EhCacheCustomCacheManager
.
class
)
.
withPropertyValues
(
"spring.cache.type=ehcache"
).
run
((
context
)
->
{
EhCacheCacheManager
cacheManager
=
getCacheManager
(
context
,
EhCacheCacheManager
.
class
);
assertThat
(
cacheManager
.
getCacheManager
())
.
isEqualTo
(
context
.
getBean
(
"customEhCacheCacheManager"
));
});
}
}
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/EhCache3CacheAutoConfigurationTests.java
0 → 100644
View file @
c7ed5c3d
/*
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
autoconfigure
.
cache
;
import
org.ehcache.jsr107.EhcacheCachingProvider
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.boot.autoconfigure.cache.CacheAutoConfigurationTests.DefaultCacheConfiguration
;
import
org.springframework.boot.testsupport.runner.classpath.ClassPathExclusions
;
import
org.springframework.boot.testsupport.runner.classpath.ModifiedClassPathRunner
;
import
org.springframework.cache.jcache.JCacheCacheManager
;
import
org.springframework.core.io.ClassPathResource
;
import
org.springframework.core.io.Resource
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link CacheAutoConfigurationTests} with EhCache 3.
*
* @author Stephane Nicoll
* @author Andy Wilkinson
*/
@RunWith
(
ModifiedClassPathRunner
.
class
)
@ClassPathExclusions
(
"ehcache-2*.jar"
)
public
class
EhCache3CacheAutoConfigurationTests
extends
AbstractCacheAutoConfigurationTests
{
@Test
public
void
ehcache3AsJCacheWithCaches
()
{
String
cachingProviderFqn
=
EhcacheCachingProvider
.
class
.
getName
();
this
.
contextRunner
.
withUserConfiguration
(
DefaultCacheConfiguration
.
class
)
.
withPropertyValues
(
"spring.cache.type=jcache"
,
"spring.cache.jcache.provider="
+
cachingProviderFqn
,
"spring.cache.cacheNames[0]=foo"
,
"spring.cache.cacheNames[1]=bar"
)
.
run
((
context
)
->
{
JCacheCacheManager
cacheManager
=
getCacheManager
(
context
,
JCacheCacheManager
.
class
);
assertThat
(
cacheManager
.
getCacheNames
()).
containsOnly
(
"foo"
,
"bar"
);
});
}
@Test
public
void
ehcache3AsJCacheWithConfig
()
{
String
cachingProviderFqn
=
EhcacheCachingProvider
.
class
.
getName
();
String
configLocation
=
"ehcache3.xml"
;
this
.
contextRunner
.
withUserConfiguration
(
DefaultCacheConfiguration
.
class
)
.
withPropertyValues
(
"spring.cache.type=jcache"
,
"spring.cache.jcache.provider="
+
cachingProviderFqn
,
"spring.cache.jcache.config="
+
configLocation
)
.
run
((
context
)
->
{
JCacheCacheManager
cacheManager
=
getCacheManager
(
context
,
JCacheCacheManager
.
class
);
Resource
configResource
=
new
ClassPathResource
(
configLocation
);
assertThat
(
cacheManager
.
getCacheManager
().
getURI
())
.
isEqualTo
(
configResource
.
getURI
());
assertThat
(
cacheManager
.
getCacheNames
()).
containsOnly
(
"foo"
,
"bar"
);
});
}
}
spring-boot-project/spring-boot-dependencies/pom.xml
View file @
c7ed5c3d
...
...
@@ -47,7 +47,7 @@
<dom4j.version>
1.6.1
</dom4j.version>
<dropwizard-metrics.version>
3.2.6
</dropwizard-metrics.version>
<ehcache.version>
2.10.4
</ehcache.version>
<ehcache3.version>
3.
4
.0
</ehcache3.version>
<ehcache3.version>
3.
5
.0
</ehcache3.version>
<embedded-mongo.version>
2.0.3
</embedded-mongo.version>
<flyway.version>
5.0.7
</flyway.version>
<freemarker.version>
2.3.27-incubating
</freemarker.version>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment