提交 a7b6996b authored 作者: Owner's avatar Owner

Checkstyle and codeStyle fixes

上级 ee84407d
......@@ -73,7 +73,7 @@ public class CreateView extends SchemaCommand {
}
public void setTableExpression(boolean isTableExpression) {
this.isTableExpression=isTableExpression;
this.isTableExpression = isTableExpression;
}
@Override
......@@ -116,11 +116,9 @@ public class CreateView extends SchemaCommand {
}
}
if (view == null) {
if(isTableExpression){
view = TableView.createTableViewMaybeRecursive(getSchema(), id, viewName, querySQL, null, columnTemplatesAsStrings, session, false /* literalsChecked */, isTableExpression, true /*isPersistent*/ , db);
}
else
{
if (isTableExpression) {
view = TableView.createTableViewMaybeRecursive(getSchema(), id, viewName, querySQL, null, columnTemplatesAsStrings, session, false /* literalsChecked */, isTableExpression, true /*isPersistent*/, db);
} else {
view = new TableView(getSchema(), id, viewName, querySQL, null, columnTemplatesAsUnknowns, session, false/* allow recursive */, false/* literalsChecked */, isTableExpression, true);
}
} else {
......
......@@ -79,10 +79,10 @@ public class DropView extends SchemaCommand {
session.getDatabase().removeSchemaObject(session, view);
// remove dependent table expressions
for( Table childTable: copyOfDependencies){
if(TableType.VIEW == childTable.getTableType()){
for (Table childTable: copyOfDependencies) {
if (TableType.VIEW == childTable.getTableType()) {
TableView childTableView = (TableView) childTable;
if(childTableView.isTableExpression() && childTableView.getName()!=null){
if (childTableView.isTableExpression() && childTableView.getName() != null) {
session.getDatabase().removeSchemaObject(session, childTableView);
}
}
......
......@@ -53,7 +53,7 @@ public class Delete extends Prepared {
this.condition = condition;
}
public Expression getCondition( ) {
public Expression getCondition() {
return this.condition;
}
......@@ -136,17 +136,16 @@ public class Delete extends Prepared {
public void prepare() {
if (condition != null) {
condition.mapColumns(targetTableFilter, 0);
if(sourceTableFilter!=null){
if (sourceTableFilter != null) {
condition.mapColumns(sourceTableFilter, 0);
}
condition = condition.optimize(session);
condition.createIndexConditions(session, targetTableFilter);
}
TableFilter[] filters;
if(sourceTableFilter==null){
if (sourceTableFilter == null) {
filters = new TableFilter[] { targetTableFilter };
}
else{
} else {
filters = new TableFilter[] { targetTableFilter, sourceTableFilter };
}
PlanItem item = targetTableFilter.getBestPlanItem(session, filters, 0,
......
......@@ -112,11 +112,11 @@ public class MergeUsing extends Prepared {
private Delete deleteCommand;
private Insert insertCommand;
private String queryAlias;
private int countUpdatedRows = 0;
private int countUpdatedRows;
private Column[] sourceKeys;
private Select targetMatchQuery;
private HashMap<Value, Integer> targetRowidsRemembered = new HashMap<>();
private int sourceQueryRowNumber = 0;
private int sourceQueryRowNumber;
public MergeUsing(Merge merge) {
super(merge.getSession());
......
......@@ -840,14 +840,14 @@ public class Select extends Query {
sort = prepareOrder(orderList, expressions.size());
orderList = null;
}
ColumnNamer columnNamer= new ColumnNamer(session);
ColumnNamer columnNamer = new ColumnNamer(session);
for (int i = 0; i < expressions.size(); i++) {
Expression e = expressions.get(i);
String proposedColumnName = e.getAlias();
String columnName = columnNamer.getColumnName(e,i,proposedColumnName);
String columnName = columnNamer.getColumnName(e, i, proposedColumnName);
// if the name changed, create an alias
if(!columnName.equals(proposedColumnName)){
e = new Alias(e,columnName,true);
if (!columnName.equals(proposedColumnName)) {
e = new Alias(e, columnName, true);
}
expressions.set(i, e.optimize(session));
}
......@@ -1087,14 +1087,13 @@ public class Select extends Query {
for (TableFilter f : topFilters) {
Table t = f.getTable();
TableView tableView = (t instanceof TableView) ? (TableView) t : null;
if (tableView!=null && tableView.isRecursive() && tableView.isTableExpression()) {
if (tableView != null && tableView.isRecursive() && tableView.isTableExpression()) {
if(tableView.isPersistent()){
if (tableView.isPersistent()) {
// skip the generation of plan SQL for this already recursive persistent ctes, since using a with
// statement will re-create the common table expression views.
continue;
}
else {
} else {
buff.append("WITH RECURSIVE ").append(t.getName()).append('(');
buff.resetCount();
for (Column c : t.getColumns()) {
......
......@@ -91,6 +91,9 @@ public class Database implements DataHandler {
private static int initialPowerOffCount;
private static final ThreadLocal<Session> META_LOCK_DEBUGGING = new ThreadLocal<Session>();
private static final ThreadLocal<Throwable> META_LOCK_DEBUGGING_STACK = new ThreadLocal<Throwable>();
/**
* The default name of the system user. This name is only used as long as
* there is no administrator user registered.
......@@ -296,7 +299,7 @@ public class Database implements DataHandler {
e.fillInStackTrace();
}
boolean alreadyOpen = e instanceof DbException
&& ((DbException)e).getErrorCode() == ErrorCode.DATABASE_ALREADY_OPEN_1;
&& ((DbException) e).getErrorCode() == ErrorCode.DATABASE_ALREADY_OPEN_1;
if (alreadyOpen) {
stopServer();
}
......@@ -899,9 +902,6 @@ public class Database implements DataHandler {
}
}
private static final ThreadLocal<Session> metaLockDebugging = new ThreadLocal<Session>();
private static final ThreadLocal<Throwable> metaLockDebuggingStack = new ThreadLocal<Throwable>();
/**
* Lock the metadata table for updates.
*
......@@ -917,13 +917,13 @@ public class Database implements DataHandler {
return true;
}
if (SysProperties.CHECK2) {
final Session prev = metaLockDebugging.get();
final Session prev = META_LOCK_DEBUGGING.get();
if (prev == null) {
metaLockDebugging.set(session);
metaLockDebuggingStack.set(new Throwable("Last meta lock granted in this stack trace, "+
META_LOCK_DEBUGGING.set(session);
META_LOCK_DEBUGGING_STACK.set(new Throwable("Last meta lock granted in this stack trace, "+
"this is debug information for following IllegalStateException"));
} else if (prev != session) {
metaLockDebuggingStack.get().printStackTrace();
META_LOCK_DEBUGGING_STACK.get().printStackTrace();
throw new IllegalStateException("meta currently locked by "
+ prev +", sessionid="+ prev.getId()
+ " and trying to be locked by different session, "
......@@ -953,9 +953,9 @@ public class Database implements DataHandler {
*/
public void unlockMetaDebug(Session session) {
if (SysProperties.CHECK2) {
if (metaLockDebugging.get() == session) {
metaLockDebugging.set(null);
metaLockDebuggingStack.set(null);
if (META_LOCK_DEBUGGING.get() == session) {
META_LOCK_DEBUGGING.set(null);
META_LOCK_DEBUGGING_STACK.set(null);
}
}
}
......
......@@ -232,16 +232,15 @@ public class Session extends SessionWithState {
// It can be recursive, thus implemented as counter.
this.parsingView += parsingView ? 1 : -1;
assert this.parsingView >= 0;
if(parsingView){
if (parsingView) {
viewNameStack.push(viewName);
}else
{
} else {
assert viewName.equals(viewNameStack.peek());
viewNameStack.pop();
}
}
public String getParsingCreateViewName() {
if(viewNameStack.size()==0){
if (viewNameStack.size() == 0) {
return null;
}
return viewNameStack.peek();
......@@ -694,7 +693,8 @@ public class Session extends SessionWithState {
for (Table table : tablesToAnalyze) {
Analyze.analyzeTable(this, table, rows, false);
}
database.unlockMeta(this); // analyze can lock the meta
// analyze can lock the meta
database.unlockMeta(this);
}
tablesToAnalyze = null;
}
......
......@@ -6,7 +6,6 @@
package org.h2.index;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.concurrent.TimeUnit;
import org.h2.api.ErrorCode;
......
......@@ -48,11 +48,24 @@ import org.h2.value.Value;
* A table stored in a MVStore.
*/
public class MVTable extends TableBase {
/**
* The table name this thread is waiting to lock.
*/
public static final DebuggingThreadLocal<String> WAITING_FOR_LOCK;
private static final String NO_EXTRA_INFO = "";
/**
* The table names this thread has exclusively locked.
*/
public static final DebuggingThreadLocal<ArrayList<String>> EXCLUSIVE_LOCKS;
// lock event types for tracing...
/**
* The tables names this thread has a shared lock on.
*/
public static final DebuggingThreadLocal<ArrayList<String>> SHARED_LOCKS;
/**
* The type of trace lock events
*/
private enum TraceLockEvent{
TRACE_LOCK_OK("ok"),
......@@ -63,31 +76,17 @@ public class MVTable extends TableBase {
TRACE_LOCK_ADDED_FOR("added for"),
TRACE_LOCK_ADD_UPGRADED_FOR("add (upgraded) for ");
private TraceLockEvent(String eventText){
private final String eventText;
TraceLockEvent(String eventText) {
this.eventText = eventText;
}
private final String eventText;
public String getEventText(){
public String getEventText() {
return eventText;
}
}
/**
* The table name this thread is waiting to lock.
*/
public static final DebuggingThreadLocal<String> WAITING_FOR_LOCK;
/**
* The table names this thread has exclusively locked.
*/
public static final DebuggingThreadLocal<ArrayList<String>> EXCLUSIVE_LOCKS;
/**
* The tables names this thread has a shared lock on.
*/
public static final DebuggingThreadLocal<ArrayList<String>> SHARED_LOCKS;
private static final String NO_EXTRA_INFO = "";
static {
if (SysProperties.THREAD_DEADLOCK_DETECTOR) {
......
......@@ -112,18 +112,18 @@ public class TableView extends Table {
private Query compileViewQuery(Session session, String sql, boolean literalsChecked, String viewName) {
Prepared p;
session.setParsingCreateView(true,viewName);
session.setParsingCreateView(true, viewName);
try {
p = session.prepare(sql, false, literalsChecked);
} finally {
session.setParsingCreateView(false,viewName);
session.setParsingCreateView(false, viewName);
}
if (!(p instanceof Query)) {
throw DbException.getSyntaxError(sql, 0);
}
Query q = (Query) p;
// only potentially recursive cte queries need to be non-lazy
if(isTableExpression && allowRecursive){
if (isTableExpression && allowRecursive) {
q.setNeverLazy(true);
}
return q;
......@@ -183,7 +183,7 @@ public class TableView extends Table {
if (name == null) {
name = expr.getAlias();
}
name = columnNamer.getColumnName(expr,i,name);
name = columnNamer.getColumnName(expr, i, name);
if (type == Value.UNKNOWN) {
type = expr.getType();
}
......@@ -455,7 +455,7 @@ public class TableView extends Table {
@Override
public String getSQL() {
if (isTemporary() && querySQL!=null) {
if (isTemporary() && querySQL != null) {
return "(\n" + StringUtils.indent(querySQL) + ")";
}
return super.getSQL();
......@@ -707,7 +707,7 @@ public class TableView extends Table {
return true;
}
public List<Table> getTables(){
public List<Table> getTables() {
return tables;
}
......@@ -717,7 +717,7 @@ public class TableView extends Table {
public static TableView createTableViewMaybeRecursive(Schema schema, int id, String name, String querySQL,
ArrayList<Parameter> parameters, Column[] columnTemplates, Session session,
boolean literalsChecked, boolean isTableExpression, boolean isPersistent, Database db){
boolean literalsChecked, boolean isTableExpression, boolean isPersistent, Database db) {
Table recursiveTable = TableView.createShadowTableForRecursiveTableExpression(isPersistent, session, name,
......@@ -726,13 +726,13 @@ public class TableView extends Table {
List<Column> columnTemplateList;
String[] querySQLOutput = new String[]{null};
ArrayList<String> columnNames = new ArrayList<String>();
for(Column columnTemplate: columnTemplates){
for (Column columnTemplate: columnTemplates) {
columnNames.add(columnTemplate.getName());
}
try {
Prepared withQuery = session.prepare(querySQL, false, false);
if(isPersistent){
if (isPersistent) {
withQuery.setSession(session);
}
columnTemplateList = TableView.createQueryColumnTemplateList(columnNames.toArray(new String[1]),
......@@ -745,11 +745,11 @@ public class TableView extends Table {
// build with recursion turned on
TableView view = new TableView(schema, id, name, querySQL,
parameters, columnTemplateList.toArray(columnTemplates), session,
true/* try recursive */, literalsChecked, isTableExpression, isPersistent );
true/* try recursive */, literalsChecked, isTableExpression, isPersistent);
// is recursion really detected ? if not - recreate it without recursion flag and no recursive index
if (!view.isRecursiveQueryDetected()) {
if(isPersistent){
if (isPersistent) {
db.addSchemaObject(session, view);
view.lock(session, true, true);
session.getDatabase().removeSchemaObject(session, view);
......@@ -757,7 +757,7 @@ public class TableView extends Table {
// during database startup - this method does not normally get called - and it needs to be
// to correctly un-register the table which the table expression uses...
view.removeChildrenAndResources(session);
}else{
} else {
session.removeLocalTempTable(view);
}
view = new TableView(schema, id, name, querySQL, parameters,
......@@ -795,7 +795,7 @@ public class TableView extends Table {
// use the passed in column name if supplied, otherwise use alias
// (if found) otherwise use column name derived from column
// expression
String columnName = columnNamer.getColumnName(columnExp,i,cols);
String columnName = columnNamer.getColumnName(columnExp, i, cols);
columnTemplateList.add(new Column(columnName,
columnExp.getType()));
......@@ -820,13 +820,13 @@ public class TableView extends Table {
// this gets a meta table lock that is not released
Table recursiveTable = schema.createTable(recursiveTableData);
if(isPersistent){
if (isPersistent) {
// this unlock is to prevent lock leak from schema.createTable()
db.unlockMeta(targetSession);
synchronized (targetSession) {
db.addSchemaObject(targetSession, recursiveTable);
}
}else{
} else {
targetSession.addLocalTempTable(recursiveTable);
}
return recursiveTable;
......@@ -834,12 +834,12 @@ public class TableView extends Table {
public static void destroyShadowTableForRecursiveExpression(boolean isPersistent, Session targetSession,
Table recursiveTable) {
if(recursiveTable!=null){
if(isPersistent){
if (recursiveTable != null) {
if (isPersistent) {
recursiveTable.lock(targetSession, true, true);
targetSession.getDatabase().removeSchemaObject(targetSession, recursiveTable);
}else{
} else {
targetSession.removeLocalTempTable(recursiveTable);
}
......
......@@ -763,7 +763,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
addTest(new TestReadOnly());
addTest(new TestRecursiveQueries());
addTest(new TestGeneralCommonTableQueries());
if(!memory){
if (!memory) {
// requires persistent store for reconnection tests
addTest(new TestPersistentCommonTableExpressions());
}
......
......@@ -6,11 +6,13 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.h2.test.TestBase;
/**
* Base class for common table expression tests
*/
public abstract class AbstractBaseForCommonTableExpressions extends TestBase {
protected void testRepeatedQueryWithSetup(int maxRetries, String[] expectedRowData, String[] expectedColumnNames, int expectedNumbeOfRows, String SETUP_SQL,
String WITH_QUERY, int closeAndReopenDatabaseConnectionOnIteration, String[] expectedColumnTypes) throws SQLException {
protected void testRepeatedQueryWithSetup(int maxRetries, String[] expectedRowData, String[] expectedColumnNames, int expectedNumbeOfRows, String setupSQL,
String withQuery, int closeAndReopenDatabaseConnectionOnIteration, String[] expectedColumnTypes) throws SQLException {
deleteDb("commonTableExpressionQueries");
Connection conn = getConnection("commonTableExpressionQueries");
......@@ -18,40 +20,40 @@ public abstract class AbstractBaseForCommonTableExpressions extends TestBase {
ResultSet rs;
for(int queryRunTries=1;queryRunTries<=maxRetries;queryRunTries++){
for (int queryRunTries = 1; queryRunTries <= maxRetries; queryRunTries++) {
Statement stat = conn.createStatement();
stat.execute(SETUP_SQL);
stat.execute(setupSQL);
stat.close();
// close and re-open connection for one iteration to make sure the query work between connections
if(queryRunTries==closeAndReopenDatabaseConnectionOnIteration){
if (queryRunTries == closeAndReopenDatabaseConnectionOnIteration) {
conn.close();
conn = getConnection("commonTableExpressionQueries");
}
prep = conn.prepareStatement(WITH_QUERY);
prep = conn.prepareStatement(withQuery);
rs = prep.executeQuery();
for(int columnIndex = 1; columnIndex <= rs.getMetaData().getColumnCount(); columnIndex++){
for (int columnIndex = 1; columnIndex <= rs.getMetaData().getColumnCount(); columnIndex++) {
assertTrue(rs.getMetaData().getColumnLabel(columnIndex)!=null);
assertEquals(expectedColumnNames[columnIndex-1],rs.getMetaData().getColumnLabel(columnIndex));
assertTrue(rs.getMetaData().getColumnLabel(columnIndex) != null);
assertEquals(expectedColumnNames[columnIndex - 1], rs.getMetaData().getColumnLabel(columnIndex));
assertEquals("wrongly type column "+rs.getMetaData().getColumnLabel(columnIndex)+" on iteration#"+queryRunTries,
expectedColumnTypes[columnIndex-1],rs.getMetaData().getColumnTypeName(columnIndex));
expectedColumnTypes[columnIndex - 1], rs.getMetaData().getColumnTypeName(columnIndex));
}
int rowNdx=0;
int rowNdx = 0;
while (rs.next()) {
StringBuffer buf = new StringBuffer();
for(int columnIndex = 1; columnIndex <= rs.getMetaData().getColumnCount(); columnIndex++){
for (int columnIndex = 1; columnIndex <= rs.getMetaData().getColumnCount(); columnIndex++) {
buf.append("|"+rs.getString(columnIndex));
}
assertEquals(expectedRowData[rowNdx], buf.toString());
rowNdx++;
}
assertEquals(expectedNumbeOfRows,rowNdx);
assertEquals(expectedNumbeOfRows, rowNdx);
rs.close();
prep.close();
......
......@@ -30,9 +30,9 @@ public class TestPersistentCommonTableExpressions extends AbstractBaseForCommonT
}
private void testRecursiveTable() throws Exception {
String[] expectedRowData =new String[]{"|meat|null","|fruit|3","|veg|2"};
String[] expectedColumnTypes =new String[]{"VARCHAR","DECIMAL"};
String[] expectedColumnNames =new String[]{"VAL",
String[] expectedRowData = new String[]{"|meat|null", "|fruit|3", "|veg|2"};
String[] expectedColumnTypes = new String[]{"VARCHAR", "DECIMAL"};
String[] expectedColumnNames = new String[]{"VAL",
"SUM(SELECT\n" +
" X\n" +
"FROM PUBLIC.\"\" BB\n" +
......@@ -54,7 +54,7 @@ public class TestPersistentCommonTableExpressions extends AbstractBaseForCommonT
" /* scanCount: 1 */\n" +
"WHERE BB.A IS A.VAL)"};
String SETUP_SQL =
String setupSQL =
"DROP TABLE IF EXISTS A; "
+"DROP TABLE IF EXISTS B; "
+"DROP TABLE IF EXISTS C; "
......@@ -73,9 +73,9 @@ public class TestPersistentCommonTableExpressions extends AbstractBaseForCommonT
+"INSERT INTO C VALUES('carrot', 'nantes'); "
+"INSERT INTO C VALUES('carrot', 'imperator'); "
+"INSERT INTO C VALUES(null, 'banapple'); "
+"INSERT INTO A VALUES('meat'); "
;
String WITH_QUERY = "WITH BB as (SELECT \n" +
+"INSERT INTO A VALUES('meat'); ";
String withQuery = "WITH BB as (SELECT \n" +
"sum(1) as X, \n" +
"a \n" +
"FROM B \n" +
......@@ -88,13 +88,13 @@ public class TestPersistentCommonTableExpressions extends AbstractBaseForCommonT
int maxRetries = 3;
int expectedNumberOfRows = expectedRowData.length;
testRepeatedQueryWithSetup(maxRetries, expectedRowData, expectedColumnNames, expectedNumberOfRows, SETUP_SQL,
WITH_QUERY, maxRetries-1, expectedColumnTypes);
testRepeatedQueryWithSetup(maxRetries, expectedRowData, expectedColumnNames, expectedNumberOfRows, setupSQL,
withQuery, maxRetries - 1, expectedColumnTypes);
}
private void testPersistentRecursiveTableInCreateView() throws Exception {
String SETUP_SQL = "--SET TRACE_LEVEL_SYSTEM_OUT 3;\n"
String setuoSQL = "--SET TRACE_LEVEL_SYSTEM_OUT 3;\n"
+"DROP TABLE IF EXISTS my_tree; \n"
+"DROP VIEW IF EXISTS v_my_tree; \n"
+"CREATE TABLE my_tree ( \n"
......@@ -118,12 +118,11 @@ public class TestPersistentCommonTableExpressions extends AbstractBaseForCommonT
+"INNER JOIN tree_cte mtc ON mtc.child_fk = mt.parent_fk \n"
+"), \n"
+"unused_cte AS ( SELECT 1 AS unUsedColumn ) \n"
+"SELECT sub_tree_root_id, tree_level, parent_fk, child_fk FROM tree_cte; \n"
;
+"SELECT sub_tree_root_id, tree_level, parent_fk, child_fk FROM tree_cte; \n";
String WITH_QUERY = "SELECT * FROM v_my_tree";
String withQuery = "SELECT * FROM v_my_tree";
int maxRetries = 4;
String[] expectedRowData =new String[]{"|1|0|null|1",
String[] expectedRowData = new String[]{"|1|0|null|1",
"|11|0|1|11",
"|111|0|11|111",
"|12|0|1|12",
......@@ -135,15 +134,15 @@ public class TestPersistentCommonTableExpressions extends AbstractBaseForCommonT
"|1|2|null|111",
"|1|2|null|121"
};
String[] expectedColumnNames =new String[]{"SUB_TREE_ROOT_ID","TREE_LEVEL","PARENT_FK","CHILD_FK"};
String[] expectedColumnTypes =new String[]{"INTEGER","INTEGER","INTEGER","INTEGER"};
String[] expectedColumnNames = new String[]{"SUB_TREE_ROOT_ID", "TREE_LEVEL", "PARENT_FK", "CHILD_FK"};
String[] expectedColumnTypes = new String[]{"INTEGER", "INTEGER", "INTEGER", "INTEGER"};
int expectedNumberOfRows = 11;
testRepeatedQueryWithSetup(maxRetries, expectedRowData, expectedColumnNames, expectedNumberOfRows, SETUP_SQL,
WITH_QUERY, maxRetries-1,expectedColumnTypes);
testRepeatedQueryWithSetup(maxRetries, expectedRowData, expectedColumnNames, expectedNumberOfRows, setuoSQL,
withQuery, maxRetries - 1, expectedColumnTypes);
}
private void testPersistentNonRecursiveTableInCreateView() throws Exception {
String SETUP_SQL = ""
String setupSQL = ""
+"DROP VIEW IF EXISTS v_my_nr_tree; \n"
+"DROP TABLE IF EXISTS my_table; \n"
+"CREATE TABLE my_table ( \n"
......@@ -163,22 +162,21 @@ public class TestPersistentCommonTableExpressions extends AbstractBaseForCommonT
+" FROM my_table mt \n"
+"), \n"
+"unused_cte AS ( SELECT 1 AS unUsedColumn ) \n"
+"SELECT sub_tree_root_id, tree_level, parent_fk, child_fk FROM tree_cte_nr; \n"
;
+"SELECT sub_tree_root_id, tree_level, parent_fk, child_fk FROM tree_cte_nr; \n";
String WITH_QUERY = "SELECT * FROM v_my_nr_tree";
String withQuery = "SELECT * FROM v_my_nr_tree";
int maxRetries = 6;
String[] expectedRowData =new String[]{
String[] expectedRowData = new String[]{
"|1|0|null|1",
"|11|0|1|11",
"|111|0|11|111",
"|12|0|1|12",
"|121|0|12|121",
};
String[] expectedColumnNames =new String[]{"SUB_TREE_ROOT_ID","TREE_LEVEL","PARENT_FK","CHILD_FK"};
String[] expectedColumnTypes =new String[]{"INTEGER","INTEGER","INTEGER","INTEGER"};
String[] expectedColumnNames = new String[]{"SUB_TREE_ROOT_ID", "TREE_LEVEL", "PARENT_FK", "CHILD_FK"};
String[] expectedColumnTypes = new String[]{"INTEGER", "INTEGER", "INTEGER", "INTEGER"};
int expectedNumberOfRows = 5;
testRepeatedQueryWithSetup(maxRetries, expectedRowData, expectedColumnNames, expectedNumberOfRows, SETUP_SQL,
WITH_QUERY, maxRetries-1, expectedColumnTypes);
testRepeatedQueryWithSetup(maxRetries, expectedRowData, expectedColumnNames, expectedNumberOfRows, setupSQL,
withQuery, maxRetries - 1, expectedColumnTypes);
}
}
......@@ -78,34 +78,37 @@ public class TestMvccMultiThreaded2 extends TestBase {
// gather stats on threads after they finished
@SuppressWarnings("unused")
int minProcessed=Integer.MAX_VALUE, maxProcessed=0, totalProcessed=0;
int minProcessed = Integer.MAX_VALUE, maxProcessed = 0, totalProcessed = 0;
for (SelectForUpdate sfu : threads) {
// make sure all threads have stopped by joining with them
sfu.join();
totalProcessed+=sfu.iterationsProcessed;
if(sfu.iterationsProcessed>maxProcessed){
totalProcessed += sfu.iterationsProcessed;
if (sfu.iterationsProcessed > maxProcessed) {
maxProcessed = sfu.iterationsProcessed;
}
if(sfu.iterationsProcessed<minProcessed){
if (sfu.iterationsProcessed < minProcessed) {
minProcessed = sfu.iterationsProcessed;
}
}
if(DISPLAY_STATS){
if (DISPLAY_STATS) {
System.out.println(String.format("+ INFO: TestMvccMultiThreaded2 RUN STATS threads=%d, minProcessed=%d, maxProcessed=%d, "+
"totalProcessed=%d, averagePerThread=%d, averagePerThreadPerSecond=%d\n",
TEST_THREAD_COUNT, minProcessed, maxProcessed, totalProcessed, totalProcessed/TEST_THREAD_COUNT,
totalProcessed/(TEST_THREAD_COUNT*TEST_TIME_SECONDS)));
totalProcessed/(TEST_THREAD_COUNT * TEST_TIME_SECONDS)));
}
IOUtils.closeSilently(conn);
deleteDb(getTestName());
}
/**
* Worker test thread selecting for update
*/
private class SelectForUpdate extends Thread {
public int iterationsProcessed = 0;
public int iterationsProcessed;
@Override
public void run() {
......@@ -133,7 +136,7 @@ public class TestMvccMultiThreaded2 extends TestBase {
iterationsProcessed++;
long now = System.currentTimeMillis();
if (now - start > 1000 * TEST_TIME_SECONDS){
if (now - start > 1000 * TEST_TIME_SECONDS) {
done = true;
}
} catch (JdbcSQLException e1) {
......@@ -142,8 +145,7 @@ public class TestMvccMultiThreaded2 extends TestBase {
}
} catch (SQLException e) {
TestBase.logError("SQL error from thread "+getName(), e);
}
catch (Exception e) {
} catch (Exception e) {
TestBase.logError("General error from thread "+getName(), e);
throw e;
}
......
......@@ -51,11 +51,11 @@ public class TestMathUtils extends TestBase {
private void testNextPowerOf2Int() {
// the largest power of two that fits into an integer
final int LARGEST_POW2 = 0x40000000;
final int largestPower2 = 0x40000000;
int[] testValues = { 0, 1, 2, 3, 4, 12, 17, 500, 1023,
LARGEST_POW2-500, LARGEST_POW2 };
largestPower2 - 500, largestPower2 };
int[] resultValues = { 1, 1, 2, 4, 4, 16, 32, 512, 1024,
LARGEST_POW2, LARGEST_POW2 };
largestPower2, largestPower2 };
for (int i = 0; i < testValues.length; i++) {
assertEquals(resultValues[i], MathUtils.nextPowerOf2(testValues[i]));
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论