mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

smaguin
24.44.2008 a94eff9bd079b85a96fd15bf7336c762c948e769
opends/tests/system-tests/scenario/singleServer/clients/secureSearch/src/Client.java
@@ -27,11 +27,15 @@
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 {
    
@@ -61,6 +65,7 @@
    static ArrayList<String> uidList;
    static long delayCnx=1000;
    static long delaySec=1;    
    static long delayPrint=60000;
    
    public Client()
    {
@@ -72,9 +77,9 @@
            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)";
            String[] attrs = { "uid"};
@@ -145,12 +150,13 @@
            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 ) ) { 
                  
@@ -160,11 +166,26 @@
          }
                  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) {
@@ -191,11 +212,6 @@
         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;
                }
            }
@@ -233,32 +249,32 @@
   // 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");
@@ -266,17 +282,17 @@
   // 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 ) {
@@ -384,7 +400,9 @@
     envLdap.put("java.naming.factory.initial",
      "com.sun.jndi.ldap.LdapCtxFactory");
     
     envLdap.put(Context.SECURITY_AUTHENTICATION, authentication);
     if ( ! protocol.equals("starttls")) {
       envLdap.put(Context.SECURITY_AUTHENTICATION, authentication);
     }
     
     if ( protocol.equals("ssl")) {
       provider = "ldaps://"+server.host+":"+server.port+"/";