Skip to content

Commit

Permalink
fix-0000: quick update & refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
rossbu committed Oct 8, 2024
1 parent 8be043a commit 0349187
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 4 deletions.
12 changes: 8 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ tasks.withType(JavaCompile) {
options.compilerArgs += ["--add-exports", "java.base/sun.security.x509=ALL-UNNAMED"]
options.compilerArgs += ["--add-exports", "java.base/sun.security.tools.keytool=ALL-UNNAMED"]
options.compilerArgs += ["--add-opens", "java.base/java.lang=ALL-UNNAMED"]
options.compilerArgs += ["--enable-preview"]
// options.compilerArgs += ["--enable-preview"]
options.encoding = 'UTF-8'
}

Expand Down Expand Up @@ -255,6 +255,7 @@ dependencies {
// benchmark
implementation 'org.openjdk.jmh:jmh-core:1.33'
annotationProcessor 'org.openjdk.jmh:jmh-generator-annprocess:1.33'
developmentOnly 'org.springframework.boot:spring-boot-devtools'

// benchmark by jmh plugin
jmh 'org.openjdk.jmh:jmh-core:1.33'
Expand Down Expand Up @@ -331,8 +332,8 @@ dependencies {
implementation 'com.redislabs:jredisearch:2.0.0'

// lombok
annotationProcessor 'org.projectlombok:lombok:1.18.20'
implementation 'org.projectlombok:lombok:1.18.20'
annotationProcessor 'org.projectlombok:lombok:1.18.32'
implementation 'org.projectlombok:lombok:1.18.32'


// okhttp
Expand Down Expand Up @@ -395,6 +396,10 @@ dependencies {
// test - xml
testImplementation group: 'xmlunit', name: 'xmlunit', version: '1.5'

// test- lombok
testCompileOnly 'org.projectlombok:lombok:1.18.32'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.32'

// test - mockito
testImplementation 'org.mockito:mockito-core:4.8.0'
testImplementation 'org.mockito:mockito-junit-jupiter:4.8.0'
Expand All @@ -406,7 +411,6 @@ dependencies {
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-params:5.7.2'


// testImplementation 'org.junit.jupiter:junit-jupiter:5.7.2'
// testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.2'
// testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.2'
Expand Down
67 changes: 67 additions & 0 deletions src/main/java/com/demo/http/FutureRequestExecutionServiceDemo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.demo.http;


import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import java.util.concurrent.Future;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.impl.client.FutureRequestExecutionMetrics;
import org.apache.http.impl.client.FutureRequestExecutionService;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpRequestFutureTask;
/**
* https://www.cnblogs.com/papering/p/9963987.html
* Preface http://hc.apache.org/httpcomponents-client-ga/tutorial/html/preface.html
*/
public class FutureRequestExecutionServiceDemo {
public static void main(String[] args) {
FutureRequestExecutionServiceDemo demo = new FutureRequestExecutionServiceDemo();
demo.test();
}

private void test() {
HttpClient httpClient = HttpClientBuilder.create().setMaxConnPerRoute(5).build();
ExecutorService executorService = Executors.newFixedThreadPool(5);
FutureRequestExecutionService futureRequestExecutionService =
new FutureRequestExecutionService(httpClient, executorService);
HttpRequestFutureTask<Void> execute = futureRequestExecutionService.execute(new HttpGet("http://www.google.com"), HttpClientContext.create(), new DummyResponseHander());
FutureRequestExecutionMetrics metrics = futureRequestExecutionService.metrics();
System.out.println("Active connection count: " + metrics.getActiveConnectionCount());
System.out.println("Scheduled connection count: " + metrics.getScheduledConnectionCount());
System.out.println("Successful connection count: " + metrics.getSuccessfulConnectionCount());
System.out.println("Successful connection average duration: " + metrics.getSuccessfulConnectionAverageDuration());
System.out.println("Failed connection count: " + metrics.getFailedConnectionCount());
System.out.println("Failed connection average duration: " + metrics.getFailedConnectionAverageDuration());
System.out.println("Task count: " + metrics.getTaskCount());
System.out.println("Request count: " + metrics.getRequestCount());
System.out.println("Request average duration: " + metrics.getRequestAverageDuration());
System.out.println("Task average duration: " + metrics.getTaskAverageDuration());
executorService.shutdown();

// metrics.getActiveConnectionCount(); // currently active connections
// metrics.getScheduledConnectionCount(); // currently scheduled connections
// metrics.getSuccessfulConnectionCount(); // total number of successful requests
// metrics.getSuccessfulConnectionAverageDuration(); // average request duration
// metrics.getFailedConnectionCount(); // total number of failed tasks
// metrics.getFailedConnectionAverageDuration(); // average duration of failed tasks
// metrics.getTaskCount(); // total number of tasks scheduled
// metrics.getRequestCount(); // total number of requests
// metrics.getRequestAverageDuration(); // average request duration
// metrics.getTaskAverageDuration(); // average task duration
}

private class DummyResponseHander implements ResponseHandler<Void> {
@Override
public Void handleResponse(org.apache.http.HttpResponse response) {
System.out.println("Response received");
response.setStatusCode(200);
return null;
}
}
}
26 changes: 26 additions & 0 deletions src/main/java/com/demo/lombok/LombokDemo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.demo.lombok;
;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

@Accessors(fluent = true)
class Person {
@Getter
@Setter
private String name;

@Getter
@Setter
private int age;
}

public class LombokDemo {
public static void main(String[] args) {
Person person = new Person();
person.name("John").age(25);

System.out.println("Name: " + person.name());
System.out.println("Age: " + person.age());
}
}
42 changes: 42 additions & 0 deletions src/main/java/com/demo/redis/RedisExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.demo.redis;


import redis.clients.jedis.Jedis;

import java.util.List;
import java.util.Set;

public class RedisExample {
public static void main(String[] args) {
// use HostAndPort
Jedis jedis = new Jedis("localhost", 6379);

System.out.println("Connection to server successfully");
//check whether server is running or not
System.out.println("Server is running: "+jedis.ping());

//set the data in redis string
jedis.set("tutorial-name", "Redis tutorial");
System.out.println("Stored string in redis:: "+ jedis.get("username"));

//store data in redis list
jedis.lpush("tutorial-list", "Redis");
jedis.lpush("tutorial-list", "Mongodb");
jedis.lpush("tutorial-list", "Mysql");

// Get the stored data and print it
List<String> list = jedis.lrange("tutorial-list", 0 ,5);

for(int i = 0; i<list.size(); i++) {
System.out.println("Stored string in redis:: "+list.get(i));
}

//store data in redis list
// Get the stored data and print it
Set<String> set = jedis.keys("*");

for (String key : set) {
System.out.println("List of stored keys:: "+key);
}
}
}

0 comments on commit 0349187

Please sign in to comment.