Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Basic test client
0003  *
0004  * @file atmiclt4.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 <unistd.h>
0039 
0040 #include <atmi.h>
0041 #include <ubf.h>
0042 #include <ndebug.h>
0043 #include <test.fd.h>
0044 #include <ndrstandard.h>
0045 /*---------------------------Externs------------------------------------*/
0046 /*---------------------------Macros-------------------------------------*/
0047 #define LOOP_NUM    10000
0048 #define THREADS_NUM 5
0049 /*---------------------------Enums--------------------------------------*/
0050 /*---------------------------Typedefs-----------------------------------*/
0051 /*---------------------------Globals------------------------------------*/
0052 
0053 /*---------------------------Statics------------------------------------*/
0054 
0055 exprivate int num1=2;
0056 exprivate int num2=1;
0057 exprivate int num3=0;
0058 exprivate int M_err = EXFALSE;
0059 /*---------------------------Prototypes---------------------------------*/
0060 
0061 /**
0062  * Run test from thread...
0063  * @param arg
0064  * @return 
0065  */
0066 void* thmain(void* arg)
0067 {
0068 
0069     UBFH *p_ub = (UBFH *)tpalloc("UBF", NULL, 1024);
0070     int i;
0071     int ret=EXSUCCEED;
0072 
0073     CBadd(p_ub, T_DOUBLE_FLD, "5", 0, BFLD_STRING);
0074     Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 2", 0);
0075     Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 3", 0);
0076     
0077     /* Do it many times...! */
0078     for (i=0; i<LOOP_NUM; i++)
0079     {
0080         ret=tppost("EVX.TEST", (char*)p_ub, 0L, TPSIGRSTRT);
0081         NDRX_LOG(log_debug, "dispatched events: %d", ret);
0082         
0083         /* two servers process this */
0084         if (ret!=num1)
0085         {
0086             NDRX_LOG(log_error, "Applied event count is not %d (which is %d)", 
0087                     num1, ret);
0088             ret=EXFAIL;
0089             goto out;
0090         }
0091         else
0092         {
0093             NDRX_LOG(log_debug, "6 dispatches - OK");
0094         }
0095     }
0096     
0097 out:
0098     if (EXFAIL==ret)
0099     {
0100         M_err=EXTRUE;
0101     }
0102         
0103     tpterm();
0104     return NULL;
0105 }
0106 /*
0107  * Do the test call to the server
0108  */
0109 int main(int argc, char** argv) {
0110 
0111     UBFH *p_ub = (UBFH *)tpalloc("UBF", NULL, 1024);
0112     int i;
0113     int ret=EXSUCCEED;
0114     pthread_t th[THREADS_NUM];
0115 
0116     CBadd(p_ub, T_DOUBLE_FLD, "5", 0, BFLD_STRING);
0117     Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 2", 0);
0118     Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 3", 0);
0119     
0120     if (argc>1 && 'Y'==argv[1][0])
0121     {
0122         /* networked run */
0123         num1*=3;
0124         num2*=3;
0125     }
0126     
0127     for (i=0; i<THREADS_NUM; i++)
0128     {
0129         pthread_create(&th[i], NULL, thmain, NULL);
0130     }
0131     
0132     for (i=0; i<THREADS_NUM; i++)
0133     {
0134         void* val;
0135         pthread_join(th[i], &val);
0136     }
0137     
0138     if (M_err)
0139     {
0140         NDRX_LOG(log_error, "TESTERROR! some thread failed");
0141         EXFAIL_OUT(ret);
0142     }
0143 
0144     ret=tppost("TEST2EV", (char*)p_ub, 0L, TPSIGRSTRT);
0145 
0146     /* one server processes this - Support #279 */
0147     if (num2!=ret)
0148     {
0149         NDRX_LOG(log_error, "TESTERROR: First post of TEST2EV did not return 3 (%d) ",
0150                                     ret);
0151         ret=EXFAIL;
0152         goto out;
0153     }
0154     sleep(10); /* << because server may not complete the unsubscribe! */
0155     ret=tppost("TEST2EV", (char*)p_ub, 0L, TPSIGRSTRT);
0156     if (num3!=ret)
0157     {
0158         NDRX_LOG(log_error, "TESTERROR: Second post of TEST2EV did not return 0 (%d) ",
0159                                     ret);
0160         ret=EXFAIL;
0161         goto out;
0162     }
0163 
0164 out:
0165 
0166 
0167     if (ret>=0)
0168     {
0169         ret=EXSUCCEED;
0170     }
0171 
0172     return ret;
0173 }
0174 
0175 /* vim: set ts=4 sw=4 et smartindent: */