directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r421363 - in /directory/branches/apacheds/optimization/benchmarks: ./ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/directory/ src/main/java/org/apache/directory/server/ src/main/java/org/apache/directory/server/benc...
Date Wed, 12 Jul 2006 18:36:17 GMT
Author: akarasulu
Date: Wed Jul 12 11:36:16 2006
New Revision: 421363

URL: http://svn.apache.org/viewvc?rev=421363&view=rev
Log:
checking in simple bind unbind test

Added:
    directory/branches/apacheds/optimization/benchmarks/src/main/java/org/
    directory/branches/apacheds/optimization/benchmarks/src/main/java/org/apache/
    directory/branches/apacheds/optimization/benchmarks/src/main/java/org/apache/directory/
    directory/branches/apacheds/optimization/benchmarks/src/main/java/org/apache/directory/server/
    directory/branches/apacheds/optimization/benchmarks/src/main/java/org/apache/directory/server/benchmarks/
    directory/branches/apacheds/optimization/benchmarks/src/main/java/org/apache/directory/server/benchmarks/BindBenchmark.java
Modified:
    directory/branches/apacheds/optimization/benchmarks/pom.xml

Modified: directory/branches/apacheds/optimization/benchmarks/pom.xml
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/optimization/benchmarks/pom.xml?rev=421363&r1=421362&r2=421363&view=diff
==============================================================================
--- directory/branches/apacheds/optimization/benchmarks/pom.xml (original)
+++ directory/branches/apacheds/optimization/benchmarks/pom.xml Wed Jul 12 11:36:16 2006
@@ -12,5 +12,12 @@
     Set of programs to run to benchmark the performance of the server.
   </description>
   <packaging>jar</packaging>
+  <dependencies>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>nlog4j</artifactId>
+      <version>1.2.25</version>
+    </dependency>
+  </dependencies>
 </project>
 

Added: directory/branches/apacheds/optimization/benchmarks/src/main/java/org/apache/directory/server/benchmarks/BindBenchmark.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/optimization/benchmarks/src/main/java/org/apache/directory/server/benchmarks/BindBenchmark.java?rev=421363&view=auto
==============================================================================
--- directory/branches/apacheds/optimization/benchmarks/src/main/java/org/apache/directory/server/benchmarks/BindBenchmark.java
(added)
+++ directory/branches/apacheds/optimization/benchmarks/src/main/java/org/apache/directory/server/benchmarks/BindBenchmark.java
Wed Jul 12 11:36:16 2006
@@ -0,0 +1,225 @@
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.directory.server.benchmarks;
+
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+import java.net.UnknownHostException;
+import java.nio.ByteBuffer;
+import java.nio.channels.SocketChannel;
+
+import javax.naming.NamingException;
+
+import org.apache.directory.shared.asn1.ber.Asn1Decoder;
+import org.apache.directory.shared.asn1.ber.IAsn1Container;
+import org.apache.directory.shared.asn1.ber.tlv.TLVStateEnum;
+import org.apache.directory.shared.asn1.codec.DecoderException;
+import org.apache.directory.shared.ldap.codec.LdapDecoder;
+import org.apache.directory.shared.ldap.codec.LdapMessage;
+import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
+import org.apache.directory.shared.ldap.codec.LdapResult;
+import org.apache.directory.shared.ldap.codec.bind.BindRequest;
+import org.apache.directory.shared.ldap.codec.bind.BindResponse;
+import org.apache.directory.shared.ldap.codec.bind.LdapAuthentication;
+import org.apache.directory.shared.ldap.codec.bind.SimpleAuthentication;
+import org.apache.directory.shared.ldap.codec.extended.ExtendedResponse;
+import org.apache.directory.shared.ldap.codec.unbind.UnBindRequest;
+import org.apache.directory.shared.ldap.codec.util.LdapResultEnum;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.util.StringTools;
+
+
+/**
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class BindBenchmark 
+{
+    private SocketChannel channel;
+    private SocketAddress serverAddress;
+    private IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+    private Asn1Decoder ldapDecoder = new LdapDecoder();
+
+    
+
+    /**
+     * Connect to the LDAP server through a socket and establish the Input and
+     * Output Streams. 
+     */
+    private void connect() throws UnknownHostException, IOException
+    {
+        serverAddress = new InetSocketAddress( "maxwell", 10389 );
+        channel = SocketChannel.open( serverAddress );
+        channel.configureBlocking( true );
+    }
+
+    
+    private void sendMessage( ByteBuffer bb ) throws IOException
+    {
+        channel.write( bb );
+        bb.clear();
+    }
+
+
+    private LdapMessage readResponse( ByteBuffer bb ) throws IOException, DecoderException,
NamingException
+    {
+        LdapMessage messageResp = null;
+
+        while ( true )
+        {
+            int nbRead = channel.read( bb );
+
+            if ( nbRead == -1 )
+            {
+                break;
+            }
+            else
+            {
+                bb.flip();
+
+                // Decode the PDU
+                ldapDecoder.decode( bb, ldapMessageContainer );
+
+                if ( ldapMessageContainer.getState() == TLVStateEnum.PDU_DECODED )
+                {
+                    messageResp = ( (LdapMessageContainer) ldapMessageContainer ).getLdapMessage();
+
+                    if ( messageResp instanceof BindResponse )
+                    {
+                        BindResponse resp = ( (LdapMessageContainer) ldapMessageContainer
).getLdapMessage().getBindResponse();
+
+                        if ( resp.getLdapResult().getResultCode() != 0 )
+                        {
+                            System.out.println( "Error : " + resp.getLdapResult().getErrorMessage()
);
+                        }
+                    }
+                    else if ( messageResp instanceof ExtendedResponse )
+                    {
+                        ExtendedResponse resp = ( (LdapMessageContainer) ldapMessageContainer
).getLdapMessage()
+                                .getExtendedResponse();
+
+                        if ( resp.getLdapResult().getResultCode() != 0 )
+                        {
+                            System.out.println( "Error : " + resp.getLdapResult().getErrorMessage()
);
+                        }
+                    }
+
+                    ( (LdapMessageContainer) ldapMessageContainer ).clean();
+                    break;
+                }
+                else
+                {
+                    bb.flip();
+                }
+            }
+        }
+
+        return messageResp;
+    }
+
+    
+    public static void main( String[] args ) throws Exception
+    {
+        BindBenchmark bb = new BindBenchmark();
+        bb.execute( args );
+    }
+
+    
+    public void execute( String[] args ) throws Exception
+    {
+        long sum = 0;
+        long[] runtimes = new long[1000];
+        long startTime = System.currentTimeMillis();
+        for ( int ii = 0; ii < runtimes.length; ii++ )
+        {
+            long time = System.currentTimeMillis();
+            bind( 1 );
+            unbind( 2 );
+            this.channel.socket().close();
+            this.channel.close();
+            runtimes[ii] = ( System.currentTimeMillis() - time );
+            System.out.println( "run #" + ii + ": " + runtimes[ii] );
+            sum += runtimes[ii];
+        }
+        System.out.println( "Total time (ms) for "+ runtimes.length 
+            + " bind unbind operations: " + ( System.currentTimeMillis() - startTime ) );
+        System.out.println( "Average time (ms) for bind unbind operations: " + sum/runtimes.length
);
+    }
+    
+
+    /**
+     * Bind to the ldap server
+     * 
+     * @param messageId The message Id
+     */
+    private void bind( int messageId ) throws Exception
+    {
+        BindRequest bindRequest = new BindRequest();
+        LdapMessage message = new LdapMessage();
+        LdapAuthentication authentication = null;
+
+        authentication = new SimpleAuthentication();
+        ( (SimpleAuthentication) authentication ).setSimple( StringTools.getBytesUtf8( "secret"
) );
+        bindRequest.setAuthentication( authentication );
+        bindRequest.setName( new LdapDN( "uid=admin,ou=system" ) );
+        bindRequest.setVersion( 3 );
+        message.setProtocolOP( bindRequest );
+        message.setMessageId( messageId );
+        
+        // Encode and send the bind request
+        ByteBuffer bb = message.encode( null );
+        bb.flip();
+
+        connect();
+        sendMessage( bb );
+
+        bb.clear();
+
+        // Get the bind response
+        LdapMessage response = readResponse( bb );
+
+        LdapResult result = response.getBindResponse().getLdapResult();
+
+        if ( result.getResultCode() == LdapResultEnum.SUCCESS )
+        {
+        }
+        else
+        {
+            throw new RuntimeException( "bind failed" );
+        }
+    }
+    
+
+    /**
+     * Unbind from the server
+     */
+    private void unbind( int messageId ) throws Exception
+    {
+        UnBindRequest unbindRequest = new UnBindRequest();
+        LdapMessage message = new LdapMessage();
+
+        message.setProtocolOP( unbindRequest );
+        message.setMessageId( messageId );
+        ByteBuffer bb = message.encode( null );
+        bb.flip();
+
+        sendMessage( bb );
+    }
+}



Mime
View raw message