0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033 #include <string.h>
0034 #include <stdio.h>
0035 #include <stdlib.h>
0036 #include <memory.h>
0037 #include <unistd.h>
0038
0039 #include <atmi.h>
0040 #include <ubf.h>
0041 #include <ndebug.h>
0042 #include <test.fd.h>
0043 #include <ndrstandard.h>
0044 #include <ubfutil.h>
0045 #include <nstopwatch.h>
0046 #include <nstdutil.h>
0047 #include <exassert.h>
0048
0049
0050
0051
0052
0053 typedef struct
0054 {
0055 int num_req;
0056 int num_rsp;
0057 } test_result_t;
0058
0059
0060
0061
0062
0063 #define MAX_TEST 100
0064
0065
0066
0067
0068
0069
0070
0071 expublic int basic_errorq(void)
0072 {
0073 int ret = EXSUCCEED;
0074 TPQCTL qc;
0075 long i;
0076 long olen;
0077 char tmpbuf[1024];
0078 long num;
0079 UBFH *p_ub = NULL;
0080 test_result_t rsp[MAX_TEST];
0081
0082 NDRX_LOG(log_error, "case basic_errorq");
0083
0084 NDRX_ASSERT_TP_OUT((NULL!=(p_ub=(UBFH *)tpalloc("UBF", NULL, 1024))), "Failed to alloc");
0085
0086 for (i=0; i<MAX_TEST; i++)
0087 {
0088 NDRX_ASSERT_UBF_OUT( (EXSUCCEED==Bchg(p_ub, T_LONG_FLD, 0, (char *)&i, 0L)),
0089 "Failed to set test num");
0090
0091 NDRX_ASSERT_UBF_OUT( (EXSUCCEED==Bchg(p_ub, T_STRING_FLD, 0, "REQ", 0L)),
0092 "Failed to set test num");
0093
0094
0095 memset(&qc, 0, sizeof(qc));
0096 qc.flags|=TPQFAILUREQ;
0097 NDRX_STRCPY_SAFE(qc.failurequeue, "ERRORRSP");
0098
0099 NDRX_ASSERT_TP_OUT((EXSUCCEED==tpenqueue("MYSPACE", "FAILSVC", &qc,
0100 (char *)p_ub, 0, 0L)), "Failed to enq");
0101 }
0102
0103
0104 sleep(30);
0105 memset(rsp, 0, sizeof(rsp));
0106
0107
0108
0109 for (i=0; i<MAX_TEST; i++)
0110 {
0111 memset(&qc, 0, sizeof(qc));
0112
0113 tpfree((char *)p_ub);
0114 p_ub = NULL;
0115
0116 NDRX_ASSERT_TP_OUT((EXFAIL==tpdequeue("MYSPACE", "FAILSVC", &qc, (char **)&p_ub, &olen, 0)),
0117 "Must not be OK");
0118
0119
0120 NDRX_ASSERT_TP_OUT((EXSUCCEED==tpdequeue("MYSPACE", "ERRORREQ", &qc, (char **)&p_ub, &olen, 0)),
0121 "Must be OK");
0122
0123 NDRX_ASSERT_UBF_OUT((EXSUCCEED==Bget(p_ub, T_STRING_FLD, 0, tmpbuf, NULL)),
0124 "Failed to get data fld");
0125 NDRX_ASSERT_VAL_OUT(0==strcmp(tmpbuf, "REQ"), "Request not found: %s", tmpbuf);
0126 NDRX_ASSERT_UBF_OUT((EXSUCCEED==Bget(p_ub, T_LONG_FLD, 0, (char *)&num, NULL)),
0127 "Failed to get num");
0128 rsp[num].num_req++;
0129
0130
0131 tpfree((char *)p_ub);
0132 p_ub = NULL;
0133 tmpbuf[0]=EXEOS;
0134
0135
0136 NDRX_ASSERT_TP_OUT((EXSUCCEED==tpdequeue("MYSPACE", "ERRORRSP", &qc, (char **)&p_ub, &olen, 0)),
0137 "Must be OK: %ld %s", qc.diagnostic, qc.diagmsg);
0138
0139 NDRX_ASSERT_UBF_OUT((EXSUCCEED==Bget(p_ub, T_STRING_FLD, 0, tmpbuf, NULL)),
0140 "Failed to get data fld");
0141 NDRX_ASSERT_VAL_OUT(0==strcmp(tmpbuf, "RSP"), "Request not found: %s", tmpbuf);
0142 NDRX_ASSERT_UBF_OUT((EXSUCCEED==Bget(p_ub, T_LONG_FLD, 0, (char *)&num, NULL)),
0143 "Failed to get num");
0144 rsp[num].num_rsp++;
0145
0146 }
0147
0148
0149 for (i=0; i<MAX_TEST; i++)
0150 {
0151 NDRX_ASSERT_VAL_OUT(rsp[i].num_req==1, "Invalid num_req at %ld: %d",
0152 i, rsp[i].num_req);
0153
0154 NDRX_ASSERT_VAL_OUT(rsp[i].num_rsp==1, "Invalid num_rsp at %ld: %d",
0155 i, rsp[i].num_rsp);
0156 }
0157
0158 out:
0159
0160 if (EXSUCCEED!=tpterm())
0161 {
0162 NDRX_LOG(log_error, "tpterm failed with: %s", tpstrerror(tperrno));
0163 ret=EXFAIL;
0164 goto out;
0165 }
0166
0167 if (NULL!=p_ub)
0168 {
0169 tpfree((char *)p_ub);
0170 }
0171
0172 return ret;
0173 }
0174
0175