📄 t_qualifiertest.java
字号:
if (ordered) { if (key != expect_key) { return( fail("(t_scanFetchNext) wrong key, expected (" + expect_key + ")" + "but got (" + key + ").")); } else { if (order == ORDER_DESC) expect_key--; else expect_key++; } } else { if (!set.remove(new Long(key))) { return( fail("(t_scanFetchNext) wrong key, expected (" + expect_key + ")" + "but got (" + key + ").")); } } numrows++; } scan.close(); if (numrows != expect_numrows) { return(fail("(t_scanFetchNext) wrong number of rows. Expected " + expect_numrows + " rows, but got " + numrows + "rows.")); } /********************************************************************** * Backward scan test case ********************************************************************** */ /* if (!ordered) { set = create_hash_set(input_expect_key, expect_numrows, order); } scan = tc.openBackwardScan( conglomid, false, 0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, (FormatableBitSet) null, stop_key, flip_scan_op(stop_op), qualifier, start_key, flip_scan_op(start_op)); expect_key = input_expect_key + expect_numrows - 1; key = -42; numrows = 0; while (scan.fetchNext(fetch_template)) { scan.fetch(init_scan_template); // make sure all columns from fetchNext() match subsequent fetch(). for (int i = 0; i < init_scan_template.length; i++) { if (((Orderable)fetch_template[i]).compare( ((Orderable)init_scan_template[i])) != 0) { return( fail("(t_scanFetchNext) wrong key, expected (" + fetch_template[i] + ")" + "but got (" + init_scan_template[i] + ").")); } } // see if we are getting the right keys. key = ((SQLLongint)(init_scan_template[2])).getLong(); if (ordered) { if (key != expect_key) { return( fail("(t_scanFetchNext) wrong key, expected (" + expect_key + ")" + "but got (" + key + ").")); } else { expect_key--; } } else { if (!set.remove(new Long(key))) { return( fail("(t_scanFetchNext) wrong key, expected (" + expect_key + ")" + "but got (" + key + ").")); } } numrows++; } scan.close(); if (numrows != expect_numrows) { return(fail("(t_scanFetchNext) wrong number of rows. Expected " + expect_numrows + " rows, but got " + numrows + "rows.")); } */ return(true); } /** * Test scan which does FetchNextGroup with all of the fields. * <p> * * @return Whether the test succeeded or not. * * @exception StandardException Standard exception policy. **/ public static boolean t_scanFetchNextGroup( TransactionController tc, int group_size, long conglomid, DataValueDescriptor[] fetch_template, DataValueDescriptor[] start_key, int start_op, Qualifier qualifier[][], DataValueDescriptor[] stop_key, int stop_op, int expect_numrows, int input_expect_key, int order) throws StandardException, T_Fail { HashSet set = null; boolean ordered = (order == ORDER_FORWARD || order == ORDER_DESC); if (!ordered) { set = create_hash_set(input_expect_key, expect_numrows, order); } /********************************************************************** * Forward scan test case ********************************************************************** */ GroupFetchScanController scan = tc.openGroupFetchScan( conglomid, false, 0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, (FormatableBitSet) null, start_key, start_op, qualifier, stop_key, stop_op); // create an array of "group_size" rows to use in the fetch group call. DataValueDescriptor[][] row_array = new DataValueDescriptor[group_size][]; row_array[0] = TemplateRow.newRow(fetch_template); int expect_key = input_expect_key; long key = -42; long numrows = 0; int group_row_count = 0; // loop asking for "group_size" rows at a time. while ((group_row_count = scan.fetchNextGroup(row_array, (RowLocation[]) null)) != 0) { // loop through the rows returned into the row_array. for (int i = 0; i < group_row_count; i++) { // see if we are getting the right keys. key = ((SQLLongint)(row_array[i][2])).getLong(); if (ordered) { if (key != expect_key) { return(fail( "(t_scanFetchNextGroup-forward) wrong key, expect (" + expect_key + ")" + "but got (" + key + "). num rows = " + numrows)); } else { if (order == ORDER_DESC) expect_key--; else expect_key++; } } else { if (!set.remove(new Long(key))) { return(fail( "(t_scanFetchNextGroup-forward) wrong key, expected (" + expect_key + ")" + "but got (" + key + ").")); } } numrows++; } } scan.close(); if (numrows != expect_numrows) { return( fail("(t_scanFetchNextGroup-forward) wrong number of rows. Expected " + expect_numrows + " rows, but got " + numrows + "rows.")); } /********************************************************************** * Backward scan test case ********************************************************************** */ /* if (!ordered) { set = create_hash_set(input_expect_key, expect_numrows, order); } scan = tc.openGroupFetchBackwardScan( conglomid, false, 0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, (FormatableBitSet) null, stop_key, flip_scan_op(stop_op), qualifier, start_key, flip_scan_op(start_op)); // create an array of "group_size" rows to use in the fetch group call. expect_key = input_expect_key + expect_numrows - 1; key = -42; numrows = 0; group_row_count = 0; // loop asking for "group_size" rows at a time. while ((group_row_count = scan.fetchNextGroup(row_array, (RowLocation[]) null)) != 0) { // loop through the rows returned into the row_array. for (int i = 0; i < group_row_count; i++) { // see if we are getting the right keys. key = ((SQLLongint)(row_array[i][2])).getLong(); if (ordered) { if (key != expect_key) { return(fail( "(t_scanFetchNextGroup-backward) wrong key, expected (" + expect_key + ")" + "but got (" + key + ").")); } else { expect_key--; } } else { if (!set.remove(new Long(key))) { return(fail( "(t_scanFetchNextGroup-backward) wrong key, expected (" + expect_key + ")" + "but got (" + key + ").")); } } numrows++; } } scan.close(); if (numrows != expect_numrows) { return( fail("(t_scanFetchNextGroup-backward) wrong number of rows. Expected " + expect_numrows + " rows, but got " + numrows + "rows.")); } */ return(true); } /** * Test scan which does FetchNext with subset of fields. * <p> * FetchNext() may be optimized by the underlying scan code to try and * not do multiple fetches of the same row for the user, but if the user * asks for one column, but the stop position depends on the whole row * this optimization is not possible. * <p> * * @return Whether the test succeeded or not. * * @exception StandardException Standard exception policy. **/ public static boolean t_scanFetchNextPartial( TransactionController tc, long conglomid, DataValueDescriptor[] fetch_template, DataValueDescriptor[] start_key, int start_op, Qualifier qualifier[][], DataValueDescriptor[] stop_key, int stop_op, int expect_numrows, int input_expect_key, int order) throws StandardException, T_Fail { HashSet set = null; boolean ordered = (order == ORDER_FORWARD || order == ORDER_DESC); /********************************************************************** * setup shared by both. ********************************************************************** */ // In the fetchNext call only ask the minimum set of columns // necessary, which is the union of the "key" (col[2]) and other // columns referenced in the qualifier list. FormatableBitSet fetch_row_validColumns = RowUtil.getQualifierBitSet(qualifier); // now add in column 2, as we always need the key field. fetch_row_validColumns.grow(3);// grow to length of 3 fetch_row_validColumns.set(2); // add in any fields in start and stop positions if (start_key != null) { for (int i = 0; i < start_key.length; i++) { fetch_row_validColumns.set(i); } } if (stop_key != null) { for (int i = 0; i < stop_key.length; i++) { fetch_row_validColumns.set(i); } } // point key at the right column in the fetch_template SQLLongint key_column = (SQLLongint) fetch_template[2]; /********************************************************************** * Forward scan test case ********************************************************************** */ if (!ordered) { set = create_hash_set(input_expect_key, expect_numrows, order); } ScanController scan = tc.openScan( conglomid, false, 0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, (FormatableBitSet) fetch_row_validColumns, start_key, start_op, qualifier, stop_key, stop_op); int expect_key = input_expect_key; long key = -42; long key2 = -42; long numrows = 0; while (scan.fetchNext(fetch_template)) { // see if we are getting the right keys. key = key_column.getLong(); // make sure a subsequent fetch also works. key_column.setValue(-42); scan.fetch(fetch_template); key2 = key_column.getLong(); if (ordered) { if ((key != expect_key) || (key2 != expect_key)) { return( fail("(t_scanFetchNext) wrong key, expected (" + expect_key + ")" + "but got (" + key + ").")); } else { if (order == ORDER_DESC) expect_key--; else expect_key++; } } else { if (!set.remove(new Long(key))) { return( fail("(t_scanFetchNext) wrong key, expected (" + expect_key + ")" + "but got (" + key + ").")); } } numrows++; } scan.close(); if (numrows != expect_numrows) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -