-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add ehcache xml * polydata 4 caching * Cache usage improvements * Imports cleanup
- Loading branch information
Showing
8 changed files
with
131 additions
and
11 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
58 changes: 58 additions & 0 deletions
58
polydata-factory/src/itest/java/com/unidev/polydata4/MongodbCacheIntegrationTest.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,58 @@ | ||
package com.unidev.polydata4; | ||
|
||
import com.unidev.polydata4.domain.BasicPoly; | ||
import org.apache.commons.io.FileUtils; | ||
import org.apache.commons.io.IOUtils; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.junit.jupiter.Container; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.charset.Charset; | ||
import java.util.Map; | ||
|
||
/** | ||
* Mongodb integration tests with ehcache. | ||
*/ | ||
@Testcontainers | ||
public class MongodbCacheIntegrationTest extends IntegrationTest { | ||
|
||
@Container | ||
private final GenericContainer mongodb = new GenericContainer("mongo:6.0.2-focal") | ||
.withExposedPorts(27017); | ||
|
||
@Container | ||
private final GenericContainer redis = new GenericContainer("redis:7.0.5") | ||
.withExposedPorts(6379); | ||
|
||
|
||
@BeforeEach | ||
public void setup() throws IOException { | ||
|
||
InputStream resourceAsStream = getClass().getResourceAsStream("/cache/ehcache.xml"); | ||
String resource = IOUtils.toString(resourceAsStream, Charset.defaultCharset()); | ||
int random = (int) (Math.random() * 10000); | ||
resource = renderTemplate(resource, Map.of("random", random)); | ||
new File("/tmp/ehcache-" + random).mkdirs(); | ||
// write stream to temp file | ||
File tempFile = File.createTempFile("ehcache", ".xml"); | ||
FileUtils.writeStringToFile(tempFile, resource, Charset.defaultCharset()); | ||
BasicPoly config = BasicPoly.newPoly() | ||
.with("type", "mongodb") | ||
.with("uri", "mongodb://localhost:" + mongodb.getMappedPort(27017) + "/polydata4") | ||
.with("cache", BasicPoly.newPoly() | ||
.with("type", "jcache") | ||
.with("provider", "org.ehcache.jsr107.EhcacheCachingProvider") | ||
.with("name", "polydata") | ||
.with("implementationUri", "file://" + tempFile.getAbsolutePath()) | ||
) | ||
; | ||
|
||
create(config); | ||
} | ||
|
||
|
||
} |
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,26 @@ | ||
<#setting number_format="computer"> | ||
<!-- https://github.com/anthonydahanne/ehcache3-disk-persistence-demo/blob/master/src/main/resources/ehcache.xml --> | ||
<!-- https://www.ehcache.org/documentation/3.6/xml.html --> | ||
<config | ||
xmlns:jsr107='http://www.ehcache.org/v3/jsr107' | ||
xmlns='http://www.ehcache.org/v3'> | ||
|
||
<service> | ||
<jsr107:defaults enable-management="true" enable-statistics="true"/> | ||
|
||
</service> | ||
|
||
<persistence directory="/tmp/ehcache-${random}"></persistence> | ||
|
||
<cache alias="polydata" uses-template="heap-cache"/> | ||
|
||
<cache-template name="heap-cache"> | ||
|
||
<resources> | ||
<heap unit="entries">1024</heap> | ||
<offheap unit="MB">1</offheap> | ||
<disk persistent="true" unit="MB">100</disk> | ||
</resources> | ||
</cache-template> | ||
|
||
</config> |
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