diff --git a/gazelle-proxy-loadtests/pom.xml b/gazelle-proxy-loadtests/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..a2d08a5bffffee15fb92a2eb20899bc4e038d6d5 --- /dev/null +++ b/gazelle-proxy-loadtests/pom.xml @@ -0,0 +1,32 @@ +<?xml version="1.0"?> +<project + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" + xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + + <parent> + <artifactId>gazelle-proxy</artifactId> + <groupId>net.ihe.gazelle.proxy</groupId> + <version>1.2-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <modelVersion>4.0.0</modelVersion> + + <groupId>net.ihe.gazelle.proxy</groupId> + <artifactId>gazelle-proxy-loadtests</artifactId> + <version>1.2-SNAPSHOT</version> + <packaging>jar</packaging> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + </dependencies> +</project> diff --git a/gazelle-proxy-loadtests/src/main/java/org/gazelle/proxy/loadtests/App.java b/gazelle-proxy-loadtests/src/main/java/org/gazelle/proxy/loadtests/App.java new file mode 100644 index 0000000000000000000000000000000000000000..ec0516e4f422a667cedb68308851f60040ce205b --- /dev/null +++ b/gazelle-proxy-loadtests/src/main/java/org/gazelle/proxy/loadtests/App.java @@ -0,0 +1,57 @@ +package org.gazelle.proxy.loadtests; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.ThreadPoolExecutor; + +public class App { + + public static void main(String[] args) throws InterruptedException, ExecutionException { + ThreadPoolExecutor threadPool = (ThreadPoolExecutor) Executors.newFixedThreadPool(12); + + List<Future<String>> futures = new ArrayList<Future<String>>(); + + for (int i = 0; i < 200; i++) { + final int j = i; + Callable<String> task = new Callable<String>() { + @Override + public String call() throws Exception { + System.out.println("Called " + j); + + Thread.sleep(500 + Math.round(Math.random() * 500)); + + System.out.println("Done " + j); + return "toto" + j; + } + }; + Future<String> future = threadPool.submit(task); + futures.add(future); + } + + while (threadPool.getQueue().size() > 0) { + Thread.sleep(1000); + } + + boolean allFinished = false; + while (!allFinished) { + allFinished = true; + for (Future<String> future : futures) { + allFinished = allFinished && future.isDone(); + } + if (!allFinished) { + Thread.sleep(1000); + } + } + + for (Future<String> future : futures) { + System.out.println(future.get()); + } + + threadPool.shutdown(); + } + +}