Created
February 20, 2014 12:25
-
-
Save gurbuzali/9112377 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| public class ClientProcessTest { | |
| static { | |
| System.setProperty(GroupProperties.PROP_WAIT_SECONDS_BEFORE_JOIN, "0"); | |
| System.setProperty("java.net.preferIPv4Stack", "true"); | |
| System.setProperty("hazelcast.local.localAddress", "127.0.0.1"); | |
| System.setProperty("hazelcast.version.check.enabled", "false"); | |
| System.setProperty("hazelcast.socket.bind.any", "true"); | |
| Random rand = new Random(); | |
| int g1 = rand.nextInt(255); | |
| int g2 = rand.nextInt(255); | |
| int g3 = rand.nextInt(255); | |
| System.setProperty("hazelcast.multicast.group", "224." + g1 + "." + g2 + "." + g3); | |
| } | |
| public static void main(String[] args) throws Exception { | |
| final HazelcastInstance instance = Hazelcast.newHazelcastInstance(); | |
| final LinkedList<Process> processes = new LinkedList<Process>(); | |
| for (int i = 0; i < 20; i++) { | |
| final Process process = startProcess("gurbuz.ClientProcess", "60", "150"); | |
| processes.offer(process); | |
| } | |
| final ClientService clientService = instance.getClientService(); | |
| int counter = 0; | |
| while (true) { | |
| checkClientSize(clientService); | |
| Thread.sleep(10000); | |
| Process p = processes.poll(); | |
| p.destroy(); | |
| p = startProcess("gurbuz.ClientProcess", "60", "150"); | |
| processes.offer(p); | |
| if (counter++ > 30) { | |
| break; | |
| } | |
| } | |
| for (Process process : processes) { | |
| process.destroy(); | |
| } | |
| checkClientSize(clientService); | |
| Thread.sleep(1000); | |
| checkClientSize(clientService); | |
| Thread.sleep(5000); | |
| checkClientSize(clientService); | |
| } | |
| public static void checkClientSize(ClientService service){ | |
| final Collection<Client> clients = service.getConnectedClients(); | |
| System.err.println("asdf clients: " + clients.size()); | |
| } | |
| public static Process startProcess(String className, String poolSize, String threadCount) throws Exception { | |
| final String property = System.getProperty("java.class.path"); | |
| String[] command = {"java", "-cp", "\"" + property + "\"", className, poolSize, threadCount}; | |
| ProcessBuilder proBuilder = new ProcessBuilder(command).redirectErrorStream(true); | |
| proBuilder.directory(new File("/java/workspace/test/target/classes")); | |
| final Process process = proBuilder.start(); | |
| final Thread thread = new Thread() { | |
| @Override | |
| public void run() { | |
| try { | |
| InputStream in = process.getInputStream(); | |
| byte[] data = new byte[1024]; | |
| int len = -1; | |
| while ((len = in.read(data)) != -1) { | |
| System.err.print(new String(data, 0, len)); | |
| } | |
| } catch (Exception e) { | |
| e.printStackTrace(); | |
| } | |
| } | |
| }; | |
| thread.setDaemon(true); | |
| thread.start(); | |
| return process; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment