Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Test for NOBLOCK operations
0003  *
0004  * @file atmiclt18.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 #include <unistd.h>
0040 
0041 #include <atmi.h>
0042 #include <ubf.h>
0043 #include <ndebug.h>
0044 #include <test.fd.h>
0045 #include <ndrstandard.h>
0046 #include <nstopwatch.h>
0047 /*---------------------------Externs------------------------------------*/
0048 /*---------------------------Macros-------------------------------------*/
0049 /*---------------------------Enums--------------------------------------*/
0050 /*---------------------------Typedefs-----------------------------------*/
0051 /*---------------------------Globals------------------------------------*/
0052 /*---------------------------Statics------------------------------------*/
0053 /*---------------------------Prototypes---------------------------------*/
0054 
0055 /*
0056  * Do the test call to the server
0057  */
0058 int main(int argc, char** argv) {
0059 
0060     UBFH *p_ub = (UBFH *)tpalloc("UBF", NULL, 9218);
0061     long rsplen;
0062     int i;
0063     int ret=EXSUCCEED;
0064     int cd_got;
0065     int cd[3];
0066     int got_send_block;
0067     char bigmsg[8000];
0068     
0069     Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 1", 0);
0070     Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 2", 0);
0071     Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 3", 0);
0072     
0073     cd[0] = tpacall("TESTSV", (char *)p_ub, 0L, 0L);
0074     if (cd[0] <= 0)
0075     {
0076         NDRX_LOG(log_error, "TESTERROR first tpacall got %d: %s",
0077             cd[0], tpstrerror(tperrno));
0078         EXFAIL_OUT(ret);
0079     }
0080     
0081     cd[1] = tpacall("TESTSV", (char *)p_ub, 0L, 0L);
0082     if (cd[1] <= 0)
0083     {
0084         NDRX_LOG(log_error, "TESTERROR second tpacall got %d: %s",
0085             cd[1], tpstrerror(tperrno));
0086         EXFAIL_OUT(ret);
0087     }
0088     
0089     cd[2] = tpacall("TESTSV", (char *)p_ub, 0L, 0L);
0090     if (cd[2] <= 0)
0091     {
0092         NDRX_LOG(log_error, "TESTERROR third tpacall got %d: %s",
0093             cd[2], tpstrerror(tperrno));
0094         EXFAIL_OUT(ret);
0095     }
0096     
0097     /* wait for tout */
0098     sleep(10);
0099     
0100     for (i = 0; i<3; i++)
0101     {
0102         cd_got = cd[i];
0103         if (EXSUCCEED==(ret = tpgetrply(&cd_got, (char **)&p_ub, &rsplen, TPNOBLOCK)))
0104         {
0105             NDRX_LOG(log_error, "TESTERROR The call was ok to server "
0106                     "- must be tout!");
0107             ret=EXFAIL;
0108             goto out;
0109         }
0110 
0111         ret = EXSUCCEED;
0112         if (cd_got != cd[i])
0113         {
0114             NDRX_LOG(log_error, "TESTERROR cd %d <> go_cd %d", cd, cd_got);
0115             ret=EXFAIL;
0116             goto out;
0117         }
0118 
0119         if (tperrno!=TPETIME)
0120         {
0121             NDRX_LOG(log_error, "Te error should be time-out!");
0122             ret=EXFAIL;
0123             goto out;
0124         }
0125     }
0126     
0127     /* the the case when we get reply back, this should not be a timeout. */
0128     cd[0] = tpacall("ECHO", (char *)p_ub, 0L, 0L);
0129     sleep(1);
0130     if (EXSUCCEED==(ret = tpgetrply(&cd_got, (char **)&p_ub, &rsplen, TPNOBLOCK | TPGETANY)))
0131     {
0132         NDRX_LOG(log_error, "TESTERROR Must be TPEBLOCK");
0133         ret=EXFAIL;
0134         goto out;
0135     }
0136     
0137     if (tperrno!=TPEBLOCK)
0138     {
0139         NDRX_LOG(log_error, "TESTERROR! got tperror=%d %s expected TPENOBLOCK %d", 
0140                 tperrno, tpstrerror(tperrno), TPEBLOCK);
0141         ret=EXFAIL;
0142         goto out;
0143     }
0144     
0145     sleep(10);
0146     if (EXSUCCEED!=(ret = tpgetrply(&cd_got, (char **)&p_ub, &rsplen, TPNOBLOCK | TPGETANY)))
0147     {
0148         NDRX_LOG(log_error, "TESTERROR Normal reply fails!!!");
0149         ret=EXFAIL;
0150         goto out;
0151     }
0152     
0153     if (cd_got!=cd[0])
0154     {
0155         NDRX_LOG(log_error, "TESTERROR Got invalid response! "
0156                 "cd[0] = %d got_cd = %d", cd[0], cd_got);
0157         ret=EXFAIL;
0158         goto out;
0159     }
0160     
0161     /* test for noblock op -> queue empty... */    
0162     if (EXSUCCEED==(ret = tpgetrply(&cd_got, (char **)&p_ub, &rsplen, TPNOBLOCK)))
0163     {
0164         NDRX_LOG(log_error, "TESTERROR Queue must be empty!");
0165         ret=EXFAIL;
0166         goto out;
0167     }
0168     
0169     NDRX_LOG(log_debug, "got tperror=%d %s", tperrno, tpstrerror(tperrno));
0170     
0171     if (tperrno!=TPEBADDESC)
0172     {
0173         NDRX_LOG(log_error, "TESTERROR! got tperror=%d %s expected TPEBADDESC %d", 
0174                 tperrno, tpstrerror(tperrno), TPEBADDESC);
0175         ret=EXFAIL;
0176         goto out;
0177     }
0178     ret=EXSUCCEED;
0179     
0180     /* Test for full service queue, we shall get TPEBLOCK back */
0181     
0182     if (EXSUCCEED!=Bchg(p_ub, T_CARRAY_FLD, 0, bigmsg, sizeof(bigmsg)))
0183     {
0184         NDRX_LOG(log_error, "TESTERROR! Failed to add bigmsg: %s", 
0185                 Bstrerror(Berror));
0186         EXFAIL_OUT(ret);
0187     }
0188     
0189     got_send_block = EXFALSE;
0190     while (1)
0191     {
0192         if (EXFAIL==tpacall("BLOCKY", (char *)p_ub, 0L, TPNOBLOCK))
0193         {
0194             if (tperrno!=TPEBLOCK)
0195             {
0196                 NDRX_LOG(log_error, "TESTERROR! got tperror=%d %s expected TPENOBLOCK %d", 
0197                         tperrno, tpstrerror(tperrno), TPEBLOCK);
0198                 ret=EXFAIL;
0199                 goto out;
0200             }
0201             else
0202             {
0203                 got_send_block = EXTRUE;
0204                 break;
0205             }
0206         }
0207     }
0208     
0209     if (!got_send_block)
0210     {
0211         NDRX_LOG(log_error, "TESTERROR: expected TPEBLOCK condition in previous run!");
0212         ret=EXFAIL;
0213         goto out;
0214     }
0215     
0216 out:
0217 
0218     if (NULL!=p_ub)
0219     {
0220         tpfree((char *)p_ub);
0221     }
0222 
0223     tpterm();
0224     NDRX_LOG(log_error, "RESULT: %d", ret);
0225     return ret;
0226 }
0227 
0228 /* vim: set ts=4 sw=4 et smartindent: */