IGNITE-7615: Find orphaned tests without test suites, create separate test suite for them; IGNITE-8344: Remove duplicate tests and suites; IGNITE-8345: Streamline tests' class names: mark Abstract and Load tests obviously so; - Fixes #3464.
Signed-off-by: Dmitriy Pavlov <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/de9227d7 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/de9227d7 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/de9227d7 Branch: refs/heads/master Commit: de9227d7c5d69d9dcc5987e060937412bb8c22c9 Parents: 609ca35 Author: Ilya Kasnacheev <[email protected]> Authored: Tue Aug 7 13:53:37 2018 +0300 Committer: Dmitriy Pavlov <[email protected]> Committed: Tue Aug 7 13:53:37 2018 +0300 ---------------------------------------------------------------------- .../singlesplit/SingleSplitsLoadTest.java | 4 +- .../gridify/GridifySingleSplitLoadTest.java | 4 +- .../client/suite/IgniteClientTestSuite.java | 8 + ...RestProcessorAuthenticationAbstractTest.java | 143 ++++ ...ettyRestProcessorAuthenticationSelfTest.java | 143 ---- ...rocessorAuthenticationWithCredsSelfTest.java | 2 +- ...rocessorAuthenticationWithTokenSelfTest.java | 2 +- .../jdbc/suite/IgniteJdbcDriverTestSuite.java | 2 + ...istenerRWThroughDisabledAtomicCacheTest.java | 2 +- ...RWThroughDisabledTransactionalCacheTest.java | 2 +- ...nerReadWriteThroughDisabledAbstractTest.java | 291 +++++++ ...ionListenerReadWriteThroughDisabledTest.java | 291 ------- .../GridCacheConcurrentTxMultiNodeLoadTest.java | 844 ++++++++++++++++++ .../GridCacheConcurrentTxMultiNodeTest.java | 845 ------------------- ...CacheFullTextQueryMultithreadedSelfTest.java | 4 +- .../processors/cache/GridCacheLeakTest.java | 9 +- .../cache/GridCacheTtlManagerLoadTest.java | 6 +- .../cache/IgniteCacheStartStopLoadTest.java | 4 +- .../paged/PageEvictionDataStreamerTest.java | 2 +- .../PageEvictionMultinodeAbstractTest.java | 123 +++ .../PageEvictionMultinodeMixedRegionsTest.java | 2 +- .../paged/PageEvictionMultinodeTest.java | 123 --- .../PageEvictionWithRebalanceAbstractTest.java | 81 ++ .../paged/PageEvictionWithRebalanceTest.java | 81 -- .../Random2LruPageEvictionMultinodeTest.java | 2 +- ...Random2LruPageEvictionWithRebalanceTest.java | 2 +- .../RandomLruPageEvictionMultinodeTest.java | 2 +- .../RandomLruPageEvictionWithRebalanceTest.java | 2 +- .../IgniteCacheExpiryPolicyTestSuite.java | 4 +- .../IgnitePdsMultiNodePutGetRestartTest.java | 248 ------ .../pagemem/PageIdDistributionTest.java | 6 +- .../extended/GridActivationAtomicCacheSuit.java | 79 -- .../GridActivationCacheAbstractTestSuit.java | 108 --- .../GridActivationLocalAndNearCacheSuit.java | 47 -- .../GridActivationPartitionedCacheSuit.java | 78 -- .../GridActivationReplicatedCacheSuit.java | 63 -- .../future/GridFutureListenPerformanceTest.java | 111 --- .../tostring/IncludeSensitiveAbstractTest.java | 149 ++++ .../tostring/IncludeSensitiveAtomicTest.java | 2 +- .../util/tostring/IncludeSensitiveTest.java | 149 ---- .../IncludeSensitiveTransactionalTest.java | 2 +- .../GridMetadataAwareAdapterLoadSelfTest.java | 134 --- .../lang/GridMetadataAwareAdapterLoadTest.java | 134 +++ .../ignite/loadtest/GridLoadTestStatistics.java | 212 ----- .../loadtest/GridSingleExecutionTest.java | 341 -------- .../apache/ignite/loadtest/package-info.java | 22 - .../loadtests/GridLoadTestStatistics.java | 212 +++++ .../loadtests/GridSingleExecutionTest.java | 341 ++++++++ .../multisplit/GridMultiSplitsLoadTest.java | 4 +- .../GridMultiSplitsRedeployLoadTest.java | 4 +- ...ridSingleSplitsNewNodesAbstractLoadTest.java | 2 +- .../GridSingleSplitsRedeployLoadTest.java | 4 +- .../direct/session/GridSessionLoadTest.java | 4 +- .../direct/stealing/GridStealingLoadTest.java | 4 +- .../GridOffHeapMapPerformanceAbstractTest.java | 294 ------- ...apPartitionedMapPerformanceAbstractTest.java | 432 ---------- .../unsafe/GridUnsafeMapPerformanceTest.java | 32 - ...GridUnsafePartitionedMapPerformanceTest.java | 34 - .../tcp/GridTcpCommunicationSpiLanLoadTest.java | 285 +++++++ .../tcp/GridTcpCommunicationSpiLanTest.java | 285 ------- .../IgniteBinaryObjectsTestSuite.java | 12 + .../IgniteCacheDataStructuresSelfTestSuite.java | 7 + .../IgniteCacheFailoverTestSuite2.java | 6 +- .../IgniteCacheFullApiSelfTestSuite.java | 3 + .../ignite/testsuites/IgniteCacheTestSuite.java | 51 ++ .../testsuites/IgniteCacheTestSuite2.java | 49 ++ .../testsuites/IgniteCacheTestSuite3.java | 15 + .../testsuites/IgniteCacheTestSuite4.java | 2 + .../testsuites/IgniteCacheTestSuite5.java | 7 + .../testsuites/IgniteCacheTestSuite6.java | 9 + .../testsuites/IgniteComputeGridTestSuite.java | 6 + .../ignite/testsuites/IgniteIgfsTestSuite.java | 4 +- .../testsuites/IgniteKernalSelfTestSuite.java | 12 + .../testsuites/IgniteLangSelfTestSuite.java | 3 + .../testsuites/IgniteLostAndFoundTestSuite.java | 86 ++ .../testsuites/IgniteP2PSelfTestSuite.java | 2 + .../ignite/testsuites/IgnitePdsTestSuite.java | 12 + .../ignite/testsuites/IgnitePdsTestSuite2.java | 3 + .../testsuites/IgnitePerformanceTestSuite.java | 119 +++ .../IgniteSpiCheckpointSelfTestSuite.java | 4 +- .../IgniteSpiCommunicationSelfTestSuite.java | 3 + .../IgniteSpiDiscoverySelfTestSuite.java | 8 + .../testsuites/IgniteStartUpTestSuite.java | 2 +- .../testsuites/IgniteUtilSelfTestSuite.java | 24 + .../TxDeadlockDetectionTestSuite.java | 2 + .../hadoop/impl/HadoopPopularWordsTest.java | 298 ------- .../hadoop/impl/HadoopTasksAllVersionsTest.java | 264 ------ .../hadoop/impl/HadoopTasksV1Test.java | 4 +- .../hadoop/impl/HadoopTasksV2Test.java | 4 +- .../impl/HadoopTasksVersionsAbstractTest.java | 264 ++++++ .../impl/examples/HadoopPopularWords.java | 298 +++++++ .../testsuites/IgniteHadoopTestSuite.java | 5 +- .../IgniteIgfsLinuxAndMacOSTestSuite.java | 5 +- .../testsuites/IgniteHibernateTestSuite.java | 2 + .../testsuites/IgniteHibernate5TestSuite.java | 2 + .../H2DynamicIndexingComplexAbstractTest.java | 361 ++++++++ ...lexClientAtomicPartitionedNoBackupsTest.java | 2 +- ...exingComplexClientAtomicPartitionedTest.java | 2 +- ...dexingComplexClientAtomicReplicatedTest.java | 2 +- ...ntTransactionalPartitionedNoBackupsTest.java | 2 +- ...mplexClientTransactionalPartitionedTest.java | 2 +- ...omplexClientTransactionalReplicatedTest.java | 2 +- ...lexServerAtomicPartitionedNoBackupsTest.java | 2 +- ...exingComplexServerAtomicPartitionedTest.java | 2 +- ...dexingComplexServerAtomicReplicatedTest.java | 2 +- ...erTransactionalPartitionedNoBackupsTest.java | 2 +- ...mplexServerTransactionalPartitionedTest.java | 2 +- ...omplexServerTransactionalReplicatedTest.java | 2 +- .../index/H2DynamicIndexingComplexTest.java | 361 -------- .../IgniteCacheQuerySelfTestSuite.java | 32 + .../IgniteCacheQuerySelfTestSuite3.java | 14 + ...ityWithJsr310Java8DateTimeApiFieldsTest.java | 2 +- ...QueryJsr310Java8DateTimeApiAbstractTest.java | 88 ++ ...acheQueryJsr310Java8DateTimeApiBaseTest.java | 88 -- .../testsuites/IgniteSpringTestSuite.java | 6 + .../IgniteUriDeploymentTestSuite.java | 9 +- .../zk/ZookeeperDiscoverySpiTestSuite1.java | 2 + 117 files changed, 4204 insertions(+), 5232 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/de9227d7/modules/aop/src/test/java/org/apache/loadtests/direct/singlesplit/SingleSplitsLoadTest.java ---------------------------------------------------------------------- diff --git a/modules/aop/src/test/java/org/apache/loadtests/direct/singlesplit/SingleSplitsLoadTest.java b/modules/aop/src/test/java/org/apache/loadtests/direct/singlesplit/SingleSplitsLoadTest.java index b42ff71..888a2f5 100644 --- a/modules/aop/src/test/java/org/apache/loadtests/direct/singlesplit/SingleSplitsLoadTest.java +++ b/modules/aop/src/test/java/org/apache/loadtests/direct/singlesplit/SingleSplitsLoadTest.java @@ -22,7 +22,7 @@ import org.apache.ignite.IgniteException; import org.apache.ignite.compute.ComputeTaskFuture; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.internal.util.typedef.G; -import org.apache.ignite.loadtest.GridLoadTestStatistics; +import org.apache.ignite.loadtests.GridLoadTestStatistics; import org.apache.ignite.logger.log4j.Log4JLogger; import org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi; import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi; @@ -127,4 +127,4 @@ public class SingleSplitsLoadTest extends GridCommonAbstractTest { info("Final test statistics: " + stats); } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/ignite/blob/de9227d7/modules/aop/src/test/java/org/apache/loadtests/gridify/GridifySingleSplitLoadTest.java ---------------------------------------------------------------------- diff --git a/modules/aop/src/test/java/org/apache/loadtests/gridify/GridifySingleSplitLoadTest.java b/modules/aop/src/test/java/org/apache/loadtests/gridify/GridifySingleSplitLoadTest.java index 096068f..9abeb6e 100644 --- a/modules/aop/src/test/java/org/apache/loadtests/gridify/GridifySingleSplitLoadTest.java +++ b/modules/aop/src/test/java/org/apache/loadtests/gridify/GridifySingleSplitLoadTest.java @@ -20,7 +20,7 @@ package org.apache.loadtests.gridify; import org.apache.ignite.Ignite; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.internal.util.typedef.G; -import org.apache.ignite.loadtest.GridLoadTestStatistics; +import org.apache.ignite.loadtests.GridLoadTestStatistics; import org.apache.ignite.logger.log4j.Log4JLogger; import org.apache.ignite.spi.communication.CommunicationSpi; import org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi; @@ -152,4 +152,4 @@ public class GridifySingleSplitLoadTest extends GridCommonAbstractTest { return num == 1 ? 1 : num * factorial(num - 1); } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/ignite/blob/de9227d7/modules/clients/src/test/java/org/apache/ignite/internal/client/suite/IgniteClientTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/client/suite/IgniteClientTestSuite.java b/modules/clients/src/test/java/org/apache/ignite/internal/client/suite/IgniteClientTestSuite.java index e5378c3..c7017d6 100644 --- a/modules/clients/src/test/java/org/apache/ignite/internal/client/suite/IgniteClientTestSuite.java +++ b/modules/clients/src/test/java/org/apache/ignite/internal/client/suite/IgniteClientTestSuite.java @@ -18,6 +18,7 @@ package org.apache.ignite.internal.client.suite; import junit.framework.TestSuite; +import org.apache.ignite.internal.TaskEventSubjectIdSelfTest; import org.apache.ignite.internal.client.ClientDefaultCacheSelfTest; import org.apache.ignite.internal.client.ClientReconnectionSelfTest; import org.apache.ignite.internal.client.ClientTcpMultiThreadedSelfTest; @@ -48,15 +49,18 @@ import org.apache.ignite.internal.client.router.TcpSslRouterSelfTest; import org.apache.ignite.internal.client.util.ClientByteUtilsTest; import org.apache.ignite.internal.client.util.ClientConsistentHashSelfTest; import org.apache.ignite.internal.client.util.ClientJavaHasherSelfTest; +import org.apache.ignite.internal.processors.rest.ChangeStateCommandHandlerTest; import org.apache.ignite.internal.processors.rest.ClientMemcachedProtocolSelfTest; import org.apache.ignite.internal.processors.rest.JettyRestProcessorAuthenticationWithCredsSelfTest; import org.apache.ignite.internal.processors.rest.JettyRestProcessorAuthenticationWithTokenSelfTest; import org.apache.ignite.internal.processors.rest.JettyRestProcessorSignedSelfTest; import org.apache.ignite.internal.processors.rest.JettyRestProcessorUnsignedSelfTest; +import org.apache.ignite.internal.processors.rest.MemcacheRestProcessorTest; import org.apache.ignite.internal.processors.rest.RestBinaryProtocolSelfTest; import org.apache.ignite.internal.processors.rest.RestMemcacheProtocolSelfTest; import org.apache.ignite.internal.processors.rest.RestProcessorMultiStartSelfTest; import org.apache.ignite.internal.processors.rest.RestProcessorStartSelfTest; +import org.apache.ignite.internal.processors.rest.RestProcessorTest; import org.apache.ignite.internal.processors.rest.TaskCommandHandlerSelfTest; import org.apache.ignite.internal.processors.rest.TcpRestUnmarshalVulnerabilityTest; import org.apache.ignite.internal.processors.rest.protocols.tcp.TcpRestParserSelfTest; @@ -82,6 +86,7 @@ public class IgniteClientTestSuite extends TestSuite { // Test memcache protocol with custom test client. suite.addTestSuite(RestMemcacheProtocolSelfTest.class); + //suite.addTestSuite(MemcacheRestProcessorTest.class); // Test custom binary protocol with test client. suite.addTestSuite(RestBinaryProtocolSelfTest.class); @@ -101,6 +106,7 @@ public class IgniteClientTestSuite extends TestSuite { suite.addTestSuite(RedisProtocolConnectSelfTest.class); suite.addTestSuite(RedisProtocolServerSelfTest.class); + //suite.addTestSuite(RestProcessorTest.class); suite.addTestSuite(RestProcessorStartSelfTest.class); // Test cache flag conversion. @@ -137,6 +143,8 @@ public class IgniteClientTestSuite extends TestSuite { // Rest task command handler test. suite.addTestSuite(TaskCommandHandlerSelfTest.class); + //suite.addTestSuite(ChangeStateCommandHandlerTest.class); + //suite.addTestSuite(TaskEventSubjectIdSelfTest.class); // Default cache only test. suite.addTestSuite(ClientDefaultCacheSelfTest.class); http://git-wip-us.apache.org/repos/asf/ignite/blob/de9227d7/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAuthenticationAbstractTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAuthenticationAbstractTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAuthenticationAbstractTest.java new file mode 100644 index 0000000..0ed9e95 --- /dev/null +++ b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAuthenticationAbstractTest.java @@ -0,0 +1,143 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.processors.rest; + +import java.util.concurrent.Callable; +import com.fasterxml.jackson.databind.JsonNode; +import org.apache.ignite.configuration.DataRegionConfiguration; +import org.apache.ignite.configuration.DataStorageConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.processors.authentication.IgniteAccessControlException; +import org.apache.ignite.internal.processors.authentication.IgniteAuthenticationProcessor; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.testframework.GridTestUtils; + +import static org.apache.ignite.configuration.WALMode.NONE; + +/** + * Test REST with enabled authentication. + */ +public abstract class JettyRestProcessorAuthenticationAbstractTest extends JettyRestProcessorUnsignedSelfTest { + /** */ + protected static final String DFLT_USER = "ignite"; + + /** */ + protected static final String DFLT_PWD = "ignite"; + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", true); + + super.beforeTestsStarted(); + } + + /** {@inheritDoc} */ + @Override protected boolean securityEnabled() { + return true; + } + + /** {@inheritDoc} */ + @Override protected void initCache() { + // We need to activate cluster. + grid(0).cluster().active(true); + + super.initCache(); + } + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); + + cfg.setAuthenticationEnabled(true); + + // For now persistence is needed because of current authentication implementation. + DataStorageConfiguration dsCfg = new DataStorageConfiguration() + .setDefaultDataRegionConfiguration(new DataRegionConfiguration() + .setMaxSize(100 * 1024 * 1024)) + .setWalMode(NONE); + + DataRegionConfiguration testDataRegionCfg = new DataRegionConfiguration(); + testDataRegionCfg.setName("testDataRegion"); + testDataRegionCfg.setMaxSize(10 * 1024 * 1024); + + DataRegionConfiguration authDataRegionCfg = new DataRegionConfiguration(); + authDataRegionCfg.setName("authDataRegion") + .setMaxSize(10 * 1024 * 1024) + .setPersistenceEnabled(true); + + dsCfg.setDataRegionConfigurations(testDataRegionCfg, authDataRegionCfg); + + cfg.setDataStorageConfiguration(dsCfg); + + return cfg; + } + + /** + * @throws Exception If failed. + */ + public void testAuthenticationCommand() throws Exception { + String ret = content(null, GridRestCommand.AUTHENTICATE); + + assertResponseSucceeded(ret, false); + } + + /** + * @throws Exception If failed. + */ + public void testAddUpdateRemoveUser() throws Exception { + // Add user. + String ret = content(null, GridRestCommand.ADD_USER, + "user", "user1", + "password", "password1"); + + JsonNode res = jsonResponse(ret); + + assertTrue(res.asBoolean()); + + IgniteAuthenticationProcessor auth = grid(0).context().authentication(); + + assertNotNull(auth.authenticate("user1", "password1")); + + // Update user password. + ret = content(null, GridRestCommand.UPDATE_USER, + "user", "user1", + "password", "password2"); + + res = jsonResponse(ret); + + assertTrue(res.asBoolean()); + + assertNotNull(auth.authenticate("user1", "password2")); + + // Remove user. + ret = content(null, GridRestCommand.REMOVE_USER, + "user", "user1"); + + res = jsonResponse(ret); + + assertTrue(res.asBoolean()); + + GridTestUtils.assertThrows(log, new Callable<Object>() { + @Override public Object call() throws Exception { + grid(0).context().authentication().authenticate("user1", "password1"); + + return null; + } + }, IgniteAccessControlException.class, "The user name or password is incorrect"); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/de9227d7/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAuthenticationSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAuthenticationSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAuthenticationSelfTest.java deleted file mode 100644 index 27b8c03..0000000 --- a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAuthenticationSelfTest.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.processors.rest; - -import java.util.concurrent.Callable; -import com.fasterxml.jackson.databind.JsonNode; -import org.apache.ignite.configuration.DataRegionConfiguration; -import org.apache.ignite.configuration.DataStorageConfiguration; -import org.apache.ignite.configuration.IgniteConfiguration; -import org.apache.ignite.internal.processors.authentication.IgniteAccessControlException; -import org.apache.ignite.internal.processors.authentication.IgniteAuthenticationProcessor; -import org.apache.ignite.internal.util.typedef.internal.U; -import org.apache.ignite.testframework.GridTestUtils; - -import static org.apache.ignite.configuration.WALMode.NONE; - -/** - * Test REST with enabled authentication. - */ -public abstract class JettyRestProcessorAuthenticationSelfTest extends JettyRestProcessorUnsignedSelfTest { - /** */ - protected static final String DFLT_USER = "ignite"; - - /** */ - protected static final String DFLT_PWD = "ignite"; - - /** {@inheritDoc} */ - @Override protected void beforeTestsStarted() throws Exception { - U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", true); - - super.beforeTestsStarted(); - } - - /** {@inheritDoc} */ - @Override protected boolean securityEnabled() { - return true; - } - - /** {@inheritDoc} */ - @Override protected void initCache() { - // We need to activate cluster. - grid(0).cluster().active(true); - - super.initCache(); - } - - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { - IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); - - cfg.setAuthenticationEnabled(true); - - // For now persistence is needed because of current authentication implementation. - DataStorageConfiguration dsCfg = new DataStorageConfiguration() - .setDefaultDataRegionConfiguration(new DataRegionConfiguration() - .setMaxSize(100 * 1024 * 1024)) - .setWalMode(NONE); - - DataRegionConfiguration testDataRegionCfg = new DataRegionConfiguration(); - testDataRegionCfg.setName("testDataRegion"); - testDataRegionCfg.setMaxSize(10 * 1024 * 1024); - - DataRegionConfiguration authDataRegionCfg = new DataRegionConfiguration(); - authDataRegionCfg.setName("authDataRegion") - .setMaxSize(10 * 1024 * 1024) - .setPersistenceEnabled(true); - - dsCfg.setDataRegionConfigurations(testDataRegionCfg, authDataRegionCfg); - - cfg.setDataStorageConfiguration(dsCfg); - - return cfg; - } - - /** - * @throws Exception If failed. - */ - public void testAuthenticationCommand() throws Exception { - String ret = content(null, GridRestCommand.AUTHENTICATE); - - assertResponseSucceeded(ret, false); - } - - /** - * @throws Exception If failed. - */ - public void testAddUpdateRemoveUser() throws Exception { - // Add user. - String ret = content(null, GridRestCommand.ADD_USER, - "user", "user1", - "password", "password1"); - - JsonNode res = jsonResponse(ret); - - assertTrue(res.asBoolean()); - - IgniteAuthenticationProcessor auth = grid(0).context().authentication(); - - assertNotNull(auth.authenticate("user1", "password1")); - - // Update user password. - ret = content(null, GridRestCommand.UPDATE_USER, - "user", "user1", - "password", "password2"); - - res = jsonResponse(ret); - - assertTrue(res.asBoolean()); - - assertNotNull(auth.authenticate("user1", "password2")); - - // Remove user. - ret = content(null, GridRestCommand.REMOVE_USER, - "user", "user1"); - - res = jsonResponse(ret); - - assertTrue(res.asBoolean()); - - GridTestUtils.assertThrows(log, new Callable<Object>() { - @Override public Object call() throws Exception { - grid(0).context().authentication().authenticate("user1", "password1"); - - return null; - } - }, IgniteAccessControlException.class, "The user name or password is incorrect"); - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/de9227d7/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAuthenticationWithCredsSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAuthenticationWithCredsSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAuthenticationWithCredsSelfTest.java index c75e8a9..63de602 100644 --- a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAuthenticationWithCredsSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAuthenticationWithCredsSelfTest.java @@ -20,7 +20,7 @@ package org.apache.ignite.internal.processors.rest; /** * Test REST with enabled authentication and credentials in each request. */ -public class JettyRestProcessorAuthenticationWithCredsSelfTest extends JettyRestProcessorAuthenticationSelfTest { +public class JettyRestProcessorAuthenticationWithCredsSelfTest extends JettyRestProcessorAuthenticationAbstractTest { /** {@inheritDoc} */ @Override protected String restUrl() { String url = super.restUrl(); http://git-wip-us.apache.org/repos/asf/ignite/blob/de9227d7/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAuthenticationWithTokenSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAuthenticationWithTokenSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAuthenticationWithTokenSelfTest.java index 5c046af..0a1b6b9 100644 --- a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAuthenticationWithTokenSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAuthenticationWithTokenSelfTest.java @@ -22,7 +22,7 @@ import org.apache.ignite.internal.util.typedef.F; /** * Test REST with enabled authentication and token. */ -public class JettyRestProcessorAuthenticationWithTokenSelfTest extends JettyRestProcessorAuthenticationSelfTest { +public class JettyRestProcessorAuthenticationWithTokenSelfTest extends JettyRestProcessorAuthenticationAbstractTest { /** */ private String tok = ""; http://git-wip-us.apache.org/repos/asf/ignite/blob/de9227d7/modules/clients/src/test/java/org/apache/ignite/jdbc/suite/IgniteJdbcDriverTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/jdbc/suite/IgniteJdbcDriverTestSuite.java b/modules/clients/src/test/java/org/apache/ignite/jdbc/suite/IgniteJdbcDriverTestSuite.java index cf6b4f6..f3490aa 100644 --- a/modules/clients/src/test/java/org/apache/ignite/jdbc/suite/IgniteJdbcDriverTestSuite.java +++ b/modules/clients/src/test/java/org/apache/ignite/jdbc/suite/IgniteJdbcDriverTestSuite.java @@ -19,6 +19,7 @@ package org.apache.ignite.jdbc.suite; import junit.framework.TestSuite; import org.apache.ignite.internal.jdbc2.JdbcBlobTest; +import org.apache.ignite.internal.jdbc2.JdbcBulkLoadSelfTest; import org.apache.ignite.internal.jdbc2.JdbcConnectionReopenTest; import org.apache.ignite.internal.jdbc2.JdbcDistributedJoinsQueryTest; import org.apache.ignite.jdbc.JdbcComplexQuerySelfTest; @@ -127,6 +128,7 @@ public class IgniteJdbcDriverTestSuite extends TestSuite { suite.addTest(new TestSuite(org.apache.ignite.internal.jdbc2.JdbcErrorsSelfTest.class)); suite.addTest(new TestSuite(org.apache.ignite.internal.jdbc2.JdbcStreamingToPublicCacheTest.class)); suite.addTest(new TestSuite(org.apache.ignite.internal.jdbc2.JdbcNoCacheStreamingSelfTest.class)); + //suite.addTest(new TestSuite(JdbcBulkLoadSelfTest.class)); suite.addTest(new TestSuite(JdbcBlobTest.class)); suite.addTest(new TestSuite(org.apache.ignite.internal.jdbc2.JdbcStreamingSelfTest.class)); http://git-wip-us.apache.org/repos/asf/ignite/blob/de9227d7/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreListenerRWThroughDisabledAtomicCacheTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreListenerRWThroughDisabledAtomicCacheTest.java b/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreListenerRWThroughDisabledAtomicCacheTest.java index 6e28a52..8087e98 100644 --- a/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreListenerRWThroughDisabledAtomicCacheTest.java +++ b/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreListenerRWThroughDisabledAtomicCacheTest.java @@ -25,7 +25,7 @@ import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC; * This class tests that redundant calls of {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} * and {@link CacheStoreSessionListener#onSessionEnd(CacheStoreSession, boolean)} are not executed. */ -public class CacheStoreListenerRWThroughDisabledAtomicCacheTest extends CacheStoreSessionListenerReadWriteThroughDisabledTest { +public class CacheStoreListenerRWThroughDisabledAtomicCacheTest extends CacheStoreSessionListenerReadWriteThroughDisabledAbstractTest { /** {@inheritDoc} */ @Override protected CacheAtomicityMode atomicityMode() { return ATOMIC; http://git-wip-us.apache.org/repos/asf/ignite/blob/de9227d7/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreListenerRWThroughDisabledTransactionalCacheTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreListenerRWThroughDisabledTransactionalCacheTest.java b/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreListenerRWThroughDisabledTransactionalCacheTest.java index fd784a3..4503815 100644 --- a/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreListenerRWThroughDisabledTransactionalCacheTest.java +++ b/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreListenerRWThroughDisabledTransactionalCacheTest.java @@ -35,7 +35,7 @@ import static org.apache.ignite.transactions.TransactionIsolation.SERIALIZABLE; * This class tests that redundant calls of {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} * and {@link CacheStoreSessionListener#onSessionEnd(CacheStoreSession, boolean)} are not executed. */ -public class CacheStoreListenerRWThroughDisabledTransactionalCacheTest extends CacheStoreSessionListenerReadWriteThroughDisabledTest { +public class CacheStoreListenerRWThroughDisabledTransactionalCacheTest extends CacheStoreSessionListenerReadWriteThroughDisabledAbstractTest { /** {@inheritDoc} */ @Override protected CacheAtomicityMode atomicityMode() { return TRANSACTIONAL; http://git-wip-us.apache.org/repos/asf/ignite/blob/de9227d7/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreSessionListenerReadWriteThroughDisabledAbstractTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreSessionListenerReadWriteThroughDisabledAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreSessionListenerReadWriteThroughDisabledAbstractTest.java new file mode 100644 index 0000000..ab4477d --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreSessionListenerReadWriteThroughDisabledAbstractTest.java @@ -0,0 +1,291 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.cache.store; + +import java.io.PrintWriter; +import java.io.Serializable; +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.SQLFeatureNotSupportedException; +import java.util.HashSet; +import java.util.Map; +import java.util.Random; +import java.util.Set; +import java.util.TreeMap; +import java.util.logging.Logger; +import javax.cache.Cache; +import javax.cache.configuration.Factory; +import javax.cache.configuration.FactoryBuilder; +import javax.cache.integration.CacheLoaderException; +import javax.cache.integration.CacheWriterException; +import javax.sql.DataSource; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.cache.store.jdbc.CacheJdbcStoreSessionListener; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.NearCacheConfiguration; +import org.apache.ignite.internal.processors.cache.GridCacheAbstractSelfTest; + +/** + * This class tests that redundant calls of {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} + * and {@link CacheStoreSessionListener#onSessionEnd(CacheStoreSession, boolean)} are not executed. + */ +public abstract class CacheStoreSessionListenerReadWriteThroughDisabledAbstractTest extends GridCacheAbstractSelfTest { + /** {@inheritDoc} */ + protected int gridCount() { + return 2; + } + + /** */ + protected final int CNT = 100; + + /** {@inheritDoc} */ + protected CacheConfiguration cacheConfiguration(String igniteInstanceName) throws Exception { + CacheConfiguration cacheCfg = super.cacheConfiguration(igniteInstanceName); + + cacheCfg.setCacheStoreFactory(FactoryBuilder.factoryOf(EmptyCacheStore.class)); + + cacheCfg.setCacheStoreSessionListenerFactories(new CacheStoreSessionFactory()); + + cacheCfg.setReadThrough(false); + cacheCfg.setWriteThrough(false); + + cacheCfg.setBackups(0); + + return cacheCfg; + } + + /** {@inheritDoc} */ + protected NearCacheConfiguration nearConfiguration() { + return null; + } + + /** + * Tests that there are no calls of {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} and + * {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} + * while {@link IgniteCache#get(Object)} performed. + * + * @throws Exception If failed. + */ + public void testLookup() throws Exception { + IgniteCache<Object, Object> cache = grid(0).getOrCreateCache(DEFAULT_CACHE_NAME); + + Random r = new Random(); + + for (int i = 0; i < CNT; ++i) + cache.get(r.nextInt()); + } + + /** + * Tests that there are no calls of {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} and + * {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} + * while {@link IgniteCache#getAll(Set)} performed. + * + * @throws Exception If failed. + */ + public void testBatchLookup() throws Exception { + IgniteCache<Object, Object> cache = grid(0).getOrCreateCache(DEFAULT_CACHE_NAME); + + Random r = new Random(); + + Set<Object> values = new HashSet<>(); + + for (int i = 0; i < CNT; ++i) + values.add(r.nextInt()); + + cache.getAll(values); + } + + /** + * Tests that there are no calls of {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} and + * {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} + * while {@link IgniteCache#put(Object, Object)} performed. + * + * @throws Exception If failed. + */ + public void testUpdate() throws Exception { + IgniteCache<Object, Object> cache = grid(0).getOrCreateCache(DEFAULT_CACHE_NAME); + + Random r = new Random(); + + for (int i = 0; i < CNT; ++i) + cache.put(r.nextInt(), "test-value"); + } + + /** + * Tests that there are no calls of {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} and + * {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} + * while {@link IgniteCache#putAll(Map)} performed. + * + * @throws Exception If failed. + */ + public void testBatchUpdate() throws Exception { + IgniteCache<Object, Object> cache = grid(0).getOrCreateCache(DEFAULT_CACHE_NAME); + + Random r = new Random(); + + Map<Object, Object> values = new TreeMap<>(); + + for (int i = 0; i < CNT; ++i) + values.put(r.nextInt(), "test-value"); + + cache.putAll(values); + } + + /** + * Tests that there are no calls of {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} and + * {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} + * while {@link IgniteCache#remove(Object)} performed. + * + * @throws Exception If failed. + */ + public void testRemove() throws Exception { + IgniteCache<Object, Object> cache = grid(0).getOrCreateCache(DEFAULT_CACHE_NAME); + + Random r = new Random(); + + for (int i = 0; i < CNT; ++i) { + int key = r.nextInt(); + + cache.put(key, "test-value"); + + cache.remove(key); + } + } + + /** + * Tests that there are no calls of {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} and + * {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} + * while {@link IgniteCache#removeAll(Set)} performed. + * + * @throws Exception If failed. + */ + public void testBatchRemove() throws Exception { + IgniteCache<Object, Object> cache = grid(0).getOrCreateCache(DEFAULT_CACHE_NAME); + + Random r = new Random(); + + Set<Object> values = new HashSet<>(); + + for (int i = 0; i < CNT; ++i) { + int key = r.nextInt(); + + cache.put(key, "test-value"); + + values.add(key); + } + + cache.removeAll(values); + } + + /** + * Cache store session factory. + */ + public static class CacheStoreSessionFactory implements Factory<TestCacheStoreSessionListener> { + /** {@inheritDoc} */ + @Override public TestCacheStoreSessionListener create() { + TestCacheStoreSessionListener lsnr = new TestCacheStoreSessionListener(); + lsnr.setDataSource(new DataSourceStub()); + return lsnr; + } + } + + /** + * Test cache store session listener. + */ + public static class TestCacheStoreSessionListener extends CacheJdbcStoreSessionListener { + /** {@inheritDoc} */ + @Override public void onSessionStart(CacheStoreSession ses) { + fail("TestCacheStoreSessionListener.onSessionStart(CacheStoreSession) should not be called."); + } + + /** {@inheritDoc} */ + @Override public void onSessionEnd(CacheStoreSession ses, boolean commit) { + fail("TestCacheStoreSessionListener.onSessionEnd(CacheStoreSession, boolean) should not be called."); + } + } + + /** Empty cache store implementation. All overridden methods should not be called while the test is running. */ + public static class EmptyCacheStore extends CacheStoreAdapter { + /** {@inheritDoc} */ + @Override public Object load(Object key) throws CacheLoaderException { + fail("EmptyCacheStore.load(Object) should not be called."); + + return null; + } + + /** {@inheritDoc} */ + @Override public void write(Cache.Entry entry) throws CacheWriterException { + fail("EmptyCacheStore.write(Cache.Entry) should not be called."); + } + + /** {@inheritDoc} */ + @Override public void delete(Object key) throws CacheWriterException { + fail("EmptyCacheStore.delete(Object) should not be called."); + } + } + + /** + * Data source stub which should not be called. + */ + public static class DataSourceStub implements DataSource, Serializable { + /** {@inheritDoc} */ + @Override public Connection getConnection() throws SQLException { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override public Connection getConnection(String username, String password) throws SQLException { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override public <T> T unwrap(Class<T> iface) throws SQLException { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override public boolean isWrapperFor(Class<?> iface) throws SQLException { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override public PrintWriter getLogWriter() throws SQLException { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override public void setLogWriter(PrintWriter out) throws SQLException { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override public void setLoginTimeout(int seconds) throws SQLException { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override public int getLoginTimeout() throws SQLException { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override public Logger getParentLogger() throws SQLFeatureNotSupportedException { + throw new UnsupportedOperationException(); + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/de9227d7/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreSessionListenerReadWriteThroughDisabledTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreSessionListenerReadWriteThroughDisabledTest.java b/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreSessionListenerReadWriteThroughDisabledTest.java deleted file mode 100644 index 150e157..0000000 --- a/modules/core/src/test/java/org/apache/ignite/cache/store/CacheStoreSessionListenerReadWriteThroughDisabledTest.java +++ /dev/null @@ -1,291 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.cache.store; - -import java.io.PrintWriter; -import java.io.Serializable; -import java.sql.Connection; -import java.sql.SQLException; -import java.sql.SQLFeatureNotSupportedException; -import java.util.HashSet; -import java.util.Map; -import java.util.Random; -import java.util.Set; -import java.util.TreeMap; -import java.util.logging.Logger; -import javax.cache.Cache; -import javax.cache.configuration.Factory; -import javax.cache.configuration.FactoryBuilder; -import javax.cache.integration.CacheLoaderException; -import javax.cache.integration.CacheWriterException; -import javax.sql.DataSource; -import org.apache.ignite.IgniteCache; -import org.apache.ignite.cache.store.jdbc.CacheJdbcStoreSessionListener; -import org.apache.ignite.configuration.CacheConfiguration; -import org.apache.ignite.configuration.NearCacheConfiguration; -import org.apache.ignite.internal.processors.cache.GridCacheAbstractSelfTest; - -/** - * This class tests that redundant calls of {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} - * and {@link CacheStoreSessionListener#onSessionEnd(CacheStoreSession, boolean)} are not executed. - */ -public abstract class CacheStoreSessionListenerReadWriteThroughDisabledTest extends GridCacheAbstractSelfTest { - /** {@inheritDoc} */ - protected int gridCount() { - return 2; - } - - /** */ - protected final int CNT = 100; - - /** {@inheritDoc} */ - protected CacheConfiguration cacheConfiguration(String igniteInstanceName) throws Exception { - CacheConfiguration cacheCfg = super.cacheConfiguration(igniteInstanceName); - - cacheCfg.setCacheStoreFactory(FactoryBuilder.factoryOf(EmptyCacheStore.class)); - - cacheCfg.setCacheStoreSessionListenerFactories(new CacheStoreSessionFactory()); - - cacheCfg.setReadThrough(false); - cacheCfg.setWriteThrough(false); - - cacheCfg.setBackups(0); - - return cacheCfg; - } - - /** {@inheritDoc} */ - protected NearCacheConfiguration nearConfiguration() { - return null; - } - - /** - * Tests that there are no calls of {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} and - * {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} - * while {@link IgniteCache#get(Object)} performed. - * - * @throws Exception If failed. - */ - public void testLookup() throws Exception { - IgniteCache<Object, Object> cache = grid(0).getOrCreateCache(DEFAULT_CACHE_NAME); - - Random r = new Random(); - - for (int i = 0; i < CNT; ++i) - cache.get(r.nextInt()); - } - - /** - * Tests that there are no calls of {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} and - * {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} - * while {@link IgniteCache#getAll(Set)} performed. - * - * @throws Exception If failed. - */ - public void testBatchLookup() throws Exception { - IgniteCache<Object, Object> cache = grid(0).getOrCreateCache(DEFAULT_CACHE_NAME); - - Random r = new Random(); - - Set<Object> values = new HashSet<>(); - - for (int i = 0; i < CNT; ++i) - values.add(r.nextInt()); - - cache.getAll(values); - } - - /** - * Tests that there are no calls of {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} and - * {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} - * while {@link IgniteCache#put(Object, Object)} performed. - * - * @throws Exception If failed. - */ - public void testUpdate() throws Exception { - IgniteCache<Object, Object> cache = grid(0).getOrCreateCache(DEFAULT_CACHE_NAME); - - Random r = new Random(); - - for (int i = 0; i < CNT; ++i) - cache.put(r.nextInt(), "test-value"); - } - - /** - * Tests that there are no calls of {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} and - * {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} - * while {@link IgniteCache#putAll(Map)} performed. - * - * @throws Exception If failed. - */ - public void testBatchUpdate() throws Exception { - IgniteCache<Object, Object> cache = grid(0).getOrCreateCache(DEFAULT_CACHE_NAME); - - Random r = new Random(); - - Map<Object, Object> values = new TreeMap<>(); - - for (int i = 0; i < CNT; ++i) - values.put(r.nextInt(), "test-value"); - - cache.putAll(values); - } - - /** - * Tests that there are no calls of {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} and - * {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} - * while {@link IgniteCache#remove(Object)} performed. - * - * @throws Exception If failed. - */ - public void testRemove() throws Exception { - IgniteCache<Object, Object> cache = grid(0).getOrCreateCache(DEFAULT_CACHE_NAME); - - Random r = new Random(); - - for (int i = 0; i < CNT; ++i) { - int key = r.nextInt(); - - cache.put(key, "test-value"); - - cache.remove(key); - } - } - - /** - * Tests that there are no calls of {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} and - * {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} - * while {@link IgniteCache#removeAll(Set)} performed. - * - * @throws Exception If failed. - */ - public void testBatchRemove() throws Exception { - IgniteCache<Object, Object> cache = grid(0).getOrCreateCache(DEFAULT_CACHE_NAME); - - Random r = new Random(); - - Set<Object> values = new HashSet<>(); - - for (int i = 0; i < CNT; ++i) { - int key = r.nextInt(); - - cache.put(key, "test-value"); - - values.add(key); - } - - cache.removeAll(values); - } - - /** - * Cache store session factory. - */ - public static class CacheStoreSessionFactory implements Factory<TestCacheStoreSessionListener> { - /** {@inheritDoc} */ - @Override public TestCacheStoreSessionListener create() { - TestCacheStoreSessionListener lsnr = new TestCacheStoreSessionListener(); - lsnr.setDataSource(new DataSourceStub()); - return lsnr; - } - } - - /** - * Test cache store session listener. - */ - public static class TestCacheStoreSessionListener extends CacheJdbcStoreSessionListener { - /** {@inheritDoc} */ - @Override public void onSessionStart(CacheStoreSession ses) { - fail("TestCacheStoreSessionListener.onSessionStart(CacheStoreSession) should not be called."); - } - - /** {@inheritDoc} */ - @Override public void onSessionEnd(CacheStoreSession ses, boolean commit) { - fail("TestCacheStoreSessionListener.onSessionEnd(CacheStoreSession, boolean) should not be called."); - } - } - - /** Empty cache store implementation. All overridden methods should not be called while the test is running. */ - public static class EmptyCacheStore extends CacheStoreAdapter { - /** {@inheritDoc} */ - @Override public Object load(Object key) throws CacheLoaderException { - fail("EmptyCacheStore.load(Object) should not be called."); - - return null; - } - - /** {@inheritDoc} */ - @Override public void write(Cache.Entry entry) throws CacheWriterException { - fail("EmptyCacheStore.write(Cache.Entry) should not be called."); - } - - /** {@inheritDoc} */ - @Override public void delete(Object key) throws CacheWriterException { - fail("EmptyCacheStore.delete(Object) should not be called."); - } - } - - /** - * Data source stub which should not be called. - */ - public static class DataSourceStub implements DataSource, Serializable { - /** {@inheritDoc} */ - @Override public Connection getConnection() throws SQLException { - throw new UnsupportedOperationException(); - } - - /** {@inheritDoc} */ - @Override public Connection getConnection(String username, String password) throws SQLException { - throw new UnsupportedOperationException(); - } - - /** {@inheritDoc} */ - @Override public <T> T unwrap(Class<T> iface) throws SQLException { - throw new UnsupportedOperationException(); - } - - /** {@inheritDoc} */ - @Override public boolean isWrapperFor(Class<?> iface) throws SQLException { - throw new UnsupportedOperationException(); - } - - /** {@inheritDoc} */ - @Override public PrintWriter getLogWriter() throws SQLException { - throw new UnsupportedOperationException(); - } - - /** {@inheritDoc} */ - @Override public void setLogWriter(PrintWriter out) throws SQLException { - throw new UnsupportedOperationException(); - } - - /** {@inheritDoc} */ - @Override public void setLoginTimeout(int seconds) throws SQLException { - throw new UnsupportedOperationException(); - } - - /** {@inheritDoc} */ - @Override public int getLoginTimeout() throws SQLException { - throw new UnsupportedOperationException(); - } - - /** {@inheritDoc} */ - @Override public Logger getParentLogger() throws SQLFeatureNotSupportedException { - throw new UnsupportedOperationException(); - } - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/de9227d7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentTxMultiNodeLoadTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentTxMultiNodeLoadTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentTxMultiNodeLoadTest.java new file mode 100644 index 0000000..0d2dc00 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentTxMultiNodeLoadTest.java @@ -0,0 +1,844 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.processors.cache; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.Callable; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.atomic.AtomicLong; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteAtomicSequence; +import org.apache.ignite.IgniteCompute; +import org.apache.ignite.IgniteException; +import org.apache.ignite.cache.CacheMode; +import org.apache.ignite.cache.affinity.AffinityKey; +import org.apache.ignite.cache.affinity.AffinityKeyMapped; +import org.apache.ignite.cache.eviction.lru.LruEvictionPolicy; +import org.apache.ignite.cache.query.annotations.QueryGroupIndex; +import org.apache.ignite.cache.query.annotations.QuerySqlField; +import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.compute.ComputeJob; +import org.apache.ignite.compute.ComputeJobAdapter; +import org.apache.ignite.compute.ComputeJobResult; +import org.apache.ignite.compute.ComputeTaskFuture; +import org.apache.ignite.compute.ComputeTaskSplitAdapter; +import org.apache.ignite.configuration.AtomicConfiguration; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.IgniteKernal; +import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter; +import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry; +import org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheAdapter; +import org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheEntry; +import org.apache.ignite.internal.util.GridAtomicLong; +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.internal.util.typedef.G; +import org.apache.ignite.internal.util.typedef.P1; +import org.apache.ignite.internal.util.typedef.T2; +import org.apache.ignite.internal.util.typedef.T5; +import org.apache.ignite.internal.util.typedef.X; +import org.apache.ignite.lang.IgnitePredicate; +import org.apache.ignite.lang.IgniteUuid; +import org.apache.ignite.resources.IgniteInstanceResource; +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 org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.apache.ignite.transactions.Transaction; +import org.jetbrains.annotations.Nullable; + +import static org.apache.ignite.cache.CacheMode.PARTITIONED; +import static org.apache.ignite.cache.CacheRebalanceMode.NONE; +import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC; +import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC; +import static org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ; + +/** + * + */ +public class GridCacheConcurrentTxMultiNodeLoadTest extends GridCommonAbstractTest { + /** IP finder. */ + private static final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); + + /** Timers. */ + private static final ConcurrentMap<Thread, ConcurrentMap<String, T5<Long, Long, Long, IgniteUuid, Object>>> timers = + new ConcurrentHashMap<>(); + + /** */ + private static final long PRINT_FREQ = 10000; + + /** */ + private static final GridAtomicLong lastPrint = new GridAtomicLong(); + + /** */ + private static final IgnitePredicate<ClusterNode> serverNode = new P1<ClusterNode>() { + @Override public boolean apply(ClusterNode n) { + String igniteInstanceName = G.ignite(n.id()).name(); + + return igniteInstanceName != null && igniteInstanceName.contains("server"); + } + }; + + /** */ + private static final IgnitePredicate<ClusterNode> clientNode = new P1<ClusterNode>() { + @Override public boolean apply(ClusterNode n) { + String igniteInstanceName = G.ignite(n.id()).name(); + + return igniteInstanceName != null && igniteInstanceName.contains("client"); + } + }; + + /** */ + private CacheMode mode = PARTITIONED; + + /** */ + private boolean cacheOn; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + IgniteConfiguration c = super.getConfiguration(igniteInstanceName); + + c.getTransactionConfiguration().setDefaultTxConcurrency(PESSIMISTIC); + c.getTransactionConfiguration().setDefaultTxIsolation(REPEATABLE_READ); + + AtomicConfiguration atomicCfg = new AtomicConfiguration(); + + atomicCfg.setAtomicSequenceReserveSize(100000); + atomicCfg.setCacheMode(mode); + + c.setAtomicConfiguration(atomicCfg); + + if (cacheOn) { + CacheConfiguration cc = defaultCacheConfiguration(); + + cc.setCacheMode(mode); + + LruEvictionPolicy plc = new LruEvictionPolicy(); + plc.setMaxSize(1000); + + cc.setEvictionPolicy(plc); + cc.setOnheapCacheEnabled(true); + cc.setWriteSynchronizationMode(FULL_SYNC); + cc.setRebalanceMode(NONE); + + c.setCacheConfiguration(cc); + } + else + c.setCacheConfiguration(); + + TcpDiscoverySpi disco = new TcpDiscoverySpi(); + + disco.setIpFinder(ipFinder); + + c.setDiscoverySpi(disco); + + c.setPeerClassLoadingEnabled(false); + + return c; + } + + /** {@inheritDoc} */ + @Override protected long getTestTimeout() { + return Long.MAX_VALUE; + } + + /** + * @throws Exception If failed. + */ + public void testEvictions() throws Exception { + try { + cacheOn = true; + + Ignite srvr1 = startGrid("server1"); + + srvr1.atomicSequence("ID", 0, true); + + startGrid("server2"); + + cacheOn = false; + + // Client processes count. + int clientCnt = 8; + + for (int i = 1; i <= clientCnt; i++) + startGrid("client" + i); + + Collection<ClusterNode> srvrNodes = srvr1.cluster().forPredicate(serverNode).nodes(); + Collection<ClusterNode> clientNodes = srvr1.cluster().forPredicate(clientNode).nodes(); + + assert srvrNodes.size() == 2; + + // Threads count per each client process. + int threadCnt = 2; + + int srvrMaxNoTerminals = threadCnt / srvrNodes.size(); + + if (srvrMaxNoTerminals * srvrNodes.size() != threadCnt) { + threadCnt = srvrMaxNoTerminals * srvrNodes.size(); + + info("Using " + threadCnt + " threads instead to ensure equal distribution of terminals"); + } + + Collection<Callable<Object>> clients = new ArrayList<>(threadCnt * clientCnt); + + info("No of servers: " + srvrNodes.size()); + info("No of clients: " + clientNodes.size()); + info("Thread count: " + threadCnt); + info("Max number of terminals / server: " + srvrMaxNoTerminals); + + // Distribute terminals evenly across all servers + for (ClusterNode node : srvrNodes) { + UUID srvrId = node.id(); + + info(">>> Node ID: " + srvrId); + + int terminalsPerSrvr = 0; + + int tid = 0; // Terminal ID. + + while (true) { + String terminalId = String.valueOf(++tid); + + // Server partition cache + UUID mappedId = srvr1.affinity(DEFAULT_CACHE_NAME).mapKeyToNode(terminalId).id(); + + if (!srvrId.equals(mappedId)) + continue; + + info("Affinity mapping [key=" + terminalId + ", nodeId=" + mappedId + ']'); + + for (int i = 1; i <= clientCnt; i++) + clients.add(new Client(G.ignite("client" + i), terminalId, srvrId)); + + info("Terminal ID: " + terminalId); + + terminalsPerSrvr++; + + if (terminalsPerSrvr == srvrMaxNoTerminals) + break; + } + } + + displayReqCount(); + + ExecutorService pool = Executors.newFixedThreadPool(clients.size()); + + pool.invokeAll(clients); + + Thread.sleep(Long.MAX_VALUE); + } + finally { + stopAllGrids(); + } + } + + /** + * + */ + private void displayReqCount() { + new Thread(new Runnable() { + @SuppressWarnings({"BusyWait", "InfiniteLoopStatement"}) + @Override public void run() { + int interval = 10; + + while (true) { + long cnt0 = Client.txCnt.get(); + long lt0 = Client.latency.get(); + + try { + Thread.sleep(interval * 1000); + } + catch (InterruptedException e) { + e.printStackTrace(); + } + + long cnt1 = Client.txCnt.get(); + long lt1 = Client.latency.get(); + + info(">>>"); + info(">>> Transaction/s: " + (cnt1 - cnt0) / interval); + info(">>> Avg Latency: " + ((cnt1 - cnt0) > 0 ? (lt1 - lt0) / (cnt1 - cnt0) + "ms" : "invalid")); + info(">>> Max Submit Time: " + Client.submitTime.getAndSet(0)); + + try { + PerfJob.printTimers(); + } + catch (Exception e) { + e.printStackTrace(); + } + } + } + }).start(); + } + + /** + * + */ + private static class Client implements Callable<Object> { + /** */ + private static AtomicLong txCnt = new AtomicLong(); + + /** */ + private static AtomicLong latency = new AtomicLong(); + + /** */ + private static GridAtomicLong submitTime = new GridAtomicLong(); + + + /** */ + private Ignite g; + + /** */ + private String terminalId; + + /** */ + private UUID nodeId; + + /** + * @param g Grid. + * @param terminalId Terminal ID. + * @param nodeId Node ID. + */ + private Client(Ignite g, String terminalId, UUID nodeId) { + this.g = g; + this.terminalId = terminalId; + this.nodeId = nodeId; + } + + /** {@inheritDoc} */ + @SuppressWarnings({"InfiniteLoopStatement"}) + @Override public Object call() throws Exception { + while (true) { + try { + long t0 = System.currentTimeMillis(); + + long submitTime1 = t0; + + IgniteCompute comp = g.compute(g.cluster().forPredicate(serverNode)); + + ComputeTaskFuture<Void> f1 = comp.executeAsync(RequestTask.class, new Message(terminalId, nodeId)); + + submitTime.setIfGreater(System.currentTimeMillis() - submitTime1); + + f1.get(); + + submitTime1 = System.currentTimeMillis(); + + ComputeTaskFuture<Void> f2 = comp.executeAsync(ResponseTask.class, new Message(terminalId, nodeId)); + + submitTime.setIfGreater(System.currentTimeMillis() - submitTime1); + + f2.get(); + + long t1 = System.currentTimeMillis(); + + txCnt.incrementAndGet(); + + latency.addAndGet(t1 - t0); + } + catch (IgniteException e) { + e.printStackTrace(); + } + } + } + } + + + /** + * + */ + private static class Message implements Serializable { + /** */ + private String terminalId; + + /** */ + private UUID nodeId; + + /** + * @param terminalId Terminal ID. + * @param nodeId Node ID. + */ + Message(String terminalId, UUID nodeId) { + this.terminalId = terminalId; + this.nodeId = nodeId; + } + + /** + * @return Terminal ID. + */ + String getTerminalId() { + return terminalId; + } + + /** + * @param terminalId Terminal ID. + */ + void setTerminalId(String terminalId) { + this.terminalId = terminalId; + } + + /** + * @return Node ID. + */ + UUID getNodeId() { + return nodeId; + } + + /** + * @param nodeId Node ID. + */ + void setNodeId(UUID nodeId) { + this.nodeId = nodeId; + } + } + + /** + * + */ + private static class PerfJob extends ComputeJobAdapter { + /** */ + private static final long MAX = 5000; + + /** */ + @AffinityKeyMapped + private String affKey; + + /** */ + @IgniteInstanceResource + private Ignite ignite; + + /** + * @param msg Message. + */ + PerfJob(Message msg) { + super(msg); + + affKey = msg.getTerminalId(); + } + + /** + * @return Message. + */ + private Message message() { + return argument(0); + } + + /** + * @return Terminal ID. + */ + public String terminalId() { + return message().getTerminalId(); + } + + /** {@inheritDoc} */ + @Override public Object execute() { + ConcurrentMap<String, T2<AtomicLong, AtomicLong>> nodeLoc = ignite.cluster().nodeLocalMap(); + + T2<AtomicLong, AtomicLong> cntrs = nodeLoc.get("cntrs"); + + if (cntrs == null) { + T2<AtomicLong, AtomicLong> other = nodeLoc.putIfAbsent("cntrs", + cntrs = new T2<>(new AtomicLong(), new AtomicLong(System.currentTimeMillis()))); + + if (other != null) + cntrs = other; + } + + long cnt = cntrs.get1().incrementAndGet(); + + doWork(); + + GridNearCacheAdapter near = (GridNearCacheAdapter)((IgniteKernal) ignite).internalCache(DEFAULT_CACHE_NAME); + GridDhtCacheAdapter dht = near.dht(); + + long start = cntrs.get2().get(); + + long now = System.currentTimeMillis(); + + long dur = now - start; + + if (dur > 20000 && cntrs.get2().compareAndSet(start, System.currentTimeMillis())) { + cntrs.get1().set(0); + + X.println("Stats [tx/sec=" + (cnt / (dur / 1000)) + ", nearSize=" + near.size() + + ", dhtSize=" + dht.size() + ']'); + } + + return null; + } + + /** + * @param name Timer name. + * @param xid XID. + * @param key Key. + * @param termId Terminal ID. + */ + private void startTimer(String name, @Nullable IgniteUuid xid, @Nullable String key, String termId) { + ConcurrentMap<String, T5<Long, Long, Long, IgniteUuid, Object>> m = timers.get(Thread.currentThread()); + + if (m == null) { + ConcurrentMap<String, T5<Long, Long, Long, IgniteUuid, Object>> old = + timers.putIfAbsent(Thread.currentThread(), + m = new ConcurrentHashMap<>()); + + if (old != null) + m = old; + } + + T5<Long, Long, Long, IgniteUuid, Object> t = m.get(name); + + if (t == null) { + T5<Long, Long, Long, IgniteUuid, Object> old = m.putIfAbsent(name, + t = new T5<>()); + + if (old != null) + t = old; + } + + t.set1(System.currentTimeMillis()); + t.set2(0L); + t.set4(xid); + t.set5(key == null ? null : new AffinityKey<String>(key, termId) {}); + } + + /** + * @param name Timer name. + */ + private void stopTimer(String name) { + ConcurrentMap<String, T5<Long, Long, Long, IgniteUuid, Object>> m = timers.get(Thread.currentThread()); + + T5<Long, Long, Long, IgniteUuid, Object> t = m.get(name); + + assert t != null; + + long now = System.currentTimeMillis(); + + t.set2(now); + t.set3(Math.max(t.get3() == null ? 0 : t.get3(), now - t.get1())); + t.set4(null); + t.set5(null); + } + + /** + * @throws Exception If failed. + */ + private static void printTimers() throws Exception { + //String termId = terminalId(); + + long now = System.currentTimeMillis(); + + if (lastPrint.get() + PRINT_FREQ < now && lastPrint.setIfGreater(now)) { + Map<String, Long> maxes = new HashMap<>(); + + Set<AffinityKey<String>> keys = null; + + for (Map.Entry<Thread, ConcurrentMap<String, T5<Long, Long, Long, IgniteUuid, Object>>> e1 : timers.entrySet()) { + for (Map.Entry<String, T5<Long, Long, Long, IgniteUuid, Object>> e2 : e1.getValue().entrySet()) { + T5<Long, Long, Long, IgniteUuid, Object> t = e2.getValue(); + + long start = t.get1(); + long end = t.get2(); + + IgniteUuid xid = t.get4(); + + long duration = end == 0 ? now - start : end - start; + + long max = t.get3() == null ? duration : t.get3(); + + if (duration < 0) + duration = now - start; + + if (duration > MAX) { + X.println("Maxed out timer [name=" + e2.getKey() + ", key=" + t.get5() + + ", duration=" + duration + ", ongoing=" + (end == 0) + + ", thread=" + e1.getKey().getName() + ", xid=" + xid + ']'); + + AffinityKey<String> key = (AffinityKey<String>)t.get5(); + + if (key != null) { + if (keys == null) + keys = new LinkedHashSet<>(); + + keys.add(key); + } + } + + Long cmax = maxes.get(e2.getKey()); + + if (cmax == null || max > cmax) + maxes.put(e2.getKey(), max); + + t.set3(null); + } + } + + if (!F.isEmpty(keys)) { + for (Ignite g : G.allGrids()) { + if (g.name().contains("server")) { + GridNearCacheAdapter<AffinityKey<String>, Object> near = + (GridNearCacheAdapter<AffinityKey<String>, Object>)((IgniteKernal)g). + <AffinityKey<String>, Object>internalCache(DEFAULT_CACHE_NAME); + GridDhtCacheAdapter<AffinityKey<String>, Object> dht = near.dht(); + + for (AffinityKey<String> k : keys) { + GridNearCacheEntry nearEntry = (GridNearCacheEntry)near.peekEx(k); + GridDhtCacheEntry dhtEntry = (GridDhtCacheEntry)dht.peekEx(k); + + X.println("Near entry [igniteInstanceName="+ g.name() + ", key=" + k + ", entry=" + + nearEntry); + X.println("DHT entry [igniteInstanceName=" + g.name() + ", key=" + k + ", entry=" + + dhtEntry); + } + } + } + } + + for (Map.Entry<String, Long> e : maxes.entrySet()) + X.println("Timer [name=" + e.getKey() + ", maxTime=" + e.getValue() + ']'); + + X.println(">>>>"); + } + } + + /** + * + */ + private void doWork() { + Session ses = new Session(terminalId()); + + try { + try (Transaction tx = ignite.transactions().txStart()) { + Request req = new Request(getId()); + + req.setMessageId(getId()); + + String key = req.getCacheKey(); + + startTimer("putRequest", tx.xid(), key, terminalId()); + + put(req, key, terminalId()); + + stopTimer("putRequest"); +// +// for (int i = 0; i < 5; i++) { +// Response rsp = new Response(getId()); +// +// startTimer("putResponse-" + i, tx.xid()); +// +// put(rsp, rsp.getCacheKey(), terminalId()); +// +// stopTimer("putResponse-" + i); +// } + + key = ses.getCacheKey(); + + startTimer("putSession", tx.xid(), key, terminalId()); + + put(ses, key, terminalId()); + + stopTimer("putSession"); + + startTimer("commit", tx.xid(), null, terminalId()); + + tx.commit(); + + stopTimer("commit"); + } + } + catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * @return New ID. + */ + private long getId() { + IgniteAtomicSequence seq = ignite.atomicSequence("ID", 0, true); + + return seq.incrementAndGet(); + } + + /** + * @param o Object to put. + * @param cacheKey Cache key. + * @param terminalId Terminal ID. + */ + private void put(Object o, String cacheKey, String terminalId) { +// CacheProjection<AffinityKey<String>, Object> cache = ((IgniteKernal)ignite).cache(DEFAULT_CACHE_NAME); +// +// AffinityKey<String> affinityKey = new AffinityKey<>(cacheKey, terminalId); +// +// Entry<AffinityKey<String>, Object> entry = cache.entry(affinityKey); +// +// entry.setx(o); + } + + /** + * @param cacheKey Cache key. + * @param terminalId Terminal ID. + * @return Cached object. + */ + @SuppressWarnings({"RedundantCast"}) + private <T> Object get(String cacheKey, String terminalId) { + Object key = new AffinityKey<>(cacheKey, terminalId); + + return (T) ignite.cache(DEFAULT_CACHE_NAME).get(key); + } + } + + /** + * + */ + @QueryGroupIndex(name = "msg_tx") + @SuppressWarnings({"UnusedDeclaration"}) + private static class Request implements Serializable { + /** */ + @QuerySqlField(index = true) + private Long id; + + /** */ + @QuerySqlField(name = "messageId") + @QuerySqlField.Group(name = "msg_tx", order = 3) + private long msgId; + + /** */ + @QuerySqlField(name = "transactionId") + @QuerySqlField.Group(name = "msg_tx", order = 1) + private long txId; + + /** + * @param id Request ID. + */ + Request(long id) { + this.id = id; + } + + /** + * @param msgId Message ID. + */ + public void setMessageId(long msgId) { + this.msgId = msgId; + } + + /** + * @return Cache key. + */ + public String getCacheKey() { + return "RESPONSE:" + id.toString(); + } + } + + /** + * + */ + @SuppressWarnings({"UnusedDeclaration"}) + private static class Response implements Serializable { + /** */ + @QuerySqlField + private Long id; + + /** */ + @QuerySqlField(name = "messageId") + private long msgId; + + /** */ + @QuerySqlField(name = "transactionId") + private long txId; + + /** + * @param id Response ID. + */ + Response(long id) { + this.id = id; + } + + /** + * @return Cache key. + */ + public String getCacheKey() { + return "REQUEST:" + id.toString(); + } + } + + /** + * + */ + private static class Session implements Serializable { + /** */ + @QuerySqlField(index = true) + private String terminalId; + + /** + * @param terminalId Terminal ID. + */ + Session(String terminalId) { + this.terminalId = terminalId; + } + + /** + * @return Cache key. + */ + public String getCacheKey() { + return "SESSION:" + terminalId; + } + } + + /** + * + */ + @SuppressWarnings( {"UnusedDeclaration"}) + private static class ResponseTask extends ComputeTaskSplitAdapter<Message, Void> { + /** {@inheritDoc} */ + @Override protected Collection<? extends ComputeJob> split(int arg0, Message msg) { + return Collections.singletonList(new PerfJob(msg)); + } + + /** {@inheritDoc} */ + @Nullable @Override public Void reduce(List<ComputeJobResult> results) { + return null; + } + } + + /** + * + */ + private static class RequestTask extends ComputeTaskSplitAdapter<Message, Void> { + /** {@inheritDoc} */ + @Override protected Collection<? extends ComputeJob> split(int arg0, Message msg) { + return Collections.singletonList(new PerfJob(msg)); + } + + /** {@inheritDoc} */ + @Nullable @Override public Void reduce(List<ComputeJobResult> results) { + return null; + } + } +}
