Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Error queue test cases
0003  * @file errorq.c
0004  */
0005 /* -----------------------------------------------------------------------------
0006  * Enduro/X Middleware Platform for Distributed Transaction Processing
0007  * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0008  * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0009  * This software is released under one of the following licenses:
0010  * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0011  * See LICENSE file for full text.
0012  * -----------------------------------------------------------------------------
0013  * AGPL license:
0014  *
0015  * This program is free software; you can redistribute it and/or modify it under
0016  * the terms of the GNU Affero General Public License, version 3 as published
0017  * by the Free Software Foundation;
0018  *
0019  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0020  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0021  * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0022  * for more details.
0023  *
0024  * You should have received a copy of the GNU Affero General Public License along 
0025  * with this program; if not, write to the Free Software Foundation, Inc.,
0026  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0027  *
0028  * -----------------------------------------------------------------------------
0029  * A commercial use license is available from Mavimax, Ltd
0030  * contact@mavimax.com
0031  * -----------------------------------------------------------------------------
0032  */
0033 #include <string.h>
0034 #include <stdio.h>
0035 #include <stdlib.h>
0036 #include <memory.h>
0037 #include <unistd.h>
0038 
0039 #include <atmi.h>
0040 #include <ubf.h>
0041 #include <ndebug.h>
0042 #include <test.fd.h>
0043 #include <ndrstandard.h>
0044 #include <ubfutil.h>
0045 #include <nstopwatch.h>
0046 #include <nstdutil.h>
0047 #include <exassert.h>
0048 /*---------------------------Externs------------------------------------*/
0049 /*---------------------------Macros-------------------------------------*/
0050 /*---------------------------Enums--------------------------------------*/
0051 /*---------------------------Typedefs-----------------------------------*/
0052 /** verify matching req/replies. */
0053 typedef struct 
0054 {
0055     int num_req;
0056     int num_rsp;
0057 } test_result_t;
0058 
0059 /*---------------------------Globals------------------------------------*/
0060 /*---------------------------Statics------------------------------------*/
0061 /*---------------------------Prototypes---------------------------------*/
0062 
0063 #define MAX_TEST    100
0064 /**
0065  * Perform error queue testing (enqueue, service fails)
0066  * - check error queue of requests
0067  * - check failurequeue for replies.
0068  * @param maxmsg
0069  * @return EXSUCCEED/EXFAIL
0070  */
0071 expublic int basic_errorq(void)
0072 {
0073     int ret = EXSUCCEED;
0074     TPQCTL qc;
0075     long i;
0076     long olen;
0077     char tmpbuf[1024];
0078     long num;
0079     UBFH *p_ub = NULL;
0080     test_result_t rsp[MAX_TEST];
0081     
0082     NDRX_LOG(log_error, "case basic_errorq");
0083     
0084     NDRX_ASSERT_TP_OUT((NULL!=(p_ub=(UBFH *)tpalloc("UBF", NULL, 1024))), "Failed to alloc");
0085     
0086     for (i=0; i<MAX_TEST; i++)
0087     {
0088         NDRX_ASSERT_UBF_OUT( (EXSUCCEED==Bchg(p_ub, T_LONG_FLD, 0, (char *)&i, 0L)), 
0089                 "Failed to set test num");
0090         
0091         NDRX_ASSERT_UBF_OUT( (EXSUCCEED==Bchg(p_ub, T_STRING_FLD, 0, "REQ", 0L)), 
0092                 "Failed to set test num");
0093         
0094         /* enq */
0095         memset(&qc, 0, sizeof(qc));
0096         qc.flags|=TPQFAILUREQ;
0097         NDRX_STRCPY_SAFE(qc.failurequeue, "ERRORRSP");
0098         
0099         NDRX_ASSERT_TP_OUT((EXSUCCEED==tpenqueue("MYSPACE", "FAILSVC", &qc, 
0100                 (char *)p_ub, 0, 0L)), "Failed to enq");
0101     }
0102     
0103     /* This shall complete in this time.. */
0104     sleep(30);
0105     memset(rsp, 0, sizeof(rsp));
0106     
0107     /* read & match results, all stuff shall be in errorreq, errorrsp */
0108     
0109     for (i=0; i<MAX_TEST; i++)
0110     {
0111         memset(&qc, 0, sizeof(qc));
0112         
0113         tpfree((char *)p_ub);
0114         p_ub = NULL;
0115         
0116         NDRX_ASSERT_TP_OUT((EXFAIL==tpdequeue("MYSPACE", "FAILSVC", &qc, (char **)&p_ub, &olen, 0)), 
0117                 "Must not be OK");
0118         
0119         /* verify req */
0120         NDRX_ASSERT_TP_OUT((EXSUCCEED==tpdequeue("MYSPACE", "ERRORREQ", &qc, (char **)&p_ub, &olen, 0)), 
0121                 "Must be OK");
0122         
0123         NDRX_ASSERT_UBF_OUT((EXSUCCEED==Bget(p_ub, T_STRING_FLD, 0, tmpbuf, NULL)), 
0124                 "Failed to get data fld");
0125         NDRX_ASSERT_VAL_OUT(0==strcmp(tmpbuf, "REQ"), "Request not found: %s", tmpbuf);
0126         NDRX_ASSERT_UBF_OUT((EXSUCCEED==Bget(p_ub, T_LONG_FLD, 0, (char *)&num, NULL)), 
0127                 "Failed to get num");
0128         rsp[num].num_req++;
0129         
0130         
0131         tpfree((char *)p_ub);
0132         p_ub = NULL;
0133         tmpbuf[0]=EXEOS;
0134         
0135         /* verify rsp */
0136         NDRX_ASSERT_TP_OUT((EXSUCCEED==tpdequeue("MYSPACE", "ERRORRSP", &qc, (char **)&p_ub, &olen, 0)), 
0137                 "Must be OK: %ld %s", qc.diagnostic, qc.diagmsg);
0138         
0139         NDRX_ASSERT_UBF_OUT((EXSUCCEED==Bget(p_ub, T_STRING_FLD, 0, tmpbuf, NULL)), 
0140                 "Failed to get data fld");
0141         NDRX_ASSERT_VAL_OUT(0==strcmp(tmpbuf, "RSP"), "Request not found: %s", tmpbuf);
0142         NDRX_ASSERT_UBF_OUT((EXSUCCEED==Bget(p_ub, T_LONG_FLD, 0, (char *)&num, NULL)), 
0143                 "Failed to get num");
0144         rsp[num].num_rsp++;
0145                 
0146     }
0147     
0148     /* verify that all msgs as been set... */
0149     for (i=0; i<MAX_TEST; i++)
0150     {
0151         NDRX_ASSERT_VAL_OUT(rsp[i].num_req==1, "Invalid num_req at %ld: %d", 
0152                 i, rsp[i].num_req);
0153         
0154         NDRX_ASSERT_VAL_OUT(rsp[i].num_rsp==1, "Invalid num_rsp at %ld: %d", 
0155                 i, rsp[i].num_rsp);
0156     }
0157     
0158 out:
0159 
0160     if (EXSUCCEED!=tpterm())
0161     {
0162         NDRX_LOG(log_error, "tpterm failed with: %s", tpstrerror(tperrno));
0163         ret=EXFAIL;
0164         goto out;
0165     }
0166 
0167     if (NULL!=p_ub)
0168     {
0169         tpfree((char *)p_ub);
0170     }
0171 
0172     return ret;
0173 }
0174 
0175 /* vim: set ts=4 sw=4 et smartindent: */