1 21 22 package org.opensubsystems.patterns.listdata.persist.db; 23 24 import java.util.Collection ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 import java.util.Map ; 28 import java.util.Properties ; 29 import java.util.Random ; 30 import java.util.logging.Logger ; 31 32 import org.opensubsystems.core.data.BasicDataObject; 33 import org.opensubsystems.core.data.DataObject; 34 import org.opensubsystems.core.error.OSSException; 35 import org.opensubsystems.core.persist.db.DatabaseTest; 36 import org.opensubsystems.core.util.CallContext; 37 import org.opensubsystems.core.util.Config; 38 import org.opensubsystems.core.util.DateUtils; 39 import org.opensubsystems.core.util.Log; 40 import org.opensubsystems.core.util.MyTimer; 41 import org.opensubsystems.core.util.NumberUtils; 42 import org.opensubsystems.core.util.StringUtils; 43 import org.opensubsystems.patterns.listdata.data.ListDefinition; 44 import org.opensubsystems.patterns.listdata.data.ListOptions; 45 import org.opensubsystems.patterns.listdata.data.SimpleRule; 46 import org.opensubsystems.patterns.listdata.persist.ListFactory; 47 48 61 public abstract class ListDatabaseFactoryTest extends DatabaseTest 62 { 63 65 71 private static final String LOADTEST_LIST_SIZE = "oss.loadtest.list.size"; 72 73 78 private static final String LOADTEST_PAGE_SIZE = "oss.loadtest.page.size"; 79 80 86 private static final String LOADTEST_LOADTIME = "oss.loadtest.loadtime"; 87 88 90 96 public static final int DEFAULT_LOADTEST_LIST_SIZE = 100; 97 98 102 public static final int DEFAULT_LOADTEST_PAGE_SIZE = 20; 103 104 108 public static final int DEFAULT_LOADTEST_LOADTIME = 4000; 109 110 112 115 protected ListDatabaseTestUtils m_listTestUtils; 116 117 119 122 private static Logger s_logger = Log.getInstance(ListDatabaseFactoryTest.class); 123 124 127 protected static int s_iLoadtestListSize; 128 129 132 protected static int s_iLoadtestPageSize; 133 134 137 protected static int s_iLoadtestLoadTime; 138 139 141 144 static 145 { 146 Properties prpSettings; 147 148 prpSettings = Config.getInstance().getPropertiesSafely(); 149 s_iLoadtestListSize = Config.getIntPropertyInRange( 150 prpSettings, 151 LOADTEST_LIST_SIZE, 152 DEFAULT_LOADTEST_LIST_SIZE, 153 "Total number of items to use for list" 154 + " performance testing", 155 1, 156 Integer.MAX_VALUE); 157 158 159 s_iLoadtestPageSize = Config.getIntPropertyInRange( 160 prpSettings, 161 LOADTEST_PAGE_SIZE, 162 DEFAULT_LOADTEST_PAGE_SIZE, 163 "Page size to use for list performance testing", 164 1, Integer.MAX_VALUE); 165 166 s_iLoadtestLoadTime = Config.getIntPropertyInRange( 167 prpSettings, 168 LOADTEST_LOADTIME, 169 DEFAULT_LOADTEST_LOADTIME, 170 "Time threshold to still consider performance" 171 + " acceptable", 172 1, 173 Integer.MAX_VALUE); 174 } 175 176 182 public ListDatabaseFactoryTest( 183 String strTestName, 184 ListDatabaseTestUtils listTestUtils 185 ) 186 { 187 super(strTestName); 188 189 m_listTestUtils = listTestUtils; 190 } 191 192 194 199 protected void setUp( 200 ) throws Exception 201 { 202 super.setUp(); 203 } 204 205 210 211 protected void tearDown() throws Exception 212 { 213 super.tearDown(); 214 } 215 216 218 230 public void testGetColumnsUsingId( 231 ) throws Exception 232 { 233 ListDatabaseSchema listSchema; 234 int iDataType; 235 236 listSchema = m_listTestUtils.getListDatabaseSchema(); 237 iDataType = m_listTestUtils.getListFactory().getDataType(); 238 239 String strSQL; 241 242 strSQL = listSchema.getColumns(false, new int[] {iDataType + 1}, null, 245 null, null).toString(); 246 247 assertEquals("The column name for the code which should identify ID column " 248 + " is not ID", "ID", strSQL.toUpperCase()); 249 } 250 251 259 public void testGetColumns( 260 ) throws Exception 261 { 262 doTestGetColumns(m_listTestUtils.getListFactory() 265 .getDefaultListDefinition().getShowColumnCodes()); 266 doTestGetColumns(m_listTestUtils.getAllColumnCodes()); 268 } 269 270 277 public void testGet( 278 ) throws Exception 279 { 280 Object [] data = null; 281 282 try 283 { 284 Object parent; 285 int[] columns = new int[] {m_listTestUtils.getColumnOneCode(), 286 m_listTestUtils.getColumnTwoCode(), 287 }; 288 289 data = m_listTestUtils.insertTestData(m_transaction); 290 parent = data[0]; 291 292 295 doTestGet(parent, 5, 2, columns); 297 doTestGet(parent, 10, 12, columns); 298 doTestGet(parent, 30, 22, columns); 299 300 doTestGet(parent, 5, 2, m_listTestUtils.getAllColumnCodes()); 302 doTestGet(parent, 10, 12, m_listTestUtils.getAllColumnCodes()); 303 doTestGet(parent, 30, 22, m_listTestUtils.getAllColumnCodes()); 304 } 305 finally 306 { 307 m_listTestUtils.deleteTestData(m_transaction, data); 308 } 309 } 310 311 318 public void testLoadPagesFromFirstToLast( 319 ) throws Exception 320 { 321 Object [] data = null; 322 323 try 324 { 325 data = m_listTestUtils.insertLoadTestData(m_transaction, 326 s_iLoadtestListSize); 327 doTestLoadPagesFromFirstToLast(data[0], "(single domain)"); 328 } 329 finally 330 { 331 m_listTestUtils.deleteLoadTestData(m_transaction, data); 332 } 333 } 334 335 343 public void testLoadPagesFromLastToFirst( 344 ) throws Exception 345 { 346 Object [] data = null; 347 348 try 349 { 350 boolean bOrderDirectionAsc = true; 351 352 data = m_listTestUtils.insertLoadTestData(m_transaction, 353 s_iLoadtestListSize); 354 355 doTestLoadPagesFromLastToFirst(data[0], 358 "(single domain)", 359 m_listTestUtils.getColumnOneCode(), 360 bOrderDirectionAsc, 361 true); 362 } 363 finally 364 { 365 m_listTestUtils.deleteLoadTestData(m_transaction, data); 366 } 367 } 368 369 378 public void testLoadPagesFromLastToFirstMoreSortableColumns( 379 ) throws Exception 380 { 381 Object [] data = null; 382 383 try 384 { 385 int iIndex; 386 boolean bOrderDirectionAsc; 387 ListFactory factory = m_listTestUtils.getListFactory(); 388 ListDatabaseSchema schema = m_listTestUtils.getListDatabaseSchema(); 389 int iDataType = factory.getDataType(); 390 Map mapSortableColumns = schema.getSortableColumns(); 391 int[] arrSortableColumns = (int[])mapSortableColumns.get( 393 new Integer (iDataType)); 394 395 data = m_listTestUtils.insertLoadTestData(m_transaction, 396 s_iLoadtestListSize); 397 398 for (iIndex = 0; iIndex < arrSortableColumns.length; iIndex++) 401 { 402 if (iIndex % 2 != 0) 403 { 404 bOrderDirectionAsc = false; 405 } 406 else 407 { 408 bOrderDirectionAsc = true; 409 } 410 doTestLoadPagesFromLastToFirst(data[0], 411 "(single domain)", 412 arrSortableColumns[iIndex], 413 bOrderDirectionAsc, 414 false); 415 } 416 } 417 finally 418 { 419 m_listTestUtils.deleteLoadTestData(m_transaction, data); 420 } 421 } 422 423 430 public void testLoadPagesRandom( 431 ) throws Exception 432 { 433 Object [] data = null; 434 435 try 436 { 437 data = m_listTestUtils.insertLoadTestData(m_transaction, 438 s_iLoadtestListSize); 439 440 doTestLoadPagesRandom(data[0], "(single domain)"); 441 } 442 finally 443 { 444 m_listTestUtils.deleteLoadTestData(m_transaction, data); 445 } 446 } 447 448 450 456 protected void doTestGetColumns( 457 int[] columns 458 ) throws OSSException 459 { 460 ListDatabaseSchema listSchema; 461 String strDefaultSQL; 462 String strSpecificSQL; 463 String strFixedSQL; 464 int iIndex; 465 int columnLength = columns.length; 466 String [] prefixes = new String [columnLength]; 467 String [] postfixes = new String [columnLength]; 468 Iterator def; 469 Iterator specific; 470 Iterator fixed; 471 String strColumn; 472 String strDefault; 473 String strSpecific; 474 String strFixed; 475 Collection colDefault; 476 Collection colSpecific; 477 Collection colFixed; 478 479 listSchema = m_listTestUtils.getListDatabaseSchema(); 480 481 for (iIndex = 0; iIndex < columns.length; iIndex++) 482 { 483 strColumn = listSchema.getColumns(false, new int[] {columns[iIndex]}, 484 null, null, null).toString(); 485 assertTrue("getColumns didnt return column name for column code " 486 + columns[iIndex], strColumn.trim().length() > 0); 487 } 488 489 strDefaultSQL = listSchema.getColumns(false, columns, null, 491 null, null).toString(); 492 strSpecificSQL = listSchema.getColumns(true, columns, null, 495 null, null).toString(); 496 497 assertFalse("getColumns in the " + listSchema.getClass().getName() + 498 " is not implemented correctly since the specific flag has no effect" 499 + " nonspecific=" + strDefaultSQL + " specific=" + strSpecificSQL, 500 strDefaultSQL.equals(strSpecificSQL)); 501 colDefault = StringUtils.parseStringToCollection( 503 strDefaultSQL, ",", true, 504 StringUtils.CASE_ORIGINAL, null); 505 colSpecific = StringUtils.parseStringToCollection( 506 strSpecificSQL, ",", true, 507 StringUtils.CASE_ORIGINAL, null); 508 509 assertEquals("Default SQL doesn't have the correct number of elements", 510 columnLength, colSpecific.size()); 511 assertEquals("Default SQL and specific SQL don't have the same" + 512 " number of elements", colDefault.size(), colSpecific.size()); 513 514 for (specific = colSpecific.iterator(), def = colDefault.iterator(), 516 iIndex = 0; specific.hasNext() && def.hasNext(); iIndex++) 517 { 518 strSpecific = (String )specific.next(); 519 strDefault = (String )def.next(); 520 assertEquals("Column was incorrectly specified", 521 strSpecific.substring(strSpecific.lastIndexOf('.') + 1), 522 strDefault); 523 } 524 525 for (iIndex = 0; iIndex < columnLength; iIndex++) 527 { 528 prefixes[iIndex] = "prefix" + iIndex; 529 postfixes[iIndex] = "postfix" + iIndex; 530 } 531 532 strFixedSQL = listSchema.getColumns(true, columns, prefixes, 534 postfixes, null).toString(); 535 colFixed = StringUtils.parseStringToCollection( 537 strFixedSQL, ",", true, 538 StringUtils.CASE_ORIGINAL, null); 539 540 assertEquals("Specific SQL and prefixes/postfixed SQL don't have the same" + 541 " number of elements", colSpecific.size(), colFixed.size()); 542 assertEquals("Specific SQL and prefixes/postfixed SQL don't have the correct" + 543 " number of elements", columnLength, colFixed.size()); 544 545 for (specific = colSpecific.iterator(), fixed = colFixed.iterator(), 548 iIndex = 0; specific.hasNext() && fixed.hasNext(); iIndex++) 549 { 550 strSpecific = (String )specific.next(); 551 strFixed = (String )fixed.next(); 552 assertEquals("Column was incorrectly prefixed and postfixed", 553 prefixes[iIndex] + strSpecific + postfixes[iIndex], strFixed); 554 } 555 } 556 557 568 protected void doTestGet( 569 Object parent, 570 int pageSize, 571 int beginPos, 572 int[] columns 573 ) throws Exception 574 { 575 ListFactory factory; 576 ListOptions options; 577 List lstTestData; 578 String [] arrExpectedData; 579 int helpCounter; 580 int assertCounter; 581 582 factory = m_listTestUtils.getListFactory(); 583 options = m_listTestUtils.getDefaultListOptions(parent); 584 arrExpectedData = m_listTestUtils.getExpectedResultListColumnOne(); 585 586 options.setPageSize(pageSize); 587 options.setActualListSize(30); 588 options.setBeginPosition(beginPos); 589 options.setEndPosition(9); 590 options.setActualPage(13); 591 options.setShowColumnCodes(new int[] {m_listTestUtils.getColumnOneCode(), 592 m_listTestUtils.getColumnTwoCode(), 593 }); 594 options.setSecurityFilter(SimpleRule.ALL_DATA); 595 596 lstTestData = factory.get(options); 597 assertNotNull("Selected data object list is null", lstTestData); 600 if ((arrExpectedData.length - options.getBeginPosition() + 1) < pageSize) 601 { 602 assertEquals("Number of selected items is incorrect", 603 (arrExpectedData.length - options.getBeginPosition() + 1), 604 lstTestData.size()); 605 } 606 else 607 { 608 assertEquals("Number of selected items is incorrect", 609 pageSize, lstTestData.size()); 610 } 611 assertEquals("PageSize should have not changed", pageSize, 612 options.getPageSize()); 613 assertEquals("ShowColumnCodes should have not changed", 2, 614 options.getShowColumnCodes().length); 615 assertEquals("ShowColumnCodes should have not changed", 616 m_listTestUtils.getColumnOneCode(), 617 options.getShowColumnCodes()[0]); 618 assertEquals("ShowColumnCodes should have not changed", 619 m_listTestUtils.getColumnTwoCode(), 620 options.getShowColumnCodes()[1]); 621 assertEquals("ActualListSize is not set correctly", 622 arrExpectedData.length, options.getActualListSize()); 623 assertTrue("BeginPosition is not set correctly", 624 (beginPos == options.getBeginPosition() 625 || (beginPos > options.getBeginPosition()))); 626 if (pageSize >= arrExpectedData.length) 627 { 628 assertTrue("BeginPosition is not set correctly", 629 options.getBeginPosition() == 1); 630 } 631 assertTrue("EndPosition is not set correctly", 632 ((options.getBeginPosition() + pageSize - 1) 633 == options.getEndPosition() 634 || (options.getEndPosition() == arrExpectedData.length))); 635 assertEquals("ActualPage is not set correctly", 636 ((options.getBeginPosition() + pageSize - 2) / pageSize) + 1, 637 options.getActualPage()); 638 639 for (assertCounter = (options.getBeginPosition() - 1), helpCounter = 0; 640 assertCounter < options.getEndPosition(); 641 assertCounter++, helpCounter++) 642 { 643 assertEquals("The retrieved element #" + helpCounter + 645 " is not correct", 646 arrExpectedData[assertCounter], 647 m_listTestUtils.getColumnOneValue( 648 (DataObject)lstTestData.get(helpCounter) 649 )); 650 } 651 } 652 653 677 protected long doLoadTestGet( 678 Object parent, 679 int iListSize, 680 int iPageSize, 681 int iBeginPos, 682 boolean bCountLastPageSize, 683 int[] arrColumns, 684 int iOrderColumn, 685 boolean bOrderDirectionAsc, 686 boolean bTestDataValues 687 ) throws Exception 688 { 689 MyTimer timer = new MyTimer(); 690 long lDataSelectDuration; 691 String strDataSelectDuration = ""; 692 int iActualPage = 0; 693 String strTestValue = ""; 694 int iCurrentPageSize = iPageSize; 695 ListFactory factory = m_listTestUtils.getListFactory(); 696 ListOptions options = m_listTestUtils.getDefaultListOptions(parent); 697 698 if (bCountLastPageSize) 700 { 701 iCurrentPageSize = iListSize % iPageSize; 702 } 703 704 if (iOrderColumn != -1) 708 { 709 options.setOrdering(new int[] {iOrderColumn}, 710 bOrderDirectionAsc ? ListDefinition.ORDER_ASCENDING_ARRAY 711 : ListDefinition.ORDER_DESCENDING_ARRAY); 712 } 713 options.setPageSize(iPageSize); 714 options.setActualListSize(iListSize); 715 options.setBeginPosition(iBeginPos); 716 options.setEndPosition(iBeginPos + iPageSize); 717 if ((iBeginPos % iPageSize) == 0) 719 { 720 iActualPage = iBeginPos / iPageSize; 721 } 722 else 723 { 724 iActualPage = (iBeginPos / iPageSize) + 1; 725 } 726 options.setActualPage(iActualPage); 727 options.setShowColumnCodes(new int[] {m_listTestUtils.getColumnOneCode(), 728 m_listTestUtils.getColumnTwoCode(), 729 }); 730 options.setSecurityFilter(SimpleRule.ALL_DATA); 731 732 try 733 { 734 timer.reset(); 735 List lstTestData = factory.get(options); 736 lDataSelectDuration = timer.getDuration(); 737 strDataSelectDuration = timer.toString(); 738 746 749 assertNotNull("Selected data object list is null", lstTestData); 750 assertEquals("Number of selected data objects is incorrect", 751 iCurrentPageSize, lstTestData.size()); 752 assertEquals("Page size should have not changed", iPageSize, 753 options.getPageSize()); 754 assertTrue("ShowColumnCodes list should have not changed", 755 m_listTestUtils.getColumnOneCode() == options.getShowColumnCodes()[0] 756 && m_listTestUtils.getColumnTwoCode() == options.getShowColumnCodes()[1]); 757 assertEquals("ActualListSize is incorrectly set", 758 iListSize, options.getActualListSize()); 759 assertTrue("BeginPosition is incorrectly set", 760 (iBeginPos == options.getBeginPosition() 761 || (iBeginPos > options.getBeginPosition()))); 762 assertTrue("EndPosition is incorrectly set", 763 ((options.getBeginPosition() + iPageSize - 1) 764 == options.getEndPosition() 765 || (options.getEndPosition() == iCurrentPageSize))); 766 assertEquals("ActualPage is incorrectly set", 767 ((options.getBeginPosition() + iPageSize - 2) 768 / iPageSize) + 1, 769 options.getActualPage()); 770 771 if (bTestDataValues) 772 { 773 if (m_listTestUtils.getListDatabaseSchema().isInDomain()) 774 { 775 assertEquals("The domain id of item in Data Object List is not correct", 776 CallContext.getInstance().getCurrentDomainId(), 777 ((BasicDataObject)lstTestData.get(0)).getDomainId()); 778 } 779 780 if (bOrderDirectionAsc) 782 { 783 strTestValue = "test_1_" + NumberUtils.getDigitNumberString( 784 options.getBeginPosition(), 8); 785 } 786 else 787 { 788 strTestValue = "test_1_" + NumberUtils.getDigitNumberString( 790 (s_iLoadtestListSize - options.getBeginPosition()) + 1, 8); 791 } 792 793 if (bOrderDirectionAsc) 797 { 798 assertEquals("The 1st value in Data Object List is not correct", 800 strTestValue, 801 m_listTestUtils.getColumnOneValue( 802 (DataObject)lstTestData.get(0) 803 )); 804 } 805 } 806 807 assertTrue("A poor perforance of data loading was acountered by" + 808 " loading page with " + iCurrentPageSize + 809 " items from list with " + iListSize + 810 " items at position " + iBeginPos + " (total" + 811 " duration of the SQL select is " + strDataSelectDuration + 812 ")", 813 lDataSelectDuration <= s_iLoadtestLoadTime); 814 } 815 catch (Throwable thr) 816 { 817 throw new Exception (thr); 818 } 819 820 return lDataSelectDuration; 821 } 822 823 833 protected void doTestLoadPagesFromFirstToLast( 834 Object parent, 835 String strExtraText 836 ) throws Exception 837 { 838 int iIndex; 839 int iTotalPages = 0; 840 boolean isLastPage = false; 841 boolean bCountLastPageSize = false; 842 long lSumDataSelectDurations = 0; 843 long lActualDataSelectDuration; 844 long[][] lMaxDataSelectDuration = {{0, 0}}; 845 long[][] lMinDataSelectDuration = {{Long.MAX_VALUE, 0}}; 846 int[] arrAllColumnCodes = m_listTestUtils.getAllColumnCodes(); 847 848 if ((s_iLoadtestListSize % s_iLoadtestPageSize) > 0) 850 { 851 iTotalPages = (s_iLoadtestListSize / s_iLoadtestPageSize) + 1; 852 isLastPage = true; 853 } 854 else 855 { 856 iTotalPages = (s_iLoadtestListSize / s_iLoadtestPageSize); 857 } 858 859 for (iIndex = 0; iIndex < iTotalPages; iIndex++) 863 { 864 if ((iIndex == iTotalPages - 1) && (isLastPage)) 865 { 866 bCountLastPageSize = true; 867 } 868 869 lActualDataSelectDuration = doLoadTestGet( 871 parent, 872 s_iLoadtestListSize, 873 s_iLoadtestPageSize, 874 (iIndex * s_iLoadtestPageSize) + 1, 875 bCountLastPageSize, 876 arrAllColumnCodes, 877 -1, 879 true, 880 true); 881 882 lSumDataSelectDurations += lActualDataSelectDuration; 883 884 if (lActualDataSelectDuration < lMinDataSelectDuration[0][0]) 886 { 887 lMinDataSelectDuration[0][0] = lActualDataSelectDuration; 889 lMinDataSelectDuration[0][1] = iIndex + 1; 891 } 892 893 if (lActualDataSelectDuration > lMaxDataSelectDuration[0][0]) 895 { 896 lMaxDataSelectDuration[0][0] = lActualDataSelectDuration; 898 lMaxDataSelectDuration[0][1] = iIndex + 1; 900 } 901 } 902 903 lActualDataSelectDuration = lSumDataSelectDurations / iTotalPages; 905 906 s_logger.info("Total retrieved pages from first to last " + strExtraText + 907 " : " + iTotalPages + 908 ", number of items for page: " + s_iLoadtestPageSize + "\n" + 909 "The best performance has page " 910 + lMinDataSelectDuration[0][1] + 911 " with duration " 912 + DateUtils.getStringTime(lMinDataSelectDuration[0][0]) + 913 ". \n" + 914 "The worst performance has page " 915 + lMaxDataSelectDuration[0][1] + 916 " with duration " 917 + DateUtils.getStringTime(lMaxDataSelectDuration[0][0]) + 918 ". \n" + 919 "Average duration for page is " + 920 DateUtils.getStringTime(lActualDataSelectDuration)); 921 } 922 923 944 protected void doTestLoadPagesFromLastToFirst( 945 Object parent, 946 String strExtraText, 947 int iOrderColumn, 948 boolean bOrderDirectionAsc, 949 boolean bTestDataValues 950 ) throws Exception 951 { 952 StringBuffer sbLogInfo = new StringBuffer (); 953 int iIndex; 954 int iTotalPages = 0; 955 boolean isLastPage = false; 956 boolean bCountLastPageSize = false; 957 long lSumDataSelectDurations = 0; 958 long lActualDataSelectDuration; 959 long[][] lMaxDataSelectDuration = {{0, 0}}; 960 long[][] lMinDataSelectDuration = {{Long.MAX_VALUE, 0}}; 961 int[] arrAllColumnCodes = m_listTestUtils.getAllColumnCodes(); 962 963 sbLogInfo.append(strExtraText); 964 if (iOrderColumn != -1) 965 { 966 sbLogInfo.append("(for column "); 967 sbLogInfo.append(iOrderColumn); 968 sbLogInfo.append(" , order direction "); 969 sbLogInfo.append(bOrderDirectionAsc ? "ASC)" : "DESC)"); 970 } 971 972 if ((s_iLoadtestListSize % s_iLoadtestPageSize) > 0) 974 { 975 iTotalPages = (s_iLoadtestListSize / s_iLoadtestPageSize) + 1; 976 isLastPage = true; 977 } 978 else 979 { 980 iTotalPages = (s_iLoadtestListSize / s_iLoadtestPageSize); 981 } 982 983 987 for (iIndex = iTotalPages - 1; iIndex >= 0; iIndex--) 991 { 992 bCountLastPageSize = false; 993 if ((iIndex == iTotalPages - 1) && (isLastPage)) 994 { 995 bCountLastPageSize = true; 996 } 997 998 lActualDataSelectDuration = doLoadTestGet( 1000 parent, 1001 s_iLoadtestListSize, 1002 s_iLoadtestPageSize, 1003 (iIndex * s_iLoadtestPageSize) + 1, 1004 bCountLastPageSize, 1005 arrAllColumnCodes, 1006 iOrderColumn, 1007 bOrderDirectionAsc, 1008 bTestDataValues); 1009 1010 lSumDataSelectDurations += lActualDataSelectDuration; 1011 1012 if (lActualDataSelectDuration < lMinDataSelectDuration[0][0]) 1014 { 1015 lMinDataSelectDuration[0][0] = lActualDataSelectDuration; 1017 lMinDataSelectDuration[0][1] = iIndex + 1; 1019 } 1020 1021 if (lActualDataSelectDuration > lMaxDataSelectDuration[0][0]) 1023 { 1024 lMaxDataSelectDuration[0][0] = lActualDataSelectDuration; 1026 lMaxDataSelectDuration[0][1] = iIndex + 1; 1028 } 1029 } 1030 1031 lActualDataSelectDuration = lSumDataSelectDurations / iTotalPages; 1033 1034 s_logger.info("Total retrieved pages from last to first " + sbLogInfo + 1035 " : " + iTotalPages + 1036 ", number of items for page: " + s_iLoadtestPageSize + "\n" + 1037 "The best performance has page " 1038 + lMinDataSelectDuration[0][1] + 1039 " with duration " 1040 + DateUtils.getStringTime(lMinDataSelectDuration[0][0]) + 1041 ". \n" + 1042 "The worst performance has page " 1043 + lMaxDataSelectDuration[0][1] + 1044 " with duration " 1045 + DateUtils.getStringTime(lMaxDataSelectDuration[0][0]) + 1046 ". \n" + 1047 "Average duration for page is " + 1048 DateUtils.getStringTime(lActualDataSelectDuration)); 1049 } 1050 1051 1061 protected void doTestLoadPagesRandom( 1062 Object parent, 1063 String strExtraText 1064 ) throws Exception 1065 { 1066 int iActualPage = 1; 1067 int iIndex; 1068 int iTotalPages = 0; 1069 boolean isLastPage = false; 1070 boolean bCountLastPageSize = false; 1071 int[] arrPageNumbers; 1072 long lSumDataSelectDurations = 0; 1073 long lActualDataSelectDuration; 1074 long[][] lMaxDataSelectDuration = {{0, 0}}; 1075 long[][] lMinDataSelectDuration = {{Long.MAX_VALUE, 0}}; 1076 int[] arrAllColumnCodes = m_listTestUtils.getAllColumnCodes(); 1077 Random generator = new Random (); 1078 1079 if ((s_iLoadtestListSize % s_iLoadtestPageSize) > 0) 1081 { 1082 iTotalPages = (s_iLoadtestListSize / s_iLoadtestPageSize) + 1; 1083 isLastPage = true; 1084 } 1085 else 1086 { 1087 iTotalPages = (s_iLoadtestListSize / s_iLoadtestPageSize); 1088 } 1089 1090 arrPageNumbers = new int[iTotalPages]; 1092 for (iIndex = 0; iIndex < iTotalPages; iIndex++) 1093 { 1094 arrPageNumbers[iIndex] = generator.nextInt(iTotalPages - 1) + 1; 1095 } 1096 1097 1101 for (iIndex = 0; iIndex < iTotalPages; iIndex++) 1105 { 1106 iActualPage = arrPageNumbers[iIndex]; 1107 bCountLastPageSize = false; 1108 if ((iActualPage == iTotalPages) && isLastPage) 1109 { 1110 bCountLastPageSize = true; 1111 } 1112 lActualDataSelectDuration = doLoadTestGet( 1114 parent, 1115 s_iLoadtestListSize, 1116 s_iLoadtestPageSize, 1117 ((iActualPage - 1) * s_iLoadtestPageSize) + 1, 1119 bCountLastPageSize, 1120 arrAllColumnCodes, 1121 -1, 1123 true, 1124 true); 1125 1126 lSumDataSelectDurations += lActualDataSelectDuration; 1127 1128 if (lActualDataSelectDuration < lMinDataSelectDuration[0][0]) 1130 { 1131 lMinDataSelectDuration[0][0] = lActualDataSelectDuration; 1133 lMinDataSelectDuration[0][1] = iActualPage; 1135 } 1136 1137 if (lActualDataSelectDuration > lMaxDataSelectDuration[0][0]) 1139 { 1140 lMaxDataSelectDuration[0][0] = lActualDataSelectDuration; 1142 lMaxDataSelectDuration[0][1] = iActualPage; 1144 } 1145 } 1146 1147 lActualDataSelectDuration = lSumDataSelectDurations / iTotalPages; 1149 1150 s_logger.info("Total randomly retrieved pages " + strExtraText + ": " + 1151 iTotalPages + ", number of items for page: " 1152 + s_iLoadtestPageSize + 1153 "\n" + 1154 "The best performance has page " 1155 + lMinDataSelectDuration[0][1] + 1156 " with duration " 1157 + DateUtils.getStringTime(lMinDataSelectDuration[0][0]) + 1158 ". \n" + 1159 "The worst performance has page " 1160 + lMaxDataSelectDuration[0][1] + 1161 " with duration " 1162 + DateUtils.getStringTime(lMaxDataSelectDuration[0][0]) + 1163 ". \n" + 1164 "Average duration for page is " + 1165 DateUtils.getStringTime(lActualDataSelectDuration)); 1166 } 1167} 1168 | Popular Tags |