Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief TP Cache tests - server
0003  *
0004  * @file atmisv48.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 #include <string.h>
0043 #include <unistd.h>
0044 #include <ubfutil.h>
0045 #include "test48.h"
0046 
0047 /*---------------------------Externs------------------------------------*/
0048 /*---------------------------Macros-------------------------------------*/
0049 /*---------------------------Enums--------------------------------------*/
0050 /*---------------------------Typedefs-----------------------------------*/
0051 /*---------------------------Globals------------------------------------*/
0052 /*---------------------------Statics------------------------------------*/
0053 /*---------------------------Prototypes---------------------------------*/
0054 
0055 /**
0056  * Standard service entry
0057  */
0058 void TESTSV01 (TPSVCINFO *p_svc)
0059 {
0060     int ret=EXSUCCEED;
0061     char testbuf[1024];
0062     UBFH *p_ub = (UBFH *)p_svc->data;
0063     char tstamp[TSTAMP_BUFSZ];
0064     NDRX_LOG(log_debug, "%s got call", __func__);
0065 
0066     
0067     if (NULL==(p_ub =(UBFH *)tprealloc((char *)p_ub, Bused(p_ub)+1024)))
0068     {
0069         NDRX_LOG(log_error, "TESTERROR: Failed to reallocate incoming buffer: %s",
0070                 tpstrerror(tperrno));
0071         EXFAIL_OUT(ret);
0072     }
0073     
0074     /* Just print the buffer */
0075     Bprint(p_ub);
0076     
0077     if (EXFAIL==Bget(p_ub, T_STRING_FLD, 0, testbuf, 0))
0078     {
0079         NDRX_LOG(log_error, "TESTERROR: Failed to get T_STRING_FLD: %s", 
0080                  Bstrerror(Berror));
0081         EXFAIL_OUT(ret);
0082     }
0083     
0084     if (0!=strcmp(testbuf, VALUE_EXPECTED))
0085     {
0086         NDRX_LOG(log_error, "TESTERROR: Expected: [%s] got [%s]",
0087             VALUE_EXPECTED, testbuf);
0088         ret=EXFAIL;
0089         goto out;
0090     }
0091     
0092     if (EXSUCCEED!=Bchg(p_ub, T_STRING_FLD, 1, VALUE_EXPECTED_RET, 0))
0093     {
0094         NDRX_LOG(log_error, "TESTERROR: Failed to set T_STRING_FLD[1]: %s", 
0095                  Bstrerror(Berror));
0096         ret=EXFAIL;
0097         goto out;
0098     }
0099     
0100     /* get stamp */
0101     
0102     test048_stamp_get(tstamp, sizeof(tstamp));
0103     
0104     if (EXSUCCEED!=Bchg(p_ub, T_STRING_5_FLD, 0, tstamp, 0))
0105     {
0106         NDRX_LOG(log_error, "Failed to set T_STRING_5_FLD: %s", Bstrerror(Berror));
0107         EXFAIL_OUT(ret);
0108     }
0109     
0110 out:
0111     tpreturn(  ret==EXSUCCEED?TPSUCCESS:TPFAIL,
0112                 0L,
0113                 (char *)p_ub,
0114                 0L,
0115                 0L);
0116 }
0117 
0118 /**
0119  * Standard service entry
0120  */
0121 void BENCH48 (TPSVCINFO *p_svc)
0122 {
0123     int ret=EXSUCCEED;
0124     
0125     /* do nothing... */
0126 out:
0127     tpreturn(  TPSUCCESS,
0128                 0L,
0129                 p_svc->data,
0130                 0L,
0131                 0L);
0132 }
0133 
0134 /**
0135  * Standard service entry
0136  */
0137 void OKSVC (TPSVCINFO *p_svc)
0138 {
0139     int ret=EXSUCCEED;
0140     UBFH *p_ub = (UBFH *)p_svc->data;
0141     
0142     long t, tusec;
0143     
0144     NDRX_LOG(log_debug, "%s got call", __func__);
0145  
0146     if (NULL==(p_ub =(UBFH *)tprealloc((char *)p_ub, Bused(p_ub)+1024)))
0147     {
0148         NDRX_LOG(log_error, "TESTERROR: Failed to reallocate incoming buffer: %s",
0149                 tpstrerror(tperrno));
0150         EXFAIL_OUT(ret);
0151     }
0152     
0153     /* Just print the buffer */
0154     ndrx_debug_dump_UBF(log_debug, "Received buffer", p_ub);
0155     
0156     ndrx_utc_tstamp2(&t, &tusec);
0157     
0158     if (EXSUCCEED!=Bchg(p_ub, T_LONG_2_FLD, 0, (char *)&t, 0L) ||
0159             EXSUCCEED!=Bchg(p_ub, T_LONG_2_FLD, 1, (char *)&tusec, 0L))
0160     {
0161         NDRX_LOG(log_error, "TESTERROR: Failed to set T_LONG_2_FLD fields!",
0162             Bstrerror(Berror));
0163         EXFAIL_OUT(ret);
0164     }
0165     
0166     
0167     ndrx_debug_dump_UBF(log_debug, "Response buffer", p_ub);
0168     
0169 out:
0170     tpreturn(  ret==EXSUCCEED?TPSUCCESS:TPFAIL,
0171                 0L,
0172                 (char *)p_ub,
0173                 0L,
0174                 0L);
0175 }
0176 
0177 /**
0178  * Standard service entry, fail
0179  */
0180 void FAILSVC (TPSVCINFO *p_svc)
0181 {
0182     int ret=EXSUCCEED;
0183     int ret_gen_succ=EXFALSE;
0184     UBFH *p_ub = (UBFH *)p_svc->data;
0185     long l;
0186     long t, tusec;
0187     
0188     NDRX_LOG(log_debug, "%s got call", __func__);
0189  
0190     if (NULL==(p_ub =(UBFH *)tprealloc((char *)p_ub, Bused(p_ub)+1024)))
0191     {
0192         NDRX_LOG(log_error, "TESTERROR: Failed to reallocate incoming buffer: %s",
0193                 tpstrerror(tperrno));
0194         EXFAIL_OUT(ret);
0195     }
0196     
0197     /* Just print the buffer */
0198     ndrx_debug_dump_UBF(log_debug, "Received buffer", p_ub);
0199     
0200     ndrx_utc_tstamp2(&t, &tusec);
0201     
0202     if (EXSUCCEED!=Bchg(p_ub, T_LONG_2_FLD, 0, (char *)&t, 0L) ||
0203             EXSUCCEED!=Bchg(p_ub, T_LONG_2_FLD, 1, (char *)&tusec, 0L))
0204     {
0205         NDRX_LOG(log_error, "TESTERROR: Failed to set T_LONG_2_FLD fields!",
0206             Bstrerror(Berror));
0207         EXFAIL_OUT(ret);
0208     }
0209     
0210     /* make succeed if value 1 */
0211             
0212     if (EXSUCCEED==Bget(p_ub, T_LONG_3_FLD, 0, (char *)&l, 0L))
0213     {
0214         if (1==l)
0215         {
0216             ret_gen_succ=EXTRUE;
0217         }
0218     }
0219     
0220     ndrx_debug_dump_UBF(log_debug, "Response buffer", p_ub);
0221     
0222 out:
0223         
0224     tpreturn(  ret_gen_succ?TPSUCCESS:TPFAIL,
0225                 0L,
0226                 (char *)p_ub,
0227                 0L,
0228                 0L);
0229 }
0230 
0231 /*
0232  * Do initialization
0233  */
0234 int NDRX_INTEGRA(tpsvrinit)(int argc, char **argv)
0235 {
0236     int ret = EXSUCCEED;
0237     NDRX_LOG(log_debug, "tpsvrinit called");
0238 
0239     if (EXSUCCEED!=tpadvertise("TESTSV01", TESTSV01))
0240     {
0241         NDRX_LOG(log_error, "Failed to initialize TESTSV01!");
0242         EXFAIL_OUT(ret);
0243     }
0244     
0245     if (EXSUCCEED!=tpadvertise("OKSVC", OKSVC))
0246     {
0247         NDRX_LOG(log_error, "Failed to initialize OKSVC!");
0248         EXFAIL_OUT(ret);
0249     }
0250     
0251     if (EXSUCCEED!=tpadvertise("FAILSVC", FAILSVC))
0252     {
0253         NDRX_LOG(log_error, "Failed to initialize FAILSVC!");
0254         EXFAIL_OUT(ret);
0255     }
0256     
0257     if (EXSUCCEED!=tpadvertise("BENCH48", BENCH48))
0258     {
0259         NDRX_LOG(log_error, "Failed to initialize BENCH48!");
0260         EXFAIL_OUT(ret);
0261     }
0262     
0263 out:
0264     return ret;
0265 }
0266 
0267 /**
0268  * Do de-initialization
0269  */
0270 void NDRX_INTEGRA(tpsvrdone)(void)
0271 {
0272     NDRX_LOG(log_debug, "tpsvrdone called");
0273 }
0274 
0275 /* vim: set ts=4 sw=4 et smartindent: */