Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Conversational tests
0003  *
0004  * @file atmisv3.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 
0035 #include <stdio.h>
0036 #include <stdlib.h>
0037 #include <ndebug.h>
0038 #include <atmi.h>
0039 #include <ndrstandard.h>
0040 #include <ubf.h>
0041 #include <test.fd.h>
0042 
0043 /**
0044  * Support #457 - test for timeout
0045  */
0046 void TOUTSV (TPSVCINFO *p_svc)
0047 {
0048     sleep(30);
0049     tpreturn(  TPFAIL,
0050                 0L,
0051                 NULL,
0052                 0L,
0053                 0L);
0054 } 
0055 
0056 /**
0057  * Perform return success without any data
0058  * for testing Bug #114 do in the loop init, connect, term by the client
0059  */
0060 void ECHO (TPSVCINFO *p_svc)
0061 {
0062         tpreturn( TPSUCCESS,
0063                 0L,
0064                 p_svc->data,
0065                 0L,
0066                 0L);
0067 }
0068 
0069 void CONVSV (TPSVCINFO *p_svc)
0070 {
0071     int ret=EXSUCCEED;
0072     long revent;
0073     static double d = 55.66;
0074     int i;
0075     UBFH *p_ub = (UBFH *)p_svc->data;
0076     char tmp[128];
0077     long len;
0078     NDRX_LOG(log_debug, "CONVSV got call");
0079 
0080     /* Just print the buffer */
0081     Bprint(p_ub);
0082 
0083     if (NULL==(p_ub = (UBFH *)tprealloc((char *)p_ub, 6000))) /* allocate some stuff for more data to put in  */
0084     {
0085         ret=EXFAIL;
0086         goto out;
0087     }
0088 
0089     d+=1;
0090 
0091     for (i=0; i<100; i++)
0092     {
0093         sprintf(tmp, "SRV SND: %d", i);
0094         if (EXFAIL==Badd(p_ub, T_STRING_FLD, (char *)tmp, 0))
0095         {
0096             ret=EXFAIL;
0097             goto out;
0098         }
0099 
0100         if (p_svc->flags & TPSENDONLY)
0101         {
0102             NDRX_LOG(log_debug, "Doing some send!");
0103             /* Lets send some data back to client */
0104             if (EXFAIL==tpsend(p_svc->cd, (char *)p_ub, 0L, 0L, &revent))
0105             {
0106                 NDRX_LOG(log_error, "Failed to send to client!");
0107             }
0108         }
0109     }   
0110 
0111     /* Now we will become as listeners, OK? */
0112     if (EXFAIL==tpsend(p_svc->cd, (char *)p_ub, 0L, TPRECVONLY, &revent))
0113     {
0114         NDRX_LOG(log_error, "Failed to send to client!");
0115         goto out;
0116     }
0117 
0118     /* now wait for messages to come in! */
0119     while (EXSUCCEED==tprecv(p_svc->cd, (char **)&p_ub, &len, 0L, &revent))
0120     {
0121         NDRX_LOG(log_debug, "Sent MSG OK!");
0122     }
0123 
0124     /* Dump the buffer */
0125     Bfprint(p_ub, stderr);
0126 
0127     if (TPEEVENT==tperrno)
0128     {
0129         if (TPEV_SENDONLY==revent)
0130         {
0131             NDRX_LOG(log_debug, "We are senders - FINISH UP!");
0132         }
0133         else
0134         {
0135             NDRX_LOG(log_debug, "Did not get TPEV_SENDONLY!!!");
0136             ret=EXFAIL;
0137         }
0138     }
0139 
0140 out:
0141     tpreturn(  ret==EXSUCCEED?TPSUCCESS:TPFAIL,
0142                 0L,
0143                 (char *)p_ub,
0144                 0L,
0145                 0L);
0146 }
0147 
0148 /**
0149  * Test non blocking error reporting Support #781
0150  * @param p_svc
0151  */
0152 void NOBLK (TPSVCINFO *p_svc)
0153 {
0154     int ret=EXSUCCEED;
0155     long revent;
0156     UBFH *p_ub = (UBFH *)p_svc->data;
0157     
0158     sleep(5);
0159     
0160 #ifdef EX_USE_EPOLL
0161     /* send till we get full Q */
0162     while (EXSUCCEED==tpsend(p_svc->cd, (char *)p_ub, 0L, TPNOBLOCK, &revent));
0163     
0164     if (TPEBLOCK!=tperrno)
0165     {
0166         NDRX_LOG(log_error, "TESTERROR: Expected TPEBLOCK got %s %ld", tpstrerror(tperrno),
0167                 revent);
0168         EXFAIL_OUT(ret);
0169     }
0170 #endif
0171     
0172     
0173 out:
0174     tpreturn(  ret==EXSUCCEED?TPSUCCESS:TPFAIL,
0175                 0L,
0176                 (char *)p_ub,
0177                 0L,
0178                 0L);
0179 } 
0180 
0181 /*
0182  * Do initialization
0183  */
0184 int NDRX_INTEGRA(tpsvrinit)(int argc, char **argv)
0185 {
0186     int ret = EXSUCCEED;
0187     NDRX_LOG(log_debug, "tpsvrinit called");
0188 
0189     if (EXSUCCEED!=tpadvertise("CONVSV", CONVSV))
0190     {
0191         NDRX_LOG(log_error, "Failed to initialize CONVSV!");
0192         ret=EXFAIL;
0193     }
0194 
0195     if (EXSUCCEED!=tpadvertise("TOUTSV", TOUTSV))
0196     {
0197         NDRX_LOG(log_error, "Failed to initialize TOUTSV!");
0198         ret=EXFAIL;
0199     }
0200     
0201     /* No blocking tests Support #781 */
0202     if (EXSUCCEED!=tpadvertise("NOBLK", NOBLK))
0203     {
0204         NDRX_LOG(log_error, "Failed to initialize NOBLK!");
0205         ret=EXFAIL;
0206     }
0207 
0208     if (EXSUCCEED!=tpadvertise("ECHO", ECHO))
0209     {
0210         NDRX_LOG(log_error, "Failed to initialize ECHO!");
0211         ret=EXFAIL;
0212     }
0213     
0214     return ret;
0215 }
0216 
0217 /**
0218  * Do de-initialization
0219  */
0220 void NDRX_INTEGRA(tpsvrdone)(void)
0221 {
0222     NDRX_LOG(log_debug, "tpsvrdone called");
0223 }
0224 /* vim: set ts=4 sw=4 et smartindent: */