Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Test buildserver, buildclient and buildtms - client
0003  *  This will run with default switch.
0004  *  - tms will be built with TestSw
0005  *  - atmisv71 will be built with TestSw too.
0006  *
0007  * @file atmiclt71_2.c
0008  */
0009 /* -----------------------------------------------------------------------------
0010  * Enduro/X Middleware Platform for Distributed Transaction Processing
0011  * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0012  * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0013  * This software is released under one of the following licenses:
0014  * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0015  * See LICENSE file for full text.
0016  * -----------------------------------------------------------------------------
0017  * AGPL license:
0018  * 
0019  * This program is free software; you can redistribute it and/or modify it under
0020  * the terms of the GNU Affero General Public License, version 3 as published
0021  * by the Free Software Foundation;
0022  *
0023  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0024  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0025  * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0026  * for more details.
0027  *
0028  * You should have received a copy of the GNU Affero General Public License along 
0029  * with this program; if not, write to the Free Software Foundation, Inc., 
0030  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0031  *
0032  * -----------------------------------------------------------------------------
0033  * A commercial use license is available from Mavimax, Ltd
0034  * contact@mavimax.com
0035  * -----------------------------------------------------------------------------
0036  */
0037 #include <string.h>
0038 #include <stdio.h>
0039 #include <stdlib.h>
0040 #include <memory.h>
0041 #include <math.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 #include <fcntl.h>
0050 #include <unistd.h>
0051 #include <nstdutil.h>
0052 #include "test71.h"
0053 /*---------------------------Externs------------------------------------*/
0054 /*---------------------------Macros-------------------------------------*/
0055 /*---------------------------Enums--------------------------------------*/
0056 /*---------------------------Typedefs-----------------------------------*/
0057 /*---------------------------Globals------------------------------------*/
0058 /*---------------------------Statics------------------------------------*/
0059 /*---------------------------Prototypes---------------------------------*/
0060 
0061 #ifdef __cplusplus
0062 extern "C"
0063 {
0064 #endif
0065 
0066 /**
0067  * Do the test call to the server
0068  */
0069 int run_tran_services(void)
0070 {
0071     UBFH *p_ub = (UBFH *)tpalloc("UBF", NULL, 56000);
0072     char *transervices[] = {"A", "B", "C", "TESTSV", NULL};
0073     long rsplen;
0074     long i, j;
0075     int ret=EXSUCCEED;
0076     
0077     /***************************************************************************/
0078     NDRX_LOG(log_debug, "Testing normal tx processing - commit() ...");
0079     /***************************************************************************/
0080     
0081     /* open the XA */
0082     if (EXSUCCEED!=tpopen())
0083     {
0084         NDRX_LOG(log_error, "TESTERROR: tpopen() fail: %d:[%s]", 
0085                                             tperrno, tpstrerror(tperrno));
0086         ret=EXFAIL;
0087         goto out;
0088     }
0089     
0090     for (j=0; NULL!=transervices[j]; j++)
0091     {
0092         for (i=0; i<200; i++)
0093         {
0094             long testval;
0095             
0096             if (EXSUCCEED!=tpbegin(5, 0))
0097             {
0098                 NDRX_LOG(log_error, "TESTERROR: tpbegin() fail: %d:[%s]", 
0099                                                     tperrno, tpstrerror(tperrno));
0100                 ret=EXFAIL;
0101                 goto out;
0102             }
0103 
0104             if (EXFAIL==CBchg(p_ub, T_STRING_FLD, 0, (char *)&i, 0, BFLD_LONG))
0105             {
0106                 NDRX_LOG(log_debug, "Failed to set T_STRING_FLD[0]: %s", Bstrerror(Berror));
0107                 ret=EXFAIL;
0108                 goto out;
0109             }    
0110 
0111             if (EXFAIL == tpcall(transervices[j], (char *)p_ub, 0L, (char **)&p_ub, &rsplen,0))
0112             {
0113                 NDRX_LOG(log_error, "%s failed: %s", transervices[j], tpstrerror(tperrno));
0114                 ret=EXFAIL;
0115                 goto out;
0116             }
0117             
0118             /* get value back.. */
0119             if (EXFAIL==CBget(p_ub, T_STRING_3_FLD, 0, (char *)&testval, 0, BFLD_LONG))
0120             {
0121                 NDRX_LOG(log_debug, "Failed to set T_STRING_3_FLD[0]: %s", Bstrerror(Berror));
0122                 ret=EXFAIL;
0123                 goto out;
0124             }
0125             
0126             if (i!=testval)
0127             {
0128                 NDRX_LOG(log_error, "TESTERROR transservices: %s fail %ld vs %ld", 
0129                         transervices[j], i, testval);
0130             }
0131 
0132             if (EXSUCCEED!=(ret=tpcommit(0)))
0133             {
0134                 NDRX_LOG(log_error, "TESTERROR: tpcommit()==%d fail: %d:[%s]", 
0135                                                     ret, tperrno, tpstrerror(tperrno));
0136                 ret=EXFAIL;
0137                 goto out;
0138             }
0139         }
0140     }
0141     
0142 out:
0143     
0144     tpabort(0); /* just in case */
0145     tpclose();
0146 
0147     return ret;
0148 }
0149 
0150 #ifdef __cplusplus
0151 } // extern "C"
0152 #endif
0153 
0154 /* vim: set ts=4 sw=4 et smartindent: */