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
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 <atmi.h>
0043 #include <ubf.h>
0044 #include <ndebug.h>
0045 #include <test.fd.h>
0046 #include <ndrstandard.h>
0047 #include <nstopwatch.h>
0048 #include <fcntl.h>
0049 #include <unistd.h>
0050 #include <nstdutil.h>
0051 #include "test67.h"
0052 #include <libpq-fe.h>
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067 expublic int q_run(UBFH **pp_ub)
0068 {
0069 int ret = EXSUCCEED;
0070 long i, j;
0071 long len;
0072 long tmp;
0073 long rsplen;
0074 TPQCTL qc;
0075
0076 for (i=0; i<3; i++)
0077 {
0078 sql_mktab();
0079
0080
0081 if (EXSUCCEED!=tpbegin(60, 0))
0082 {
0083 NDRX_LOG(log_error, "TESTERROR: Failed to begin: %s", tpstrerror(tperrno));
0084 EXFAIL_OUT(ret);
0085 }
0086
0087 for (j=0; j<100; j++)
0088 {
0089 if (EXFAIL==Bchg(*pp_ub, T_LONG_FLD, 0, (char *)&j, 0))
0090 {
0091 NDRX_LOG(log_debug, "TESTERROR: Failed to set T_LONG_FLD: %s",
0092 Bstrerror(Berror));
0093 EXFAIL_OUT(ret);
0094 }
0095
0096 if (EXFAIL == tpcall("TESTSV", (char *)*pp_ub, 0L, (char **)pp_ub, &rsplen,0))
0097 {
0098 NDRX_LOG(log_error, "TESTERROR: TESTSV failed: %s", tpstrerror(tperrno));
0099 EXFAIL_OUT(ret);
0100 }
0101
0102
0103
0104
0105 memset(&qc, 0, sizeof(qc));
0106 if (EXSUCCEED!=tpenqueue("MYSPACE", "STATQ", &qc, (char *)*pp_ub,
0107 0L, 0L))
0108 {
0109 NDRX_LOG(log_error, "TESTERROR: tpenqueue() failed %s diag: %d:%s",
0110 tpstrerror(tperrno), qc.diagnostic, qc.diagmsg);
0111 EXFAIL_OUT(ret);
0112 }
0113 }
0114
0115 if (0==i || 2==i)
0116 {
0117 if (2==i)
0118 {
0119
0120 sleep(70);
0121
0122 if (EXSUCCEED==tpcommit(0L))
0123 {
0124 NDRX_LOG(log_error, "TESTERROR: tpcommit must fail but succeed!");
0125 EXFAIL_OUT(ret);
0126 }
0127
0128 if (TPEABORT!=tperrno)
0129 {
0130 NDRX_LOG(log_error, "TESTERROR: transaction must be aborted but: %s!",
0131 tpstrerror(tperrno));
0132 EXFAIL_OUT(ret);
0133 }
0134
0135 }
0136 else
0137 {
0138 if (EXSUCCEED!=tpabort(0L))
0139 {
0140 NDRX_LOG(log_error, "TESTERROR: Failed to abort: %s",
0141 tpstrerror(tperrno));
0142 EXFAIL_OUT(ret);
0143 }
0144 }
0145
0146
0147 if (0!=(ret=(int)sql_count()))
0148 {
0149 NDRX_LOG(log_error, "TESTERROR: Invalid count expected 0 got: %d", ret);
0150 EXFAIL_OUT(ret);
0151 }
0152
0153
0154
0155 memset(&qc, 0, sizeof(qc));
0156
0157 if (EXSUCCEED==tpdequeue("MYSPACE", "STATQ", &qc, (char **)pp_ub,
0158 &len, TPNOTRAN))
0159 {
0160
0161
0162
0163
0164 NDRX_LOG(log_error, "TESTERROR: Queue must be empty but it is not!");
0165 EXFAIL_OUT(ret);
0166 }
0167
0168 if (TPEDIAGNOSTIC!=tperrno)
0169 {
0170 NDRX_LOG(log_error, "TESTERROR: Expected TPEDIAGNOSTIC, but got %d", tperrno);
0171 EXFAIL_OUT(ret);
0172 }
0173
0174 if (QMENOMSG!=qc.diagnostic)
0175 {
0176 NDRX_LOG(log_error, "TESTERROR: Expected QMENOMSG, but got %d",
0177 qc.diagnostic);
0178 EXFAIL_OUT(ret);
0179 }
0180 }
0181 else
0182 {
0183 if (EXSUCCEED!=tpcommit(0L))
0184 {
0185 NDRX_LOG(log_error, "TESTERROR: Failed to commit: %s",
0186 tpstrerror(tperrno));
0187 EXFAIL_OUT(ret);
0188 }
0189
0190
0191 if (100!=(ret=(int)sql_count()))
0192 {
0193 NDRX_LOG(log_error, "TESTERROR: Invalid count expected 100 got: %d",
0194 ret);
0195 EXFAIL_OUT(ret);
0196 }
0197 ret = EXSUCCEED;
0198
0199 for (j=0; j<100; j++)
0200 {
0201
0202
0203 memset(&qc, 0, sizeof(qc));
0204
0205 if (EXSUCCEED!=tpdequeue("MYSPACE", "STATQ", &qc, (char **)pp_ub,
0206 &len, TPNOTRAN))
0207 {
0208 NDRX_LOG(log_error, "TESTERROR: tpdequeue() failed at %d %s diag: %d:%s",
0209 i, tpstrerror(tperrno), qc.diagnostic, qc.diagmsg);
0210 EXFAIL_OUT(ret);
0211 }
0212
0213
0214
0215 if (EXSUCCEED!=Bget(*pp_ub, T_LONG_FLD, 0, (char *)&tmp, 0L))
0216 {
0217 NDRX_LOG(log_error, "TESTERROR: Failed to get T_LONG_FLD at %d: %s",
0218 i, Bstrerror(Berror));
0219 EXFAIL_OUT(ret);
0220 }
0221
0222 if (tmp!=j)
0223 {
0224 NDRX_LOG(log_error, "TESTERROR: Invalid msg from Q: expected %ld got %ld",
0225 j, tmp);
0226 EXFAIL_OUT(ret);
0227 }
0228 }
0229 }
0230
0231
0232 }
0233 out:
0234 return ret;
0235 }
0236
0237