#ignite-128: Moved classes in other packages.
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/756034f3 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/756034f3 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/756034f3 Branch: refs/heads/ignite-176 Commit: 756034f382c8ded94587840e5428f896ca4361ee Parents: b5b2f30 Author: vozerov-gridgain <voze...@gridgain.com> Authored: Tue Feb 3 12:39:25 2015 +0300 Committer: vozerov-gridgain <voze...@gridgain.com> Committed: Tue Feb 3 12:39:26 2015 +0300 ---------------------------------------------------------------------- .../ClientAbstractMultiThreadedSelfTest.java | 618 ------- .../client/ClientDefaultCacheSelfTest.java | 157 -- .../ignite/client/ClientGetAffinityTask.java | 64 - .../apache/ignite/client/ClientHttpTask.java | 59 - .../apache/ignite/client/ClientNodeStartup.java | 57 - .../client/ClientPortableArgumentTask.java | 53 - .../ignite/client/ClientPutPortableTask.java | 44 - .../client/ClientReconnectionSelfTest.java | 236 --- .../ignite/client/ClientSslNodeStartup.java | 59 - .../ignite/client/ClientStartNodeTask.java | 180 -- .../ignite/client/ClientStopNodeTask.java | 127 -- .../ignite/client/ClientStringLengthTask.java | 73 - .../client/ClientTcpMultiThreadedSelfTest.java | 46 - .../ClientTcpSslAuthenticationSelfTest.java | 266 --- .../ClientTcpSslMultiThreadedSelfTest.java | 47 - .../org/apache/ignite/client/ClientTcpTask.java | 73 - ...skExecutionAfterTopologyRestartSelfTest.java | 76 - .../ignite/client/ClientTestPortable.java | 490 ------ .../ClientTestPortableAffinityKeyTask.java | 85 - .../ignite/client/ClientTestRestServer.java | 275 --- .../client/ClientTopologyCacheSelfTest.java | 290 ---- .../org/apache/ignite/client/HashMapStore.java | 53 - .../org/apache/ignite/client/SleepTestTask.java | 68 - .../client/TaskSingleJobSplitAdapter.java | 75 - .../client/impl/ClientCacheFlagsCodecTest.java | 83 - .../client/impl/ClientComputeImplSelfTest.java | 168 -- .../client/impl/ClientDataImplSelfTest.java | 269 --- .../impl/ClientFutureAdapterSelfTest.java | 116 -- .../impl/ClientPartitionAffinitySelfTest.java | 407 ----- .../ClientPropertiesConfigurationSelfTest.java | 233 --- .../ClientAbstractConnectivitySelfTest.java | 304 ---- .../ClientAbstractMultiNodeSelfTest.java | 858 ---------- .../integration/ClientAbstractSelfTest.java | 1605 ------------------ .../integration/ClientPreferDirectSelfTest.java | 194 --- .../ClientTcpConnectivitySelfTest.java | 75 - .../ClientTcpDirectMultiNodeSelfTest.java | 56 - .../integration/ClientTcpDirectSelfTest.java | 59 - .../integration/ClientTcpMultiNodeSelfTest.java | 35 - .../client/integration/ClientTcpSelfTest.java | 46 - .../ClientTcpSslDirectMultiNodeSelfTest.java | 63 - .../integration/ClientTcpSslDirectSelfTest.java | 60 - .../ClientTcpSslMultiNodeSelfTest.java | 42 - .../integration/ClientTcpSslSelfTest.java | 47 - .../ClientTcpUnreachableMultiNodeSelfTest.java | 147 -- .../ignite/client/integration/package.html | 24 - .../client/router/ClientFailedInitSelfTest.java | 277 --- .../client/router/RouterFactorySelfTest.java | 108 -- .../router/TcpRouterAbstractSelfTest.java | 127 -- .../router/TcpRouterMultiNodeSelfTest.java | 112 -- .../ignite/client/router/TcpRouterSelfTest.java | 35 - .../client/router/TcpSslRouterSelfTest.java | 49 - .../apache/ignite/client/router/package.html | 24 - .../testsuites/IgniteRouterTestSuite.java | 41 - .../client/suite/IgniteClientTestSuite.java | 118 -- .../ignite/client/util/ClientByteUtilsTest.java | 172 -- .../util/ClientConsistentHashSelfTest.java | 282 --- .../client/util/ClientJavaHasherSelfTest.java | 84 - .../ClientAbstractMultiThreadedSelfTest.java | 619 +++++++ .../client/ClientDefaultCacheSelfTest.java | 158 ++ .../internal/client/ClientGetAffinityTask.java | 64 + .../ignite/internal/client/ClientHttpTask.java | 59 + .../internal/client/ClientNodeStartup.java | 57 + .../client/ClientPortableArgumentTask.java | 53 + .../internal/client/ClientPutPortableTask.java | 44 + .../client/ClientReconnectionSelfTest.java | 234 +++ .../internal/client/ClientSslNodeStartup.java | 59 + .../internal/client/ClientStartNodeTask.java | 180 ++ .../internal/client/ClientStopNodeTask.java | 127 ++ .../internal/client/ClientStringLengthTask.java | 73 + .../client/ClientTcpMultiThreadedSelfTest.java | 45 + .../ClientTcpSslAuthenticationSelfTest.java | 267 +++ .../ClientTcpSslMultiThreadedSelfTest.java | 46 + .../ignite/internal/client/ClientTcpTask.java | 73 + ...skExecutionAfterTopologyRestartSelfTest.java | 76 + .../internal/client/ClientTestPortable.java | 490 ++++++ .../ClientTestPortableAffinityKeyTask.java | 85 + .../internal/client/ClientTestRestServer.java | 275 +++ .../client/ClientTopologyCacheSelfTest.java | 291 ++++ .../ignite/internal/client/HashMapStore.java | 53 + .../ignite/internal/client/SleepTestTask.java | 68 + .../client/TaskSingleJobSplitAdapter.java | 75 + .../client/impl/ClientCacheFlagsCodecTest.java | 83 + .../client/impl/ClientComputeImplSelfTest.java | 168 ++ .../client/impl/ClientDataImplSelfTest.java | 269 +++ .../impl/ClientFutureAdapterSelfTest.java | 116 ++ .../impl/ClientPartitionAffinitySelfTest.java | 407 +++++ .../ClientPropertiesConfigurationSelfTest.java | 233 +++ .../ClientAbstractConnectivitySelfTest.java | 304 ++++ .../ClientAbstractMultiNodeSelfTest.java | 858 ++++++++++ .../integration/ClientAbstractSelfTest.java | 1605 ++++++++++++++++++ .../integration/ClientPreferDirectSelfTest.java | 194 +++ .../ClientTcpConnectivitySelfTest.java | 75 + .../ClientTcpDirectMultiNodeSelfTest.java | 56 + .../integration/ClientTcpDirectSelfTest.java | 59 + .../integration/ClientTcpMultiNodeSelfTest.java | 35 + .../client/integration/ClientTcpSelfTest.java | 46 + .../ClientTcpSslDirectMultiNodeSelfTest.java | 63 + .../integration/ClientTcpSslDirectSelfTest.java | 60 + .../ClientTcpSslMultiNodeSelfTest.java | 42 + .../integration/ClientTcpSslSelfTest.java | 47 + .../ClientTcpUnreachableMultiNodeSelfTest.java | 147 ++ .../client/router/ClientFailedInitSelfTest.java | 276 +++ .../client/router/RouterFactorySelfTest.java | 108 ++ .../router/TcpRouterAbstractSelfTest.java | 126 ++ .../router/TcpRouterMultiNodeSelfTest.java | 111 ++ .../client/router/TcpRouterSelfTest.java | 35 + .../client/router/TcpSslRouterSelfTest.java | 48 + .../testsuites/IgniteRouterTestSuite.java | 41 + .../client/suite/IgniteClientTestSuite.java | 118 ++ .../client/util/ClientByteUtilsTest.java | 172 ++ .../util/ClientConsistentHashSelfTest.java | 282 +++ .../client/util/ClientJavaHasherSelfTest.java | 84 + .../loadtests/client/ClientTcpSslLoadTest.java | 2 +- .../clients/src/test/resources/spring-cache.xml | 2 +- .../src/test/resources/spring-server-node.xml | 6 +- .../test/resources/spring-server-ssl-node.xml | 4 +- 116 files changed, 9846 insertions(+), 9898 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/756034f3/modules/clients/src/test/java/org/apache/ignite/client/ClientAbstractMultiThreadedSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/client/ClientAbstractMultiThreadedSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/client/ClientAbstractMultiThreadedSelfTest.java deleted file mode 100644 index c714084..0000000 --- a/modules/clients/src/test/java/org/apache/ignite/client/ClientAbstractMultiThreadedSelfTest.java +++ /dev/null @@ -1,618 +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.client; - -import org.apache.ignite.*; -import org.apache.ignite.cache.*; -import org.apache.ignite.cache.affinity.*; -import org.apache.ignite.cluster.*; -import org.apache.ignite.compute.*; -import org.apache.ignite.configuration.*; -import org.apache.ignite.internal.*; -import org.apache.ignite.internal.client.*; -import org.apache.ignite.internal.client.balancer.*; -import org.apache.ignite.internal.client.impl.*; -import org.apache.ignite.internal.client.ssl.*; -import org.apache.ignite.lang.*; -import org.apache.ignite.resources.*; -import org.apache.ignite.internal.processors.affinity.*; -import org.apache.ignite.spi.discovery.tcp.*; -import org.apache.ignite.spi.discovery.tcp.ipfinder.*; -import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*; -import org.apache.ignite.internal.util.typedef.*; -import org.apache.ignite.internal.util.typedef.internal.*; -import org.apache.ignite.testframework.junits.common.*; -import org.jetbrains.annotations.*; -import org.junit.*; - -import java.util.*; -import java.util.concurrent.*; -import java.util.concurrent.atomic.*; - -import static org.apache.ignite.cache.CacheAtomicityMode.*; -import static org.apache.ignite.cache.CacheDistributionMode.*; -import static org.apache.ignite.cache.CacheMode.*; -import static org.apache.ignite.cache.CacheWriteSynchronizationMode.*; -import static org.apache.ignite.testframework.GridTestUtils.*; - -/** - * - */ -public abstract class ClientAbstractMultiThreadedSelfTest extends GridCommonAbstractTest { - /** IP finder. */ - private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); - - /** Partitioned cache name. */ - protected static final String PARTITIONED_CACHE_NAME = "partitioned"; - - /** Partitioned cache with async commit and backup name. */ - protected static final String PARTITIONED_ASYNC_BACKUP_CACHE_NAME = "partitioned-async-backup"; - - /** Replicated cache name. */ - private static final String REPLICATED_CACHE_NAME = "replicated"; - - /** Replicated cache with async commit name. */ - private static final String REPLICATED_ASYNC_CACHE_NAME = "replicated-async"; - - /** Nodes count. */ - protected static final int NODES_CNT = 5; - - /** Thread count to run tests. */ - private static final int THREAD_CNT = 20; - - /** Count of tasks to run. */ - private static final int TASK_EXECUTION_CNT = 50000; - - /** Count of cache puts in tests. */ - private static final int CACHE_PUT_CNT = 10000; - - /** Topology update frequency. */ - private static final int TOP_REFRESH_FREQ = 1000; - - /** Info messages will be printed each 5000 iterations. */ - private static final int STATISTICS_PRINT_STEP = 5000; - - /** Host. */ - public static final String HOST = "127.0.0.1"; - - /** Base for tcp rest ports. */ - public static final int REST_TCP_PORT_BASE = 12345; - - static { - System.setProperty("CLIENTS_MODULE_PATH", U.resolveGridGainPath("modules/clients").getAbsolutePath()); - } - - /** Client instance for each test. */ - private GridClient client; - - /** - * @return Client protocol that should be used. - */ - protected abstract GridClientProtocol protocol(); - - /** - * @return Server address to create first connection. - */ - protected abstract String serverAddress(); - - /** - * @return Whether SSL should be used. - */ - protected abstract boolean useSsl(); - - /** - * @return SSL context factory to use if SSL is enabled. - */ - protected abstract GridSslContextFactory sslContextFactory(); - - /** - * @return Count of iterations for sync commit test. - */ - protected int syncCommitIterCount() { - return 1000; - } - - /** - * @return Topology refresh frequency interval. - */ - protected int topologyRefreshFrequency() { - return TOP_REFRESH_FREQ; - } - - /** - * @return Max connection idle time. - */ - protected int maxConnectionIdleTime() { - return 5000; - } - - /** - * @return Number of tasks that should be executed during test. - */ - protected int taskExecutionCount() { - return TASK_EXECUTION_CNT; - } - - /** - * @return Number of puts to the cache. - */ - protected int cachePutCount() { - return CACHE_PUT_CNT; - } - - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { - IgniteConfiguration c = super.getConfiguration(gridName); - - c.setLocalHost(HOST); - - assert c.getClientConnectionConfiguration() == null; - - ClientConnectionConfiguration clientCfg = new ClientConnectionConfiguration(); - - clientCfg.setRestTcpPort(REST_TCP_PORT_BASE); - - if (useSsl()) { - clientCfg.setRestTcpSslEnabled(true); - - clientCfg.setRestTcpSslContextFactory(sslContextFactory()); - } - - c.setClientConnectionConfiguration(clientCfg); - - TcpDiscoverySpi disco = new TcpDiscoverySpi(); - - disco.setIpFinder(IP_FINDER); - - c.setDiscoverySpi(disco); - - c.setCacheConfiguration(cacheConfiguration(null), cacheConfiguration(PARTITIONED_CACHE_NAME), - cacheConfiguration(REPLICATED_CACHE_NAME), cacheConfiguration(PARTITIONED_ASYNC_BACKUP_CACHE_NAME), - cacheConfiguration(REPLICATED_ASYNC_CACHE_NAME)); - - return c; - } - - /** - * @param cacheName Cache name. - * @return Cache configuration. - * @throws Exception In case of error. - */ - private CacheConfiguration cacheConfiguration(@Nullable String cacheName) throws Exception { - CacheConfiguration cfg = defaultCacheConfiguration(); - - cfg.setDistributionMode(NEAR_PARTITIONED); - cfg.setAtomicityMode(TRANSACTIONAL); - - if (cacheName == null) - cfg.setCacheMode(LOCAL); - else if (PARTITIONED_CACHE_NAME.equals(cacheName)) { - cfg.setCacheMode(PARTITIONED); - - cfg.setBackups(0); - } - else if (PARTITIONED_ASYNC_BACKUP_CACHE_NAME.equals(cacheName)) { - cfg.setCacheMode(PARTITIONED); - - cfg.setBackups(1); - } - else - cfg.setCacheMode(REPLICATED); - - cfg.setName(cacheName); - - if (cacheName != null && !cacheName.contains("async")) - cfg.setWriteSynchronizationMode(FULL_SYNC); - - return cfg; - } - - /** {@inheritDoc} */ - @Override protected void beforeTestsStarted() throws Exception { - startGridsMultiThreaded(NODES_CNT); - } - - /** {@inheritDoc} */ - @Override protected void afterTestsStopped() throws Exception { - stopAllGrids(); - } - - /** {@inheritDoc} */ - @Override protected void beforeTest() throws Exception { - client = GridClientFactory.start(clientConfiguration()); - } - - /** {@inheritDoc} */ - @Override protected void afterTest() throws Exception { - GridClientFactory.stop(client.id(), false); - - client = null; - } - - /** - * @throws Exception If failed. - */ - public void testSyncCommitFlagReplicated() throws Exception { - doTestSyncCommitFlag(client.data(REPLICATED_ASYNC_CACHE_NAME)); - } - - /** - * @throws Exception If failed. - */ - public void testSyncCommitFlagPartitioned() throws Exception { - doTestSyncCommitFlag(client.data(PARTITIONED_ASYNC_BACKUP_CACHE_NAME)); - } - - /** - * Extracts array from given iterator. - * - * @param nodes Iterator of nodes. - * @return Nodes array. - */ - private GridClientNode[] toArray(Iterator<? extends GridClientNode> nodes) { - ArrayList<GridClientNode> res = new ArrayList<>(); - - while (nodes.hasNext()) - res.add(nodes.next()); - - return res.toArray(new GridClientNode[res.size()]); - } - - /** - * Runs test on SYNC_COMMIT flag. - * - * @param data Client data to run test on. - * @throws Exception If failed. - */ - private void doTestSyncCommitFlag(final GridClientData data) throws Exception { - final String key = "k0"; - - Collection<UUID> affNodesIds = F.viewReadOnly( - grid(0).cache(data.cacheName()).affinity().mapKeyToPrimaryAndBackups(key), - F.node2id()); - - final GridClientData dataFirst = data.pinNodes(F.first(client.compute().nodes())); - - List<GridClientNode> affNodes = new ArrayList<>(); - - for (GridClientNode node : client.compute().nodes()) { - if (affNodesIds.contains(node.nodeId())) - affNodes.add(node); - } - - Assert.assertFalse(affNodes.isEmpty()); - - Iterator<? extends GridClientNode> it = affNodes.iterator(); - - final GridClientData dataOthers = data.pinNodes(it.next(), toArray(it)); - - for (int i = 0; i < syncCommitIterCount(); i++) { - final CountDownLatch l = new CountDownLatch(1); - - final String val = "v" + i; - - IgniteInternalFuture<?> f = multithreadedAsync(new Callable<Object>() { - @Override public Object call() throws Exception { - l.await(); - - assertEquals(val, dataOthers.get(key)); - - return null; - } - }, THREAD_CNT); - - dataFirst.flagsOn(GridClientCacheFlag.SYNC_COMMIT).put(key, val); - - l.countDown(); - - f.get(); - } - } - - /** - * @throws Exception If failed. - */ - public void testMultithreadedTaskRun() throws Exception { - final AtomicLong cnt = new AtomicLong(); - - final AtomicReference<GridClientException> err = new AtomicReference<>(); - - final ConcurrentLinkedQueue<String> execQueue = new ConcurrentLinkedQueue<>(); - - IgniteInternalFuture<?> fut = multithreadedAsync(new Runnable() { - @Override - public void run() { - long processed; - - while ((processed = cnt.getAndIncrement()) < taskExecutionCount()) { - try { - if (processed > 0 && processed % STATISTICS_PRINT_STEP == 0) - info(">>>>>>> " + processed + " tasks finished."); - - String res = client.compute().execute(TestTask.class.getName(), null); - - execQueue.add(res); - } - catch (GridClientException e) { - err.compareAndSet(null, e); - } - } - } - }, THREAD_CNT, "client-task-request"); - - fut.get(); - - if (err.get() != null) - throw new Exception(err.get()); - - assertEquals(taskExecutionCount(), execQueue.size()); - - // With round-robin balancer each node must receive equal count of task requests. - Collection<String> executionIds = new HashSet<>(execQueue); - - assertTrue(executionIds.size() == NODES_CNT); - - Map<String, AtomicInteger> statisticsMap = new HashMap<>(); - - for (String id : executionIds) - statisticsMap.put(id, new AtomicInteger()); - - for (String id : execQueue) - statisticsMap.get(id).incrementAndGet(); - - info(">>>>>>> Execution statistics per node:"); - - for (Map.Entry<String, AtomicInteger> e : statisticsMap.entrySet()) - info(">>>>>>> " + e.getKey() + " run " + e.getValue().get() + " tasks"); - } - - /** - * @throws Exception If failed. - */ - public void test6Affinity() throws Exception { - GridClientData cache = client.data(PARTITIONED_CACHE_NAME); - UUID nodeId = cache.affinity("6"); - - info("Affinity node: " + nodeId); - } - - /** - * @throws Exception If failed. - */ - public void testMultithreadedCachePut() throws Exception { - final AtomicLong keyCnt = new AtomicLong(); - - final AtomicReference<Exception> err = new AtomicReference<>(); - - final ConcurrentMap<String, T2<UUID, String>> puts = new ConcurrentHashMap<>(); - - final Map<UUID, Ignite> gridMap = new HashMap<>(); - - for (int i = 0; i < NODES_CNT; i++) { - Ignite g = grid(i); - - gridMap.put(g.cluster().localNode().id(), g); - } - - final Ignite ignite = F.first(gridMap.values()); - - assertEquals(NODES_CNT, client.compute().refreshTopology(false, false).size()); - - IgniteInternalFuture<?> fut = multithreadedAsync(new Runnable() { - @SuppressWarnings("OverlyStrongTypeCast") - @Override public void run() { - try { - GridClientData cache = client.data(PARTITIONED_CACHE_NAME); - - assertEquals(NODES_CNT, ((GridClientDataImpl)cache).projectionNodes().size()); - - long rawKey; - - while ((rawKey = keyCnt.getAndIncrement()) < cachePutCount()) { - String key = String.valueOf(rawKey); - - UUID nodeId = cache.affinity(key); - UUID srvNodeId = ignite.cluster().mapKeyToNode(PARTITIONED_CACHE_NAME, key).id(); - - if (!nodeId.equals(srvNodeId)) { - //GridClientDataAffinity clAff = - // ((GridClientConfiguration)getFieldValue(client, "cfg")). - // getDataConfiguration(PARTITIONED_CACHE_NAME).getAffinity(); - - //printAffinityState(gridMap.values()); - //info("Client affinity: " + clAff); - - info("Got wrong client mapping [key=" + key + ", exp=" + srvNodeId + - ", actual=" + nodeId + "]"); - } - - String val = "val" + rawKey; - - if (cache.put(key, val)) { - T2<UUID, String> old = puts.putIfAbsent(key, new T2<>(nodeId, val)); - - assert old == null : "Map contained entry [key=" + rawKey + ", entry=" + old + ']'; - } - } - } - catch (Exception e) { - err.compareAndSet(null, e); - } - } - }, THREAD_CNT, "client-cache-put"); - - fut.get(); - - if (err.get() != null) - throw new Exception(err.get()); - - assertEquals(cachePutCount(), puts.size()); - - // Now check that all puts went to primary nodes. - for (long i = 0; i < cachePutCount(); i++) { - String key = String.valueOf(i); - - ClusterNode node = ignite.cluster().mapKeyToNode(PARTITIONED_CACHE_NAME, key); - - if (!puts.get(key).get2().equals(gridMap.get(node.id()).cache(PARTITIONED_CACHE_NAME).peek(key))) { - // printAffinityState(gridMap.values()); - - failNotEquals("Node don't have value for key [nodeId=" + node.id() + ", key=" + key + "]", - puts.get(key).get2(), gridMap.get(node.id()).cache(PARTITIONED_CACHE_NAME).peek(key)); - } - - // Assert that client has properly determined affinity node. - if (!node.id().equals(puts.get(key).get1())) { - //GridClientDataAffinity clAff = - // ((GridClientConfiguration)getFieldValue(client, "cfg")). - // getDataConfiguration(PARTITIONED_CACHE_NAME).getAffinity(); - - //printAffinityState(gridMap.values()); - //info("Client affinity: " + clAff); - - UUID curAffNode = client.data(PARTITIONED_CACHE_NAME).affinity(key); - - failNotEquals( - "Got different mappings [key=" + key + ", currId=" + curAffNode + "]", - node.id(), puts.get(key).get1()); - } - - // Check that no other nodes see this key. - for (UUID id : F.view(gridMap.keySet(), F.notEqualTo(node.id()))) - assertNull("Got value in near cache.", gridMap.get(id).cache(PARTITIONED_CACHE_NAME).peek(key)); - } - - for (Ignite g : gridMap.values()) - g.cache(PARTITIONED_CACHE_NAME).clearAll(); - } - - /** - * @param grids Collection for Grids to print affinity info. - */ - private void printAffinityState(Iterable<Ignite> grids) { - for (Ignite g : grids) { - GridAffinityAssignmentCache affCache = getFieldValue( - ((IgniteKernal)g).internalCache(PARTITIONED_CACHE_NAME).context().affinity(), - "aff"); - - CacheAffinityFunction aff = getFieldValue(affCache, "aff"); - - info("Affinity [nodeId=" + g.cluster().localNode().id() + ", affinity=" + aff + "]"); - } - } - - /** {@inheritDoc} */ - @Override protected long getTestTimeout() { - return 5 * 60 * 1000; - } - - /** - * Creates client that will try to connect to only first node in grid. - * - * @return Client. - */ - private GridClientConfiguration clientConfiguration() { - GridClientConfiguration cfg = new GridClientConfiguration(); - - cfg.setTopologyRefreshFrequency(topologyRefreshFrequency()); - cfg.setMaxConnectionIdleTime(maxConnectionIdleTime()); - - cfg.setProtocol(protocol()); - cfg.setServers(Arrays.asList(serverAddress())); - cfg.setBalancer(new GridClientRoundRobinBalancer()); - - if (useSsl()) - cfg.setSslContextFactory(sslContextFactory()); - - GridClientDataConfiguration loc = new GridClientDataConfiguration(); - - GridClientDataConfiguration partitioned = new GridClientDataConfiguration(); - partitioned.setName(PARTITIONED_CACHE_NAME); - partitioned.setAffinity(new GridClientPartitionAffinity()); - - GridClientDataConfiguration partitionedAsyncBackup = new GridClientDataConfiguration(); - partitionedAsyncBackup.setName(PARTITIONED_ASYNC_BACKUP_CACHE_NAME); - partitionedAsyncBackup.setAffinity(new GridClientPartitionAffinity()); - - GridClientDataConfiguration replicated = new GridClientDataConfiguration(); - replicated.setName(REPLICATED_CACHE_NAME); - - GridClientDataConfiguration replicatedAsync = new GridClientDataConfiguration(); - replicatedAsync.setName(REPLICATED_ASYNC_CACHE_NAME); - - cfg.setDataConfigurations(Arrays.asList(loc, partitioned, replicated, replicatedAsync, partitionedAsyncBackup)); - - return cfg; - } - - /** - * Test task. Returns a tuple in which first component is id of node that has split the task, - * and second component is count of nodes that executed jobs. - */ - private static class TestTask extends ComputeTaskSplitAdapter<Object, String> { - /** Injected grid. */ - @IgniteInstanceResource - private Ignite ignite; - - /** Count of tasks this job was split to. */ - private int gridSize; - - /** {@inheritDoc} */ - @Override protected Collection<? extends ComputeJob> split(int gridSize, Object arg) - throws IgniteCheckedException { - Collection<ComputeJobAdapter> jobs = new ArrayList<>(gridSize); - - this.gridSize = gridSize; - - final String locNodeId = ignite.cluster().localNode().id().toString(); - - for (int i = 0; i < gridSize; i++) { - jobs.add(new ComputeJobAdapter() { - @Override public Object execute() { - return new IgniteBiTuple<>(locNodeId, 1); - } - }); - } - - return jobs; - } - - /** {@inheritDoc} */ - @Override public String reduce(List<ComputeJobResult> results) throws IgniteCheckedException { - int sum = 0; - - String locNodeId = null; - - for (ComputeJobResult res : results) { - IgniteBiTuple<String, Integer> part = res.getData(); - - if (locNodeId == null) - locNodeId = part.get1(); - - Integer i = part.get2(); - - if (i != null) - sum += i; - } - - assert gridSize == sum; - - return locNodeId; - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/756034f3/modules/clients/src/test/java/org/apache/ignite/client/ClientDefaultCacheSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/client/ClientDefaultCacheSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/client/ClientDefaultCacheSelfTest.java deleted file mode 100644 index 01a4a10..0000000 --- a/modules/clients/src/test/java/org/apache/ignite/client/ClientDefaultCacheSelfTest.java +++ /dev/null @@ -1,157 +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.client; - -import org.apache.ignite.configuration.*; -import org.apache.ignite.internal.client.*; -import org.apache.ignite.lang.*; -import org.apache.ignite.spi.discovery.tcp.*; -import org.apache.ignite.spi.discovery.tcp.ipfinder.*; -import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*; -import org.apache.ignite.internal.util.typedef.*; -import org.apache.ignite.testframework.junits.common.*; - -import java.util.*; - -import static org.apache.ignite.internal.client.GridClientProtocol.*; -import static org.apache.ignite.IgniteSystemProperties.*; - -/** - * Tests that client is able to connect to a grid with only default cache enabled. - */ -public class ClientDefaultCacheSelfTest extends GridCommonAbstractTest { - /** Path to jetty config configured with SSL. */ - private static final String REST_JETTY_CFG = "modules/clients/src/test/resources/jetty/rest-jetty.xml"; - - /** IP finder. */ - private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); - - /** Host. */ - private static final String HOST = "127.0.0.1"; - - /** Port. */ - private static final int TCP_PORT = 11211; - - /** Cached local node id. */ - private UUID locNodeId; - - /** Http port. */ - private static final int HTTP_PORT = 8081; - - /** {@inheritDoc} */ - @Override protected void beforeTestsStarted() throws Exception { - System.setProperty(IGNITE_JETTY_PORT, String.valueOf(HTTP_PORT)); - - startGrid(); - } - - /** {@inheritDoc} */ - @Override protected void afterTestsStopped() throws Exception { - stopGrid(); - - System.clearProperty (IGNITE_JETTY_PORT); - } - - /** {@inheritDoc} */ - @Override protected void beforeTest() throws Exception { - locNodeId = grid().localNode().id(); - } - - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { - IgniteConfiguration cfg = super.getConfiguration(gridName); - - assert cfg.getClientConnectionConfiguration() == null; - - ClientConnectionConfiguration clientCfg = new ClientConnectionConfiguration(); - - clientCfg.setRestJettyPath(REST_JETTY_CFG); - - cfg.setClientConnectionConfiguration(clientCfg); - - TcpDiscoverySpi disco = new TcpDiscoverySpi(); - - disco.setIpFinder(IP_FINDER); - - cfg.setDiscoverySpi(disco); - - cfg.setCacheConfiguration(defaultCacheConfiguration()); - - return cfg; - } - - /** - * @return Client. - * @throws GridClientException In case of error. - */ - private GridClient clientTcp() throws GridClientException { - GridClientConfiguration cfg = new GridClientConfiguration(); - - cfg.setProtocol(TCP); - cfg.setServers(getServerList(TCP_PORT)); - cfg.setDataConfigurations(Collections.singleton(new GridClientDataConfiguration())); - - GridClient gridClient = GridClientFactory.start(cfg); - - assert F.exist(gridClient.compute().nodes(), new IgnitePredicate<GridClientNode>() { - @Override public boolean apply(GridClientNode n) { - return n.nodeId().equals(locNodeId); - } - }); - - return gridClient; - } - - /** - * Builds list of connection strings with few different ports. - * Used to avoid possible failures in case of port range active. - * - * @param startPort Port to start list from. - * @return List of client connection strings. - */ - private Collection<String> getServerList(int startPort) { - Collection<String> srvs = new ArrayList<>(); - - for (int i = startPort; i < startPort + 10; i++) - srvs.add(HOST + ":" + i); - - return srvs; - } - - /** - * @throws Exception If failed. - */ - public void testTcp() throws Exception { - try { - boolean putRes = cache().putx("key", 1); - - assert putRes : "Put operation failed"; - - GridClient client = clientTcp(); - - Integer val = client.data().<String, Integer>get("key"); - - assert val != null; - - assert val == 1; - } - finally { - GridClientFactory.stopAll(); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/756034f3/modules/clients/src/test/java/org/apache/ignite/client/ClientGetAffinityTask.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/client/ClientGetAffinityTask.java b/modules/clients/src/test/java/org/apache/ignite/client/ClientGetAffinityTask.java deleted file mode 100644 index c6b317d..0000000 --- a/modules/clients/src/test/java/org/apache/ignite/client/ClientGetAffinityTask.java +++ /dev/null @@ -1,64 +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.client; - -import org.apache.ignite.*; -import org.apache.ignite.cluster.*; -import org.apache.ignite.compute.*; -import org.apache.ignite.resources.*; -import org.apache.ignite.internal.util.typedef.internal.*; - -import java.util.*; - -import static org.apache.ignite.compute.ComputeJobResultPolicy.*; - -/** - * Get affinity for task argument. - */ -public class ClientGetAffinityTask extends TaskSingleJobSplitAdapter<String, Integer> { - /** Grid. */ - @IgniteInstanceResource - private transient Ignite ignite; - - /** {@inheritDoc} */ - @Override protected Object executeJob(int gridSize, String arg) throws IgniteCheckedException { - A.notNull(arg, "task argument"); - - String[] split = arg.split(":", 2); - - A.ensure(split.length == 2, "Task argument should have format 'cacheName:affinityKey'."); - - String cacheName = split[0]; - String affKey = split[1]; - - if ("null".equals(cacheName)) - cacheName = null; - - ClusterNode node = ignite.cluster().mapKeyToNode(cacheName, affKey); - - return node.id().toString(); - } - - /** {@inheritDoc} */ - @Override public ComputeJobResultPolicy result(ComputeJobResult res, List<ComputeJobResult> rcvd) throws IgniteCheckedException { - if (res.getException() != null) - return FAILOVER; - - return WAIT; - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/756034f3/modules/clients/src/test/java/org/apache/ignite/client/ClientHttpTask.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/client/ClientHttpTask.java b/modules/clients/src/test/java/org/apache/ignite/client/ClientHttpTask.java deleted file mode 100644 index c3f466c..0000000 --- a/modules/clients/src/test/java/org/apache/ignite/client/ClientHttpTask.java +++ /dev/null @@ -1,59 +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.client; - -import net.sf.json.*; -import org.apache.ignite.*; -import org.apache.ignite.compute.*; - -import java.util.*; - -import static org.apache.ignite.compute.ComputeJobResultPolicy.*; - -/** - * Test task summarizes length of all strings in the arguments list. - * <p> - * The argument of the task is JSON-serialized array of objects to calculate string length sum of. - */ -public class ClientHttpTask extends ComputeTaskSplitAdapter<String, Integer> { - /** Task delegate. */ - private final ClientTcpTask delegate = new ClientTcpTask(); - - /** {@inheritDoc} */ - @Override protected Collection<? extends ComputeJob> split(int gridSize, String arg) throws IgniteCheckedException { - JSON json = JSONSerializer.toJSON(arg); - - List list = json.isArray() ? JSONArray.toList((JSONArray)json, String.class, new JsonConfig()) : null; - - //noinspection unchecked - return delegate.split(gridSize, list); - } - - /** {@inheritDoc} */ - @Override public Integer reduce(List<ComputeJobResult> results) throws IgniteCheckedException { - return delegate.reduce(results); - } - - /** {@inheritDoc} */ - @Override public ComputeJobResultPolicy result(ComputeJobResult res, List<ComputeJobResult> rcvd) throws IgniteCheckedException { - if (res.getException() != null) - return FAILOVER; - - return WAIT; - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/756034f3/modules/clients/src/test/java/org/apache/ignite/client/ClientNodeStartup.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/client/ClientNodeStartup.java b/modules/clients/src/test/java/org/apache/ignite/client/ClientNodeStartup.java deleted file mode 100644 index 49ff4e7..0000000 --- a/modules/clients/src/test/java/org/apache/ignite/client/ClientNodeStartup.java +++ /dev/null @@ -1,57 +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.client; - -import org.apache.ignite.*; -import org.apache.ignite.internal.util.typedef.*; -import org.apache.ignite.internal.util.typedef.internal.*; - -/** - * Starts up one grid node (server) with pre-defined ports and tasks to test client-server interactions. - * <p> - * Note that different nodes cannot share the same port for rest services. If you want - * to start more than one node on the same physical machine you must provide different - * configurations for each node. Otherwise, this example would not work. - * <p> - * After this example has been started you can use pre-defined endpoints and task names in your - * client-server interactions to work with the node over un-secure protocols (binary or http). - * <p> - * Usually you cannot start secured and unsecured nodes in one grid, so started together - * secured and unsecured nodes belong to different grids. - * <p> - * Available endponts: - * <ul> - * <li>127.0.0.1:10080 - TCP unsecured endpoint.</li> - * <li>127.0.0.1:11080 - HTTP unsecured endpoint.</li> - * </ul> - * <p> - * Required credentials for remote client authentication: "s3cret". - */ -public class ClientNodeStartup { - /** - * Starts up two nodes with specified cache configuration on pre-defined endpoints. - * - * @param args Command line arguments, none required. - * @throws IgniteCheckedException In case of any exception. - */ - public static void main(String[] args) throws IgniteCheckedException { - try (Ignite g = G.start("modules/clients/src/test/resources/spring-server-node.xml")) { - U.sleep(Long.MAX_VALUE); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/756034f3/modules/clients/src/test/java/org/apache/ignite/client/ClientPortableArgumentTask.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/client/ClientPortableArgumentTask.java b/modules/clients/src/test/java/org/apache/ignite/client/ClientPortableArgumentTask.java deleted file mode 100644 index a137fe1..0000000 --- a/modules/clients/src/test/java/org/apache/ignite/client/ClientPortableArgumentTask.java +++ /dev/null @@ -1,53 +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.client; - -import org.apache.ignite.*; -import org.apache.ignite.portables.*; - -import java.util.*; - -/** - * Task where argument and result are {@link ClientTestPortable}. - */ -public class ClientPortableArgumentTask extends TaskSingleJobSplitAdapter { - /** {@inheritDoc} */ - @Override protected Object executeJob(int gridSize, Object arg) throws IgniteCheckedException { - Collection args = (Collection)arg; - - Iterator<Object> it = args.iterator(); - - assert args.size() == 2 : args.size(); - - boolean expPortable = (Boolean)it.next(); - - ClientTestPortable p; - - if (expPortable) { - PortableObject obj = (PortableObject)it.next(); - - p = obj.deserialize(); - } - else - p = (ClientTestPortable)it.next(); - - assert p != null; - - return new ClientTestPortable(p.i + 1, true); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/756034f3/modules/clients/src/test/java/org/apache/ignite/client/ClientPutPortableTask.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/client/ClientPutPortableTask.java b/modules/clients/src/test/java/org/apache/ignite/client/ClientPutPortableTask.java deleted file mode 100644 index cd5f85c..0000000 --- a/modules/clients/src/test/java/org/apache/ignite/client/ClientPutPortableTask.java +++ /dev/null @@ -1,44 +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.client; - -import org.apache.ignite.*; -import org.apache.ignite.cache.*; -import org.apache.ignite.resources.*; - -/** - * Task creates portable object and puts it in cache. - */ -public class ClientPutPortableTask extends TaskSingleJobSplitAdapter { - /** */ - @IgniteInstanceResource - private Ignite ignite; - - /** {@inheritDoc} */ - @Override protected Object executeJob(int gridSize, Object arg) throws IgniteCheckedException { - String cacheName = (String)arg; - - GridCache<Object, Object> cache = ignite.cache(cacheName); - - ClientTestPortable p = new ClientTestPortable(100, true); - - cache.put(1, p); - - return true; - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/756034f3/modules/clients/src/test/java/org/apache/ignite/client/ClientReconnectionSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/client/ClientReconnectionSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/client/ClientReconnectionSelfTest.java deleted file mode 100644 index 7f7ed6f..0000000 --- a/modules/clients/src/test/java/org/apache/ignite/client/ClientReconnectionSelfTest.java +++ /dev/null @@ -1,236 +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.client; - -import org.apache.ignite.*; -import org.apache.ignite.internal.client.*; -import org.apache.ignite.internal.client.impl.connection.*; -import org.apache.ignite.internal.util.typedef.*; -import org.apache.ignite.testframework.junits.common.*; - -import java.nio.channels.*; -import java.util.*; - -import static org.apache.ignite.client.ClientTestRestServer.*; - -/** - * - */ -public class ClientReconnectionSelfTest extends GridCommonAbstractTest { - /** */ - public static final String HOST = "127.0.0.1"; - - /** */ - private ClientTestRestServer[] srvs = new ClientTestRestServer[SERVERS_CNT]; - - /** {@inheritDoc} */ - @Override protected void afterTest() throws Exception { - for (int i = 0; i < srvs.length; i++) { - ClientTestRestServer srv = srvs[i]; - - if (srv != null) - srv.stop(); - - srvs[i] = null; - } - - super.afterTest(); - } - - /** - * @return Client for test. - * @throws GridClientException In case of error. - */ - private GridClient client() throws GridClientException { - return client(HOST); - } - - /** - * @param host - server host - * @return Client for test. - * @throws GridClientException In case of error. - */ - private GridClient client(String host) throws GridClientException { - GridClientConfiguration cfg = new GridClientConfiguration(); - - cfg.setProtocol(GridClientProtocol.TCP); - - Collection<String> addrs = new ArrayList<>(); - - for (int port = FIRST_SERVER_PORT; port < FIRST_SERVER_PORT + SERVERS_CNT; port++) - addrs.add(host + ":" + port); - - cfg.setServers(addrs); - - cfg.setTopologyRefreshFrequency(60 * 60 * 1000); - - return GridClientFactory.start(cfg); - } - - /** - * @throws Exception If failed. - */ - public void testNoFailedReconnection() throws Exception { - for (int i = 0; i < SERVERS_CNT; i++) - runServer(i, false); - - try (GridClient client = client()) { // Here client opens initial connection and fetches topology. - // Only first server in list should be contacted. - assertEquals(1, srvs[0].getConnectCount()); - - for (int i = 1; i < SERVERS_CNT; i++) - assertEquals(0, srvs[i].getConnectCount()); - - srvs[0].resetCounters(); - - int contactedSrv = 0; - - for (int i = 0; i < 100; i++) { - int failed = contactedSrv; - - srvs[failed].fail(); - - // Sometimes session close missing on client side. Retry few times until request succeeds. - while (true) - try { - client.compute().refreshTopology(false, false); - - break; - } - catch (GridClientConnectionResetException e) { - info("Exception caught: " + e); - } - - // Check which servers where contacted, - int connects = 0; - - for (int srv = 0; srv < SERVERS_CNT; srv++) { - if (srvs[srv].getSuccessfulConnectCount() > 0) { - assertTrue("Failed server was contacted: " + srv, srv != failed); - - contactedSrv = srv; - } - - connects += srvs[srv].getSuccessfulConnectCount(); - } - - assertEquals(1, connects); // Only one new connection should be opened. - - srvs[failed].repair(); - - srvs[contactedSrv].resetCounters(); // It should be the only server with non-0 counters. - } - - } - } - - /** - * @throws Exception If failed. - */ - public void testCorrectInit() throws Exception { - for (int i = 0; i < SERVERS_CNT; i++) - runServer(i, i == 0); - - try (GridClient ignored = client()) { // Here client opens initial connection and fetches topology. - // First and second should be contacted, due to failure in initial request to the first. - for (int i = 0; i < 2; i++) - assertEquals("Iteration: " + i, 1, srvs[i].getConnectCount()); - - for (int i = 2; i < SERVERS_CNT; i++) - assertEquals(0, srvs[i].getConnectCount()); - } - } - - /** - * @throws Exception If failed. - */ - public void testFailedInit() throws Exception { - for (int i = 0; i < SERVERS_CNT; i++) - runServer(i, true); - - GridClient c = client(); - - try { - c.compute().execute("fake", "arg"); - - fail("Client operation should fail when server resets connections."); - } - catch (GridClientDisconnectedException e) { - assertTrue("Thrown exception doesn't have an expected cause: " + X.getFullStackTrace(e), - X.hasCause(e, GridClientConnectionResetException.class, ClosedChannelException.class)); - } - - for (int i = 0; i < SERVERS_CNT; i++) - // Connection manager does 3 attempts to get topology before failure. - assertEquals("Server: " + i, 3, srvs[i].getConnectCount()); - } - - /** - * @throws Exception If failed. - */ - // TODO Uncomment when GG-3789 fixed. -// public void testIdleConnection() throws Exception { -// for (int i = 0; i < SERVERS_CNT; i++) -// runServer(i, false); -// -// GridClient client = client(); // Here client opens initial connection and fetches topology. -// -// try { -// // Only first server in list should be contacted. -// assertEquals(1, srvs[0].getConnectCount()); -// -// Thread.sleep(35000); // Timeout as idle. -// -// assertEquals(1, srvs[0].getDisconnectCount()); -// -// for (int i = 1; i < SERVERS_CNT; i++) -// assertEquals(0, srvs[i].getConnectCount()); -// -// srvs[0].resetCounters(); -// -// // On new request connection should be re-opened. -// client.compute().refreshTopology(false, false); -// -// assertEquals(1, srvs[0].getConnectCount()); -// -// for (int i = 1; i < SERVERS_CNT; i++) -// assertEquals(0, srvs[i].getConnectCount()); -// } -// finally { -// GridClientFactory.stop(client.id()); -// } -// } - - /** - * Runs a new server with given index. - * - * @param idx Server index, same as in client configuration's servers property. - * @param failOnConnect If {@code true} the server should fail incoming connection immediately. - * @return Server instance. - * @throws IgniteCheckedException If failed. - */ - private ClientTestRestServer runServer(int idx, boolean failOnConnect) throws IgniteCheckedException { - ClientTestRestServer srv = new ClientTestRestServer(FIRST_SERVER_PORT + idx, failOnConnect, log()); - - srv.start(); - - srvs[idx] = srv; - - return srv; - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/756034f3/modules/clients/src/test/java/org/apache/ignite/client/ClientSslNodeStartup.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/client/ClientSslNodeStartup.java b/modules/clients/src/test/java/org/apache/ignite/client/ClientSslNodeStartup.java deleted file mode 100644 index f29f427..0000000 --- a/modules/clients/src/test/java/org/apache/ignite/client/ClientSslNodeStartup.java +++ /dev/null @@ -1,59 +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.client; - -import org.apache.ignite.*; -import org.apache.ignite.internal.util.typedef.*; -import org.apache.ignite.internal.util.typedef.internal.*; - -/** - * Starts up one grid node (server) with pre-defined ports and tasks to test client-server interactions. - * <p> - * Note that different nodes cannot share the same port for rest services. If you want - * to start more than one node on the same physical machine you must provide different - * configurations for each node. Otherwise, this example would not work. - * <p> - * After this example has been started you can use pre-defined endpoints and task names in your - * client-server interactions to work with the node over secured protocols (binary over SSL or https). - * <p> - * Usually you cannot start secured and unsecured nodes in one grid, so started together - * secured and unsecured nodes belong to different grids. - * <p> - * Available endponts: - * <ul> - * <li>127.0.0.1:10443 - TCP SSL-protected endpoint.</li> - * <li>127.0.0.1:11443 - HTTP SSL-protected endpoint.</li> - * </ul> - * <p> - * Required credentials for remote client authentication: "s3cret". - */ -public class ClientSslNodeStartup { - /** - * Starts up two nodes with specified cache configuration on pre-defined endpoints. - * - * @param args Command line arguments, none required. - * @throws IgniteCheckedException In case of any exception. - */ - public static void main(String[] args) throws IgniteCheckedException { - System.setProperty("CLIENTS_MODULE_PATH", U.resolveGridGainPath("modules/clients").getAbsolutePath()); - - try (Ignite g = G.start("modules/clients/src/test/resources/spring-server-ssl-node.xml")) { - U.sleep(Long.MAX_VALUE); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/756034f3/modules/clients/src/test/java/org/apache/ignite/client/ClientStartNodeTask.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/client/ClientStartNodeTask.java b/modules/clients/src/test/java/org/apache/ignite/client/ClientStartNodeTask.java deleted file mode 100644 index 5560593..0000000 --- a/modules/clients/src/test/java/org/apache/ignite/client/ClientStartNodeTask.java +++ /dev/null @@ -1,180 +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.client; - -import org.apache.ignite.*; -import org.apache.ignite.compute.*; -import org.apache.ignite.configuration.*; -import org.apache.ignite.resources.*; -import org.apache.ignite.internal.util.typedef.*; -import org.apache.ignite.internal.util.typedef.internal.*; -import org.springframework.beans.factory.*; -import org.springframework.context.support.*; - -import java.net.*; -import java.util.*; - -import static org.apache.ignite.compute.ComputeJobResultPolicy.*; - -/** - * Start node task, applicable arguments: - * <ul> - * <li>tcp</li> - * <li>http</li> - * <li>tcp+ssl</li> - * <li>http+ssl</li> - * </ul> - */ -public class ClientStartNodeTask extends TaskSingleJobSplitAdapter<String, Integer> { - /** - * Available node's configurations. - */ - private static final Map<String, String> NODE_CFG = new HashMap<String, String>() {{ - put("tcp", "modules/clients/src/test/resources/spring-server-node.xml"); - put("http", "modules/clients/src/test/resources/spring-server-node.xml"); - put("tcp+ssl", "modules/clients/src/test/resources/spring-server-ssl-node.xml"); - put("http+ssl", "modules/clients/src/test/resources/spring-server-ssl-node.xml"); - }}; - - /** */ - @IgniteLoggerResource - private transient IgniteLogger log; - - /** */ - @IgniteInstanceResource - private transient Ignite ignite; - - /** {@inheritDoc} */ - @Override protected Object executeJob(int gridSize, String type) throws IgniteCheckedException { - log.info(">>> Starting new grid node [currGridSize=" + gridSize + ", arg=" + type + "]"); - - if (type == null) - throw new IllegalArgumentException("Node type to start should be specified."); - - IgniteConfiguration cfg = getConfig(type); - - // Generate unique for this VM grid name. - String gridName = cfg.getGridName() + " (" + UUID.randomUUID() + ")"; - - // Update grid name (required to be unique). - cfg.setGridName(gridName); - - // Start new node in current VM. - Ignite g = G.start(cfg); - - log.info(">>> Grid started [nodeId=" + g.cluster().localNode().id() + ", name='" + g.name() + "']"); - - return true; - } - - /** {@inheritDoc} */ - @Override public ComputeJobResultPolicy result(ComputeJobResult res, List<ComputeJobResult> rcvd) - throws IgniteCheckedException { - if (res.getException() != null) - return FAILOVER; - - return WAIT; - } - - /** - * Load grid configuration for specified node type. - * - * @param type Node type to load configuration for. - * @return Grid configuration for specified node type. - */ - static IgniteConfiguration getConfig(String type) { - String path = NODE_CFG.get(type); - - if (path == null) - throw new IllegalArgumentException("Unsupported node type: " + type); - - URL url = U.resolveGridGainUrl(path); - - BeanFactory ctx = new FileSystemXmlApplicationContext(url.toString()); - - return (IgniteConfiguration)ctx.getBean("grid.cfg"); - } - - /** - * Example for start/stop node tasks. - * - * @param args Not used. - */ - public static void main(String[] args) { - String nodeType = "tcp+ssl"; - - // Start initial node = 1 - try (Ignite g = G.start(NODE_CFG.get(nodeType))) { - // Change topology. - changeTopology(g, 4, 1, nodeType); - changeTopology(g, 1, 4, nodeType); - - // Stop node by id = 0 - g.compute().execute(ClientStopNodeTask.class, g.cluster().localNode().id().toString()); - - // Wait for node stops. - //U.sleep(1000); - - assert G.allGrids().isEmpty(); - } - catch (IgniteCheckedException e) { - System.err.println("Uncaught exception: " + e.getMessage()); - - e.printStackTrace(System.err); - } - } - - /** - * Change topology. - * - * @param parent Grid to execute tasks on. - * @param add New nodes count. - * @param rmv Remove nodes count. - * @param type Type of nodes to manipulate. - * @throws IgniteCheckedException On any exception. - */ - private static void changeTopology(Ignite parent, int add, int rmv, String type) throws IgniteCheckedException { - Collection<ComputeTaskFuture<?>> tasks = new ArrayList<>(); - - IgniteCompute comp = parent.compute().withAsync(); - - // Start nodes in parallel. - while (add-- > 0) { - comp.execute(ClientStartNodeTask.class, type); - - tasks.add(comp.future()); - } - - for (ComputeTaskFuture<?> task : tasks) - task.get(); - - // Stop nodes in sequence. - while (rmv-- > 0) - parent.compute().execute(ClientStopNodeTask.class, type); - - // Wait for node stops. - //U.sleep(1000); - - Collection<String> gridNames = new ArrayList<>(); - - for (Ignite g : G.allGrids()) - gridNames.add(g.name()); - - parent.log().info(">>> Available grids: " + gridNames); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/756034f3/modules/clients/src/test/java/org/apache/ignite/client/ClientStopNodeTask.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/client/ClientStopNodeTask.java b/modules/clients/src/test/java/org/apache/ignite/client/ClientStopNodeTask.java deleted file mode 100644 index 364c05b..0000000 --- a/modules/clients/src/test/java/org/apache/ignite/client/ClientStopNodeTask.java +++ /dev/null @@ -1,127 +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.client; - -import org.apache.ignite.*; -import org.apache.ignite.compute.*; -import org.apache.ignite.resources.*; -import org.apache.ignite.internal.util.typedef.*; - -import java.util.*; - -import static org.apache.ignite.compute.ComputeJobResultPolicy.*; - -/** - * Stop node task, applicable arguments: - * <ul> - * <li>node id (as string) to stop or</li> - * <li>node type (see start nodes task).</li> - * </ul> - */ -public class ClientStopNodeTask extends ComputeTaskSplitAdapter<String, Integer> { - /** */ - @IgniteLoggerResource - private transient IgniteLogger log; - - /** */ - @IgniteInstanceResource - private transient Ignite ignite; - - /** {@inheritDoc} */ - @Override protected Collection<? extends ComputeJob> split(int gridSize, String arg) throws IgniteCheckedException { - Collection<ComputeJob> jobs = new ArrayList<>(); - - for (int i = 0; i < gridSize; i++) - jobs.add(new StopJob(arg)); - - return jobs; - } - - /** {@inheritDoc} */ - @Override public ComputeJobResultPolicy result(ComputeJobResult res, List<ComputeJobResult> rcvd) throws IgniteCheckedException { - ComputeJobResultPolicy superRes = super.result(res, rcvd); - - // Deny failover. - if (superRes == FAILOVER) - superRes = WAIT; - - return superRes; - } - - /** {@inheritDoc} */ - @Override public Integer reduce(List<ComputeJobResult> results) throws IgniteCheckedException { - int stoppedCnt = 0; - - for (ComputeJobResult res : results) - if (!res.isCancelled()) - stoppedCnt+=(Integer)res.getData(); - - return stoppedCnt; - } - - /** - * Stop node job it is executed on. - */ - private static class StopJob extends ComputeJobAdapter { - /** */ - private final String gridType; - - /** */ - @IgniteLoggerResource - private IgniteLogger log; - - /** */ - @IgniteInstanceResource - private Ignite ignite; - - /** */ - private StopJob(String gridType) { - this.gridType = gridType; - } - - /** {@inheritDoc} */ - @Override public Object execute() { - log.info(">>> Stop node [nodeId=" + ignite.cluster().localNode().id() + ", name='" + ignite.name() + "']"); - - String prefix = ClientStartNodeTask.getConfig(gridType).getGridName() + " ("; - - if (!ignite.name().startsWith(prefix)) { - int stoppedCnt = 0; - - for (Ignite g : G.allGrids()) - if (g.name().startsWith(prefix)) { - try { - log.info(">>> Grid stopping [nodeId=" + g.cluster().localNode().id() + - ", name='" + g.name() + "']"); - - G.stop(g.name(), true); - - stoppedCnt++; - } - catch (IllegalStateException e) { - log.warning("Failed to stop grid.", e); - } - } - - return stoppedCnt; - } - - return 0; - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/756034f3/modules/clients/src/test/java/org/apache/ignite/client/ClientStringLengthTask.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/client/ClientStringLengthTask.java b/modules/clients/src/test/java/org/apache/ignite/client/ClientStringLengthTask.java deleted file mode 100644 index 7e292d9..0000000 --- a/modules/clients/src/test/java/org/apache/ignite/client/ClientStringLengthTask.java +++ /dev/null @@ -1,73 +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.client; - -import org.apache.ignite.*; -import org.apache.ignite.compute.*; - -import java.util.*; - -import static org.apache.ignite.compute.ComputeJobResultPolicy.*; - -/** - * Test task calculate length of the string passed in the argument. - * <p> - * The argument of the task is a simple string to calculate length of. - */ -public class ClientStringLengthTask extends ComputeTaskSplitAdapter<String, Integer> { - /** {@inheritDoc} */ - @Override protected Collection<? extends ComputeJob> split(int gridSize, String arg) throws IgniteCheckedException { - Collection<ComputeJobAdapter> jobs = new ArrayList<>(); - - if (arg != null) - for (final Object val : arg.split("")) - jobs.add(new ComputeJobAdapter() { - @Override public Object execute() { - try { - Thread.sleep(5); - } - catch (InterruptedException ignored) { - Thread.currentThread().interrupt(); - } - - return val == null ? 0 : val.toString().length(); - } - }); - - return jobs; - } - - /** {@inheritDoc} */ - @Override public Integer reduce(List<ComputeJobResult> results) throws IgniteCheckedException { - int sum = 0; - - for (ComputeJobResult res : results) - sum += res.<Integer>getData(); - - return sum; - } - - /** {@inheritDoc} */ - @Override public ComputeJobResultPolicy result(ComputeJobResult res, List<ComputeJobResult> rcvd) - throws IgniteCheckedException { - if (res.getException() != null) - return FAILOVER; - - return WAIT; - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/756034f3/modules/clients/src/test/java/org/apache/ignite/client/ClientTcpMultiThreadedSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/client/ClientTcpMultiThreadedSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/client/ClientTcpMultiThreadedSelfTest.java deleted file mode 100644 index 88ebf40..0000000 --- a/modules/clients/src/test/java/org/apache/ignite/client/ClientTcpMultiThreadedSelfTest.java +++ /dev/null @@ -1,46 +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.client; - -import org.apache.ignite.internal.client.*; -import org.apache.ignite.internal.client.ssl.*; - -/** - * Runs multi-threaded tests on tcp binary protocol (ssl is disabled). - */ -public class ClientTcpMultiThreadedSelfTest extends ClientAbstractMultiThreadedSelfTest { - /** {@inheritDoc} */ - @Override protected GridClientProtocol protocol() { - return GridClientProtocol.TCP; - } - - /** {@inheritDoc} */ - @Override protected String serverAddress() { - return HOST + ":" + REST_TCP_PORT_BASE; - } - - /** {@inheritDoc} */ - @Override protected boolean useSsl() { - return false; - } - - /** {@inheritDoc} */ - @Override protected GridSslContextFactory sslContextFactory() { - return null; - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/756034f3/modules/clients/src/test/java/org/apache/ignite/client/ClientTcpSslAuthenticationSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/client/ClientTcpSslAuthenticationSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/client/ClientTcpSslAuthenticationSelfTest.java deleted file mode 100644 index 48b9862..0000000 --- a/modules/clients/src/test/java/org/apache/ignite/client/ClientTcpSslAuthenticationSelfTest.java +++ /dev/null @@ -1,266 +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.client; - -import org.apache.ignite.configuration.*; -import org.apache.ignite.internal.client.*; -import org.apache.ignite.internal.client.balancer.*; -import org.apache.ignite.internal.client.impl.*; -import org.apache.ignite.internal.client.ssl.*; -import org.apache.ignite.internal.util.typedef.*; -import org.apache.ignite.internal.util.typedef.internal.*; -import org.apache.ignite.testframework.*; -import org.apache.ignite.testframework.junits.common.*; - -import javax.net.ssl.*; -import java.security.cert.*; -import java.util.*; -import java.util.concurrent.atomic.*; - -/** - * Tests - */ -public class ClientTcpSslAuthenticationSelfTest extends GridCommonAbstractTest { - /** REST TCP port. */ - private static final int REST_TCP_PORT = 12121; - - /** Test trust manager for server. */ - private MockX509TrustManager srvTrustMgr = new MockX509TrustManager(); - - /** Test trust manager for client. */ - private MockX509TrustManager clientTrustMgr = new MockX509TrustManager(); - - /** Whether server should check clients. */ - private volatile boolean checkClient; - - /** {@inheritDoc} */ - @Override protected void afterTest() throws Exception { - assertEquals(0, srvTrustMgr.serverCheckCallCount()); - assertEquals(0, clientTrustMgr.clientCheckCallCount()); - } - - /** {@inheritDoc} */ - @Override protected void beforeTest() throws Exception { - srvTrustMgr.reset(); - clientTrustMgr.reset(); - } - - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { - IgniteConfiguration c = super.getConfiguration(gridName); - - c.setLocalHost(getTestResources().getLocalHost()); - - assert c.getClientConnectionConfiguration() == null; - - ClientConnectionConfiguration clientCfg = new ClientConnectionConfiguration(); - - clientCfg.setRestTcpPort(REST_TCP_PORT); - clientCfg.setRestTcpSslEnabled(true); - - clientCfg.setRestTcpSslClientAuth(checkClient); - clientCfg.setRestTcpSslClientAuth(checkClient); - - GridSslBasicContextFactory factory = (GridSslBasicContextFactory)GridTestUtils.sslContextFactory(); - - factory.setTrustManagers(srvTrustMgr); - - clientCfg.setRestTcpSslContextFactory(factory); - - c.setClientConnectionConfiguration(clientCfg); - - return c; - } - - /** - * Creates client that will try to connect to only first node in grid. - * - * @return Client. - * @throws Exception If failed to create client. - */ - private GridClientImpl createClient() throws Exception { - GridClientConfiguration cfg = new GridClientConfiguration(); - - cfg.setServers(Arrays.asList(U.getLocalHost().getHostAddress() + ":" + REST_TCP_PORT)); - cfg.setBalancer(new GridClientRoundRobinBalancer()); - - GridSslBasicContextFactory factory = (GridSslBasicContextFactory)GridTestUtils.sslContextFactory(); - - factory.setTrustManagers(clientTrustMgr); - - cfg.setSslContextFactory(factory); - - return (GridClientImpl)GridClientFactory.start(cfg); - } - - /** - * @throws Exception If failed. - */ - public void testServerAuthenticated() throws Exception { - checkServerAuthenticatedByClient(false); - } - - /** - * @throws Exception If failed. - */ - public void testServerNotAuthenticatedByClient() throws Exception { - try { - checkServerAuthenticatedByClient(true); - } - catch (GridClientDisconnectedException e) { - assertTrue(X.hasCause(e, GridServerUnreachableException.class)); - } - } - - /** - * @throws Exception If failed. - */ - public void testClientAuthenticated() throws Exception { - checkClientAuthenticatedByServer(false); - } - - /** - * @throws Exception If failed. - */ - public void testClientNotAuthenticated() throws Exception { - try { - checkServerAuthenticatedByClient(true); - } - catch (GridClientDisconnectedException e) { - assertTrue(X.hasCause(e, GridServerUnreachableException.class)); - } - } - - /** - * @param fail Should client trust manager fail. - * @throws Exception If failed. - */ - private void checkServerAuthenticatedByClient(boolean fail) throws Exception { - checkClient = false; - srvTrustMgr.shouldFail(false); - clientTrustMgr.shouldFail(fail); - - startGrid(); - - try { - try (GridClientImpl c = createClient()) { - c.compute().refreshTopology(false, false); - } - } - finally { - G.stopAll(false); - } - - assertEquals(0, srvTrustMgr.clientCheckCallCount()); - assertEquals(1, clientTrustMgr.serverCheckCallCount()); - } - - /** - * @param fail Should server trust manager fail. - * @throws Exception If failed. - */ - private void checkClientAuthenticatedByServer(boolean fail) throws Exception { - checkClient = true; - srvTrustMgr.shouldFail(fail); - clientTrustMgr.shouldFail(false); - - startGrid(); - - try { - try (GridClientImpl c = createClient()) { - c.compute().refreshTopology(false, false); - } - } - finally { - G.stopAll(false); - } - - assertEquals(1, srvTrustMgr.clientCheckCallCount()); - assertEquals(1, clientTrustMgr.serverCheckCallCount()); - } - - /** - * Test trust manager to emulate certificate check failures. - */ - private static class MockX509TrustManager implements X509TrustManager { - /** Empty array. */ - private static final X509Certificate[] EMPTY = new X509Certificate[0]; - - /** Whether checks should fail. */ - private volatile boolean shouldFail; - - /** Client check call count. */ - private AtomicInteger clientCheckCallCnt = new AtomicInteger(); - - /** Server check call count. */ - private AtomicInteger srvCheckCallCnt = new AtomicInteger(); - - /** - * @param shouldFail Whether checks should fail. - */ - private void shouldFail(boolean shouldFail) { - this.shouldFail = shouldFail; - } - - /** {@inheritDoc} */ - @Override public void checkClientTrusted(X509Certificate[] x509Certificates, String s) - throws CertificateException { - clientCheckCallCnt.incrementAndGet(); - - if (shouldFail) - throw new CertificateException("Client check failed."); - } - - /** {@inheritDoc} */ - @Override public void checkServerTrusted(X509Certificate[] x509Certificates, String s) - throws CertificateException { - srvCheckCallCnt.incrementAndGet(); - - if (shouldFail) - throw new CertificateException("Server check failed."); - } - - /** {@inheritDoc} */ - @Override public X509Certificate[] getAcceptedIssuers() { - return EMPTY; - } - - /** - * @return Call count to checkClientTrusted method. - */ - public int clientCheckCallCount() { - return clientCheckCallCnt.get(); - } - - /** - * @return Call count to checkServerTrusted method. - */ - public int serverCheckCallCount() { - return srvCheckCallCnt.get(); - } - - /** - * Clears should fail flag and resets call counters. - */ - public void reset() { - shouldFail = false; - clientCheckCallCnt.set(0); - srvCheckCallCnt.set(0); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/756034f3/modules/clients/src/test/java/org/apache/ignite/client/ClientTcpSslMultiThreadedSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/client/ClientTcpSslMultiThreadedSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/client/ClientTcpSslMultiThreadedSelfTest.java deleted file mode 100644 index 79691f2..0000000 --- a/modules/clients/src/test/java/org/apache/ignite/client/ClientTcpSslMultiThreadedSelfTest.java +++ /dev/null @@ -1,47 +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.client; - -import org.apache.ignite.internal.client.*; -import org.apache.ignite.internal.client.ssl.*; -import org.apache.ignite.testframework.*; - -/** - * Runs multithreaded tests for client over tcp binary protocol with ssl enabled. - */ -public class ClientTcpSslMultiThreadedSelfTest extends ClientAbstractMultiThreadedSelfTest { - /** {@inheritDoc} */ - @Override protected GridClientProtocol protocol() { - return GridClientProtocol.TCP; - } - - /** {@inheritDoc} */ - @Override protected String serverAddress() { - return HOST + ":" + REST_TCP_PORT_BASE; - } - - /** {@inheritDoc} */ - @Override protected boolean useSsl() { - return true; - } - - /** {@inheritDoc} */ - @Override protected GridSslContextFactory sslContextFactory() { - return GridTestUtils.sslContextFactory(); - } -}