Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Basic test client
0003  *
0004  * @file atmiclt3.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 
0039 #include <atmi.h>
0040 #include <ubf.h>
0041 #include <ndebug.h>
0042 #include <test.fd.h>
0043 #include <ndrstandard.h>
0044 
0045 #include "exassert.h"
0046 /*---------------------------Externs------------------------------------*/
0047 /*---------------------------Macros-------------------------------------*/
0048 /*---------------------------Enums--------------------------------------*/
0049 /*---------------------------Typedefs-----------------------------------*/
0050 /*---------------------------Globals------------------------------------*/
0051 /*---------------------------Statics------------------------------------*/
0052 /*---------------------------Prototypes---------------------------------*/
0053 
0054 /*
0055  * Do the test call to the server
0056  */
0057 int main(int argc, char** argv) {
0058 
0059     UBFH *p_ub = (UBFH *)tpalloc("UBF", NULL, 4048);
0060     long rsplen;
0061     int i;
0062     int ret=EXSUCCEED;
0063     double d;
0064     double dv = 55.66;
0065     int cd;
0066     long revent;
0067     int received = 0;
0068     char tmp[126];
0069     long len;
0070 
0071     /* add test case selector normal vs timeout vs invalid arg... */
0072     if (argc < 2)
0073     {
0074         fprintf(stderr, "Usage: %s normal|timeout\n", argv[0]);
0075         exit(EXFAIL);
0076     }
0077     else if (0==strcmp(argv[1], "normal"))
0078     {
0079         
0080         Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 1", 0);
0081         Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 2", 0);
0082         Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 3", 0);
0083 
0084         if (EXFAIL==(cd=tpconnect("CONVSV", (char *)p_ub, 0L, TPRECVONLY)))
0085         {
0086             NDRX_LOG(log_error, "TESTSV connect failed!: %s",
0087                                     tpstrerror(tperrno));
0088             ret=EXFAIL;
0089             goto out;
0090         }
0091 
0092         /* Recieve the stuff back */
0093         NDRX_LOG(log_debug, "About to tprecv!");
0094 
0095         while (EXSUCCEED==tprecv(cd, (char **)&p_ub, &len, 0L, &revent))
0096         {
0097             received++;
0098             NDRX_LOG(log_debug, "MSG RECEIVED OK!");
0099         }
0100         
0101 
0102         /* If we have event, we would like to become recievers if so */
0103         if (TPEEVENT==tperrno)
0104         {
0105             received++;
0106             snprintf(tmp, sizeof(tmp), "CLT: %d", received);
0107             
0108             Bprint(p_ub);
0109             Badd(p_ub, T_STRING_FLD, tmp, 0L);
0110             if (TPEV_SENDONLY==revent)
0111             {
0112                 int i=0;
0113                 /* Start the sending stuff now! */
0114                 for (i=0; i<100 && EXSUCCEED==ret; i++)
0115                 {
0116                     ret=tpsend(cd, (char *)p_ub, 0L, 0L, &revent);
0117                 }
0118             }
0119         }
0120 
0121         /* Now give the control to the server, so that he could finish up */
0122         if (EXFAIL==tpsend(cd, NULL, 0L, TPRECVONLY, &revent))
0123         {
0124             NDRX_LOG(log_debug, "Failed to give server control!!");
0125             ret=EXFAIL;
0126             goto out;
0127         }
0128 
0129         NDRX_LOG(log_debug, "Get response from tprecv!");
0130         Bfprint(p_ub, stderr);
0131 
0132         /* Wait for return from server */
0133         ret=tprecv(cd, (char **)&p_ub, &len, 0L, &revent);
0134         NDRX_LOG(log_error, "tprecv failed with revent=%ld tperrno=%d", revent, tperrno);
0135 
0136         if (EXFAIL==ret && TPEEVENT==tperrno && TPEV_SVCSUCC==revent)
0137         {
0138             NDRX_LOG(log_error, "Service finished with TPEV_SVCSUCC!");
0139             ret=EXSUCCEED;
0140         }
0141         
0142         /* check that we do not core dump when trying to fetch from closed connection */
0143         ret=tprecv(cd, (char **)&p_ub, &len, 0L, &revent);
0144         
0145         if (EXSUCCEED==ret)
0146         {
0147             NDRX_LOG(log_error, "TESTERROR ! Error shall be generated when "
0148                     "fetching from closed connection!");
0149             EXFAIL_OUT(ret);
0150         }
0151         else
0152         {
0153             ret = EXSUCCEED;
0154         }
0155         
0156         if (tperrno!=TPEINVAL)
0157         {
0158             NDRX_LOG(log_error, "TESTERROR ! Expected err %d got %d!", 
0159                     TPEINVAL, tperrno);
0160             EXFAIL_OUT(ret);
0161         }
0162         
0163     } 
0164     else if (0==strcmp(argv[1], "timeout"))
0165     {
0166 
0167         /* kill the atmisv -> conn will fail.. 
0168         system("xadmin killall atmisv3");*/
0169 
0170         /* test for timeout */
0171         if (EXFAIL!=(cd=tpconnect("TOUTSV", (char *)p_ub, 0L, TPRECVONLY)))
0172         {
0173             NDRX_LOG(log_error, "TOUTSV not failed!");
0174             ret=EXFAIL;
0175             goto out;
0176         }
0177 
0178         if (tperrno!=TPETIME)
0179         {
0180             NDRX_LOG(log_error, "TESTERROR ! Expected err %d got %d!", 
0181                     TPETIME, tperrno);
0182             EXFAIL_OUT(ret);
0183         }
0184     }
0185     else if (0==strcmp(argv[1], "noblk"))
0186     {
0187         if (EXFAIL==(cd=tpconnect("NOBLK", (char *)p_ub, 0L, TPRECVONLY)))
0188         {
0189             NDRX_LOG(log_error, "NOBLK failed: %s", tpstrerror(tperrno));
0190             ret=EXFAIL;
0191             goto out;
0192         }
0193         
0194         NDRX_ASSERT_TP_OUT( (EXFAIL==tprecv(cd, (char **)&p_ub, &len, TPNOBLOCK, &revent) 
0195                 && TPEBLOCK==tperrno), "Invalid blocking condition");
0196   
0197 #ifdef EX_USE_EPOLL
0198         /* let the server to overfill the queues. */
0199         sleep(15);
0200 #endif
0201       
0202        /* dump the msgs, used for send blk testing  */
0203        while (EXSUCCEED==tprecv(cd, (char **)&p_ub, &len, 0, &revent));
0204        
0205        NDRX_ASSERT_TP_OUT((TPEEVENT==tperrno && TPEV_SVCSUCC==revent),
0206                "Invalid term event %ld", revent);
0207     }
0208     else if (0==strcmp(argv[1], "echoloop"))
0209     {
0210 
0211         for (i=0; i<100000; i++)
0212         {
0213             if (EXFAIL==(cd=tpconnect("ECHO", (char *)p_ub, 0L, TPRECVONLY)))
0214             {
0215                 NDRX_LOG(log_error, "ECHO failed: %s", tpstrerror(tperrno));
0216                 ret=EXFAIL;
0217                 goto out;
0218             }
0219         
0220             while (EXSUCCEED==tprecv(cd, (char **)&p_ub, &len, 0L, &revent))
0221             {
0222                 NDRX_LOG(log_error, "ECHO no msg expected");
0223                 ret=EXFAIL;
0224                 goto out;
0225             }
0226 
0227             NDRX_ASSERT_TP_OUT((TPEEVENT==tperrno && TPEV_SVCSUCC==revent),
0228                "Invalid term event %ld", revent);
0229 
0230             tpterm();
0231         }
0232     }
0233     else
0234     {
0235         NDRX_LOG(log_error, "TESTERROR: invalid test case [%s]", argv[1]);
0236         ret=EXFAIL;
0237         goto out;
0238     }
0239     
0240 out:
0241 
0242     if (EXSUCCEED!=tpterm())
0243     {
0244         NDRX_LOG(log_error, "tpterm failed with: %s", tpstrerror(tperrno));
0245     }
0246 
0247     return ret;
0248 }
0249 
0250 /* vim: set ts=4 sw=4 et smartindent: */