Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief XA transaction processing, tests
0003  *
0004  * @file atmiclt21.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 #include <unistd.h>
0040 
0041 #include <atmi.h>
0042 #include <atmi_int.h>
0043 #include <ubf.h>
0044 #include <ndebug.h>
0045 #include <test.fd.h>
0046 #include <ndrstandard.h>
0047 #include <nstopwatch.h>
0048 /*---------------------------Externs------------------------------------*/
0049 /*---------------------------Macros-------------------------------------*/
0050 /*---------------------------Enums--------------------------------------*/
0051 /*---------------------------Typedefs-----------------------------------*/
0052 /*---------------------------Globals------------------------------------*/
0053 /*---------------------------Statics------------------------------------*/
0054 /*---------------------------Prototypes---------------------------------*/
0055 
0056 /*
0057  * Do the test call to the server
0058  */
0059 int main(int argc, char** argv) {
0060 
0061     UBFH *p_ub = (UBFH *)tpalloc("UBF", NULL, 9216);
0062     long rsplen;
0063     int i=0;
0064     int ret=EXSUCCEED;
0065     
0066     if (EXSUCCEED!=tpopen())
0067     {
0068         NDRX_LOG(log_error, "TESTERROR: tpopen() fail: %d:[%s]", 
0069                                             tperrno, tpstrerror(tperrno));
0070         ret=EXFAIL;
0071         goto out;
0072     }
0073     
0074     /***************************************************************************/
0075     NDRX_LOG(log_debug, "Testing normal tx processing - commit() ...");
0076     /***************************************************************************/
0077     for (i=0; i<100; i++)
0078     {
0079 
0080         if (EXSUCCEED!=tpbegin(5, 0))
0081         {
0082             NDRX_LOG(log_error, "TESTERROR: tpbegin() fail: %d:[%s]", 
0083                                                 tperrno, tpstrerror(tperrno));
0084             ret=EXFAIL;
0085             goto out;
0086         }
0087         
0088         ret=tpacall("RUNTX", (char *)p_ub, 0, TPNOREPLY);
0089         
0090         if (EXSUCCEED==ret)
0091         {
0092             NDRX_LOG(log_error, "TESTERROR: tpacall+TPNOREPLY must fail");
0093             ret=EXFAIL;
0094             goto out;
0095         }
0096         
0097         if (tperrno!=TPEINVAL)
0098         {
0099             NDRX_LOG(log_error, "TESTERROR: tpacall+TPNOREPLY: expected TPEINVAL got %d:%s",
0100                     tperrno, tpstrerror(tperrno));
0101             ret=EXFAIL;
0102             goto out;
0103         }
0104         
0105         /* Bug #827 tpcallex check too: */
0106         ret=tpacallex("RUNTX", (char *)p_ub, 0, TPNOREPLY, NULL, 0, 0, 0, 0, 0, 0);
0107 
0108         if (EXSUCCEED==ret)
0109         {
0110             NDRX_LOG(log_error, "TESTERROR: tpacallex+TPNOREPLY must fail");
0111             ret=EXFAIL;
0112             goto out;
0113         }
0114 
0115         if (tperrno!=TPEINVAL)
0116         {
0117             NDRX_LOG(log_error, "TESTERROR: tpacallex+TPNOREPLY: expected TPEINVAL got %d:%s",
0118                     tperrno, tpstrerror(tperrno));
0119             ret=EXFAIL;
0120             goto out;
0121         }
0122 
0123         ret = EXSUCCEED;
0124 
0125 
0126         /* <Bug #827 - check TPNOREPLY|TPNOTRAN -> tpacall() shall succeed> */
0127         ret=tpacall("NOTRANFAIL", (char *)p_ub, 0, TPNOREPLY|TPNOTRAN);
0128         if (EXSUCCEED!=ret)
0129         {
0130             NDRX_LOG(log_error, "TESTERROR: tpacall+TPNOREPLY|TPNOTRAN must "
0131                 "not fail, but got: %s", tpstrerror(tperrno));
0132             ret=EXFAIL;
0133             goto out;
0134         }
0135 
0136         ret=tpacallex("NOTRANFAIL", (char *)p_ub, 0, TPNOREPLY|TPNOTRAN,
0137             NULL, 0, 0, 0, 0, 0, 0);
0138         if (EXSUCCEED!=ret)
0139         {
0140             NDRX_LOG(log_error, "TESTERROR: tpacall+TPNOREPLY|TPNOTRAN must "
0141                 "not fail, but got: %s", tpstrerror(tperrno));
0142             ret=EXFAIL;
0143             goto out;
0144         }
0145 
0146         /*</Bug #827>*/
0147 
0148         Bchg(p_ub, T_STRING_FLD, 0, "TEST HELLO WORLD COMMIT", 0L);
0149 
0150         /* Call Svc1 */
0151         if (EXFAIL == (ret=tpcall("RUNTX", (char *)p_ub, 0L, (char **)&p_ub, &rsplen,0)))
0152         {
0153             NDRX_LOG(log_error, "TX3SVC failed: %s", tpstrerror(tperrno));
0154             ret=EXFAIL;
0155             goto out;
0156         }
0157 
0158         if (EXSUCCEED!=(ret=tpcommit(0)))
0159         {
0160             NDRX_LOG(log_error, "TESTERROR: tpcommit()==%d fail: %d:[%s]", 
0161                                                 ret, tperrno, tpstrerror(tperrno));
0162             ret=EXFAIL;
0163             goto out;
0164         }
0165     }
0166     
0167     /***************************************************************************/
0168     NDRX_LOG(log_debug, "Testing normal tx processing - abort() ...");
0169     /***************************************************************************/
0170     for (i=0; i<100; i++)
0171     {
0172         if (EXSUCCEED!=tpbegin(5, 0))
0173         {
0174             NDRX_LOG(log_error, "TESTERROR: tpbegin() fail: %d:[%s]", 
0175                                                 tperrno, tpstrerror(tperrno));
0176             ret=EXFAIL;
0177             goto out;
0178         }
0179 
0180         Bchg(p_ub, T_STRING_FLD, 0, "TEST HELLO WORLD ABORT", 0L);
0181 
0182         /* Call Svc1 */
0183         if (EXFAIL == (ret=tpcall("RUNTX", (char *)p_ub, 0L, (char **)&p_ub, &rsplen,0)))
0184         {
0185             NDRX_LOG(log_error, "TX3SVC failed: %s", tpstrerror(tperrno));
0186             ret=EXFAIL;
0187             goto out;
0188         }
0189 
0190         if (EXSUCCEED!=(ret=tpabort(0)))
0191         {
0192             NDRX_LOG(log_error, "TESTERROR: tpabort()==%d fail: %d:[%s]", 
0193                                                 ret, tperrno, tpstrerror(tperrno));
0194             ret=EXFAIL;
0195             goto out;
0196         }
0197     }
0198     
0199     /***************************************************************************/
0200     NDRX_LOG(log_debug, "Service returns fail");
0201     /***************************************************************************/
0202     for (i=0; i<100; i++)
0203     {
0204         if (EXSUCCEED!=tpbegin(5, 0))
0205         {
0206             NDRX_LOG(log_error, "TESTERROR: tpbegin() fail: %d:[%s]", 
0207                                                 tperrno, tpstrerror(tperrno));
0208             ret=EXFAIL;
0209             goto out;
0210         }
0211 
0212         Bchg(p_ub, T_STRING_FLD, 0, "TEST HELLO WORLD SVCFAIL", 0L);
0213 
0214         /* Call Svc1 */
0215         if (EXFAIL != (ret=tpcall("RUNTXFAIL", (char *)p_ub, 0L, (char **)&p_ub, &rsplen,0)))
0216         {
0217             NDRX_LOG(log_error, "RUNTXFAIL should return fail!");
0218         }
0219 
0220         ret=tpcommit(0);
0221         
0222         if (EXSUCCEED==ret || tperrno!=TPEABORT)
0223         {
0224             NDRX_LOG(log_error, "TESTERROR: abort()==%d fail: %d:[%s] - must be TPEABORT!", 
0225                                                 ret, tperrno, tpstrerror(tperrno));
0226             ret=EXFAIL;
0227             goto out;
0228         }
0229         
0230         ret = EXSUCCEED;
0231     }    
0232     /***************************************************************************/
0233     NDRX_LOG(log_debug, "Transaction time-out (by tmsrv)");
0234     /***************************************************************************/
0235     for (i=0; i<5; i++)
0236     {
0237         if (EXSUCCEED!=tpbegin(5, 0))
0238         {
0239             NDRX_LOG(log_error, "TESTERROR: tpbegin() fail: %d:[%s]", 
0240                                                 tperrno, tpstrerror(tperrno));
0241             ret=EXFAIL;
0242             goto out;
0243         }
0244 
0245         Bchg(p_ub, T_STRING_FLD, 0, "TEST HELLO WORLD TOUT", 0L);
0246 
0247         /* Call Svc1 */
0248         if (EXFAIL == (ret=tpcall("RUNTX", (char *)p_ub, 0L, (char **)&p_ub, &rsplen,0)))
0249         {
0250             NDRX_LOG(log_error, "TESTERROR: RUNTX should not return fail!");
0251         }
0252         
0253         sleep(10);
0254 
0255         ret=tpcommit(0);
0256         
0257         if (EXSUCCEED==ret || tperrno!=TPEABORT)
0258         {
0259             NDRX_LOG(log_error, "TESTERROR: tpcommit()==%d fail: %d:[%s] - must be TPEABORT!", 
0260                                                 ret, tperrno, tpstrerror(tperrno));
0261             ret=EXFAIL;
0262             goto out;
0263         }
0264         
0265         ret = EXSUCCEED;
0266     }    
0267 
0268     /***************************************************************************/
0269     NDRX_LOG(log_debug, "Call service, but not in tran mode - transaction must not be aborted!");
0270     /***************************************************************************/
0271     for (i=0; i<100; i++)
0272     {
0273         if (EXSUCCEED!=tpbegin(5, 0))
0274         {
0275             NDRX_LOG(log_error, "TESTERROR: tpbegin() fail: %d:[%s]", 
0276                                                 tperrno, tpstrerror(tperrno));
0277             ret=EXFAIL;
0278             goto out;
0279         }
0280 
0281         Bchg(p_ub, T_STRING_FLD, 0, "TEST HELLO WORLD SVCFAIL", 0L);
0282 
0283         /* Call Svc1 */
0284         if (EXFAIL != (ret=tpcall("NOTRANFAIL", (char *)p_ub, 0L, (char **)&p_ub, &rsplen,TPNOTRAN)))
0285         {
0286             NDRX_LOG(log_error, "TESTERROR: NOTRANFAIL should return fail!");
0287         }
0288 
0289         ret=tpcommit(0);
0290         
0291         if (EXSUCCEED!=ret)
0292         {
0293             NDRX_LOG(log_error, "TESTERROR: tpcommit()==%d fail: %d:[%s] - must be SUCCEED!", 
0294                                                 ret, tperrno, tpstrerror(tperrno));
0295             ret=EXFAIL;
0296             goto out;
0297         }
0298         
0299         ret = EXSUCCEED;
0300     }    
0301 
0302     /***************************************************************************/
0303     NDRX_LOG(log_debug, "Done...");
0304     /***************************************************************************/
0305     
0306     if (EXSUCCEED!=tpclose())
0307     {
0308         NDRX_LOG(log_error, "TESTERROR: tpclose() fail: %d:[%s]", 
0309                                             tperrno, tpstrerror(tperrno));
0310         ret=EXFAIL;
0311         goto out;
0312     }
0313     
0314 out:
0315     if (EXSUCCEED!=ret)
0316     {
0317         /* atleast try... */
0318         if (EXSUCCEED!=tpabort(0))
0319         {
0320             NDRX_LOG(log_error, "TESTERROR: tpabort() fail: %d:[%s]", 
0321                                                 tperrno, tpstrerror(tperrno));
0322         }
0323         tpclose();
0324     }
0325 
0326     tpterm();
0327     
0328     NDRX_LOG(log_error, "Exiting with %d", ret);
0329             
0330     return ret;
0331 }
0332 
0333 /* vim: set ts=4 sw=4 et smartindent: */