Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief TMSRV State Driving verification - server
0003  *
0004  * @file atmisv87_1.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 
0040 /*---------------------------Externs------------------------------------*/
0041 /*---------------------------Macros-------------------------------------*/
0042 /*---------------------------Enums--------------------------------------*/
0043 /*---------------------------Typedefs-----------------------------------*/
0044 /*---------------------------Globals------------------------------------*/
0045 /*---------------------------Statics------------------------------------*/
0046 /*---------------------------Prototypes---------------------------------*/
0047 
0048 /**
0049  * Standard service entry
0050  */
0051 void TESTSV1 (TPSVCINFO *p_svc)
0052 {
0053     tpforward("TESTSV2", NULL, 0, 0);
0054 }
0055 
0056 /**
0057  * Standard service entry, Error server.
0058  */
0059 void TESTSVE1 (TPSVCINFO *p_svc)
0060 {
0061     char *odata=NULL;
0062     long olen;
0063     
0064     /* shall generate error */
0065     tpcall("TESTSVE2", NULL, 0, &odata, &olen, 0);
0066     
0067     /* shall keep the error */
0068     tpforward("TESTSV2", NULL, 0, 0);
0069 }
0070 
0071 /**
0072  * Standard service entry, Error server, Return
0073  */
0074 void TESTSVE1_RET (TPSVCINFO *p_svc)
0075 {
0076     char *odata=NULL;
0077     long olen;
0078     
0079     /* shall generate error */
0080     tpcall("TESTSVE2", NULL, 0, &odata, &olen, 0);
0081     
0082     tpreturn(TPSUCCESS, 0, NULL, 0, 0);
0083 }
0084 
0085 
0086 /**
0087  * Participant tests of the transaction APIs.
0088  */
0089 void TEST1_PART (TPSVCINFO *p_svc)
0090 {
0091     int ret = EXSUCCEED;
0092     
0093     if (EXSUCCEED==tpabort(0))
0094     {
0095         NDRX_LOG(log_error, "TESTERROR: Must not abort!");
0096         EXFAIL_OUT(ret);
0097     }
0098     
0099     if (TPEPROTO!=tperrno)
0100     {
0101         NDRX_LOG(log_error, "TESTERROR: Must be TPEPROTO, got %d!", tperrno);
0102         EXFAIL_OUT(ret);
0103     }
0104     
0105     if (!tpgetlev())
0106     {
0107         NDRX_LOG(log_error, "TESTERROR: Process shall stay in transaction, but is not");
0108         EXFAIL_OUT(ret);
0109     }
0110     
0111     if (EXSUCCEED==tpcommit(0))
0112     {
0113         NDRX_LOG(log_error, "TESTERROR: Must not commit!");
0114         EXFAIL_OUT(ret);
0115     }
0116     
0117     if (TPEPROTO!=tperrno)
0118     {
0119         NDRX_LOG(log_error, "TESTERROR: Must be TPEPROTO, got %d!", tperrno);
0120         EXFAIL_OUT(ret);
0121     }
0122     
0123     if (!tpgetlev())
0124     {
0125         NDRX_LOG(log_error, "TESTERROR: Process shall stay in transaction, but is not");
0126         EXFAIL_OUT(ret);
0127     }
0128     
0129     
0130 out:
0131     
0132     if (EXSUCCEED==ret)
0133     {
0134         tpreturn(TPSUCCESS, 0, NULL, 0, 0);
0135     }
0136     else
0137     {
0138         tpreturn(TPFAIL, 0, NULL, 0, 0); 
0139     }
0140 }
0141 
0142 
0143 /**
0144  * Our transaction still attached
0145  */
0146 void TESTSVE1_TRANRET (TPSVCINFO *p_svc)
0147 {
0148     int ret = EXSUCCEED;
0149     
0150     if (EXSUCCEED!=tpbegin(40, 0))
0151     {
0152         NDRX_LOG(log_error, "TESTERROR: Failed to begin transaction: %s",
0153                 tpstrerror(tperrno));
0154         userlog("TESTERROR: Failed to begin transaction: %s",
0155                 tpstrerror(tperrno));
0156         EXFAIL_OUT(ret);
0157     }    
0158 out:
0159     if (EXSUCCEED==ret)
0160     {
0161         tpreturn(TPSUCCESS, 0, NULL, 0, 0);
0162     }
0163     else
0164     {
0165         tpreturn(TPFAIL, 0, NULL, 0, 0);
0166     }
0167 }
0168 
0169 /**
0170  * Open tran, forward
0171  */
0172 void TESTSVE1_TRANFWD (TPSVCINFO *p_svc)
0173 {
0174     if (EXSUCCEED!=tpbegin(40, 0))
0175     {
0176         NDRX_LOG(log_error, "TESTERROR: Failed to begin transaction: %s",
0177                 tpstrerror(tperrno));
0178         userlog("TESTERROR: Failed to begin transaction: %s",
0179                 tpstrerror(tperrno));
0180     }    
0181     
0182     tpforward("TESTSV2", NULL, 0, 0);
0183 }
0184 
0185 /**
0186  * Standard service entry, Error server, Return
0187  */
0188 void TESTSVE1_NORET (TPSVCINFO *p_svc)
0189 {
0190     char *odata=NULL;
0191     long olen;
0192 }
0193 
0194 
0195 int tpsvrinit (int argc, char **argv)
0196 {
0197     return tpopen();
0198 }
0199 
0200 void tpsvrdone(void)
0201 {
0202     tpclose();
0203 }
0204 
0205 
0206 /* vim: set ts=4 sw=4 et smartindent: */