Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Test auto-transaction functionality - server
0003  *
0004  * @file atmisv82.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 <stdio.h>
0035 #include <stdlib.h>
0036 #include <ndebug.h>
0037 #include <atmi.h>
0038 #include <ndrstandard.h>
0039 #include <ubf.h>
0040 #include <test.fd.h>
0041 #include <string.h>
0042 #include <unistd.h>
0043 #include "test82.h"
0044 
0045 /*---------------------------Externs------------------------------------*/
0046 /*---------------------------Macros-------------------------------------*/
0047 /*---------------------------Enums--------------------------------------*/
0048 /*---------------------------Typedefs-----------------------------------*/
0049 /*---------------------------Globals------------------------------------*/
0050 /*---------------------------Statics------------------------------------*/
0051 /*---------------------------Prototypes---------------------------------*/
0052 
0053 /**
0054  * Standard service entry
0055  */
0056 void TESTSV2 (TPSVCINFO *p_svc)
0057 {
0058     int ret=EXSUCCEED;
0059     UBFH *p_ub = (UBFH *)p_svc->data;
0060     char testbuf[1024];
0061     TPQCTL qc;
0062 
0063     NDRX_LOG(log_debug, "%s got call", __func__);
0064     
0065     if (EXFAIL==Bget(p_ub, T_STRING_FLD, 0, testbuf, 0))
0066     {
0067         NDRX_LOG(log_error, "TESTERROR: Failed to get T_STRING_FLD: %s", 
0068                  Bstrerror(Berror));
0069         ret=EXFAIL;
0070         goto out;
0071     }
0072     
0073     /* enqueue the data buffer */
0074     memset(&qc, 0, sizeof(qc));
0075     
0076     /* add msg 1 */
0077     if (EXSUCCEED!=tpenqueue("MYSPACE", "MSGQ", &qc, (char *)p_ub, 0, 0))
0078     {
0079         NDRX_LOG(log_error, "TESTERROR: tpenqueue() failed %s diag: %d:%s", 
0080                 tpstrerror(tperrno), qc.diagnostic, qc.diagmsg);
0081         EXFAIL_OUT(ret);
0082     }
0083     
0084     if (0==strcmp(testbuf, "FAIL"))
0085     {
0086         ret=EXFAIL;
0087     }
0088     else if (0==strcmp(testbuf, "SLEEP"))
0089     {
0090         /* make tout */
0091         sleep(15);
0092     }
0093     else if (0==strcmp(testbuf, "COMMIT"))
0094     {
0095         if (EXSUCCEED!=tpcommit(0))
0096         {
0097             NDRX_LOG(log_error, "TESTERROR: tpcommit() failed: %s", 
0098                     tpstrerror(tperrno));
0099             EXFAIL_OUT(ret);
0100         }
0101     }
0102     else if (0==strcmp(testbuf, "ABORT") || 0==strcmp(testbuf, "ABORT2") ||
0103             0==strcmp(testbuf, "ABORT3"))
0104     {
0105         if (EXSUCCEED!=tpabort(0))
0106         {
0107             NDRX_LOG(log_error, "TESTERROR: tpabort() failed: %s", 
0108                     tpstrerror(tperrno));
0109             EXFAIL_OUT(ret);
0110         }
0111     }
0112     else if (0==strcmp(testbuf, "RETURN"))
0113     {
0114         return;
0115     }
0116 #if 0
0117    due to Support #658 bug, cannot perform dynamic unadvertise/advertise to reach the stable works mode
0118     if (0==strcmp(testbuf, "OK"))
0119     {
0120         /* perform dynamic advertise, so that next cases OK works too */
0121         if (EXSUCCEED!=tpunadvertise("TESTSV2"))
0122         {
0123             NDRX_LOG(log_error, "TESTERROR: Failed to unadvertise: %s", tpstrerror(tperrno));
0124             EXFAIL_OUT(ret);
0125         }
0126 
0127         /* let ndrxd to flush the queues
0128          * otherwise with next requests the queues are not restored? 
0129          */
0130         sleep(3);
0131 
0132         if (EXSUCCEED!=tpadvertise("TESTSV2", TESTSV2))
0133         {
0134             NDRX_LOG(log_error, "TESTERROR: Failed to advertise: %s", tpstrerror(tperrno));
0135             EXFAIL_OUT(ret);
0136         }
0137     }
0138 #endif
0139     
0140 out:
0141     
0142     tpreturn(  EXSUCCEED==ret?TPSUCCESS:TPFAIL,
0143                 0L,
0144                 (char *)p_ub,
0145                 0L,
0146                 0L);
0147 
0148 }
0149 
0150 /**
0151  * Do initialisation
0152  */
0153 int NDRX_INTEGRA(tpsvrinit)(int argc, char **argv)
0154 {
0155     int ret = EXSUCCEED;
0156     NDRX_LOG(log_debug, "tpsvrinit called");
0157     
0158     if (EXSUCCEED!=tpopen())
0159     {
0160         NDRX_LOG(log_error, "Failed to tpopen: %s", tpstrerror(tperrno));
0161         EXFAIL_OUT(ret);
0162     }
0163 
0164     if (EXSUCCEED!=tpadvertise("TESTSV2", TESTSV2))
0165     {
0166         NDRX_LOG(log_error, "Failed to initialise TESTSV2!");
0167         EXFAIL_OUT(ret);
0168     }
0169 out:
0170     return ret;
0171 }
0172 
0173 /**
0174  * Do de-initialisation
0175  */
0176 void NDRX_INTEGRA(tpsvrdone)(void)
0177 {
0178     tpclose();
0179     
0180     NDRX_LOG(log_debug, "tpsvrdone called");
0181 }
0182 
0183 /* vim: set ts=4 sw=4 et smartindent: */