1 4 package com.tctest.performance.http.load; 5 6 import java.io.File ; 7 import java.io.FileInputStream ; 8 import java.util.Properties ; 9 10 public class TestProperties { 11 static final String PROPERTIES_FILE = "http-load-client.properties"; 12 static final String PROP_HOSTS = "hosts"; static final String PROP_THREADS = "threads"; 14 static final String PROP_STICKY_RATIO = "sticky-ratio"; 15 static final String PROP_SESSIONS = "sessions"; 16 17 private final int stickyRatio; 18 private final int sessionsCount; 19 private final String [] hosts; 20 private final int threadCount; 21 22 public TestProperties(File workingDir) { 23 this(workingDir.getAbsolutePath()); 24 } 25 26 public TestProperties(String workingDir) { 27 Properties props = new Properties (); 28 try { 29 props.load(new FileInputStream (workingDir + File.separator + PROPERTIES_FILE)); 30 } catch (Exception e) { 31 e.printStackTrace(); 32 throw new RuntimeException (e); 33 } 34 stickyRatio = toInt(props.getProperty(PROP_STICKY_RATIO, "100"), 100); 35 sessionsCount = toInt(props.getProperty(PROP_SESSIONS, "100"), 100); 36 hosts = props.getProperty(PROP_HOSTS, "http://127.0.0.1").split(","); 37 threadCount = toInt(props.getProperty(PROP_THREADS, "50"), 50); 38 } 39 40 public String [] getHosts() { 41 return hosts; 42 } 43 44 public int getSessionsCount() { 45 return sessionsCount; 46 } 47 48 public int getStickyRatio() { 49 return stickyRatio; 50 } 51 52 public int getThreadCount() { 53 return threadCount; 54 } 55 56 private static int toInt(String v, int def) { 57 try { 58 return Integer.parseInt(v); 59 } catch (Exception e) { 60 return def; 61 } 62 } 63 } 64 | Popular Tags |