Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Feature #139 mvitolin, 09/05/2017
0003  *   Call the server with GETNEXT which will unadvertise old service and advertise
0004  *   New name. This should exceed NDRX_SVCMAX and complete successfully.
0005  *
0006  * @file atmiclt34.c
0007  */
0008 /* -----------------------------------------------------------------------------
0009  * Enduro/X Middleware Platform for Distributed Transaction Processing
0010  * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0011  * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0012  * This software is released under one of the following licenses:
0013  * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0014  * See LICENSE file for full text.
0015  * -----------------------------------------------------------------------------
0016  * AGPL license:
0017  *
0018  * This program is free software; you can redistribute it and/or modify it under
0019  * the terms of the GNU Affero General Public License, version 3 as published
0020  * by the Free Software Foundation;
0021  *
0022  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0023  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0024  * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0025  * for more details.
0026  *
0027  * You should have received a copy of the GNU Affero General Public License along 
0028  * with this program; if not, write to the Free Software Foundation, Inc.,
0029  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0030  *
0031  * -----------------------------------------------------------------------------
0032  * A commercial use license is available from Mavimax, Ltd
0033  * contact@mavimax.com
0034  * -----------------------------------------------------------------------------
0035  */
0036 #include <string.h>
0037 #include <stdio.h>
0038 #include <stdlib.h>
0039 #include <memory.h>
0040 #include <math.h>
0041 
0042 #include <ndebug.h>
0043 #include <atmi.h>
0044 
0045 
0046 #include <ubf.h>
0047 #include <Exfields.h>
0048 #include <test.fd.h>
0049 /*---------------------------Externs------------------------------------*/
0050 /*---------------------------Macros-------------------------------------*/
0051 
0052 #ifndef SUCCEED
0053 #define SUCCEED         0
0054 #endif
0055 
0056 #ifndef FAIL
0057 #define FAIL            -1
0058 #endif
0059 
0060 /*---------------------------Enums--------------------------------------*/
0061 /*---------------------------Typedefs-----------------------------------*/
0062 /*---------------------------Globals------------------------------------*/
0063 /*---------------------------Statics------------------------------------*/
0064 /*---------------------------Prototypes---------------------------------*/
0065 
0066 
0067 /**
0068  * Initialise the application
0069  * @param argc  argument count
0070  * @param argv  argument values
0071  * @return SUCCEED/FAIL
0072  */
0073 int init(int argc, char** argv)
0074 {
0075     int ret = SUCCEED;
0076 
0077     TP_LOG(log_info, "Initialising...");
0078 
0079     if (SUCCEED!=tpinit(NULL))
0080     {
0081         TP_LOG(log_error, "Failed to Initialise: %s", 
0082                 tpstrerror(tperrno));
0083         ret = FAIL;
0084         goto out;
0085     }
0086 
0087 out:
0088     return ret;
0089 }
0090 
0091 /**
0092  * Terminate the application
0093  */
0094 int uninit(int status)
0095 {
0096     int ret = SUCCEED;
0097 
0098     TP_LOG(log_info, "Uninitialising...");
0099 
0100     ret = tpterm();
0101 
0102     return ret;
0103 }
0104 
0105 /**
0106  * Do processing (call some service)
0107  * @return SUCCEED/FAIL
0108  */
0109 int process (void)
0110 {
0111     int ret = SUCCEED;
0112     long i;
0113     UBFH *p_ub = NULL;
0114     long rsplen;
0115     BFLDLEN sz;
0116     char svcnm[MAXTIDENT+1];
0117     char svcnm_ret[MAXTIDENT+1];
0118 
0119 
0120     TP_LOG(log_info, "Processing...");
0121 
0122 
0123     /* Call sample server... */
0124 
0125     for (i=0; i<24000; i++)
0126     {
0127         if (NULL==(p_ub = (UBFH *)tpalloc("UBF", NULL, 1024)))
0128         {
0129             TP_LOG(log_error, "Failed to tpalloc: %s",  tpstrerror(tperrno));
0130             ret=FAIL;
0131             goto out;
0132         }
0133 
0134         if (SUCCEED!=Bchg(p_ub, T_LONG_FLD, 0, (char *)&i, 0L))
0135         {
0136             TP_LOG(log_error, "Failed to set T_LONG_FLD: %s",  
0137                   Bstrerror(Berror));
0138             ret=FAIL;
0139             goto out;
0140         }
0141 
0142         if (FAIL==tpcall("GETNEXT", (char *)p_ub, 0L, (char **)&p_ub, &rsplen, TPNOTIME))
0143         {
0144             TP_LOG(log_error, "TESTERROR: Failed to call GETNEXT: %s",
0145                     tpstrerror(tperrno));
0146             ret=FAIL;
0147             goto out;
0148         }
0149 
0150         tplogprintubf(log_debug, "Got response from test server...", p_ub);
0151 
0152         /* Get the service number to advertise */
0153         snprintf(svcnm, sizeof(svcnm), "SVC%06ld", i);
0154 
0155         NDRX_LOG(log_info, "About to call service: [%s] - must be advertised",
0156                         svcnm);
0157 
0158         if (FAIL==tpcall(svcnm, (char *)p_ub, 0L, (char **)&p_ub, &rsplen, TPNOTIME))
0159         {
0160             TP_LOG(log_error, "TESTERROR: Failed to call %s: %s",
0161                     svcnm, tpstrerror(tperrno));
0162             ret=FAIL;
0163             goto out;
0164         }
0165 
0166         if (SUCCEED!=Bget(p_ub, T_STRING_2_FLD, 0, svcnm_ret, 0))
0167         {
0168             TP_LOG(log_error, "Failed to set T_STRING_2_FLD: %s",  
0169                   Bstrerror(Berror));
0170             ret=FAIL;
0171             goto out;
0172         }
0173 
0174         TP_LOG(log_info, "Response called [%s], returned [%s]", 
0175                  svcnm, svcnm_ret);
0176 
0177         if (0!=strcmp(svcnm, svcnm_ret))
0178         {
0179             TP_LOG(log_error, "TESTERROR!!!, expected service [%s], "
0180                     "but got [%s]", 
0181                     svcnm, svcnm_ret);
0182             ret=FAIL;
0183             goto out;
0184         }
0185     }
0186     
0187 out:
0188 
0189 
0190     /* free up config data... */
0191     if (NULL!=p_ub)
0192     {
0193         tpfree((char *)p_ub);
0194     }
0195 
0196     return ret;
0197 }
0198 
0199 
0200 /**
0201  * Call 19' dynamic service
0202  * @return SUCCEED/FAIL
0203  */
0204 int call19 (void)
0205 {
0206     int ret = SUCCEED;
0207     long i;
0208     UBFH *p_ub = NULL;
0209     long rsplen;
0210     BFLDLEN sz;
0211     char svcnm[MAXTIDENT+1] = "ZZZ000019";
0212     char svcnm_ret[MAXTIDENT+1];
0213 
0214     TP_LOG(log_info, "Call19...");
0215 
0216     /* Call sample server... */
0217 
0218     for (i=0; i<24000; i++)
0219     {
0220         if (NULL==(p_ub = (UBFH *)tpalloc("UBF", NULL, 1024)))
0221         {
0222             TP_LOG(log_error, "Failed to tpalloc: %s",  tpstrerror(tperrno));
0223             ret=FAIL;
0224             goto out;
0225         }
0226 
0227         if (FAIL==tpcall(svcnm, (char *)p_ub, 0L, (char **)&p_ub, &rsplen, TPNOTIME))
0228         {
0229             TP_LOG(log_error, "TESTERROR: Failed to call %s: %s",
0230                     svcnm, tpstrerror(tperrno));
0231             ret=FAIL;
0232             goto out;
0233         }
0234 
0235         if (SUCCEED!=Bget(p_ub, T_STRING_2_FLD, 0, svcnm_ret, 0))
0236         {
0237             TP_LOG(log_error, "Failed to set T_STRING_2_FLD: %s",  
0238                   Bstrerror(Berror));
0239             ret=FAIL;
0240             goto out;
0241         }
0242 
0243         TP_LOG(log_info, "Response called [%s], returned [%s]", 
0244                  svcnm, svcnm_ret);
0245 
0246         if (0!=strcmp(svcnm, svcnm_ret))
0247         {
0248             TP_LOG(log_error, "TESTERROR!!!, expected service [%s], "
0249                     "but got [%s]", 
0250                     svcnm, svcnm_ret);
0251             ret=FAIL;
0252             goto out;
0253         }
0254     }
0255     
0256 out:
0257 
0258     /* free up config data... */
0259     if (NULL!=p_ub)
0260     {
0261         tpfree((char *)p_ub);
0262     }
0263 
0264     return ret;
0265 }
0266 
0267 /**
0268  * Advertise full shm and free up...
0269  * and do it again...
0270  * @param limit - how much services to test. If shm is less than 50, then we test
0271  *  shm limit, shm is above, then we can test per server service count limit.
0272  * @return SUCCEED/FAIL
0273  */
0274 int chkfull (long limit)
0275 {
0276     int ret = SUCCEED;
0277     long i;
0278     UBFH *p_ub = NULL;
0279     long rsplen;
0280 
0281     TP_LOG(log_info, "chkfull...");
0282 
0283     /* Call sample server... */
0284     if (NULL==(p_ub = (UBFH *)tpalloc("UBF", NULL, 1024)))
0285     {
0286         TP_LOG(log_error, "Failed to tpalloc: %s",  tpstrerror(tperrno));
0287         ret=FAIL;
0288         goto out;
0289     }
0290     
0291     if (SUCCEED!=Bchg(p_ub, T_LONG_FLD, 0, (char *)&limit, 0L))
0292     {
0293         TP_LOG(log_error, "Failed to set T_LONG_FLD: %s",  
0294               Bstrerror(Berror));
0295         ret=FAIL;
0296         goto out;
0297     }
0298     
0299     for (i=0; i<10; i++)
0300     {
0301         if (FAIL==tpcall("CHKFULL", (char *)p_ub, 0L, (char **)&p_ub, 
0302                 &rsplen, TPNOTIME))
0303         {
0304             TP_LOG(log_error, "TESTERROR: Failed to call CHKFULL: %s",
0305                     tpstrerror(tperrno));
0306             ret=FAIL;
0307             goto out;
0308         }
0309     }
0310     
0311 out:
0312 
0313 
0314     /* free up config data... */
0315     if (NULL!=p_ub)
0316     {
0317         tpfree((char *)p_ub);
0318     }
0319 
0320     return ret;
0321 }
0322 
0323 
0324 /**
0325  * Main entry of th program
0326  * @param argc  argument count
0327  * @param argv  argument values
0328  * @return SUCCEED/FAIL
0329  */
0330 int main(int argc, char** argv)
0331 {
0332     int ret = SUCCEED;
0333 
0334     if (argc < 2)
0335     {
0336         fprintf(stderr, "usage: %s readv|chkfull|call19 [limit for chkfull]", argv[0]);
0337         return -1;
0338     }
0339     
0340     if (SUCCEED!=init(argc, argv))
0341     {
0342         TP_LOG(log_error, "Failed to Initialize!");
0343         ret=FAIL;
0344         goto out;
0345     }
0346 
0347     if (0==strcmp(argv[1], "readv"))
0348     {
0349         if (SUCCEED!=process())
0350         {
0351             TP_LOG(log_error, "Process failed!");
0352             EXFAIL_OUT(ret);
0353         }
0354     }
0355     else if (0==strcmp(argv[1], "chkfull"))
0356     {
0357         long limit;
0358         if (argc<3)
0359         {
0360             fprintf(stderr, "Expected limit at arg 3\n");
0361             EXFAIL_OUT(ret);
0362         }
0363         
0364         limit = atoi(argv[2]);
0365         
0366         if (SUCCEED!=chkfull(limit))
0367         {
0368             TP_LOG(log_error, "ckfull failed!");
0369             ret=FAIL;
0370             goto out;
0371         }
0372     }
0373     else if (0==strcmp(argv[1], "call19"))
0374     {
0375         if (SUCCEED!=call19())
0376         {
0377             TP_LOG(log_error, "call19 failed!");
0378             ret=FAIL;
0379             goto out;
0380         }
0381     }
0382     else
0383     {
0384         TP_LOG(log_error, "Invalid function [%s]!", argv[1]);
0385         ret=FAIL;
0386         goto out;
0387     }
0388     
0389 out:
0390     uninit(ret);
0391 
0392     return ret;
0393 }
0394 
0395 /* vim: set ts=4 sw=4 et smartindent: */