1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030
|
//-----------------------------------------------------------------------------
// Copyright (c) 2017, 2025, Oracle and/or its affiliates.
//
// This software is dual-licensed to you under the Universal Permissive License
// (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
// 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose
// either license.
//
// If you elect to accept the software under the Apache License, Version 2.0,
// the following applies:
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// test_1400_pool.c
// Test suite for testing dpiPool functions.
//-----------------------------------------------------------------------------
#include "TestLib.h"
//-----------------------------------------------------------------------------
// dpiTest__callFunctionsWithError() [INTERNAL]
// Call all public functions with the specified pool and expect an error for
// each of them.
//-----------------------------------------------------------------------------
int dpiTest__callFunctionsWithError(dpiTestCase *testCase,
dpiTestParams *params, dpiPool *pool, const char *expectedError)
{
dpiEncodingInfo info;
dpiPoolGetMode value;
int pingInterval;
uint32_t count;
dpiConn *conn;
dpiPool_acquireConnection(pool, NULL, 0, NULL, 0, NULL, &conn);
if (dpiTestCase_expectError(testCase, expectedError) < 0)
return DPI_FAILURE;
dpiPool_close(pool, DPI_MODE_POOL_CLOSE_DEFAULT);
if (dpiTestCase_expectError(testCase, expectedError) < 0)
return DPI_FAILURE;
dpiPool_getBusyCount(pool, &count);
if (dpiTestCase_expectError(testCase, expectedError) < 0)
return DPI_FAILURE;
dpiPool_getEncodingInfo(pool, &info);
if (dpiTestCase_expectError(testCase, expectedError) < 0)
return DPI_FAILURE;
dpiPool_getGetMode(pool, &value);
if (dpiTestCase_expectError(testCase, expectedError) < 0)
return DPI_FAILURE;
dpiPool_getMaxLifetimeSession(pool, &count);
if (dpiTestCase_expectError(testCase, expectedError) < 0)
return DPI_FAILURE;
dpiPool_getOpenCount(pool, &count);
if (dpiTestCase_expectError(testCase, expectedError) < 0)
return DPI_FAILURE;
dpiPool_getTimeout(pool, &count);
if (dpiTestCase_expectError(testCase, expectedError) < 0)
return DPI_FAILURE;
dpiPool_setGetMode(pool, value);
if (dpiTestCase_expectError(testCase, expectedError) < 0)
return DPI_FAILURE;
dpiPool_setMaxLifetimeSession(pool, 5);
if (dpiTestCase_expectError(testCase, expectedError) < 0)
return DPI_FAILURE;
dpiPool_setTimeout(pool, 5);
if (dpiTestCase_expectError(testCase, expectedError) < 0)
return DPI_FAILURE;
dpiPool_setMaxSessionsPerShard(pool, 5);
if (dpiTestCase_expectError(testCase, expectedError) < 0)
return DPI_FAILURE;
dpiPool_getMaxSessionsPerShard(pool, &count);
if (dpiTestCase_expectError(testCase, expectedError) < 0)
return DPI_FAILURE;
dpiPool_setPingInterval(pool, 30);
if (dpiTestCase_expectError(testCase, expectedError) < 0)
return DPI_FAILURE;
dpiPool_getPingInterval(pool, &pingInterval);
if (dpiTestCase_expectError(testCase, expectedError) < 0)
return DPI_FAILURE;
dpiPool_reconfigure(pool, 1, 5, 1);
if (dpiTestCase_expectError(testCase, expectedError) < 0)
return DPI_FAILURE;
return DPI_SUCCESS;
}
//-----------------------------------------------------------------------------
// dpiTest__acquireAndVerifySession() [INTERNAL]
// Acquire a session from the pool using the given credentials and then
// verify that the session user and proxy user are the expected values.
//-----------------------------------------------------------------------------
static int dpiTest__acquireAndVerifySession(dpiTestCase *testCase,
dpiPool *pool, const char *userName, uint32_t userNameLength,
const char *password, uint32_t passwordLength,
const char *expectedSessionUser, uint32_t expectedSessionUserLength,
const char *proxyUser, uint32_t proxyUserLength)
{
const char *sql =
"select sys_context('userenv', 'session_user'), "
"sys_context('userenv', 'proxy_user') from dual";
dpiNativeTypeNum nativeTypeNum;
uint32_t bufferRowIndex;
dpiData *getValue;
dpiStmt *stmt;
dpiConn *conn;
int found;
// acquire connection from the pool
if (dpiPool_acquireConnection(pool, userName, userNameLength, password,
passwordLength, NULL, &conn) < 0)
return dpiTestCase_setFailedFromError(testCase);
// fetch session user and proxy user
if (dpiConn_prepareStmt(conn, 0, sql, strlen(sql), NULL, 0, &stmt) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiStmt_execute(stmt, DPI_MODE_EXEC_DEFAULT, NULL) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiStmt_fetch(stmt, &found, &bufferRowIndex) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiStmt_getQueryValue(stmt, 1, &nativeTypeNum, &getValue) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectStringEqual(testCase, getValue->value.asBytes.ptr,
getValue->value.asBytes.length, expectedSessionUser,
expectedSessionUserLength) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiStmt_getQueryValue(stmt, 2, &nativeTypeNum, &getValue) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectStringEqual(testCase, getValue->value.asBytes.ptr,
getValue->value.asBytes.length, proxyUser, proxyUserLength) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiStmt_release(stmt) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiConn_release(conn) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
//-----------------------------------------------------------------------------
// dpiTest_1400()
// Verify that dpiPool_create() succeeds when valid credentials are passed
// and both the dpiCommonParams and dpiPoolCreateParams structures are NULL.
//-----------------------------------------------------------------------------
int dpiTest_1400(dpiTestCase *testCase, dpiTestParams *params)
{
dpiContext *context;
dpiPool *pool;
dpiTestSuite_getContext(&context);
if (dpiPool_create(context, params->mainUserName,
params->mainUserNameLength, params->mainPassword,
params->mainPasswordLength, params->connectString,
params->connectStringLength, NULL, NULL, &pool) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiPool_release(pool) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
//-----------------------------------------------------------------------------
// dpiTest_1401()
// Verify that dpiPool_create() succeeds when valid credentials are passed
// and dpiCommonParams structure set to NULL.
//-----------------------------------------------------------------------------
int dpiTest_1401(dpiTestCase *testCase, dpiTestParams *params)
{
dpiCommonCreateParams commonParams;
dpiContext *context;
dpiPool *pool;
dpiTestSuite_getContext(&context);
if (dpiContext_initCommonCreateParams(context, &commonParams) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiPool_create(context, params->mainUserName,
params->mainUserNameLength, params->mainPassword,
params->mainPasswordLength, params->connectString,
params->connectStringLength, &commonParams, NULL, &pool) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiPool_release(pool) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
//-----------------------------------------------------------------------------
// dpiTest_1402()
// Verify that dpiPool_create() succeeds when valid credentials are passed
// and dpiPoolCreateParams structure set to NULL.
//-----------------------------------------------------------------------------
int dpiTest_1402(dpiTestCase *testCase, dpiTestParams *params)
{
dpiPoolCreateParams createParams;
dpiContext *context;
dpiPool *pool;
dpiTestSuite_getContext(&context);
if (dpiContext_initPoolCreateParams(context, &createParams) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiPool_create(context, params->mainUserName,
params->mainUserNameLength, params->mainPassword,
params->mainPasswordLength, params->connectString,
params->connectStringLength, NULL, &createParams, &pool) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiPool_release(pool) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
//-----------------------------------------------------------------------------
// dpiTest_1403()
// Verify that dpiPool_create() succeeds when valid credentials are passed
// and both the dpiCommonParams and dpiPoolCreateParams structures are set.
//-----------------------------------------------------------------------------
int dpiTest_1403(dpiTestCase *testCase, dpiTestParams *params)
{
dpiCommonCreateParams commonParams;
dpiPoolCreateParams createParams;
dpiContext *context;
dpiPool *pool;
dpiTestSuite_getContext(&context);
if (dpiContext_initCommonCreateParams(context, &commonParams) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiContext_initPoolCreateParams(context, &createParams) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiPool_create(context, params->mainUserName,
params->mainUserNameLength, params->mainPassword,
params->mainPasswordLength, params->connectString,
params->connectStringLength, &commonParams,
&createParams, &pool) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiPool_release(pool) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
//-----------------------------------------------------------------------------
// dpiTest_1404()
// Verify that dpiPool_create() fails when invalid credentials are passed.
//-----------------------------------------------------------------------------
int dpiTest_1404(dpiTestCase *testCase, dpiTestParams *params)
{
dpiContext *context;
dpiPool *pool;
dpiTestSuite_getContext(&context);
dpiPool_create(context, "X", 1, "X", 1, params->connectString,
params->connectStringLength, NULL, NULL, &pool);
return dpiTestCase_expectError(testCase, "ORA-01017:");
}
//-----------------------------------------------------------------------------
// dpiTest_1405()
// Verify that dpiPool_create() specifying a non-default value for
// minSessions and confirm that this number of sessions is created (no error).
//-----------------------------------------------------------------------------
int dpiTest_1405(dpiTestCase *testCase, dpiTestParams *params)
{
uint32_t count;
dpiPool *pool;
// create a pool
if (dpiTestCase_getPool(testCase, &pool) < 0)
return DPI_FAILURE;
// verify open count matches the minimum number of sessions
if (dpiPool_getOpenCount(pool, &count) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectUintEqual(testCase, count,
DPI_TEST_POOL_MIN_SESSIONS) < 0)
return DPI_FAILURE;
// cleanup
if (dpiPool_release(pool) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
//-----------------------------------------------------------------------------
// dpiTest_1406()
// Verify that dpiPool_create() specifying a non-default value for
// maxSessions and confirm that this number of sessions is the maximum that is
// created (no error).
//-----------------------------------------------------------------------------
int dpiTest_1406(dpiTestCase *testCase, dpiTestParams *params)
{
const char *expectedErrors[] = { "ORA-24418:", "ORA-24496:", NULL };
dpiConn *conn[DPI_TEST_POOL_MAX_SESSIONS], *tempConn;
uint32_t count, i;
dpiPool *pool;
// create a pool
if (dpiTestCase_getPool(testCase, &pool) < 0)
return DPI_FAILURE;
// acquire connections up to the maximum
for (i = 0; i < DPI_TEST_POOL_MAX_SESSIONS; i++) {
if (dpiPool_acquireConnection(pool, NULL, 0, NULL, 0, NULL,
&conn[i]) < 0)
return dpiTestCase_setFailedFromError(testCase);
}
// verify that the open count matches
if (dpiPool_getOpenCount(pool, &count) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectUintEqual(testCase, count,
DPI_TEST_POOL_MAX_SESSIONS) < 0)
return DPI_FAILURE;
// attempt to acquire one more connection
dpiPool_acquireConnection(pool, NULL, 0, NULL, 0, NULL, &tempConn);
if (dpiTestCase_expectAnyError(testCase, expectedErrors) < 0)
return DPI_FAILURE;
// cleanup
for (i = 0; i < DPI_TEST_POOL_MAX_SESSIONS; i++) {
if (dpiConn_release(conn[i]) < 0)
return dpiTestCase_setFailedFromError(testCase);
}
if (dpiPool_release(pool) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
//-----------------------------------------------------------------------------
// dpiTest_1407()
// Verify that dpiPool_create() specifying a non-default value for
// sessionIncrement and confirm that this number of sessions is created each
// time more session are needed (no error).
//-----------------------------------------------------------------------------
int dpiTest_1407(dpiTestCase *testCase, dpiTestParams *params)
{
dpiConn *conn[DPI_TEST_POOL_MIN_SESSIONS + 1];
uint32_t count, i;
dpiPool *pool;
// create a pool
if (dpiTestCase_getPool(testCase, &pool) < 0)
return DPI_FAILURE;
// acquire connections up to the minimum number of sessions
for (i = 0; i < DPI_TEST_POOL_MIN_SESSIONS; i++) {
if (dpiPool_acquireConnection(pool, NULL, 0, NULL, 0, NULL,
&conn[i]) < 0)
return dpiTestCase_setFailedFromError(testCase);
}
// verify that the number of open connections matches
if (dpiPool_getOpenCount(pool, &count) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectUintEqual(testCase, count,
DPI_TEST_POOL_MIN_SESSIONS) < 0)
return DPI_FAILURE;
// acquire one more connection; this should create the number of
// connections defined by the session increment
if (dpiPool_acquireConnection(pool, NULL, 0, NULL, 0, NULL,
&conn[DPI_TEST_POOL_MIN_SESSIONS]) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiPool_getOpenCount(pool, &count) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectUintEqual(testCase, count,
DPI_TEST_POOL_MIN_SESSIONS + DPI_TEST_POOL_SESSION_INCREMENT) < 0)
return DPI_FAILURE;
// cleanup
for (i = 0; i < DPI_TEST_POOL_MIN_SESSIONS + 1; i++) {
if (dpiConn_release(conn[i]) < 0)
return dpiTestCase_setFailedFromError(testCase);
}
if (dpiPool_release(pool) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
//-----------------------------------------------------------------------------
// dpiTest_1408()
// Verify that dpiPool_create() specifying no wait for the get mode works as
// expected (no error).
//-----------------------------------------------------------------------------
int dpiTest_1408(dpiTestCase *testCase, dpiTestParams *params)
{
const char *expectedErrors[] = { "ORA-24418:", "ORA-24496:", NULL };
dpiPoolCreateParams createParams;
dpiConn *conn1, *conn2;
dpiContext *context;
dpiPool *pool;
// create a pool that can contain only one connection
dpiTestSuite_getContext(&context);
if (dpiContext_initPoolCreateParams(context, &createParams) < 0)
return dpiTestCase_setFailedFromError(testCase);
createParams.minSessions = 0;
createParams.maxSessions = 1;
createParams.sessionIncrement = 1;
createParams.getMode = DPI_MODE_POOL_GET_NOWAIT;
if (dpiPool_create(context, params->mainUserName,
params->mainUserNameLength, params->mainPassword,
params->mainPasswordLength, params->connectString,
params->connectStringLength, NULL, &createParams, &pool) < 0)
return dpiTestCase_setFailedFromError(testCase);
// acquire that connection from the pool
if (dpiPool_acquireConnection(pool, NULL, 0, NULL, 0, NULL, &conn1) < 0)
return dpiTestCase_setFailedFromError(testCase);
// attempt to acquire a second connection from the pool; this should fail
dpiPool_acquireConnection(pool, NULL, 0, NULL, 0, NULL, &conn2);
if (dpiTestCase_expectAnyError(testCase, expectedErrors) < 0)
return DPI_FAILURE;
// cleanup
if (dpiConn_release(conn1) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiPool_release(pool) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
//-----------------------------------------------------------------------------
// dpiTest_1409()
// Verify that dpiPool_create() specifying force get for the get mode works
// as expected (no error).
//-----------------------------------------------------------------------------
int dpiTest_1409(dpiTestCase *testCase, dpiTestParams *params)
{
dpiPoolCreateParams createParams;
dpiConn *conn1, *conn2;
dpiContext *context;
dpiPool *pool;
// create a pool that can contain only one connection
dpiTestSuite_getContext(&context);
if (dpiContext_initPoolCreateParams(context, &createParams) < 0)
return dpiTestCase_setFailedFromError(testCase);
createParams.minSessions = 0;
createParams.maxSessions = 1;
createParams.sessionIncrement = 1;
createParams.getMode = DPI_MODE_POOL_GET_FORCEGET;
if (dpiPool_create(context, params->mainUserName,
params->mainUserNameLength, params->mainPassword,
params->mainPasswordLength, params->connectString,
params->connectStringLength, NULL, &createParams, &pool) < 0)
return dpiTestCase_setFailedFromError(testCase);
// acquire that connection from the pool
if (dpiPool_acquireConnection(pool, NULL, 0, NULL, 0, NULL, &conn1) < 0)
return dpiTestCase_setFailedFromError(testCase);
// attempt to acquire a second connection from the pool; this should
// succeed, even though the maximum number of sessions has been reached
if (dpiPool_acquireConnection(pool, NULL, 0, NULL, 0, NULL, &conn2) < 0)
return dpiTestCase_setFailedFromError(testCase);
// cleanup
if (dpiConn_release(conn1) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiConn_release(conn2) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiPool_release(pool) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
//-----------------------------------------------------------------------------
// dpiTest_1410()
// Verify that dpiPool_create() with NULL context (error DPI-1002)
//-----------------------------------------------------------------------------
int dpiTest_1410(dpiTestCase *testCase, dpiTestParams *params)
{
dpiPool *pool;
dpiPool_create(NULL, params->mainUserName, params->mainUserNameLength,
params->mainPassword, params->mainPasswordLength,
params->connectString, params->connectStringLength, NULL, NULL,
&pool);
return dpiTestCase_expectError(testCase, "DPI-1002:");
}
//-----------------------------------------------------------------------------
// dpiTest_1411()
// Verify that dpiPool_create() followed by dpiPool_release() twice
// (error DPI-1002).
//-----------------------------------------------------------------------------
int dpiTest_1411(dpiTestCase *testCase, dpiTestParams *params)
{
dpiContext *context;
dpiPool *pool;
dpiTestSuite_getContext(&context);
if (dpiPool_create(context, params->mainUserName,
params->mainUserNameLength, params->mainPassword,
params->mainPasswordLength, params->connectString,
params->connectStringLength, NULL, NULL, &pool) < 0)
return DPI_SUCCESS;
if (dpiPool_release(pool) < 0)
return dpiTestCase_setFailedFromError(testCase);
dpiPool_release(pool);
return dpiTestCase_expectError(testCase, "DPI-1002:");
}
//-----------------------------------------------------------------------------
// dpiTest_1412()
// Call dpiPool_create() with valid credentials and call dpiPool_close();
// then call all other public dpiPool functions except for dpiPool_addRef() and
// dpiPool_release() (error DPI-1010).
//-----------------------------------------------------------------------------
int dpiTest_1412(dpiTestCase *testCase, dpiTestParams *params)
{
dpiContext *context;
dpiPool *pool;
dpiTestSuite_getContext(&context);
if (dpiPool_create(context, params->mainUserName,
params->mainUserNameLength, params->mainPassword,
params->mainPasswordLength, params->connectString,
params->connectStringLength, NULL, NULL, &pool) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiPool_close(pool, DPI_MODE_POOL_CLOSE_DEFAULT) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTest__callFunctionsWithError(testCase, params, pool,
"DPI-1010: not connected") < 0)
return DPI_FAILURE;
dpiPool_release(pool);
return DPI_SUCCESS;
}
//-----------------------------------------------------------------------------
// dpiTest_1413()
// Call each of the public functions for dpiPool with the pool parameter set
// to NULL (error DPI-1002).
//-----------------------------------------------------------------------------
int dpiTest_1413(dpiTestCase *testCase, dpiTestParams *params)
{
return dpiTest__callFunctionsWithError(testCase, params, NULL,
"DPI-1002: invalid dpiPool handle");
}
//-----------------------------------------------------------------------------
// dpiTest_1414()
// Verify that proxy authentication can be used with a pool (no error).
//-----------------------------------------------------------------------------
int dpiTest_1414(dpiTestCase *testCase, dpiTestParams *params)
{
dpiPoolCreateParams createParams;
dpiContext *context;
dpiPool *pool;
dpiTestSuite_getContext(&context);
if (dpiContext_initPoolCreateParams(context, &createParams) < 0)
return dpiTestCase_setFailedFromError(testCase);
createParams.homogeneous = 0;
if (dpiPool_create(context, params->mainUserName,
params->mainUserNameLength, params->mainPassword,
params->mainPasswordLength, params->connectString,
params->connectStringLength, NULL, &createParams, &pool) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTest__acquireAndVerifySession(testCase, pool, params->proxyUserName,
params->proxyUserNameLength, NULL, 0, params->proxyUserName,
params->proxyUserNameLength, params->mainUserName,
params->mainUserNameLength) < 0)
return DPI_FAILURE;
if (dpiPool_release(pool) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
//-----------------------------------------------------------------------------
// dpiTest_1415()
// Verify that proxy authentication cannot be used with a homogeneous pool
// (error DPI-1012).
//-----------------------------------------------------------------------------
int dpiTest_1415(dpiTestCase *testCase, dpiTestParams *params)
{
dpiPoolCreateParams createParams;
dpiContext *context;
dpiPool *pool;
dpiConn *conn;
dpiTestSuite_getContext(&context);
if (dpiContext_initPoolCreateParams(context, &createParams) < 0)
return dpiTestCase_setFailedFromError(testCase);
createParams.homogeneous = 1;
if (dpiPool_create(context, params->mainUserName,
params->mainUserNameLength, params->mainPassword,
params->mainPasswordLength, params->connectString,
params->connectStringLength, NULL, &createParams, &pool) < 0)
return dpiTestCase_setFailedFromError(testCase);
dpiPool_acquireConnection(pool, params->proxyUserName,
params->proxyUserNameLength, NULL, 0, NULL, &conn);
if (dpiTestCase_expectError(testCase, "DPI-1012:") < 0)
return DPI_FAILURE;
if (dpiPool_release(pool) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
//-----------------------------------------------------------------------------
// dpiTest_1416()
// Call dpiPool_create with valid credentials and NULL pool (error DPI-1046).
//-----------------------------------------------------------------------------
int dpiTest_1416(dpiTestCase *testCase, dpiTestParams *params)
{
dpiContext *context;
dpiTestSuite_getContext(&context);
dpiPool_create(context, params->mainUserName, params->mainUserNameLength,
params->mainPassword, params->mainPasswordLength,
params->connectString, params->connectStringLength, NULL, NULL,
NULL);
return dpiTestCase_expectError(testCase, "DPI-1046:");
}
//-----------------------------------------------------------------------------
// dpiTest_1417()
// Call dpiPool_create with no credentials (error ORA-24415).
//-----------------------------------------------------------------------------
int dpiTest_1417(dpiTestCase *testCase, dpiTestParams *params)
{
dpiContext *context;
dpiPool *pool;
dpiTestSuite_getContext(&context);
dpiPool_create(context, NULL, 0, NULL, 0, NULL, 0, NULL, NULL, &pool);
return dpiTestCase_expectError(testCase, "ORA-24415:");
}
//-----------------------------------------------------------------------------
// dpiTest_1418()
// Verify that dpiPool_create() fails when an invalid connect string
// is passed (error ORA-12154).
//-----------------------------------------------------------------------------
int dpiTest_1418(dpiTestCase *testCase, dpiTestParams *params)
{
const char *connectString = "an_invalid_connect_string";
dpiContext *context;
dpiPool *pool;
dpiTestSuite_getContext(&context);
dpiPool_create(context, params->mainUserName, params->mainUserNameLength,
params->mainPassword, params->mainPasswordLength,
connectString, strlen(connectString), NULL, NULL, &pool);
return dpiTestCase_expectError(testCase, "ORA-12154:");
}
//-----------------------------------------------------------------------------
// dpiTest_1419()
// Create a heterogeneous pool with credentials and verify that acquiring
// connections from it works as expected (no error).
//-----------------------------------------------------------------------------
int dpiTest_1419(dpiTestCase *testCase, dpiTestParams *params)
{
dpiPoolCreateParams createParams;
uint32_t userNameLength;
dpiContext *context;
char *userName;
dpiPool *pool;
// create heterogeneous pool with credentials specified
dpiTestSuite_getContext(&context);
if (dpiContext_initPoolCreateParams(context, &createParams) < 0)
return dpiTestCase_setFailedFromError(testCase);
createParams.homogeneous = 0;
if (dpiPool_create(context, params->mainUserName,
params->mainUserNameLength, params->mainPassword,
params->mainPasswordLength, params->connectString,
params->connectStringLength, NULL, &createParams, &pool) < 0)
return dpiTestCase_setFailedFromError(testCase);
// acquiring connection without password
if (dpiTest__acquireAndVerifySession(testCase, pool, NULL, 0, NULL, 0,
params->mainUserName, params->mainUserNameLength, NULL, 0) < 0)
return DPI_FAILURE;
// acquiring connection with the same user name and pasword specified
if (dpiTest__acquireAndVerifySession(testCase, pool, params->mainUserName,
params->mainUserNameLength, params->mainPassword,
params->mainPasswordLength, params->mainUserName,
params->mainUserNameLength, NULL, 0) < 0)
return DPI_FAILURE;
// acquiring connection with a different user name and pasword specified
if (dpiTest__acquireAndVerifySession(testCase, pool, params->proxyUserName,
params->proxyUserNameLength, params->proxyPassword,
params->proxyPasswordLength, params->proxyUserName,
params->proxyUserNameLength, NULL, 0) < 0)
return DPI_FAILURE;
// acquiring connection with proxy syntax
userNameLength = params->mainUserNameLength + params->proxyUserNameLength +
2;
userName = malloc(userNameLength + 1);
if (!userName)
return dpiTestCase_setFailed(testCase, "Out of memory!");
sprintf(userName, "%.*s[%.*s]", params->mainUserNameLength,
params->mainUserName, params->proxyUserNameLength,
params->proxyUserName);
if (dpiTest__acquireAndVerifySession(testCase, pool, userName,
userNameLength, params->mainPassword, params->mainPasswordLength,
params->proxyUserName, params->proxyUserNameLength,
params->mainUserName, params->mainUserNameLength) < 0)
return DPI_FAILURE;
free(userName);
if (dpiPool_release(pool) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
//-----------------------------------------------------------------------------
// dpiTest_1420()
// Create a heterogeneous pool with no credentials and verify that acquiring
// connections from it works as expected (no error).
//-----------------------------------------------------------------------------
int dpiTest_1420(dpiTestCase *testCase, dpiTestParams *params)
{
dpiPoolCreateParams createParams;
uint32_t userNameLength;
dpiContext *context;
char *userName;
dpiPool *pool;
// create heterogeneous pool with no credentials specified
dpiTestSuite_getContext(&context);
if (dpiContext_initPoolCreateParams(context, &createParams) < 0)
return dpiTestCase_setFailedFromError(testCase);
createParams.homogeneous = 0;
if (dpiPool_create(context, NULL, 0, NULL, 0, params->connectString,
params->connectStringLength, NULL, &createParams, &pool) < 0)
return dpiTestCase_setFailedFromError(testCase);
// acquiring connection with the main user name and pasword specified
if (dpiTest__acquireAndVerifySession(testCase, pool, params->mainUserName,
params->mainUserNameLength, params->mainPassword,
params->mainPasswordLength, params->mainUserName,
params->mainUserNameLength, NULL, 0) < 0)
return DPI_FAILURE;
// acquiring connection with the proxy user name and pasword specified
if (dpiTest__acquireAndVerifySession(testCase, pool, params->proxyUserName,
params->proxyUserNameLength, params->proxyPassword,
params->proxyPasswordLength, params->proxyUserName,
params->proxyUserNameLength, NULL, 0) < 0)
return DPI_FAILURE;
// acquiring connection with proxy syntax
userNameLength = params->mainUserNameLength + params->proxyUserNameLength +
2;
userName = malloc(userNameLength + 1);
if (!userName)
return dpiTestCase_setFailed(testCase, "Out of memory!");
sprintf(userName, "%.*s[%.*s]", params->mainUserNameLength,
params->mainUserName, params->proxyUserNameLength,
params->proxyUserName);
if (dpiTest__acquireAndVerifySession(testCase, pool, userName,
userNameLength, params->mainPassword, params->mainPasswordLength,
params->proxyUserName, params->proxyUserNameLength,
params->mainUserName, params->mainUserNameLength) < 0)
return DPI_FAILURE;
free(userName);
if (dpiPool_release(pool) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
//-----------------------------------------------------------------------------
// dpiTest_1421()
// Verify that attempting to acquire a connection from a heterogeneous pool
// with invalid or missing credentials fails as expected (ORA-24415, ORA-01017,
// and ORA-24419).
//-----------------------------------------------------------------------------
int dpiTest_1421(dpiTestCase *testCase, dpiTestParams *params)
{
const char *invalidPassword = "an_invalid_password";
dpiPoolCreateParams createParams;
dpiContext *context;
dpiPool *pool;
dpiConn *conn;
// create heterogeneous pool without credentials
dpiTestSuite_getContext(&context);
if (dpiContext_initPoolCreateParams(context, &createParams) < 0)
return dpiTestCase_setFailedFromError(testCase);
createParams.homogeneous = 0;
if (dpiPool_create(context, NULL, 0, NULL, 0, params->connectString,
params->connectStringLength, NULL, &createParams, &pool) < 0)
return dpiTestCase_setFailedFromError(testCase);
// acquire connection without specifying credentials
dpiPool_acquireConnection(pool, NULL, 0, NULL, 0, NULL, &conn);
if (dpiTestCase_expectError(testCase, "ORA-24415:") < 0)
return DPI_FAILURE;
// acquire connection with invalid password
dpiPool_acquireConnection(pool, params->mainUserName,
params->mainUserNameLength, invalidPassword,
strlen(invalidPassword), NULL, &conn);
if (dpiTestCase_expectError(testCase, "ORA-01017:") < 0)
return DPI_FAILURE;
// acquire connection with user name but no password
dpiPool_acquireConnection(pool, params->proxyUserName,
params->proxyUserNameLength, NULL, 0, NULL, &conn);
if (dpiTestCase_expectError(testCase, "ORA-24419:") < 0)
return DPI_FAILURE;
return DPI_SUCCESS;
}
//-----------------------------------------------------------------------------
// dpiTest_1422()
// Verify that dpiPool_setPingInterval() and dpiPool_getPingInterval() work
// as expected.
//-----------------------------------------------------------------------------
int dpiTest_1422(dpiTestCase *testCase, dpiTestParams *params)
{
int getVal, setVal;
dpiPool *pool;
if (dpiTestCase_getPool(testCase, &pool) < 0)
return DPI_FAILURE;
if (dpiPool_getPingInterval(pool, &getVal) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectIntEqual(testCase, getVal,
DPI_DEFAULT_PING_INTERVAL) < 0)
return DPI_FAILURE;
setVal = -1;
if (dpiPool_setPingInterval(pool, setVal) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiPool_getPingInterval(pool, &getVal) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectIntEqual(testCase, getVal, setVal) < 0)
return DPI_FAILURE;
setVal = 30;
if (dpiPool_setPingInterval(pool, setVal) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiPool_getPingInterval(pool, &getVal) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiTestCase_expectIntEqual(testCase, getVal, setVal) < 0)
return DPI_FAILURE;
if (dpiPool_release(pool) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
//-----------------------------------------------------------------------------
// dpiTest_1423()
// Verify dpiPool_reconfigure() adjusts maximum sessions correctly.
//-----------------------------------------------------------------------------
int dpiTest_1423(dpiTestCase *testCase, dpiTestParams *params)
{
const char *expectedErrors[] = { "ORA-24418:", "ORA-24496:", NULL };
uint32_t minSessions = 1, maxSessions = 3, sessionIncrement = 1;
dpiConn *connections[3], *tempConn;
dpiPool *pool;
int i;
// create a pool
if (dpiTestCase_getPool(testCase, &pool) < 0)
return DPI_FAILURE;
// acquire 3 connections from the pool
for (i = 0; i < 3; i++) {
if (dpiPool_acquireConnection(pool, NULL, 0, NULL, 0, NULL,
&connections[i]) < 0)
return dpiTestCase_setFailedFromError(testCase);
}
// the fourth connection should be able to be acquired as well
if (dpiPool_acquireConnection(pool, NULL, 0, NULL, 0, NULL, &tempConn) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiConn_release(tempConn) < 0)
return dpiTestCase_setFailedFromError(testCase);
// reconfigure the pool to only allow a maximum of 3 sessions
if (dpiPool_reconfigure(pool, minSessions, maxSessions,
sessionIncrement) < 0)
return dpiTestCase_setFailedFromError(testCase);
// now attempt to acquire the fourth connection, which should fail
dpiPool_acquireConnection(pool, NULL, 0, NULL, 0, NULL, &tempConn);
if (dpiTestCase_expectAnyError(testCase, expectedErrors) < 0)
return DPI_FAILURE;
// release the third connection; an attempt to acquire the third connection
// should now succeed
if (dpiConn_release(connections[2]) < 0)
return dpiTestCase_setFailedFromError(testCase);
if (dpiPool_acquireConnection(pool, NULL, 0, NULL, 0, NULL, &tempConn) < 0)
return dpiTestCase_setFailedFromError(testCase);
// cleanup
if (dpiConn_release(tempConn) < 0)
return dpiTestCase_setFailedFromError(testCase);
for (i = 0; i < 2; i++) {
if (dpiConn_release(connections[i]) < 0)
return dpiTestCase_setFailedFromError(testCase);
}
if (dpiPool_release(pool) < 0)
return dpiTestCase_setFailedFromError(testCase);
return DPI_SUCCESS;
}
//-----------------------------------------------------------------------------
// main()
//-----------------------------------------------------------------------------
int main(int argc, char **argv)
{
dpiTestSuite_initialize(1400);
dpiTestSuite_addCase(dpiTest_1400,
"dpiPool_create() with valid credentials, no parameters");
dpiTestSuite_addCase(dpiTest_1401,
"dpiPool_create() with valid credentials and common params");
dpiTestSuite_addCase(dpiTest_1402,
"dpiPool_create() with valid credentials and create params");
dpiTestSuite_addCase(dpiTest_1403,
"dpiPool_create() with valid credentials and both params");
dpiTestSuite_addCase(dpiTest_1404,
"dpiPool_create() with invalid credentials fails");
dpiTestSuite_addCase(dpiTest_1405,
"dpiPool_create() with Min Sessions");
dpiTestSuite_addCase(dpiTest_1406,
"dpiPool_create() with Max Sessions");
dpiTestSuite_addCase(dpiTest_1407,
"dpiPool_create() with Session Increment");
dpiTestSuite_addCase(dpiTest_1408,
"dpiPool_create() with get mode set to no wait");
dpiTestSuite_addCase(dpiTest_1409,
"dpiPool_create() with get mode set to force get");
dpiTestSuite_addCase(dpiTest_1410,
"dpiPool_create() with NULL context");
dpiTestSuite_addCase(dpiTest_1411,
"dpiPool_create() and release twice");
dpiTestSuite_addCase(dpiTest_1412,
"call all pool functions with closed pool");
dpiTestSuite_addCase(dpiTest_1413,
"call all pool functions with NULL pool");
dpiTestSuite_addCase(dpiTest_1414,
"proxy authentication with pool");
dpiTestSuite_addCase(dpiTest_1415,
"proxy authentication cannot be used with homogeneous pool");
dpiTestSuite_addCase(dpiTest_1416,
"dpiPool_create() with NULL pool");
dpiTestSuite_addCase(dpiTest_1417,
"dpiPool_create() with no credentials");
dpiTestSuite_addCase(dpiTest_1418,
"dpiPool_create() with invalid connect string");
dpiTestSuite_addCase(dpiTest_1419,
"dpiPool_acquireConnection() from hetero pool with credentials");
dpiTestSuite_addCase(dpiTest_1420,
"dpiPool_acquireConnection() from hetero pool without credentials");
dpiTestSuite_addCase(dpiTest_1421,
"dpiPool_acquireConnection() from hetero pool invalid credentials");
dpiTestSuite_addCase(dpiTest_1422,
"dpiPool_getPingInterval() and dpiPool_setPingInterval()");
dpiTestSuite_addCase(dpiTest_1423,
"dpiPool_reconfigure() adjusting max sessions");
return dpiTestSuite_run();
}
|