Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Test Enduro/X server dispatch threading - client
0003  *
0004  * @file atmiclt75_conv.c
0005  */
0006 /* -----------------------------------------------------------------------------
0007  * Enduro/X Middleware Platform for Distributed Transaction Processing
0008  * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0009  * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0010  * This software is released under one of the following licenses:
0011  * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0012  * See LICENSE file for full text.
0013  * -----------------------------------------------------------------------------
0014  * AGPL license:
0015  * 
0016  * This program is free software; you can redistribute it and/or modify it under
0017  * the terms of the GNU Affero General Public License, version 3 as published
0018  * by the Free Software Foundation;
0019  *
0020  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0021  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0022  * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0023  * for more details.
0024  *
0025  * You should have received a copy of the GNU Affero General Public License along 
0026  * with this program; if not, write to the Free Software Foundation, Inc., 
0027  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0028  *
0029  * -----------------------------------------------------------------------------
0030  * A commercial use license is available from Mavimax, Ltd
0031  * contact@mavimax.com
0032  * -----------------------------------------------------------------------------
0033  */
0034 #include <string.h>
0035 #include <stdio.h>
0036 #include <stdlib.h>
0037 #include <memory.h>
0038 #include <math.h>
0039 
0040 #include <atmi.h>
0041 #include <ubf.h>
0042 #include <ndebug.h>
0043 #include <test.fd.h>
0044 #include <ndrstandard.h>
0045 #include <nstopwatch.h>
0046 #include <fcntl.h>
0047 #include <unistd.h>
0048 #include <nstdutil.h>
0049 #include "test75.h"
0050 #include "exassert.h"
0051 /*---------------------------Externs------------------------------------*/
0052 /*---------------------------Macros-------------------------------------*/
0053 
0054 /*
0055  * This must match the ndrxconfig atmi server dispatch thread count
0056  * otherwise if there is greater number of threads, they might
0057  * accumulate the messages and once at random passed to other
0058  * thread, the will count messages from first broadcast. 
0059  */
0060 #define TEST_THREADS            5
0061 /*---------------------------Enums--------------------------------------*/
0062 /*---------------------------Typedefs-----------------------------------*/
0063 /*---------------------------Globals------------------------------------*/
0064 /*---------------------------Statics------------------------------------*/
0065 /*---------------------------Prototypes---------------------------------*/
0066 
0067 /**
0068  * Do the test call to the server
0069  */
0070 int main(int argc, char** argv)
0071 {
0072     int i, j;
0073     int ret=EXSUCCEED;
0074     int cd[TEST_THREADS];
0075     long revent, len;
0076     /* for (i=0; i<1000000; i++) */
0077     for (i=0; i<10000; i++)
0078     {
0079         char *buf[TEST_THREADS];
0080         
0081         if (i%1000 == 0)
0082         {
0083             printf("processed: %d\n", i);
0084         }
0085         
0086         for (j=0; j<TEST_THREADS; j++)
0087         {
0088             buf[j]= tpalloc("STRING", NULL, 1024);
0089             NDRX_ASSERT_TP_OUT( (NULL!=buf[j]), "tpalloc failed %d", j);
0090         }
0091         
0092         /* connect to the server */
0093         for (j=0; j<TEST_THREADS; j++)
0094         {
0095             strcpy(buf[j], "HELLO");
0096             cd[j]=tpconnect("CONVSV1", buf[j], 0, TPSENDONLY);
0097             NDRX_ASSERT_TP_OUT( (EXFAIL!=cd[j]), "Failed to connect to CONVSV1!");
0098         }
0099         
0100         /* give control  */
0101         for (j=0; j<TEST_THREADS; j++)
0102         {
0103             strcpy(buf[j], "CLWAIT");
0104             revent=0;
0105             
0106             NDRX_ASSERT_TP_OUT( (EXSUCCEED==tpsend(cd[j], buf[j], 0, TPRECVONLY, &revent)), 
0107                     "Failed send CLWAIT");
0108         }
0109         
0110         /* now do broadcast... */
0111         for (j=0; j<9; j++)
0112         {
0113             NDRX_ASSERT_UBF_OUT((0==tpbroadcast("", "", "atmi.sv75_conv", NULL, 0, 0)), 
0114                     "Failed to broadcast");
0115         }
0116         
0117         /* now receive data... */
0118         for (j=0; j<TEST_THREADS; j++)
0119         {
0120             revent=0;
0121             NDRX_ASSERT_TP_OUT( (EXSUCCEED==tprecv(cd[j], &buf[j], &len, 0, &revent)), 
0122                     "Failed to get counts");
0123             NDRX_ASSERT_VAL_OUT( (0==revent),  "Invalid revent");
0124             NDRX_ASSERT_VAL_OUT( (0==strcmp(buf[j], "9")),  
0125                     "Invalid count received but got: %s", buf[j]);
0126         }
0127         
0128         /* expect to finish the conv */
0129         for (j=0; j<TEST_THREADS; j++)
0130         {
0131             revent=0;
0132             NDRX_ASSERT_TP_OUT( (EXFAIL==tprecv(cd[j], &buf[j], &len, 0, &revent)), 
0133                     "Failed to recv");
0134             
0135             NDRX_ASSERT_TP_OUT( (TPEEVENT==tperrno),  "Expected TPEEVENT");
0136             NDRX_ASSERT_TP_OUT( (TPEV_SVCSUCC==revent),  "Expected TPEV_SVCSUCC");
0137         }
0138         
0139         for (j=0; j<TEST_THREADS; j++)
0140         {
0141             if (NULL!=buf[j])
0142             {
0143                 tpfree(buf[j]);
0144             }
0145         }
0146     }
0147         
0148 out:
0149     tpterm();
0150     fprintf(stderr, "Exit with %d\n", ret);
0151 
0152     return ret;
0153     
0154 }
0155 
0156 /* vim: set ts=4 sw=4 et smartindent: */