Advertisement
muncescu

Netscape LDAP SDK - test

Mar 3rd, 2014
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.66 KB | None | 0 0
  1. public static void main(String[] args) {
  2.  
  3.         String host = "*****";
  4.         int port = 389;
  5.  
  6.         String authid = "*****";
  7.         String authpw = "*****";
  8.  
  9.         String[] ATTR = {*****};
  10.         String[] ATTR1 = {*****};
  11.  
  12.         String base = "*****";
  13.         LDAPConnection ld = null;
  14.         LDAPSearchResults searchResult;
  15.         int numSubord = 0;
  16.         int index = 0;
  17.         long totalTime = 0;
  18.         long startTime = 0;
  19.         int iter = 1;
  20.  
  21.         for (int i = 0; i < iter; i++) {
  22.             startTime = System.currentTimeMillis();
  23.             try {
  24.                 ld = new LDAPConnection();
  25.                 ld.connect(3, host, port, authid, authpw);
  26.  
  27.                 searchResult = ld.search(base, LDAPConnection.SCOPE_BASE, "(objectclass=*)", ATTR1, false);
  28.  
  29.                 if (searchResult.getCount() == 0) {
  30.                     return;
  31.                 }
  32.  
  33.                 LDAPEntry en = searchResult.next();
  34.                 numSubord = Integer.parseInt(en.getAttribute(ATTR1[0]).getStringValueArray()[0]);
  35.                 index = numSubord - 4;
  36.                 if (index < 1) {
  37.                     index = 1;
  38.                 }
  39.                 searchResult = ld.search(base, LDAPConnection.SCOPE_ONE, "(&(index>=" + index + ")(index<=" + numSubord + "))", ATTR, false);
  40.             } catch (LDAPException e) {
  41.             }
  42.             try {
  43.                 if (ld != null) {
  44.                     ld.disconnect();
  45.                 }
  46.             } catch (LDAPException ex) {
  47.  
  48.             }
  49.  
  50.             totalTime += System.currentTimeMillis() - startTime;
  51.         }
  52.  
  53.         System.out.println(totalTime / iter);
  54.  
  55.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement