-
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.
#2 Infinispan test: test performance
- Loading branch information
Showing
7 changed files
with
177 additions
and
2 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
40 changes: 40 additions & 0 deletions
40
src/main/java/com/share/memory/controller/InfinispanCheckSetAndRevoke.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,40 @@ | ||
package com.share.memory.controller; | ||
|
||
import com.share.memory.infinispan.CacheType; | ||
import com.share.memory.infinispan.InfinispanStarter; | ||
import com.share.memory.infinispan.model.Person; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
/** | ||
* author : fanzhe | ||
* email : [email protected] | ||
* date : 2019/10/12 AM9:54. | ||
*/ | ||
@RestController | ||
@RequestMapping("/api") | ||
public class InfinispanCheckSetAndRevoke { | ||
@RequestMapping(value = "/check",method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_UTF8_VALUE) | ||
public Object getPerson(@RequestParam(name = "cacheType",required = false) String cacheType, | ||
@RequestParam(name = "key")String key){ | ||
return InfinispanStarter.check(key); | ||
} | ||
|
||
@RequestMapping(value = "/set",method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_UTF8_VALUE) | ||
public String setPerson( | ||
@RequestParam(name = "key")String key, | ||
@RequestParam(name = "name")String name, | ||
@RequestParam(name = "age")int age | ||
){ | ||
InfinispanStarter.put(key,new Person(name,age)); | ||
return key; | ||
} | ||
|
||
@RequestMapping(value = "/revoke",method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_UTF8_VALUE) | ||
public Person revokePerson( | ||
@RequestParam(name = "key")String key | ||
|
||
){ | ||
return InfinispanStarter.revoke(key); | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
src/main/java/com/share/memory/httpclient/RemoteClient.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,82 @@ | ||
package com.share.memory.httpclient; | ||
|
||
import org.apache.http.client.methods.HttpGet; | ||
import org.apache.http.client.utils.URIBuilder; | ||
import org.apache.http.impl.client.CloseableHttpClient; | ||
import org.apache.http.impl.client.HttpClients; | ||
import org.apache.http.util.EntityUtils; | ||
|
||
import java.io.IOException; | ||
import java.net.URISyntaxException; | ||
import java.util.UUID; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
/** | ||
* author : fanzhe | ||
* email : [email protected] | ||
* date : 2019/10/28 PM11:15. | ||
*/ | ||
public class RemoteClient { | ||
static CloseableHttpClient httpclient = HttpClients.createDefault(); | ||
|
||
private static final String GET = "http://192.168.128.149:8080/share_memory/api/check"; | ||
private static final String SET = "http://192.168.128.148:8080/share_memory/api/set"; | ||
private static final String REVOKE = "http://192.168.128.148:8080/share_memory/api/revoke"; | ||
|
||
public static void main(String[] args) throws IOException, URISyntaxException, InterruptedException { | ||
Logger root = Logger.getLogger(""); | ||
root.setLevel(Level.INFO); | ||
String key ; | ||
for(int i =0 ;i< 1000;i++){ | ||
key = set(); | ||
System.out.println("key: "+ key); | ||
check(key); | ||
revoke(key); | ||
} | ||
|
||
} | ||
|
||
public static String set() throws URISyntaxException, IOException { | ||
long t1 = System.currentTimeMillis(); | ||
URIBuilder uriBuilder = new URIBuilder(SET); | ||
String key = UUID.randomUUID().toString(); | ||
uriBuilder.addParameter("key", key); | ||
uriBuilder.addParameter("name",key+"_1"); | ||
uriBuilder.addParameter("age","1000"); | ||
HttpGet get = new HttpGet(uriBuilder.build()); | ||
String result = EntityUtils.toString(httpclient.execute(get).getEntity()); | ||
System.out.println("get : "+ (System.currentTimeMillis()-t1)/1000.0 +" seconds!"); | ||
return result; | ||
} | ||
|
||
public static void check(String key) throws URISyntaxException, IOException, InterruptedException { | ||
long t1 = System.currentTimeMillis(); | ||
URIBuilder uriBuilder = new URIBuilder(GET); | ||
|
||
uriBuilder.addParameter("key", key); | ||
|
||
HttpGet get = new HttpGet(uriBuilder.build()); | ||
String flag = EntityUtils.toString(httpclient.execute(get).getEntity()); | ||
while (!"true".equals(flag)){ | ||
Thread.sleep(200); | ||
flag = EntityUtils.toString(httpclient.execute(get).getEntity()); | ||
} | ||
System.out.println("check : "+ (System.currentTimeMillis()-t1)/1000.0 +" seconds!"); | ||
return ; | ||
} | ||
public static void revoke(String key) throws URISyntaxException, IOException, InterruptedException { | ||
long t1 = System.currentTimeMillis(); | ||
URIBuilder uriBuilder = new URIBuilder(REVOKE); | ||
|
||
uriBuilder.addParameter("key", key); | ||
|
||
HttpGet get = new HttpGet(uriBuilder.build()); | ||
|
||
EntityUtils.toString(httpclient.execute(get).getEntity()); | ||
|
||
System.out.println("revoke : "+ (System.currentTimeMillis()-t1)/1000.0 +" seconds!"); | ||
return ; | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
package com.share.memory.infinispan.model; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* author : fanzhe | ||
* email : [email protected] | ||
* date : 2019/10/22 AM8:33. | ||
*/ | ||
public class Cat { | ||
public class Cat implements Serializable{ | ||
private String name; | ||
private int age; | ||
|
||
|
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 |
---|---|---|
@@ -1,14 +1,23 @@ | ||
package com.share.memory.infinispan.model; | ||
|
||
import java.io.Serializable; | ||
import java.util.Arrays; | ||
|
||
/** | ||
* author : fanzhe | ||
* email : [email protected] | ||
* date : 2019/10/22 AM8:33. | ||
*/ | ||
public class Person { | ||
public class Person implements Serializable{ | ||
public Person(String name, int age){ | ||
this.name = name; | ||
setAge(age); | ||
} | ||
private String name; | ||
private int age; | ||
|
||
private double[] arr= new double[10000]; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
@@ -22,6 +31,7 @@ public int getAge() { | |
} | ||
|
||
public void setAge(int age) { | ||
Arrays.fill(arr,1000.0); | ||
this.age = age; | ||
} | ||
} |
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,11 @@ | ||
<configuration> | ||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder> | ||
<pattern>%-4relative [%thread] %-5level %logger{35} - %msg %n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<root level="INFO"> | ||
<appender-ref ref="STDOUT" /> | ||
</root> | ||
</configuration> |