Repository: ignite Updated Branches: refs/heads/master 82ccc9a7b -> ccf3c9b5b
IGNITE-5243: CREATE INDEX and DROP INDEX are now allowed only on SQL caches. This closes #2049. Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/ccf3c9b5 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/ccf3c9b5 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/ccf3c9b5 Branch: refs/heads/master Commit: ccf3c9b5b5ae1fa419728babbb91fd78bc1a6227 Parents: 82ccc9a Author: Alexander Paschenko <[email protected]> Authored: Thu Jun 1 13:00:03 2017 +0300 Committer: devozerov <[email protected]> Committed: Thu Jun 1 13:00:03 2017 +0300 ---------------------------------------------------------------------- .../jdbc2/JdbcAbstractDmlStatementSelfTest.java | 5 +- .../processors/query/GridQueryProcessor.java | 10 +++ .../query/h2/ddl/DdlStatementsProcessor.java | 42 +++++++--- .../cache/index/AbstractSchemaSelfTest.java | 28 +++++++ .../DynamicIndexAbstractBasicSelfTest.java | 82 +++++++++++++++++++- .../DynamicIndexAbstractConcurrentSelfTest.java | 50 +++++++----- .../index/DynamicIndexAbstractSelfTest.java | 7 +- .../index/H2DynamicIndexAbstractSelfTest.java | 4 +- .../cache/index/SchemaExchangeSelfTest.java | 14 ++-- 9 files changed, 201 insertions(+), 41 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/ccf3c9b5/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcAbstractDmlStatementSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcAbstractDmlStatementSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcAbstractDmlStatementSelfTest.java index 81c913d..82f9cd2 100644 --- a/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcAbstractDmlStatementSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcAbstractDmlStatementSelfTest.java @@ -27,6 +27,7 @@ import java.util.Collections; import org.apache.ignite.cache.QueryEntity; import org.apache.ignite.cache.query.annotations.QuerySqlField; import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.internal.IgniteEx; import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; @@ -70,7 +71,7 @@ public abstract class JdbcAbstractDmlStatementSelfTest extends GridCommonAbstrac /** {@inheritDoc} */ @Override protected void beforeTest() throws Exception { - ignite(0).getOrCreateCache(cacheConfig()); + ((IgniteEx)ignite(0)).context().cache().dynamicStartSqlCache(cacheConfig()); conn = DriverManager.getConnection(getCfgUrl()); } @@ -136,7 +137,7 @@ public abstract class JdbcAbstractDmlStatementSelfTest extends GridCommonAbstrac /** {@inheritDoc} */ @Override protected void afterTest() throws Exception { - grid(0).destroyCache(DEFAULT_CACHE_NAME); + ((IgniteEx)ignite(0)).context().cache().dynamicDestroyCache(DEFAULT_CACHE_NAME, true, true); conn.close(); assertTrue(conn.isClosed()); http://git-wip-us.apache.org/repos/asf/ignite/blob/ccf3c9b5/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java index fef7d4c..bfbfb6c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java @@ -358,6 +358,14 @@ public class GridQueryProcessor extends GridProcessorAdapter { msg.onError(new SchemaOperationException(SchemaOperationException.CODE_CACHE_NOT_FOUND, cacheName)); } + else if (!cacheDesc.sql()) { + if (log.isDebugEnabled()) + log.debug("Received schema propose discovery message, but cache was not created through " + + "CREATE TABLE command (will report error) [opId=" + opId + ", msg=" + msg + ']');; + + msg.onError(new SchemaOperationException("CREATE INDEX and DROP INDEX operations are only allowed on " + + "caches created with CREATE TABLE command [cacheName=" + cacheName + ']')); + } else { CacheConfiguration ccfg = cacheDesc.cacheConfiguration(); @@ -593,6 +601,8 @@ public class GridQueryProcessor extends GridProcessorAdapter { boolean nop = false; if (cacheExists) { + assert cacheDesc.sql(); + if (cacheRegistered) { // If cache is started, we perform validation against real schema. T3<QueryTypeDescriptorImpl, Boolean, SchemaOperationException> res = prepareChangeOnStartedCache(op); http://git-wip-us.apache.org/repos/asf/ignite/blob/ccf3c9b5/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/ddl/DdlStatementsProcessor.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/ddl/DdlStatementsProcessor.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/ddl/DdlStatementsProcessor.java index e324ed9..7051f09 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/ddl/DdlStatementsProcessor.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/ddl/DdlStatementsProcessor.java @@ -28,6 +28,8 @@ import org.apache.ignite.cache.QueryIndex; import org.apache.ignite.cache.query.FieldsQueryCursor; import org.apache.ignite.internal.GridKernalContext; import org.apache.ignite.internal.IgniteInternalFuture; +import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor; +import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.QueryCursorImpl; import org.apache.ignite.internal.processors.cache.query.IgniteQueryErrorCode; import org.apache.ignite.internal.processors.query.GridQueryProperty; @@ -44,6 +46,7 @@ import org.apache.ignite.internal.processors.query.h2.sql.GridSqlQueryParser; import org.apache.ignite.internal.processors.query.h2.sql.GridSqlStatement; import org.apache.ignite.internal.processors.query.schema.SchemaOperationException; import org.apache.ignite.internal.util.future.GridFinishedFuture; +import org.apache.ignite.internal.util.typedef.internal.A; import org.h2.command.Prepared; import org.h2.command.ddl.CreateIndex; import org.h2.command.ddl.CreateTable; @@ -96,6 +99,15 @@ public class DdlStatementsProcessor { if (stmt0 instanceof GridSqlCreateIndex) { GridSqlCreateIndex cmd = (GridSqlCreateIndex)stmt0; + GridH2Table tbl = idx.dataTable(cmd.schemaName(), cmd.tableName()); + + if (tbl == null) + throw new SchemaOperationException(SchemaOperationException.CODE_TABLE_NOT_FOUND, cmd.tableName()); + + checkSqlCache(tbl.cache()); + + assert tbl.rowDescriptor() != null; + QueryIndex newIdx = new QueryIndex(); newIdx.setName(cmd.index().getName()); @@ -104,14 +116,6 @@ public class DdlStatementsProcessor { LinkedHashMap<String, Boolean> flds = new LinkedHashMap<>(); - GridH2Table tbl = idx.dataTable(cmd.schemaName(), cmd.tableName()); - - if (tbl == null) - throw new SchemaOperationException(SchemaOperationException.CODE_TABLE_NOT_FOUND, - cmd.tableName()); - - assert tbl.rowDescriptor() != null; - // Let's replace H2's table and property names by those operated by GridQueryProcessor. GridQueryTypeDescriptor typeDesc = tbl.rowDescriptor().type(); @@ -134,9 +138,12 @@ public class DdlStatementsProcessor { GridH2Table tbl = idx.dataTableForIndex(cmd.schemaName(), cmd.indexName()); - if (tbl != null) + if (tbl != null) { + checkSqlCache(tbl.cache()); + fut = ctx.query().dynamicIndexDrop(tbl.cacheName(), cmd.schemaName(), cmd.indexName(), cmd.ifExists()); + } else { if (cmd.ifExists()) fut = new GridFinishedFuture(); @@ -273,6 +280,23 @@ public class DdlStatementsProcessor { } /** + * Check that given context corresponds to an SQL cache. + * @param cctx Cache context. + * @throws SchemaOperationException if given context does not correspond to an SQL cache. + */ + private static void checkSqlCache(GridCacheContext cctx) throws SchemaOperationException { + A.notNull(cctx, "cctx"); + + DynamicCacheDescriptor desc = cctx.grid().context().cache().cacheDescriptor(cctx.cacheId()); + + assert desc != null; + + if (!desc.sql()) + throw new SchemaOperationException("CREATE INDEX and DROP INDEX operations are only allowed on caches " + + "created with CREATE TABLE command [cacheName=" + cctx.name() + ']'); + } + + /** * @param cmd Statement. * @return Whether {@code cmd} is a DDL statement we're able to handle. */ http://git-wip-us.apache.org/repos/asf/ignite/blob/ccf3c9b5/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/AbstractSchemaSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/AbstractSchemaSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/AbstractSchemaSelfTest.java index 91ae2f7..406cba5 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/AbstractSchemaSelfTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/AbstractSchemaSelfTest.java @@ -18,6 +18,8 @@ package org.apache.ignite.internal.processors.cache.index; import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.Ignition; import org.apache.ignite.cache.QueryEntity; import org.apache.ignite.cache.QueryIndex; @@ -25,6 +27,7 @@ import org.apache.ignite.cache.QueryIndexType; import org.apache.ignite.cache.query.SqlFieldsQuery; import org.apache.ignite.cache.query.annotations.QuerySqlField; import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.internal.IgniteEx; import org.apache.ignite.internal.IgniteInterruptedCheckedException; import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor; @@ -505,6 +508,31 @@ public class AbstractSchemaSelfTest extends GridCommonAbstractTest { } /** + * Start SQL cache on given node. + * @param node Node to create cache on. + * @param ccfg Cache configuration. + * @return Created cache. + */ + protected IgniteCache<?, ?> createSqlCache(Ignite node, CacheConfiguration ccfg) throws IgniteCheckedException { + ((IgniteEx)node).context().cache().dynamicStartSqlCache(ccfg).get(); + + IgniteCache<?, ?> res = node.cache(CACHE_NAME); + + assertNotNull(res); + + return res; + } + + /** + * Destroy SQL cache on given node. + * @param node Node to create cache on. + * @return Created cache. + */ + protected void destroySqlCache(Ignite node) throws IgniteCheckedException { + ((IgniteEx)node).context().cache().dynamicDestroyCache(CACHE_NAME, true, true).get(); + } + + /** * Execute SQL. * * @param node Ignite node. http://git-wip-us.apache.org/repos/asf/ignite/blob/ccf3c9b5/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractBasicSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractBasicSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractBasicSelfTest.java index cc6fb9a..cf83319 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractBasicSelfTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractBasicSelfTest.java @@ -18,9 +18,11 @@ package org.apache.ignite.internal.processors.cache.index; import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.Ignition; import org.apache.ignite.cache.CacheAtomicityMode; import org.apache.ignite.cache.CacheMode; +import org.apache.ignite.cache.QueryEntity; import org.apache.ignite.cache.QueryIndex; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; @@ -29,9 +31,11 @@ import org.apache.ignite.internal.IgniteEx; import org.apache.ignite.internal.processors.cache.query.IgniteQueryErrorCode; import org.apache.ignite.internal.processors.query.IgniteSQLException; import org.apache.ignite.internal.processors.query.schema.SchemaOperationException; +import org.apache.ignite.internal.util.typedef.F; import javax.cache.CacheException; import java.util.Arrays; +import java.util.Collections; import java.util.List; import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC; @@ -60,6 +64,9 @@ public abstract class DynamicIndexAbstractBasicSelfTest extends DynamicIndexAbst /** Node index for client with near-only cache. */ protected static final int IDX_CLI_NEAR_ONLY = 4; + /** Cache. */ + protected static final String STATIC_CACHE_NAME = "cache_static"; + /** {@inheritDoc} */ @Override protected void beforeTestsStarted() throws Exception { super.beforeTestsStarted(); @@ -70,7 +77,7 @@ public abstract class DynamicIndexAbstractBasicSelfTest extends DynamicIndexAbst /** {@inheritDoc} */ @Override protected void afterTest() throws Exception { - node().destroyCache(CACHE_NAME); + node().context().cache().dynamicDestroyCache(CACHE_NAME, true, true).get(); super.afterTest(); } @@ -82,8 +89,9 @@ public abstract class DynamicIndexAbstractBasicSelfTest extends DynamicIndexAbst * @param atomicityMode Atomicity mode. * @param near Near flag. */ - private void initialize(CacheMode mode, CacheAtomicityMode atomicityMode, boolean near) { - node().getOrCreateCache(cacheConfiguration(mode, atomicityMode, near)); + private void initialize(CacheMode mode, CacheAtomicityMode atomicityMode, boolean near) + throws IgniteCheckedException { + createSqlCache(node(), cacheConfiguration(mode, atomicityMode, near)); grid(IDX_CLI_NEAR_ONLY).getOrCreateNearCache(CACHE_NAME, new NearCacheConfiguration<>()); @@ -868,7 +876,7 @@ public abstract class DynamicIndexAbstractBasicSelfTest extends DynamicIndexAbst public void testFailOnLocalCache() throws Exception { for (Ignite node : Ignition.allGrids()) { if (!node.configuration().isClientMode()) - node.getOrCreateCache(cacheConfiguration().setCacheMode(LOCAL)); + createSqlCache(node, cacheConfiguration().setCacheMode(LOCAL)); } final QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_1_ESCAPED)); @@ -889,6 +897,31 @@ public abstract class DynamicIndexAbstractBasicSelfTest extends DynamicIndexAbst } /** + * Test that operations fail on statically configured cache. + * + * @throws Exception If failed. + */ + public void testFailOnNonSqlCache() throws Exception { + final QueryIndex idx = index(IDX_NAME_2, field(FIELD_NAME_1)); + + assertSchemaException(new RunnableX() { + @Override public void run() throws Exception { + dynamicIndexCreate(STATIC_CACHE_NAME, TBL_NAME, idx, true); + } + }, "CREATE INDEX and DROP INDEX operations are only allowed on caches created with CREATE TABLE command " + + "[cacheName=cache_static]", IgniteQueryErrorCode.UNKNOWN); + + assertNoIndex(STATIC_CACHE_NAME, TBL_NAME, IDX_NAME_2); + + assertSchemaException(new RunnableX() { + @Override public void run() throws Exception { + dynamicIndexDrop(STATIC_CACHE_NAME, IDX_NAME_1, true); + } + }, "CREATE INDEX and DROP INDEX operations are only allowed on caches created with CREATE TABLE command " + + "[cacheName=cache_static]", IgniteQueryErrorCode.UNKNOWN); + } + + /** * Get node which should be used to start operations. * * @return If failed. @@ -920,6 +953,32 @@ public abstract class DynamicIndexAbstractBasicSelfTest extends DynamicIndexAbst ); } + /** {@inheritDoc} */ + @Override protected IgniteConfiguration commonConfiguration(int idx) throws Exception { + IgniteConfiguration cfg = super.commonConfiguration(idx); + + if (idx != nodeIndex()) + return cfg; + + CacheConfiguration staticCacheCfg = cacheConfiguration().setName(STATIC_CACHE_NAME); + + ((QueryEntity)staticCacheCfg.getQueryEntities().iterator().next()).setIndexes(Collections.singletonList(index( + IDX_NAME_1, field(FIELD_NAME_1) + ))); + + CacheConfiguration[] newCfgs = new CacheConfiguration[F.isEmpty(cfg.getCacheConfiguration()) ? 1 : + cfg.getCacheConfiguration().length + 1]; + + if (newCfgs.length > 1) + System.arraycopy(cfg.getCacheConfiguration(), 0, newCfgs, 0, newCfgs.length - 1); + + newCfgs[newCfgs.length - 1] = staticCacheCfg; + + cfg.setCacheConfiguration(newCfgs); + + return cfg; + } + /** * Get server coordinator configuration. * @@ -988,6 +1047,17 @@ public abstract class DynamicIndexAbstractBasicSelfTest extends DynamicIndexAbst * @param expCode Error code. */ protected static void assertSchemaException(RunnableX r, int expCode) { + assertSchemaException(r, null, expCode); + } + + /** + * Ensure that schema exception is thrown. + * + * @param r Runnable. + * @param msg Exception message to expect, or {@code null} if it can be waived. + * @param expCode Error code. + */ + protected static void assertSchemaException(RunnableX r, String msg, int expCode) { try { r.run(); } @@ -1004,6 +1074,10 @@ public abstract class DynamicIndexAbstractBasicSelfTest extends DynamicIndexAbst assertEquals("Unexpected error code [expected=" + expCode + ", actual=" + code + ", msg=" + cause.getMessage() + ']', expCode, code); + if (msg != null) + assertEquals("Unexpected error message [expected=" + msg + ", actual=" + cause0.getMessage() + ']', + msg, cause0.getMessage()); + return; } catch (Exception e) { http://git-wip-us.apache.org/repos/asf/ignite/blob/ccf3c9b5/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractConcurrentSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractConcurrentSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractConcurrentSelfTest.java index 9936a81..3fb8a30 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractConcurrentSelfTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractConcurrentSelfTest.java @@ -141,7 +141,7 @@ public abstract class DynamicIndexAbstractConcurrentSelfTest extends DynamicInde // Start client which will execute operations. Ignite cli = Ignition.start(clientConfiguration(5)); - cli.getOrCreateCache(cacheConfiguration()); + createSqlCache(cli); put(srv1, 0, KEY_AFTER); @@ -200,7 +200,7 @@ public abstract class DynamicIndexAbstractConcurrentSelfTest extends DynamicInde Ignition.start(serverConfiguration(3, true)); Ignition.start(clientConfiguration(4)); - srv1.getOrCreateCache(cacheConfiguration()); + createSqlCache(srv1); blockIndexing(srv1); @@ -248,7 +248,7 @@ public abstract class DynamicIndexAbstractConcurrentSelfTest extends DynamicInde public void testNodeJoinOnPendingOperation() throws Exception { Ignite srv1 = Ignition.start(serverConfiguration(1)); - srv1.getOrCreateCache(cacheConfiguration()); + createSqlCache(srv1); blockIndexing(srv1); @@ -291,7 +291,7 @@ public abstract class DynamicIndexAbstractConcurrentSelfTest extends DynamicInde awaitPartitionMapExchange(); - IgniteCache<BinaryObject, BinaryObject> cache = srv1.createCache(cacheConfiguration()).withKeepBinary(); + IgniteCache<BinaryObject, BinaryObject> cache = createSqlCache(srv1).withKeepBinary(); // Start data change operations from several threads. final AtomicBoolean stopped = new AtomicBoolean(); @@ -384,7 +384,7 @@ public abstract class DynamicIndexAbstractConcurrentSelfTest extends DynamicInde Ignite srv1 = Ignition.start(serverConfiguration(1)); Ignite srv2 = Ignition.start(serverConfiguration(2)); - srv1.createCache(cacheConfiguration()); + createSqlCache(srv1); awaitPartitionMapExchange(); @@ -435,7 +435,7 @@ public abstract class DynamicIndexAbstractConcurrentSelfTest extends DynamicInde Ignite cli = Ignition.start(clientConfiguration(4)); // Start cache and populate it with data. - IgniteCache cache = cli.getOrCreateCache(cacheConfiguration()); + IgniteCache cache = createSqlCache(cli); put(cli, KEY_AFTER); @@ -449,8 +449,8 @@ public abstract class DynamicIndexAbstractConcurrentSelfTest extends DynamicInde Thread.sleep(100); - // Destroy cache. - cache.destroy(); + // Destroy cache (drop table). + destroySqlCache(cli); // Unblock indexing and see what happens. unblockIndexing(srv1); @@ -478,7 +478,7 @@ public abstract class DynamicIndexAbstractConcurrentSelfTest extends DynamicInde Ignite cli = Ignition.start(clientConfiguration(4)); - cli.createCache(cacheConfiguration()); + createSqlCache(cli); final AtomicBoolean stopped = new AtomicBoolean(); @@ -552,7 +552,7 @@ public abstract class DynamicIndexAbstractConcurrentSelfTest extends DynamicInde Ignite cli = Ignition.start(clientConfiguration(4)); - cli.createCache(cacheConfiguration()); + createSqlCache(cli); put(cli, 0, KEY_AFTER); @@ -650,7 +650,7 @@ public abstract class DynamicIndexAbstractConcurrentSelfTest extends DynamicInde final Ignite cli = Ignition.start(clientConfiguration(4)); - cli.createCache(cacheConfiguration()); + createSqlCache(cli); // Check index create. reconnectClientNode(srv, cli, restartCache, new RunnableX() { @@ -712,9 +712,14 @@ public abstract class DynamicIndexAbstractConcurrentSelfTest extends DynamicInde IgniteClientReconnectAbstractTest.reconnectClientNode(log, cliNode, srvNode, new Runnable() { @Override public void run() { if (restart) { - srvNode.destroyCache(CACHE_NAME); + try { + destroySqlCache(srvNode); - srvNode.getOrCreateCache(cacheConfiguration().setName(CACHE_NAME)); + createSqlCache(srvNode); + } + catch (IgniteCheckedException e) { + throw new AssertionError(e); + } } try { @@ -743,7 +748,7 @@ public abstract class DynamicIndexAbstractConcurrentSelfTest extends DynamicInde final Ignite cli = Ignition.start(clientConfiguration(4)); - cli.createCache(cacheConfiguration()); + createSqlCache(cli); final AtomicBoolean stopped = new AtomicBoolean(); @@ -842,7 +847,7 @@ public abstract class DynamicIndexAbstractConcurrentSelfTest extends DynamicInde idxFut.get(); // Make sure cache is operational at this point. - cli.getOrCreateCache(cacheConfiguration()); + createSqlCache(cli); queryProcessor(cli).dynamicIndexDrop(CACHE_NAME, CACHE_NAME, IDX_NAME_1, true).get(); queryProcessor(cli).dynamicIndexCreate(CACHE_NAME, CACHE_NAME, TBL_NAME, idx, true).get(); @@ -879,12 +884,12 @@ public abstract class DynamicIndexAbstractConcurrentSelfTest extends DynamicInde Ignite node = grid(ThreadLocalRandom.current().nextInt(1, 5)); if (exists) { - node.destroyCache(CACHE_NAME); + destroySqlCache(node); exists = false; } else { - node.createCache(cacheConfiguration()); + createSqlCache(node); exists = true; } @@ -943,7 +948,7 @@ public abstract class DynamicIndexAbstractConcurrentSelfTest extends DynamicInde idxFut.get(); // Make sure cache is operational at this point. - cli.getOrCreateCache(cacheConfiguration()); + createSqlCache(cli); queryProcessor(cli).dynamicIndexDrop(CACHE_NAME, CACHE_NAME, IDX_NAME_1, true).get(); queryProcessor(cli).dynamicIndexCreate(CACHE_NAME, CACHE_NAME, TBL_NAME, idx, true).get(); @@ -1059,4 +1064,13 @@ public abstract class DynamicIndexAbstractConcurrentSelfTest extends DynamicInde super.dynamicIndexDrop(schemaName, idxName, ifExists); } } + + /** + * Start SQL cache on given node. + * @param node Node to create cache on. + * @return Created cache. + */ + private IgniteCache<?, ?> createSqlCache(Ignite node) throws IgniteCheckedException { + return createSqlCache(node, cacheConfiguration()); + } } http://git-wip-us.apache.org/repos/asf/ignite/blob/ccf3c9b5/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractSelfTest.java index 5a58965..df1a0fc 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractSelfTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DynamicIndexAbstractSelfTest.java @@ -36,6 +36,8 @@ import org.apache.ignite.internal.binary.BinaryMarshaller; import org.apache.ignite.internal.util.typedef.T2; import org.apache.ignite.lang.IgnitePredicate; import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi; +import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder; +import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder; import javax.cache.Cache; import java.io.Serializable; @@ -50,6 +52,9 @@ import java.util.UUID; */ @SuppressWarnings({"unchecked", "ThrowableResultOfMethodCallIgnored"}) public abstract class DynamicIndexAbstractSelfTest extends AbstractSchemaSelfTest { + /** IP finder. */ + private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); + /** Attribute to filter node out of cache data nodes. */ protected static final String ATTR_FILTERED = "FILTERED"; @@ -132,7 +137,7 @@ public abstract class DynamicIndexAbstractSelfTest extends AbstractSchemaSelfTes protected IgniteConfiguration commonConfiguration(int idx) throws Exception { IgniteConfiguration cfg = super.getConfiguration(getTestIgniteInstanceName(idx)); - cfg.setDiscoverySpi(new TcpDiscoverySpi()); + cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(IP_FINDER)); cfg.setMarshaller(new BinaryMarshaller()); http://git-wip-us.apache.org/repos/asf/ignite/blob/ccf3c9b5/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicIndexAbstractSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicIndexAbstractSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicIndexAbstractSelfTest.java index 85b4e8c..ba848fb 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicIndexAbstractSelfTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/H2DynamicIndexAbstractSelfTest.java @@ -64,7 +64,7 @@ public abstract class H2DynamicIndexAbstractSelfTest extends AbstractSchemaSelfT @Override protected void beforeTest() throws Exception { super.beforeTest(); - client().getOrCreateCache(cacheConfiguration()); + createSqlCache(client(), cacheConfiguration()); assertNoIndex(CACHE_NAME, TBL_NAME_ESCAPED, IDX_NAME_1_ESCAPED); @@ -77,7 +77,7 @@ public abstract class H2DynamicIndexAbstractSelfTest extends AbstractSchemaSelfT /** {@inheritDoc} */ @Override protected void afterTest() throws Exception { - client().destroyCache(CACHE_NAME); + destroySqlCache(client()); super.afterTest(); } http://git-wip-us.apache.org/repos/asf/ignite/blob/ccf3c9b5/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/SchemaExchangeSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/SchemaExchangeSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/SchemaExchangeSelfTest.java index 33478a2..0524c75 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/SchemaExchangeSelfTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/SchemaExchangeSelfTest.java @@ -174,7 +174,7 @@ public class SchemaExchangeSelfTest extends AbstractSchemaSelfTest { assertTypes(node3, ValueClass.class); // Check restarts from the first node. - node1.destroyCache(CACHE_NAME); + destroySqlCache(node1); node1.getOrCreateCache(cacheConfiguration()); @@ -325,7 +325,7 @@ public class SchemaExchangeSelfTest extends AbstractSchemaSelfTest { if (dynamic) { node2 = startClientNoCache(2); - node2.getOrCreateCache(cacheConfiguration(KeyClass.class, ValueClass.class)); + createSqlCache(node2, cacheConfiguration(KeyClass.class, ValueClass.class)); } else node2 = startClient(2, KeyClass.class, ValueClass.class); @@ -353,7 +353,8 @@ public class SchemaExchangeSelfTest extends AbstractSchemaSelfTest { node8.cache(CACHE_NAME); assertTypes(node8, ValueClass.class); - node2.destroyCache(CACHE_NAME); + destroySqlCache(node2); + node2.getOrCreateCache( cacheConfiguration(KeyClass.class, ValueClass.class, KeyClass2.class, ValueClass2.class)); @@ -540,13 +541,16 @@ public class SchemaExchangeSelfTest extends AbstractSchemaSelfTest { cfg.setClientMode(client); cfg.setLocalHost("127.0.0.1"); - cfg.setCacheConfiguration(cacheConfiguration(clss)); cfg.setDiscoverySpi(new TestTcpDiscoverySpi()); if (filterNodeName != null && F.eq(name, filterNodeName)) cfg.setUserAttributes(Collections.singletonMap("AFF_NODE", true)); - return (IgniteEx)Ignition.start(cfg); + IgniteEx res = (IgniteEx)Ignition.start(cfg); + + createSqlCache(res, cacheConfiguration(clss)); + + return res; } /**
