Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Test of tptoutset()/get() - client
0003  *
0004  * @file atmiclt51.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 "test51.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 cd;
0066     int ret=EXSUCCEED;
0067     int err;
0068 
0069     if (EXSUCCEED!=tpinit(NULL))
0070     {
0071         NDRX_LOG(log_debug, "TESTERROR: Failed to init: %s", 
0072                 tpstrerror(tperrno));
0073         EXFAIL_OUT(ret);
0074     }
0075     
0076     NDRX_LOG(log_debug, "running of the case");
0077     
0078     
0079     if (EXSUCCEED!=tptoutset(1))
0080     {
0081         NDRX_LOG(log_debug, "TESTERROR: Failed to set timeout to 1: %s", 
0082                 tpstrerror(tperrno));
0083         EXFAIL_OUT(ret);
0084     }
0085     
0086     if (EXFAIL==CBchg(p_ub, T_STRING_FLD, 0, VALUE_EXPECTED, 0, BFLD_STRING))
0087     {
0088         NDRX_LOG(log_debug, "Failed to set T_STRING_FLD[0]: %s", Bstrerror(Berror));
0089         ret=EXFAIL;
0090         goto out;
0091     }    
0092 
0093     /* get standard timeout due to 1 sec... */
0094     if (EXSUCCEED == tpcall("TESTSV", (char *)p_ub, 0L, (char **)&p_ub, &rsplen,0))
0095     {
0096         NDRX_LOG(log_error, "TESTERROR!  Call succeed but must fail!");
0097         ret=EXFAIL;
0098         goto out;
0099     }
0100     
0101     err = tperrno;
0102     
0103     if (tperrno!=TPETIME)
0104     {
0105         NDRX_LOG(log_error, "TESTERROR! Expected TPETIME, but got: %d!", err);
0106         ret=EXFAIL;
0107         goto out;
0108     }
0109 
0110     /* TODO: Shouldn't the cd canceled? */
0111     
0112     /* invoke now with full wait first 2 sec + 3 sec, we get 6-7 sec 
0113      * thus receive normal response...
0114      */
0115     if (EXSUCCEED!=tptoutset(6))
0116     {
0117         NDRX_LOG(log_debug, "TESTERROR: Failed to set timeout to 6: %s", 
0118                 tpstrerror(tperrno));
0119         EXFAIL_OUT(ret);
0120     }
0121 
0122     /* now wait fully for response, the first call shall be dropped.. */
0123     if (EXFAIL == tpcall("TESTSV", (char *)p_ub, 0L, (char **)&p_ub, &rsplen,0))
0124     {
0125         NDRX_LOG(log_error, "TESTERROR!  Second call failed: %s", 
0126                 tpstrerror(tperrno));
0127         ret=EXFAIL;
0128         goto out;
0129     }
0130     
0131     /* also this will make assumtion that if we receive message
0132      * we do not check was it actually expired by previous timeout settings
0133      * this applies on waiting on reply queue and not actual msg age.
0134      * call age is checked by dest server.
0135      */ 
0136     if (EXSUCCEED!=tptoutset(2))
0137     {
0138         NDRX_LOG(log_debug, "TESTERROR: Failed to set timeout to 2: %s", 
0139                 tpstrerror(tperrno));
0140         EXFAIL_OUT(ret);
0141     }
0142 
0143     /* shall test the case when message sits in queue for too long by custom
0144      * timeout setting, thus it must be dropped, thus lets do three async calls
0145      * for atleast one we shall get the dropped message in server log.
0146      * We will receive only one message... as issued in the same time
0147      */
0148     
0149     if (EXFAIL == tpacall("TESTSV", (char *)p_ub, 0L, 0))
0150     {
0151         NDRX_LOG(log_error, "TESTERROR! tpacall failed (1): %s", 
0152                 tpstrerror(tperrno));
0153         ret=EXFAIL;
0154         goto out;
0155     }
0156     
0157     if (EXFAIL == tpacall("TESTSV", (char *)p_ub, 0L, 0))
0158     {
0159         NDRX_LOG(log_error, "TESTERROR! tpacall failed (2): %s", 
0160                 tpstrerror(tperrno));
0161         ret=EXFAIL;
0162         goto out;
0163     }
0164     
0165     if (EXFAIL == tpacall("TESTSV", (char *)p_ub, 0L, 0))
0166     {
0167         NDRX_LOG(log_error, "TESTERROR! tpacall failed (3): %s", 
0168                 tpstrerror(tperrno));
0169         ret=EXFAIL;
0170         goto out;
0171     }
0172 
0173     /* wait 5 sec for each... */
0174     if (EXSUCCEED!=tptoutset(5))
0175     {
0176         NDRX_LOG(log_debug, "TESTERROR: Failed to set timeout to 5: %s", 
0177                 tpstrerror(tperrno));
0178         EXFAIL_OUT(ret);
0179     }
0180     
0181     /* wait for reply
0182      * this one shall come back, as first processed in 3 sec.
0183      * The others must be dropped due to expired.. as the server requires wait for 3 sec
0184      * but we marked packets to live only for 2 sec
0185      */
0186     if (EXSUCCEED!=tpgetrply(&cd, (char **)&p_ub, &rsplen, TPGETANY))
0187     {
0188         NDRX_LOG(log_error, "TESTERROR! tpgetrply (1) failed: %s", 
0189                 tpstrerror(tperrno));
0190         ret=EXFAIL;
0191         goto out;
0192     }
0193     
0194     /*
0195     if (EXSUCCEED!=tptoutset(1))
0196     {
0197         NDRX_LOG(log_debug, "TESTERROR: Failed to set timeout to 1 (for tpgetrply): %s", 
0198                 tpstrerror(tperrno));
0199         EXFAIL_OUT(ret);
0200     }
0201     */
0202     
0203     /* these shall be zapped by dest server due to expired */
0204     /* the other shall fail as total 4+4 > 4 tout setting */
0205     if (EXSUCCEED==tpgetrply(&cd, (char **)&p_ub, &rsplen, TPGETANY))
0206     {
0207         NDRX_LOG(log_error, "TESTERROR! tpgetrply (2) SUCCEED but must fail!");
0208         ret=EXFAIL;
0209         goto out;
0210     }
0211     
0212     err = tperrno;
0213     if (tperrno!=TPETIME)
0214     {
0215         NDRX_LOG(log_error, "TESTERROR! Expected TPETIME (2), but got: %d!", err);
0216         ret=EXFAIL;
0217         goto out;
0218     }
0219     
0220     if (EXSUCCEED==tpgetrply(&cd, (char **)&p_ub, &rsplen, TPGETANY))
0221     {
0222         NDRX_LOG(log_error, "TESTERROR! tpgetrply (3) SUCCEED but must fail!");
0223         ret=EXFAIL;
0224         goto out;
0225     }
0226     
0227     err = tperrno;
0228     if (tperrno!=TPETIME)
0229     {
0230         NDRX_LOG(log_error, "TESTERROR! Expected TPETIME (3), but got: %d!", err);
0231         ret=EXFAIL;
0232         goto out;
0233     }
0234     
0235 out:
0236     tpterm();
0237     fprintf(stderr, "Exit with %d\n", ret);
0238 
0239     return ret;
0240 }
0241 /* vim: set ts=4 sw=4 et smartindent: */