Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Both sites max send, avoid deadlock of full sockets - client
0003  *
0004  * @file atmiclt72.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 "test72.h"
0050 /*---------------------------Externs------------------------------------*/
0051 /*---------------------------Macros-------------------------------------*/
0052 /*---------------------------Enums--------------------------------------*/
0053 /*---------------------------Typedefs-----------------------------------*/
0054 /*---------------------------Globals------------------------------------*/
0055 /*---------------------------Statics------------------------------------*/
0056 /*---------------------------Prototypes---------------------------------*/
0057 
0058 /**
0059  * Do the test call to the server
0060  */
0061 int main(int argc, char** argv)
0062 {
0063     UBFH *p_ub = (UBFH *)tpalloc("UBF", NULL, 56000);
0064     long rsplen;
0065     int ret=EXSUCCEED;
0066     long sent=0;
0067     long sentread=0;
0068     long t;
0069     char *action = getenv("TEST_ACTION");
0070     ndrx_stopwatch_t w;
0071     
0072     /* send msg for 5 min.... */
0073     
0074     if (argc < 2)
0075     {
0076         fprintf(stderr, "Usage: %s <Service_name>\n", argv[0]);
0077         EXFAIL_OUT(ret);
0078     }
0079     
0080     if (NULL==action)
0081     {
0082         fprintf(stderr, "Missing env TEST_ACTION!");
0083         EXFAIL_OUT(ret);
0084     }
0085     
0086     ndrx_stopwatch_reset(&w);
0087     
0088     /* have shorter test on RPI/32bit sys */
0089 #if EX_SIZEOF_LONG==4
0090     while (ndrx_stopwatch_get_delta_sec(&w) < 5)
0091 #else
0092     while (ndrx_stopwatch_get_delta_sec(&w) < 200)
0093 #endif
0094     {
0095         if (EXFAIL==CBchg(p_ub, T_STRING_FLD, 0, VALUE_EXPECTED, 0, BFLD_STRING))
0096         {
0097             NDRX_LOG(log_debug, "Failed to set T_STRING_FLD[0]: %s", Bstrerror(Berror));
0098             EXFAIL_OUT(ret);
0099         }    
0100 
0101         /* do the sync call... */
0102         if (EXFAIL == tpacall(argv[1], (char *)p_ub, 0L, TPNOREPLY|TPNOTIME))
0103         {
0104             NDRX_LOG(log_error, "%s failed: %s", argv[1], tpstrerror(tperrno));
0105             EXFAIL_OUT(ret);
0106         }
0107         
0108         sent++;
0109     }
0110     
0111     
0112     /* wait for leftover from queue, if service was unable to cope with the traffic */
0113     ndrx_stopwatch_reset(&w);
0114     
0115     /* wait about 16 min, seems for some reason it gets too log to process all on some servers */
0116     while (sentread!=sent && (t=ndrx_stopwatch_get_delta_sec(&w)) < 1000)
0117     {
0118         NDRX_LOG(log_warn, "Waiting sent=%ld got=%ld for queues to flush at bridges... (spent: %lds)",
0119                 sent, sentread, t);
0120         
0121         /* maybe call different service ... 
0122          * an few minutes to get the right number, before give up?
0123          */
0124         if (EXFAIL == tpcall(argv[2], (char *)p_ub, 0L, (char **)&p_ub, &rsplen, 0))
0125         {
0126             NDRX_LOG(log_error, "%s failed: %s", argv[2], tpstrerror(tperrno));
0127             EXFAIL_OUT(ret);
0128         }
0129 
0130         /* read the value */
0131         if (EXSUCCEED!=Bget(p_ub, T_LONG_FLD, 0, (char *)&sentread, 0L))
0132         {
0133             NDRX_LOG(log_error, "TESTERROR: Failed to get T_LONG_FLD: %s", Bstrerror(Berror));
0134             EXFAIL_OUT(ret);
0135         }
0136         
0137         sleep(1);
0138     }
0139     
0140     if (sentread!=sent)
0141     {
0142         NDRX_LOG(log_error, "error: sent: %ld but server have seen: %ld", 
0143                 sent, sentread);
0144         userlog("testcl finished - failed");
0145         
0146         if ('1' == action[0])
0147         {
0148             EXFAIL_OUT(ret);
0149         }
0150     }
0151     
0152     userlog("testcl finished - OK");
0153     
0154 out:
0155     tpterm();
0156     fprintf(stderr, "Exit with %d\n", ret);
0157 
0158     return ret;
0159 }
0160 
0161 /* vim: set ts=4 sw=4 et smartindent: */