Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Basic test client
0003  *
0004  * @file atmiclt2.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 /*---------------------------Externs------------------------------------*/
0046 /*---------------------------Macros-------------------------------------*/
0047 
0048 /* async messages get stuck for a while in tpbridge, for RPI mem is low... */
0049 #if EX_SIZEOF_LONG==4
0050 #define TEST_ASYNC_LOOPS    20000
0051 #else
0052 #define TEST_ASYNC_LOOPS    200000
0053 #endif
0054 
0055 /*---------------------------Enums--------------------------------------*/
0056 /*---------------------------Typedefs-----------------------------------*/
0057 /*---------------------------Globals------------------------------------*/
0058 /*---------------------------Statics------------------------------------*/
0059 /*---------------------------Prototypes---------------------------------*/
0060 
0061 
0062 /**
0063  * This will test that tpacall forward will not hang in TPNOREPLY mode.
0064  * i.e. at the at the second forwarded service reply shall be ignored,
0065  * and not delivered back to client.
0066  * What happened here: Bug #570 is that client receive unexpected replies
0067  * and client queue become full.
0068  * @return EXSUCCEED/EXFAIL.
0069  */
0070 exprivate int tpacall_tpnoreply_forward_test(void)
0071 {
0072     int ret = EXSUCCEED;
0073     int j;
0074     long rsplen;
0075     UBFH *p_ub = (UBFH *)tpalloc("UBF", NULL, 8192);
0076     
0077     for (j=0; j<TEST_ASYNC_LOOPS; j++)
0078     {
0079         Binit(p_ub, Bsizeof(p_ub));
0080         Badd(p_ub, T_STRING_FLD, "tpacall_tpnoreply_forward_test", 0);
0081 
0082         if (EXFAIL==tpacall("TEST2_1ST_AL", (char *)p_ub, 0, TPNOREPLY))
0083         {
0084             NDRX_LOG(log_error, "TESTERROR: failed to call TEST2_1ST_AL with TPNOREPLY: %s", 
0085                     tpstrerror(tperrno));
0086             
0087             EXFAIL_OUT(ret);
0088         }
0089     }
0090 
0091     /* wait for queue to finish ...*/
0092     if (EXFAIL == tpcall("TEST2_1ST_AL", (char *)p_ub, 0L, (char **)&p_ub, &rsplen,TPNOTIME))
0093     {
0094         NDRX_LOG(log_error, "TEST2_1ST_AL failed: %s",
0095                tpstrerror(tperrno));
0096         ret=EXFAIL;
0097         goto out;
0098     }
0099 out:
0100     if (NULL!=p_ub)
0101     {
0102         tpfree((char *)p_ub);
0103     }
0104     return ret;
0105 }
0106 
0107 /**
0108  * Test that tpforward fails, but for TPNOREPLY we shall not receive any reply
0109  * Bug #570 - currently client queue may fill up
0110  * @return EXSUCCEED/EXFAIL
0111  */
0112 exprivate int tpacall_tpnoreply_forward_nodestsrv(void)
0113 {
0114     int ret = EXSUCCEED;
0115     int j;
0116     UBFH *p_ub = (UBFH *)tpalloc("UBF", NULL, 8192);
0117     long rsplen;
0118     
0119     for (j=0; j<TEST_ASYNC_LOOPS; j++)
0120     {
0121         Binit(p_ub, Bsizeof(p_ub));
0122         Badd(p_ub, T_STRING_FLD, "tpacall_tpnoreply_forward_nodestsrv", 0);
0123         Badd(p_ub, T_STRING_10_FLD, "failure set", 0);
0124 
0125         if (EXFAIL==tpacall("TEST2_1ST_AL", (char *)p_ub, 0, TPNOREPLY))
0126         {
0127             NDRX_LOG(log_error, "TESTERROR: failed to call TEST2_1ST_AL with TPNOREPLY: %s", 
0128                     tpstrerror(tperrno));
0129             
0130             EXFAIL_OUT(ret);
0131         }
0132     }
0133 
0134     /* sync off */
0135     Bdel(p_ub, T_STRING_10_FLD, 0);
0136     if (EXFAIL == tpcall("TEST2_1ST_AL", (char *)p_ub, 0L, (char **)&p_ub, &rsplen,TPNOTIME))
0137     {
0138         NDRX_LOG(log_error, "TEST2_1ST_AL failed: %s",
0139                tpstrerror(tperrno));
0140         ret=EXFAIL;
0141         goto out;
0142     }
0143 
0144 out:
0145     if (NULL!=p_ub)
0146     {
0147         tpfree((char *)p_ub);
0148     }
0149     return ret;
0150 }
0151 
0152 /*
0153  * Do the test call to the server
0154  */
0155 int main(int argc, char** argv) {
0156 
0157     UBFH *p_ub = (UBFH *)tpalloc("UBF", NULL, 8192);
0158     long rsplen;
0159     int i,j;
0160     long cnt = 0;
0161     int ret=EXSUCCEED;
0162     double d, d2;
0163     double dv = 55.66;
0164     double dv2 = 11.66;
0165     
0166     for (j=0; j<100000; j++)
0167     {
0168         Binit(p_ub, Bsizeof(p_ub));
0169 
0170         Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 1", 0);
0171         Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 2", 0);
0172         Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 3", 0);
0173 
0174         for (i=0; i<100; i++)
0175         {
0176             cnt++;
0177             dv+=1;
0178             dv2+=1;
0179 
0180             if (EXFAIL == tpcall("TEST2_1ST_AL", (char *)p_ub, 0L, (char **)&p_ub, &rsplen,0))
0181             {
0182                 NDRX_LOG(log_error, "TEST2_1ST_AL failed: %s",
0183                         tpstrerror(tperrno));
0184                 ret=EXFAIL;
0185                 goto out;
0186             }
0187 
0188             /* Verify the data */
0189             if (EXFAIL==Bget(p_ub, T_DOUBLE_FLD, i, (char *)&d, 0))
0190             {
0191                 NDRX_LOG(log_debug, "Failed to get T_DOUBLE_FLD[%d]", i);
0192                 ret=EXFAIL;
0193                 goto out;
0194             }
0195 
0196             if (EXFAIL==Bget(p_ub, T_DOUBLE_2_FLD, i, (char *)&d2, 0))
0197             {
0198                 NDRX_LOG(log_debug, "Failed to get T_DOUBLE_2_FLD[%d]", i);
0199                 ret=EXFAIL;
0200                 goto out;
0201             }
0202 
0203             if (fabs(dv-d) > 0.00001)
0204             {
0205                 NDRX_LOG(log_debug, "T_DOUBLE_FLD: %lf!=%lf =>  FAIL", dv, d);
0206                 ret=EXFAIL;
0207                 goto out;
0208             }
0209 
0210             if (fabs(dv2 - d2) > 0.00001)
0211             {
0212                 NDRX_LOG(log_debug, "T_DOUBLE_2_FLD: %lf!=%lf =>  FAIL", dv, d);
0213                 ret=EXFAIL;
0214                 goto out;
0215             }
0216 
0217             /* print the output */
0218             Bfprint(p_ub, stderr);
0219         }
0220 
0221         NDRX_LOG(log_debug, "CURRENT CNT: %ld", cnt);
0222         if (argc<=1)
0223         {
0224             break;
0225         }
0226     }
0227     
0228     /* test Bug #570 */
0229     if (EXSUCCEED!=tpacall_tpnoreply_forward_test())
0230     {
0231         EXFAIL_OUT(ret);
0232     }
0233     
0234     if (EXSUCCEED!=tpacall_tpnoreply_forward_nodestsrv())
0235     {
0236         EXFAIL_OUT(ret);
0237     }
0238 
0239 out:
0240     if (NULL!=p_ub)
0241     {
0242         tpfree((char *)p_ub);
0243     }
0244     return ret;
0245 }
0246 
0247 /* vim: set ts=4 sw=4 et smartindent: */