| | |
| | | import java.io.*; |
| | | import java.lang.Thread; |
| | | import javax.naming.*; |
| | | import javax.naming.directory.InitialDirContext; |
| | | //import javax.naming.directory.InitialDirContext; |
| | | import javax.naming.directory.SearchControls; |
| | | import javax.naming.directory.DirContext; |
| | | //import javax.naming.directory.DirContext; |
| | | import javax.naming.directory.SearchResult; |
| | | import javax.naming.directory.Attributes; |
| | | import javax.naming.ldap.*; |
| | | import javax.naming.ldap.StartTlsResponse; |
| | | import javax.naming.ldap.StartTlsRequest; |
| | | import javax.net.ssl.*; |
| | | |
| | | public class Client { |
| | | |
| | |
| | | static ArrayList<String> uidList; |
| | | static long delayCnx=1000; |
| | | static long delaySec=1; |
| | | static long delayPrint=60000; |
| | | |
| | | public Client() |
| | | { |
| | |
| | | |
| | | Hashtable envLdap = set_properties_LDAP_simpleBind(); |
| | | |
| | | DirContext ctx = null; |
| | | ctx = new InitialDirContext(envLdap); |
| | | LdapContext ctx = null; |
| | | ctx = new InitialLdapContext(envLdap,null); |
| | | |
| | | // Search options |
| | | String filter = "(objectclass=inetorgperson)"; |
| | |
| | | |
| | | int seconds=0; |
| | | long t1=System.currentTimeMillis(); |
| | | long print_t1=System.currentTimeMillis(); |
| | | |
| | | // work until Max duration is reached |
| | | while (true) { |
| | | |
| | | long new_t1=System.currentTimeMillis(); |
| | | |
| | | long print_t2=System.currentTimeMillis(); |
| | | // end of the system test. Exit |
| | | if ( ( timeTostopTest != 0 ) && ( new_t1 > timeTostopTest ) ) { |
| | | |
| | |
| | | break; |
| | | } |
| | | |
| | | // status every delayPrint |
| | | if ( (print_t2 - print_t1) >= delayPrint ) { |
| | | duration=((print_t2-print_t1)/1000); |
| | | println("INFO", "Rate: " + (total_nb_srchs/duration) + " srchs/sec"); |
| | | print_t1=System.currentTimeMillis(); |
| | | try { |
| | | synchronized(this) { |
| | | total_nb_srchs=0; |
| | | } |
| | | } catch ( Exception e2 ) { |
| | | System.out.println("E2"); |
| | | e2.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | // status every second |
| | | if ( (new_t1 - t1) >= delayCnx ) { |
| | | |
| | | println("INFO", (nb_srchs_done/delaySec) + " srch/sec."); |
| | | // println("INFO", (nb_srchs_done/delaySec) + " srch/sec."); |
| | | |
| | | // inform all the threads the max nb searchs has been reached |
| | | synchronized (this) { |
| | |
| | | e1.printStackTrace(); |
| | | } |
| | | |
| | | if ( (seconds++) >= 9 ) { |
| | | duration=((new_t1-startup)/1000); |
| | | println("INFO", "Avg rate: " + (total_nb_srchs/duration) + " srchs/sec. after " + getTime(duration)); |
| | | seconds=0; |
| | | } |
| | | t1=new_t1; |
| | | } |
| | | } |
| | |
| | | |
| | | // BaseDN |
| | | suffix = System.getProperty("suffix"); |
| | | println ("INFO" , "suffix " + suffix); |
| | | println ("INFO" , "CONFIG suffix " + suffix); |
| | | |
| | | // nb_threads |
| | | String snb_threads = System.getProperty("nb_threads"); |
| | | nb_threads = Integer.parseInt(snb_threads); |
| | | |
| | | println ("INFO" , "nb_threads " + snb_threads); |
| | | println ("INFO" , "CONFIG nb_threads " + snb_threads); |
| | | |
| | | // test duration |
| | | String sMaxDuration = System.getProperty("maxDuration"); |
| | | maxDuration = Long.parseLong(sMaxDuration); |
| | | println ("INFO" , "maxDuration " + maxDuration); |
| | | println ("INFO" , "CONFIG maxDuration " + maxDuration); |
| | | |
| | | // credential for simple bind |
| | | bindDN = System.getProperty("bindDN"); |
| | | bindPW = System.getProperty("bindPW"); |
| | | println ("INFO" , "bindDN " + bindDN); |
| | | println ("INFO" , "CONFIG bindDN " + bindDN); |
| | | |
| | | // attribute to search |
| | | attributeName = System.getProperty("attributeName"); |
| | | println ("INFO" , "attributeName " + attributeName); |
| | | println ("INFO" , "CONFIG attributeName " + attributeName); |
| | | |
| | | // Max number of searchs |
| | | String sNB_MAX_srchs = System.getProperty("NB_MAX_srchs"); |
| | | NB_MAX_srchs = Integer.parseInt(sNB_MAX_srchs); |
| | | println ("INFO" , "sNB_MAX_srchs " + sNB_MAX_srchs); |
| | | println ("INFO" , "CONFIG sNB_MAX_srchs " + sNB_MAX_srchs); |
| | | |
| | | // hostname |
| | | hostname = System.getProperty("hostname"); |
| | |
| | | |
| | | // protocol : SSL or TLS |
| | | protocol = System.getProperty("protocol"); |
| | | println ("INFO" , "protocol " + protocol); |
| | | println ("INFO" , "CONFIG protocol " + protocol); |
| | | |
| | | // authentication : EXTERNAL or simple |
| | | authentication = System.getProperty("authentication"); |
| | | println ("INFO" , "authentication " + authentication); |
| | | println ("INFO" , "CONFIG authentication " + authentication); |
| | | |
| | | // delay Sec before closing conx |
| | | String sdelaySec = System.getProperty("delaySec"); |
| | | delaySec = Long.parseLong(sdelaySec); |
| | | delayCnx = delaySec * 1000; |
| | | println ("INFO" , "delayCnx " + delayCnx); |
| | | println ("INFO" , "CONFIG delayCnx " + delayCnx); |
| | | |
| | | |
| | | if ( maxDuration != 0 ) { |
| | |
| | | envLdap.put("java.naming.factory.initial", |
| | | "com.sun.jndi.ldap.LdapCtxFactory"); |
| | | |
| | | if ( ! protocol.equals("starttls")) { |
| | | envLdap.put(Context.SECURITY_AUTHENTICATION, authentication); |
| | | } |
| | | |
| | | if ( protocol.equals("ssl")) { |
| | | provider = "ldaps://"+server.host+":"+server.port+"/"; |