Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7abae6f
commit 022ab2f
Showing
6 changed files
with
692 additions
and
62 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
85 changes: 85 additions & 0 deletions
85
src/test/java/org/appng/application/manager/business/CacheTest.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,85 @@ | ||
/* | ||
* Copyright 2011-2021 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.appng.application.manager.business; | ||
|
||
import java.util.List; | ||
|
||
import javax.cache.Cache; | ||
|
||
import org.appng.api.support.CallableDataSource; | ||
import org.appng.core.controller.CachedResponse; | ||
import org.appng.core.service.CacheService; | ||
import org.appng.testsupport.validation.DateFieldDifferenceHandler; | ||
import org.appng.testsupport.validation.WritingXmlValidator; | ||
import org.appng.testsupport.validation.XPathDifferenceHandler; | ||
import org.appng.xml.platform.Datasource; | ||
import org.appng.xml.platform.Result; | ||
import org.junit.FixMethodOrder; | ||
import org.junit.Test; | ||
import org.junit.runners.MethodSorters; | ||
import org.springframework.http.MediaType; | ||
|
||
import com.hazelcast.config.ClasspathXmlConfig; | ||
import com.hazelcast.core.Hazelcast; | ||
import com.hazelcast.core.HazelcastInstance; | ||
|
||
@FixMethodOrder(MethodSorters.NAME_ASCENDING) | ||
public class CacheTest extends AbstractTest { | ||
|
||
static HazelcastInstance hz; | ||
|
||
static { | ||
WritingXmlValidator.writeXml = false; | ||
hz = Hazelcast.getOrCreateHazelcastInstance(new ClasspathXmlConfig("hazelcast-test.xml")); | ||
CacheService.createCacheManager(hz, false); | ||
} | ||
|
||
@Test | ||
public void testCache() throws Exception { | ||
Cache<String, CachedResponse> cache = CacheService.createCache(site); | ||
|
||
for (int i = 0; i < 500; i++) { | ||
String key = "/element/" + i; | ||
cache.put(key, new CachedResponse(key, site, servletRequest, 200, MediaType.TEXT_PLAIN_VALUE, new byte[0], | ||
null, 3600)); | ||
} | ||
|
||
addParameter("sortCacheElements", "pageSize:10;page:4"); | ||
initParameters(); | ||
CallableDataSource ds = getDataSource("cacheElements").withParam("siteid", "1").getCallableDataSource(); | ||
ds.perform(""); | ||
|
||
Datasource datasource = ds.getDatasource(); | ||
List<Result> results = datasource.getData().getResultset().getResults(); | ||
for (int i = 0; i < 10;) { | ||
results.get(i).getFields().get(0).setValue("/element/" + String.valueOf(++i)); | ||
} | ||
validate(datasource, new DateFieldDifferenceHandler()); | ||
} | ||
|
||
@Test | ||
public void testCacheStatistics() throws Exception { | ||
CallableDataSource ds = getDataSource("cacheStatistics").withParam("siteid", "1").getCallableDataSource(); | ||
ds.perform(""); | ||
Datasource datasource = ds.getDatasource(); | ||
XPathDifferenceHandler dh = new XPathDifferenceHandler(false); | ||
// avg put/get times | ||
dh.ignoreDifference("/datasource[1]/data[1]/resultset[1]/result[8]/field[2]/value[1]/text()[1]"); | ||
dh.ignoreDifference("/datasource[1]/data[1]/resultset[1]/result[10]/field[2]/value[1]/text()[1]"); | ||
validate(datasource, dh); | ||
} | ||
|
||
} |
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,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<hazelcast xmlns="http://www.hazelcast.com/schema/config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.hazelcast.com/schema/config http://www.hazelcast.com/schema/config/hazelcast-config-5.0.xsd"> | ||
|
||
<properties> | ||
<property name="hazelcast.logging.type">slf4j</property> | ||
</properties> | ||
<cluster-name>appNG</cluster-name> | ||
<instance-name>test</instance-name> | ||
<network> | ||
<join> | ||
<auto-detection enabled="false" /> | ||
<multicast enabled="false" /> | ||
<tcp-ip enabled="false" /> | ||
<aws enabled="false" /> | ||
<gcp enabled="false" /> | ||
<azure enabled="false" /> | ||
<kubernetes enabled="false" /> | ||
<eureka enabled="false" /> | ||
<discovery-strategies /> | ||
</join> | ||
</network> | ||
</hazelcast> |
Oops, something went wrong.