Skip to content

Commit

Permalink
手工merge pull request里的更新
Browse files Browse the repository at this point in the history
  • Loading branch information
Calvin committed Nov 21, 2014
1 parent 26d543b commit da72edb
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<ehcache updateCheck="false" name="shiroCache">

<!-- http://ehcache.org/ehcache.xml -->
<defaultCache
maxElementsInMemory="10000"
eternal="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
package org.springside.examples.showcase.demos.cache.ehcache;

import static org.assertj.core.api.Assertions.*;

import java.util.List;

import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
Expand All @@ -15,6 +18,8 @@
import org.springframework.test.context.ContextConfiguration;
import org.springside.modules.test.spring.SpringContextTestCase;

import com.google.common.collect.Lists;

/**
* 演示Ehcache的配置.
*
Expand All @@ -24,35 +29,38 @@
*/
@ContextConfiguration(locations = { "/cache/applicationContext-ehcache.xml" })
public class EhcacheDemo extends SpringContextTestCase {

private static final String CACHE_NAME = "demoCache";

@Autowired
private CacheManager ehcacheManager;

private Cache cache;

@Test
public void demo() {

cache = ehcacheManager.getCache(CACHE_NAME);

String key = "foo";
String value = "boo";
List<Element> list = Lists.newArrayList(new Element(key, value), new Element("foo1", "value1"));

put(key, value);
Object result = get(key);

assertThat(result).isEqualTo(value);

cache.remove(key);
result = get(key);
assertThat(result).isNull();

cache.putAll(list);
assertThat(cache.getSize()).isEqualTo(2);
}

public Object get(String key) {
Element element = cache.get(key);
return element.getObjectValue();
return null == element ? null : element.getObjectValue();
}

public void put(String key, Object value) {
Element element = new Element(key, value);
cache.put(element);
}
}
}
23 changes: 17 additions & 6 deletions examples/showcase/src/main/resources/cache/ehcache-demo.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<ehcache updateCheck="false" name="demoCache">

<!-- http://ehcache.org/ehcache.xml -->
<diskStore path="java.io.tmpdir/ehcache/showcase/demo" />

<!-- DefaultCache setting. -->
<defaultCache maxEntriesLocalHeap="10000" eternal="false" timeToIdleSeconds="300" timeToLiveSeconds="600"
overflowToDisk="true" maxEntriesLocalDisk="100000" />

<defaultCache
maxEntriesLocalHeap="10000"
eternal="false"
timeToIdleSeconds="300"
timeToLiveSeconds="600"
overflowToDisk="true"
maxEntriesLocalDisk="100000" />

<!-- Special objects setting. -->
<!-- Refresh demoCache every hour,按Cache实际大小而不是Element数量进行限制,超过限制后不保存到磁盘。 -->
<cache name="demoCache" maxBytesLocalHeap="10M" eternal="false" timeToIdleSeconds="3600"
timeToLiveSeconds="3600" overflowToDisk="false" />
<cache
name="demoCache"
maxBytesLocalHeap="10M"
eternal="false"
timeToIdleSeconds="3600"
timeToLiveSeconds="3600"
overflowToDisk="false" />
</ehcache>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<ehcache updateCheck="false" name="hibernateCache">

<!-- http://ehcache.org/ehcache.xml -->
<diskStore path="java.io.tmpdir/ehcache/showcase/hibernate" />

<!-- DefaultCache setting. -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<ehcache updateCheck="false" name="hibernateCache">

<!-- http://ehcache.org/ehcache.xml -->
<diskStore path="java.io.tmpdir/ehcache/showcase/hibernate" />

<cacheManagerPeerProviderFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<ehcache updateCheck="false" name="shiroCache">

<!-- http://ehcache.org/ehcache.xml -->
<defaultCache
maxElementsInMemory="10000"
eternal="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
*******************************************************************************/
package org.springside.modules.test.data;

import java.sql.SQLException;

import javax.sql.DataSource;

import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.io.support.EncodedResource;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.jdbc.JdbcTestUtils;
import org.springframework.jdbc.datasource.init.ScriptUtils;

/**
* SQL数据文件导入工具类。
Expand All @@ -26,11 +27,11 @@ public class DataFixtures {

private static ResourceLoader resourceLoader = new DefaultResourceLoader();

public static void executeScript(DataSource dataSource, String... sqlResourcePaths) throws DataAccessException {
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
public static void executeScript(DataSource dataSource, String... sqlResourcePaths) throws DataAccessException,
SQLException {
for (String sqlResourcePath : sqlResourcePaths) {
Resource resource = resourceLoader.getResource(sqlResourcePath);
JdbcTestUtils.executeSqlScript(jdbcTemplate, new EncodedResource(resource, DEFAULT_ENCODING), true);
ScriptUtils.executeSqlScript(dataSource.getConnection(), new EncodedResource(resource, DEFAULT_ENCODING));
}
}
}
32 changes: 0 additions & 32 deletions modules/parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1002,37 +1002,5 @@
</plugins>
</build>
</profile>

<!-- 忽略@Category(UnStable.class)的TestCase -->
<profile>
<id>skip-unstable</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludedGroups>org.springside.modules.test.category.UnStable</excludedGroups>
</configuration>
</plugin>
</plugins>
</build>
</profile>

<!-- 执行@Category(UnStable.class)的TestCase -->
<profile>
<id>run-unstable</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includedGroups>org.springside.modules.test.category.UnStable</includedGroups>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

0 comments on commit da72edb

Please sign in to comment.