Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief This is transactional client
0003  *
0004  * @file atmiclt71_txn.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 #ifndef _GNU_SOURCE
0035 #define _GNU_SOURCE
0036 #endif
0037 
0038 #include <string.h>
0039 #include <stdio.h>
0040 #include <stdlib.h>
0041 #include <memory.h>
0042 #include <math.h>
0043 
0044 #include <atmi.h>
0045 #include <ubf.h>
0046 #include <ndebug.h>
0047 #include <test.fd.h>
0048 #include <ndrstandard.h>
0049 #include <nstopwatch.h>
0050 #include <fcntl.h>
0051 #include <unistd.h>
0052 #include <nstdutil.h>
0053 #include "test71.h"
0054 
0055 
0056 #include <dlfcn.h>
0057 
0058 #ifdef __cplusplus
0059 extern "C"
0060 {
0061 #endif
0062 
0063 /*---------------------------Externs------------------------------------*/
0064 extern int __write_to_tx_file(char *buf);
0065 /*---------------------------Macros-------------------------------------*/
0066 /*---------------------------Enums--------------------------------------*/
0067 /*---------------------------Typedefs-----------------------------------*/
0068 /*---------------------------Globals------------------------------------*/
0069 /*---------------------------Statics------------------------------------*/
0070 /*---------------------------Prototypes---------------------------------*/
0071 
0072 /**
0073  * Do the test call to the server
0074  */
0075 int main(int argc, char** argv)
0076 {
0077     int ret = EXSUCCEED;
0078     int i;
0079     char buf[64];
0080     
0081     if (EXSUCCEED!=tpinit(NULL))
0082     {
0083         NDRX_LOG(log_error, "TESTERROR: failed to init: %s", tpstrerror(tperrno));
0084         EXFAIL_OUT(ret);
0085     }
0086     
0087     if (EXSUCCEED!=tpopen())
0088     {
0089         NDRX_LOG(log_error, "TESTERROR: failed to tpopen: %s", tpstrerror(tperrno));
0090         EXFAIL_OUT(ret);
0091     }
0092 
0093     for (i=0; i<33; i++)
0094     {
0095         if (EXSUCCEED!=tpbegin(10, 0))
0096         {
0097             NDRX_LOG(log_error, "TESTERROR: failed to begin: %s", tpstrerror(tperrno));
0098             EXFAIL_OUT(ret);
0099         }
0100         
0101         snprintf(buf, sizeof(buf), "CLT %d\n", i);
0102         NDRX_LOG(log_debug, "TRA: %s", buf);
0103         
0104         if (EXSUCCEED!=__write_to_tx_file(buf)) /* symbol from xa switch lib */
0105         {
0106             NDRX_LOG(log_error, "TESTERROR: Failed to write to transaction: %s", 
0107                      Bstrerror(Berror));
0108             EXFAIL_OUT(ret);
0109         }
0110         
0111         if (EXSUCCEED!=tpcommit(0))
0112         {
0113             NDRX_LOG(log_error, "TESTERROR: failed to commit: %s", tpstrerror(tperrno));
0114             EXFAIL_OUT(ret);
0115         }
0116         
0117     }
0118     
0119 out:
0120     /* close anyway.. */
0121     tpabort(0);
0122     tpclose();
0123     tpterm();
0124 
0125     return ret;
0126         
0127 }
0128 
0129 #ifdef __cplusplus
0130 } // extern "C"
0131 #endif
0132 
0133 /* vim: set ts=4 sw=4 et smartindent: */