Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IGNITE-4994 Restored GridH2TableSelfTest #1997

Closed
wants to merge 10 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@

package org.apache.ignite.internal.processors.query.h2;

import org.apache.ignite.internal.processors.cache.GridCacheContext;
import org.apache.ignite.internal.processors.query.h2.database.H2RowFactory;
import org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor;
import org.apache.ignite.internal.processors.query.h2.opt.GridH2SystemIndexFactory;
import org.apache.ignite.internal.processors.query.h2.opt.GridH2Table;
import org.h2.api.TableEngine;
import org.h2.command.ddl.CreateTableData;
Expand All @@ -40,7 +42,7 @@ public class H2TableEngine implements TableEngine {
private static H2RowFactory rowFactory0;

/** */
private static H2TableDescriptor tblDesc0;
private static GridH2SystemIndexFactory idxFactory0;

/** */
private static GridH2Table resTbl0;
Expand All @@ -52,37 +54,43 @@ public class H2TableEngine implements TableEngine {
* @param sql DDL clause.
* @param rowDesc Row descriptor.
* @param rowFactory Row factory.
* @param tblDesc Table descriptor.
* @param idxFactory Index factory.
* @throws SQLException If failed.
* @return Created table.
*/
public static synchronized GridH2Table createTable(Connection conn, String sql,
@Nullable GridH2RowDescriptor rowDesc, H2RowFactory rowFactory, H2TableDescriptor tblDesc)
@Nullable GridH2RowDescriptor rowDesc, H2RowFactory rowFactory, GridH2SystemIndexFactory idxFactory)
throws SQLException {
rowDesc0 = rowDesc;
rowFactory0 = rowFactory;
tblDesc0 = tblDesc;
idxFactory0 = idxFactory;

try {
try (Statement s = conn.createStatement()) {
s.execute(sql + " engine \"" + H2TableEngine.class.getName() + "\"");
}

tblDesc.table(resTbl0);
if (idxFactory instanceof H2TableDescriptor)
((H2TableDescriptor)idxFactory).table(resTbl0);

return resTbl0;
}
finally {
resTbl0 = null;
tblDesc0 = null;
idxFactory0 = null;
rowFactory0 = null;
rowDesc0 = null;
}
}

/** {@inheritDoc} */
@Override public TableBase createTable(CreateTableData createTblData) {
resTbl0 = new GridH2Table(createTblData, rowDesc0, rowFactory0, tblDesc0, tblDesc0.cache());
GridCacheContext cctx = null;

if (idxFactory0 instanceof H2TableDescriptor)
cctx = ((H2TableDescriptor)idxFactory0).cache();

resTbl0 = new GridH2Table(createTblData, rowDesc0, rowFactory0, idxFactory0, cctx);

return resTbl0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public GridH2RowDescriptor rowDescriptor() {
* @return Cache name.
*/
public String cacheName() {
return cctx.name();
return cctx != null ? cctx.name() : null;
}

/**
Expand All @@ -243,8 +243,6 @@ public GridCacheContext cache() {

ses.addLock(this);

lock(exclusive);

if (destroyed) {
unlock(exclusive);

Expand All @@ -259,6 +257,10 @@ public GridCacheContext cache() {
snapshotIndexes(null, qctx.segment());
}

// Actually lock only after we're done with snapshots - otherwise we'd get stuck forever
// as snapshotIndexes does tryLock inside its body.
lock(exclusive);

return false;
}

Expand All @@ -273,7 +275,7 @@ private boolean snapshotInLock() {
GridH2QueryContext qctx = GridH2QueryContext.get();

// On MAP queries with distributed joins we lock tables before the queries.
return qctx == null || qctx.type() != MAP || !qctx.hasIndexSnapshots();
return qctx != null && (qctx.type() != MAP || !qctx.hasIndexSnapshots());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.internal.processors.query.h2.H2TableEngine;
import org.apache.ignite.internal.processors.query.h2.database.H2PkHashIndex;
import org.apache.ignite.internal.processors.query.h2.database.H2RowFactory;
import org.apache.ignite.internal.util.lang.GridCursor;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
Expand Down Expand Up @@ -89,36 +89,29 @@ public class GridH2TableSelfTest extends GridCommonAbstractTest {

/** {@inheritDoc} */
@Override protected void beforeTest() throws Exception {
// TODO: IGNITE-4994: Restore mock.
// Driver.load();
//
// conn = DriverManager.getConnection(DB_URL);
//
// tbl = GridH2Table.Engine.createTable(conn, CREATE_TABLE_SQL, null, new GridH2Table.IndexesFactory() {
// @Override public void onTableCreated(GridH2Table tbl) {
// // No-op.
// }
//
// @Override public H2RowFactory createRowFactory(GridH2Table tbl) {
// return null;
// }
//
// @Override public ArrayList<Index> createIndexes(GridH2Table tbl) {
// ArrayList<Index> idxs = new ArrayList<>();
//
// IndexColumn id = tbl.indexColumn(0, SortOrder.ASCENDING);
// IndexColumn t = tbl.indexColumn(1, SortOrder.ASCENDING);
// IndexColumn str = tbl.indexColumn(2, SortOrder.DESCENDING);
// IndexColumn x = tbl.indexColumn(3, SortOrder.DESCENDING);
//
// idxs.add(new H2PkHashIndex(null, tbl, HASH, F.asList(id)));
// idxs.add(new GridH2TreeIndex(PK_NAME, tbl, true, F.asList(id)));
// idxs.add(new GridH2TreeIndex(NON_UNIQUE_IDX_NAME, tbl, false, F.asList(x, t, id)));
// idxs.add(new GridH2TreeIndex(STR_IDX_NAME, tbl, false, F.asList(str, id)));
//
// return idxs;
// }
// }, null);
Driver.load();

conn = DriverManager.getConnection(DB_URL);

tbl = H2TableEngine.createTable(conn, CREATE_TABLE_SQL, null, null,
new GridH2SystemIndexFactory() {
/** {@inheritDoc} */
@Override public ArrayList<Index> createSystemIndexes(GridH2Table tbl) {
ArrayList<Index> idxs = new ArrayList<>();

IndexColumn id = tbl.indexColumn(0, SortOrder.ASCENDING);
IndexColumn t = tbl.indexColumn(1, SortOrder.ASCENDING);
IndexColumn str = tbl.indexColumn(2, SortOrder.DESCENDING);
IndexColumn x = tbl.indexColumn(3, SortOrder.DESCENDING);

idxs.add(new H2PkHashIndex(null, tbl, HASH, F.asList(id)));
idxs.add(new GridH2TreeIndex(PK_NAME, tbl, true, F.asList(id)));
idxs.add(new GridH2TreeIndex(NON_UNIQUE_IDX_NAME, tbl, false, F.asList(x, t, id)));
idxs.add(new GridH2TreeIndex(STR_IDX_NAME, tbl, false, F.asList(str, id)));

return idxs;
}
});
}

/** {@inheritDoc} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@
import org.apache.ignite.internal.processors.cache.index.DynamicIndexServerNodeFilterCoordinatorBasicSelfTest;
import org.apache.ignite.internal.processors.cache.index.DynamicIndexServerBasicSelfTest;
import org.apache.ignite.internal.processors.cache.index.H2DynamicTableSelfTest;
import org.apache.ignite.internal.processors.cache.index.QueryEntityValidationSelfTest;
import org.apache.ignite.internal.processors.cache.index.SchemaExchangeSelfTest;
import org.apache.ignite.internal.processors.cache.local.IgniteCacheLocalAtomicQuerySelfTest;
import org.apache.ignite.internal.processors.cache.local.IgniteCacheLocalFieldsQuerySelfTest;
Expand All @@ -117,6 +116,7 @@
import org.apache.ignite.internal.processors.query.h2.GridH2IndexingInMemSelfTest;
import org.apache.ignite.internal.processors.query.h2.GridH2IndexingOffheapSelfTest;
import org.apache.ignite.internal.processors.query.h2.IgniteSqlQueryMinMaxTest;
import org.apache.ignite.internal.processors.query.h2.opt.GridH2TableSelfTest;
import org.apache.ignite.internal.processors.query.h2.sql.BaseH2CompareQueryTest;
import org.apache.ignite.internal.processors.query.h2.sql.GridQueryParsingTest;
import org.apache.ignite.internal.processors.query.h2.sql.H2CompareBigQueryDistributedJoinsTest;
Expand Down Expand Up @@ -150,9 +150,7 @@ public static TestSuite suite() throws Exception {
suite.addTest(new TestSuite(DynamicIndexClientBasicSelfTest.class));

// H2 tests.

// TODO: IGNITE-4994: Restore mock.
// suite.addTest(new TestSuite(GridH2TableSelfTest.class));
suite.addTest(new TestSuite(GridH2TableSelfTest.class));

suite.addTest(new TestSuite(GridH2IndexingInMemSelfTest.class));
suite.addTest(new TestSuite(GridH2IndexingOffheapSelfTest.class));
Expand Down