Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Test the failover of TMSRV+TMQ with the singleton groups between two domains - client
0003  *
0004  * @file atmiclt104.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 
0040 #include <atmi.h>
0041 #include <ubf.h>
0042 #include <ndebug.h>
0043 #include <test.fd.h>
0044 #include <ndrstandard.h>
0045 #include <nstopwatch.h>
0046 #include <fcntl.h>
0047 #include <unistd.h>
0048 #include <nstdutil.h>
0049 #include "test104.h"
0050 /*---------------------------Externs------------------------------------*/
0051 /*---------------------------Macros-------------------------------------*/
0052 /*---------------------------Enums--------------------------------------*/
0053 /*---------------------------Typedefs-----------------------------------*/
0054 /*---------------------------Globals------------------------------------*/
0055 /*---------------------------Statics------------------------------------*/
0056 /*---------------------------Prototypes---------------------------------*/
0057 
0058 /**
0059  * Do the test call to the server
0060  */
0061 int main(int argc, char** argv)
0062 {
0063     UBFH *p_ub = (UBFH *)tpalloc("UBF", NULL, 56000);
0064     long rsplen;
0065     int i;
0066     int ret=EXSUCCEED;
0067     TPQCTL qctl;
0068     short num;
0069     long len;
0070 
0071     if (argc < 3)
0072     {
0073         fprintf(stderr, "Usage: %s {enq <msg_no> | deq <msg_tot> }\n", argv[0]);
0074         exit(EXFAIL);
0075     }
0076     num = atoi(argv[2]);
0077 
0078     if (0==strcmp(argv[1], "enq"))
0079     {
0080         if (EXSUCCEED!=Bchg(p_ub, T_SHORT_FLD, 0, (char *)&num, 0L))
0081         {
0082             fprintf(stderr, "Failed to set T_SHORT_FLD\n");
0083             EXFAIL_OUT(ret);
0084         }
0085 
0086         /* enqueue buffer */
0087         memset(&qctl, 0, sizeof(qctl));
0088 
0089         if (EXSUCCEED!=tpenqueue("TESTSP", "Q1", &qctl, (char *)p_ub, 0, 0))
0090         {
0091             NDRX_LOG(log_error, "TESTERROR: tpenqueue() to `Q1' failed %s diag: %d:%s",
0092                             tpstrerror(tperrno), qctl.diagnostic, qctl.diagmsg);
0093                     EXFAIL_OUT(ret);
0094             EXFAIL_OUT(ret);
0095         }
0096     }
0097     else if (0==strcmp(argv[1], "deq"))
0098     {
0099         /* read number of message and match slots, check for duplicates */
0100         short messages[num];
0101         short val;
0102         char q[2][16] = {"Q1", "Q2"};
0103         int j;
0104         memset(messages, 0, sizeof(messages));
0105 
0106         for (j=0; j<2; j++)
0107         {
0108             /* read from q1 or q2, if no msg present, then generate error */
0109             memset(&qctl, 0, sizeof(qctl));
0110             while (EXSUCCEED==tpdequeue("TESTSP", q[j], &qctl, (char **)&p_ub, &len, 0))
0111             {
0112                 if (EXSUCCEED!=Bget(p_ub, T_SHORT_FLD, 0, (char *)&val, NULL))
0113                 {
0114                     NDRX_LOG(log_error, "TESTERROR: Failed to get T_SHORT_FLD: %s", Bstrerror(Berror));
0115                     EXFAIL_OUT(ret);
0116                 }
0117 
0118                 if (val<0 || val>=num)
0119                 {
0120                     NDRX_LOG(log_error, "TESTERROR: Message %d out of range in Q [%s]", val, q[j]);
0121                     EXFAIL_OUT(ret);
0122                 }
0123 
0124                 if (messages[val]!=0)
0125                 {
0126                     NDRX_LOG(log_error, "TESTERROR: Duplicate message %d in Q [%s]", val, q[j]);
0127                     EXFAIL_OUT(ret);
0128                 }
0129                 NDRX_LOG(log_error, "GOT j=%d, val=%hd", j, val);
0130                 messages[val] = 1;
0131                 memset(&qctl, 0, sizeof(qctl));
0132             }
0133 
0134             if (TPEDIAGNOSTIC!=tperrno)
0135             {
0136                 NDRX_LOG(log_error, "TESTRROR: Expected TPEDIAGNOSTIC, got %s", tpstrerror(tperrno));
0137                 EXFAIL_OUT(ret);
0138             }
0139 
0140             NDRX_LOG(log_error, "tpdequeue(%s) failed %s diag: %d:%s", q[j],
0141                         tpstrerror(tperrno), qctl.diagnostic, qctl.diagmsg);
0142         }
0143 
0144         for (j=0; j<num; j++)
0145         {
0146             if (messages[j]!=1)
0147             {
0148                 NDRX_LOG(log_error, "TESTERROR: Message %d not found in Q", j);
0149                 EXFAIL_OUT(ret);
0150             }
0151         }
0152     }
0153     else
0154     {
0155         NDRX_LOG(log_error, "Unknown command %s", argv[1]);
0156         exit(EXFAIL);
0157     }
0158     
0159 out:
0160     tpterm();
0161     fprintf(stderr, "Exit with %d\n", ret);
0162 
0163     return ret;
0164 }
0165 
0166 /* vim: set ts=4 sw=4 et smartindent: */