Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief xa_start command fails. This could be problems with connections to DB.
0003  *   thus if RECON flags are set, it must succeed. If flags are not set, the
0004  *   test case must fail.
0005  *
0006  * @file atmiclt21-startfail.c
0007  */
0008 /* -----------------------------------------------------------------------------
0009  * Enduro/X Middleware Platform for Distributed Transaction Processing
0010  * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0011  * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0012  * This software is released under one of the following licenses:
0013  * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0014  * See LICENSE file for full text.
0015  * -----------------------------------------------------------------------------
0016  * AGPL license:
0017  *
0018  * This program is free software; you can redistribute it and/or modify it under
0019  * the terms of the GNU Affero General Public License, version 3 as published
0020  * by the Free Software Foundation;
0021  *
0022  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0023  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0024  * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0025  * for more details.
0026  *
0027  * You should have received a copy of the GNU Affero General Public License along 
0028  * with this program; if not, write to the Free Software Foundation, Inc.,
0029  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0030  *
0031  * -----------------------------------------------------------------------------
0032  * A commercial use license is available from Mavimax, Ltd
0033  * contact@mavimax.com
0034  * -----------------------------------------------------------------------------
0035  */
0036 #include <string.h>
0037 #include <stdio.h>
0038 #include <stdlib.h>
0039 #include <memory.h>
0040 #include <math.h>
0041 #include <unistd.h>
0042 
0043 #include <atmi.h>
0044 #include <ubf.h>
0045 #include <ndebug.h>
0046 #include <test.fd.h>
0047 #include <ndrstandard.h>
0048 #include <nstopwatch.h>
0049 /*---------------------------Externs------------------------------------*/
0050 /*---------------------------Macros-------------------------------------*/
0051 /*---------------------------Enums--------------------------------------*/
0052 /*---------------------------Typedefs-----------------------------------*/
0053 /*---------------------------Globals------------------------------------*/
0054 /*---------------------------Statics------------------------------------*/
0055 /*---------------------------Prototypes---------------------------------*/
0056 
0057 /*
0058  * Do the test call to the server
0059  */
0060 int main(int argc, char** argv) {
0061 
0062     UBFH *p_ub = (UBFH *)tpalloc("UBF", NULL, 9216);
0063     long rsplen;
0064     int i=0;
0065     int ret=EXSUCCEED;
0066     int nr_fails = 0;
0067     if (EXSUCCEED!=tpopen())
0068     {
0069         NDRX_LOG(log_error, "TESTERROR: tpopen() fail: %d:[%s]", 
0070                                             tperrno, tpstrerror(tperrno));
0071         ret=EXFAIL;
0072         goto out;
0073     }
0074     
0075     /***************************************************************************/
0076     NDRX_LOG(log_debug, "Testing Bug #160 - startfails");
0077     /***************************************************************************/
0078 
0079     for (i=0; i<1000; i++)
0080     {
0081         ret=tpbegin(20, 0);
0082         
0083         if (argc>1) /* we have "fail" flag */
0084         {
0085             if (EXSUCCEED!=ret)
0086             {
0087                 nr_fails++;
0088             }
0089             else
0090             {
0091                 /* abort tran... do not want whole loop */
0092                 tpabort(0L);
0093             }
0094             ret = EXSUCCEED;
0095             continue; /* ok to fail */
0096         }
0097         else if (EXSUCCEED!=ret)
0098         {
0099             NDRX_LOG(log_error, "TESTERROR: tpbegin() fail: %d:[%s]", 
0100                                                 tperrno, tpstrerror(tperrno));
0101             ret=EXFAIL;
0102             goto out;
0103         }
0104         
0105         Bchg(p_ub, T_STRING_FLD, 0, "TEST HELLO WORLD COMMIT", 0L);
0106 
0107         /* Call Svc1 */
0108         if (EXFAIL == (ret=tpcall("RUNTX", (char *)p_ub, 0L, (char **)&p_ub, &rsplen,0)))
0109         {
0110             NDRX_LOG(log_error, "TX3SVC failed: %s", tpstrerror(tperrno));
0111             ret=EXFAIL;
0112             goto out;
0113         }
0114 
0115         if (EXSUCCEED!=tpcommit(0))
0116         {
0117             NDRX_LOG(log_error, "TESTERROR: tpcommit()==%d fail: %d:[%s]", 
0118                                         ret, tperrno, tpstrerror(tperrno));
0119             ret=EXFAIL;
0120             goto out;
0121         }
0122     }
0123    
0124     /***************************************************************************/
0125     NDRX_LOG(log_debug, "Done...");
0126     /***************************************************************************/
0127     
0128     if (EXSUCCEED!=tpclose())
0129     {
0130         NDRX_LOG(log_error, "tpclose() fail: %d:[%s]", 
0131                                     tperrno, tpstrerror(tperrno));
0132     }
0133     
0134 out:
0135 
0136     if (argc>1 && nr_fails <= 100)
0137     {
0138         NDRX_LOG(log_error, "TESTERROR! flags not present and nr_fails %d must be > 100!",
0139                 nr_fails);
0140         ret=EXFAIL;
0141     }
0142                 
0143     if (EXSUCCEED!=ret)
0144     {
0145         /* atleast try... */
0146         if (EXSUCCEED!=tpabort(0))
0147         {
0148             NDRX_LOG(log_error, "TESTERROR: tpabort() fail: %d:[%s]", 
0149                                                 tperrno, tpstrerror(tperrno));
0150         }
0151         tpclose();
0152     }
0153 
0154     tpterm();
0155     
0156     NDRX_LOG(log_error, "Exiting with %d", ret);
0157             
0158     return ret;
0159 }
0160 
0161 /* vim: set ts=4 sw=4 et smartindent: */