You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by sa...@apache.org on 2004/06/14 09:33:39 UTC

cvs commit: ws-axis/c/tests/client/threadSafe Client.cpp readme.txt

samisa      2004/06/14 00:33:39

  Modified:    c/tests/client/threadSafe Client.cpp readme.txt
  Log:
  Made the output more useful and readable.
  Added documentation in readme.txt
  
  Revision  Changes    Path
  1.3       +88 -84    ws-axis/c/tests/client/threadSafe/Client.cpp
  
  Index: Client.cpp
  ===================================================================
  RCS file: /home/cvs/ws-axis/c/tests/client/threadSafe/Client.cpp,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Client.cpp	10 Jun 2004 10:28:37 -0000	1.2
  +++ Client.cpp	14 Jun 2004 07:33:38 -0000	1.3
  @@ -1,5 +1,27 @@
  -// InteropBaseClient.cpp : Defines the entry point for the console application.
  -//
  +/*
  + *   Copyright 2003-2004 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.
  + */
  +
  +/*
  + * This software consists of voluntary contributions made by many
  + * individuals on behalf of the Apache Software Foundation.  For more
  + * information on the Apache Software Foundation, please see
  + * <http://www.apache.org/>.
  + *
  + * @author Samisa Abeysinghe (sabeysinghe@virtusa.com)
  + */
   #include <string>
   #include <pthread.h>
   #include <stdio.h>
  @@ -11,7 +33,7 @@
   #include "gen_src/InteropTestPortType.h"
   
   #define ARRAYSIZE 2
  -#define NUM_THREADS     3
  +#define NUM_THREADS     30
   
   
   const char *server = "localhost";
  @@ -37,7 +59,7 @@
   	ws = (InteropTestPortType *) arg;
   
   
  -    printf("invoking echoString...\n");
  +    //printf("invoking echoString...\n");
       //testing echoString 
       string bigstring;
       for (int ii = 0; ii < 2; ii++)
  @@ -45,11 +67,9 @@
   	bigstring += "hello world ";
       }
       strcpy(buffer1, bigstring.c_str());
  -    printf(ws->echoString(buffer1));
  -    if (0 == strcmp(ws->echoString("hello world"), "hello world"))
  -	printf("successful\n");
  -    else
  -	printf("failed\n");
  +    if (0 != strcmp(ws->echoString("hello world"), "hello world"))
  +	printf("echoString failed\n");
  +    
       // testing echoStringArray 
       xsd__string_Array arrstr;
       arrstr.m_Array = new char *[ARRAYSIZE];
  @@ -61,17 +81,15 @@
   	arrstr.m_Array[i] = buffer1;
       }
       //arrstr.m_Array[1] = buffer2;
  -    printf("invoking echoStringArray...\n");
  -    if (ws->echoStringArray(arrstr).m_Array != NULL)
  -	printf("successful\n");
  -    else
  -	printf("failed\n");
  +    //printf("invoking echoStringArray...\n");
  +    if (ws->echoStringArray(arrstr).m_Array == NULL)
  +	printf("echoStringArray failed\n");
  +
       // testing echoInteger 
  -    printf("invoking echoInteger...\n");
  -    if (ws->echoInteger(56) == 56)
  -	printf("successful\n");
  -    else
  -	printf("failed\n");
  +    //printf("invoking echoInteger...\n");
  +    if (ws->echoInteger(56) != 56)
  +	printf("echoInteger failed\n");
  +
       // testing echoIntegerArray 
       xsd__int_Array arrint;
       arrint.m_Array = new int[ARRAYSIZE];
  @@ -80,18 +98,17 @@
       {
   	arrint.m_Array[x] = x;
       }
  -    printf("invoking echoIntegerArray...\n");
  -    if (ws->echoIntegerArray(arrint).m_Array != NULL)
  -	printf("successful\n");
  -    else
  -	printf("failed\n");
  +    //printf("invoking echoIntegerArray...\n");
  +    if (ws->echoIntegerArray(arrint).m_Array == NULL)
  +	printf("echoIntegerArray failed\n");
  +
       // testing echoFloat 
  -    printf("invoking echoFloat...\n");
  +    //printf("invoking echoFloat...\n");
       float fvalue = 1.4214;
  -    if (ws->echoFloat(fvalue) > 1.42)
  -	printf("successful\n");
  -    else
  -	printf("failed\n");
  +    float retVal = ws->echoFloat(fvalue);
  +    if ( retVal < 1.42 || retVal > 1.43 )
  +	printf("echoFloat failed\n");
  +
       // testing echoFloat 
       xsd__float_Array arrfloat;
       arrfloat.m_Array = new float[ARRAYSIZE];
  @@ -100,21 +117,19 @@
       {
   	arrfloat.m_Array[x] = 1.1111 * x;
       }
  -    printf("invoking echoFloatArray...\n");
  -    if (ws->echoFloatArray(arrfloat).m_Array != NULL)
  -	printf("successful\n");
  -    else
  -	printf("failed\n");
  +    //printf("invoking echoFloatArray...\n");
  +    if (ws->echoFloatArray(arrfloat).m_Array == NULL)
  +	printf("echoFloatArray failed\n");
  +
       // testing echo Struct
       SOAPStruct stct;
       stct.varFloat = 12345.7346345;
       stct.varInt = 5000;
       stct.varString = strdup("This is string in SOAPStruct");
  -    printf("invoking echoStruct...\n");
  -    if (ws->echoStruct(&stct) != NULL)
  -	printf("successful\n");
  -    else
  -	printf("failed\n");
  +    //printf("invoking echoStruct...\n");
  +    if (ws->echoStruct(&stct) == NULL)
  +	printf("echoStruct failed\n");
  +
       //testing echo Array of Struct
       SOAPStruct_Array arrstct;
       arrstct.m_Array = new SOAPStruct[ARRAYSIZE];
  @@ -127,66 +142,52 @@
   	arrstct.m_Array[x].varString = buffer1;
       }
       //testing echo Struct Array
  -    printf("invoking echoStructArray...\n");
  -    if (ws->echoStructArray(arrstct).m_Array != NULL)
  -	printf("successful\n");
  -    else
  -	printf("failed\n");
  +    //printf("invoking echoStructArray...\n");
  +    if (ws->echoStructArray(arrstct).m_Array == NULL)
  +	printf("echoStructArray failed\n");
  +
       //testing echo void
  -    printf("invoking echoVoid...\n");
  +    //printf("invoking echoVoid...\n");
       ws->echoVoid();
  -    printf("successful\n");
       //testing echo base 64 binary
   
       const char *bstr =
   	"some string that is sent encoded to either base64Binary or hexBinary";
   
  -    printf("invoking echoBase64...\n");
  +    //printf("invoking echoBase64...\n");
       xsd__base64Binary bb;
       bb.__ptr = (unsigned char *) strdup(bstr);
       bb.__size = strlen(bstr);
  -    if (bb.__size == ws->echoBase64(bb).__size)
  -    {
  -	printf("successful\n");
  -	printf("Returned String :\n%s\n", bb.__ptr);
  -    }
  -    else
  -	printf("failed\n");
  +    if (bb.__size != ws->echoBase64(bb).__size)
  +	printf("echoBase64 failed\n");
   
       time_t tim;
       time(&tim);
       tm *lt = gmtime(&tim);
  -    printf("invoking echoDate...\n");
  -    if (memcmp(&ws->echoDate(*lt), lt, sizeof(tm)) == 0)
  -	printf("successful\n");
  -    else
  -	printf("failed\n");
  -    //testing echo hex binary
  +    //printf("invoking echoDate...\n");
  +    if (memcmp(&ws->echoDate(*lt), lt, sizeof(tm)) != 0)
  +	printf("echoDate failed\n");
   
  -    printf("invoking echoHexBinary...\n");
  +    //testing echo hex binary
  +    //printf("invoking echoHexBinary...\n");
       xsd__hexBinary hb;
       hb.__ptr = (unsigned char *) strdup(bstr);
       hb.__size = strlen(bstr);
  -    if (hb.__size == ws->echoHexBinary(hb).__size)
  -    {
  -	printf("successful\n");
  -	printf("Returned String :\n%s\n", hb.__ptr);
  -    }
  -    else
  -	printf("failed\n");
  +    if (hb.__size != ws->echoHexBinary(hb).__size)
  +	printf("echoHexBinary failed\n");
  +
       //testing echo decimal
  -    printf("invoking echoDecimal...\n");
  -    if (ws->echoDecimal(1234.567890) > 1234.56)
  -	printf("successful\n");
  -    else
  -	printf("failed\n");
  +    //printf("invoking echoDecimal...\n");
  +    retVal = ws->echoDecimal(1234.567890);
  +    if (retVal < 1234.56 || retVal > 1234.57 )
  +	printf("echoDecimal failed\n");
  +
       //testing echo boolean
  -    printf("invoking echoBoolean...\n");
  -    if (ws->echoBoolean(true_) == true_)
  -	printf("successful\n");
  -    else
  -	printf("failed\n");
  +    //printf("invoking echoBoolean...\n");
  +    if (ws->echoBoolean(true_) != true_)
  +	printf("echoBoolean failed\n");
   
  +    printf( "%ld Done\n", pthread_self() );
       return 0;
   }
   
  @@ -214,7 +215,7 @@
   
       pthread_t thread[NUM_THREADS];
       pthread_attr_t attr;
  -    int rc, t, status;
  +    int rc, t, status = 0;
   
       /* Initialize and set thread detached attribute */
       pthread_attr_init(&attr);
  @@ -227,23 +228,26 @@
   	if (rc)
   	{
   	    printf("ERROR; return code from pthread_create() is %d\n", rc);
  -	    exit(-1);
  +            printf("error:%s\n", strerror(rc));
  +	    //exit(-1);
   	}
  +	printf("Created thread %ld\n", thread[t]);
       }
   
       /* Free attribute and wait for the other threads */
       pthread_attr_destroy(&attr);
  -    for (t = 0; t < NUM_THREADS; t++)
  +    /*for (t = 0; t < NUM_THREADS; t++)
       {
   	//rc = pthread_join(thread[t], (void **)&status);
   	rc = pthread_detach(thread[t]);
   	if (rc)
   	{
   	    printf("ERROR return code from pthread_join() is %d\n", rc);
  -	    exit(-1);
  +            printf("error:%s\n", strerror(rc));
  +	    //exit(-1);
   	}
  -	printf("Completed join with thread %d status= %d\n", t, status);
  -    }
  +	printf("Joined thread %ld\n", thread[t]);
  +    }*/
   
       pthread_exit(NULL);
   }
  
  
  
  1.2       +34 -2     ws-axis/c/tests/client/threadSafe/readme.txt
  
  Index: readme.txt
  ===================================================================
  RCS file: /home/cvs/ws-axis/c/tests/client/threadSafe/readme.txt,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- readme.txt	9 Jun 2004 10:53:28 -0000	1.1
  +++ readme.txt	14 Jun 2004 07:33:38 -0000	1.2
  @@ -1,2 +1,34 @@
  -1. Generate stub.
  -java -classpath $AXISCPP_HOME/build/lib/wsdl2ws.jar:$CLASSPATH org.apache.axis.wsdl.wsdl2ws.WSDL2Ws -o./gen_src -lc++ -sclient wsdlFile
  \ No newline at end of file
  +This test case can be used to test the thread safety of the Axis C++ client
  +engine.
  +This sample used thread package; and hence would only work on Linux/Unix
  +platforms.
  +You are invited to write a threaded test for Windows like this (or a better
  +one;-) )
  +
  +I tested this with Axis Java echo sample. (Axis Java service and C++ client)
  +BTW: echo sample is equivalent to base sample of Axis C++ sample set.
  +
  +Usage:
  +You can run the sample by simply running:
  +./thSafeTest hostname port [use-same]
  +
  +1. If you run with just hostname and port the client will create a stub object
  +for each thread.
  +2. If the third argument is present, then the client will use a single stub
  +object for multiple threads.
  +I am not sure if the second scenario is much useful.
  +
  +The number of threads used is hard coded with NUM_THREADS macro in Client.cpp.
  +(yes you can improve it by making it a command line option)
  +If you have set  NUM_THREADS to some number, say 30, and if you want to know
  +if all threads were successful you could use the following command:
  +./thSafeTest localhost 8080 | grep Done | nl
  +and count the Done lines in output to see how many threads succeeded. 
  +(Note: I have printf( "%ld Done\n", pthread_self() ); as the last line of my
  +run function)
  +I mentioned this tip because you will find the output confusing at times if
  +you are using large number of threads. However I have the thread IDs on the
  +output so that those you have patience can verify the creation and completion
  +of the threads one by one.
  +
  +- Samisa