# ignite-63

Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/1b0e45a2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/1b0e45a2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/1b0e45a2

Branch: refs/heads/ignite-63
Commit: 1b0e45a212d1ee0f1d45e9ec62fbe89f0cc595ef
Parents: f87f82f
Author: sboikov <[email protected]>
Authored: Thu Jan 22 23:54:17 2015 +0300
Committer: sboikov <[email protected]>
Committed: Thu Jan 22 23:54:25 2015 +0300

----------------------------------------------------------------------
 .../ignite/client/GridClientTestRestServer.java |    4 +-
 .../impl/GridClientCacheFlagsCodecTest.java     |    2 +-
 .../client/suite/GridClientTestSuite.java       |    4 +-
 .../rest/GridAbstractRestProcessorSelfTest.java |   95 ++
 .../GridClientMemcachedProtocolSelfTest.java    |  443 +++++
 .../GridJettyRestProcessorAbstractSelfTest.java |  724 ++++++++
 .../GridJettyRestProcessorSignedSelfTest.java   |  103 ++
 .../GridJettyRestProcessorUnsignedSelfTest.java |   36 +
 .../rest/GridMemcacheRestProcessorTest.java     |   76 +
 .../rest/GridRestBinaryProtocolSelfTest.java    |  633 +++++++
 .../rest/GridRestMemcacheProtocolSelfTest.java  |  331 ++++
 .../GridRestProcessorMultiStartSelfTest.java    |   55 +
 .../rest/GridRestProcessorStartSelfTest.java    |  163 ++
 .../processors/rest/GridRestProcessorTest.java  |  346 ++++
 .../rest/GridTaskCommandHandlerSelfTest.java    |  211 +++
 .../processors/rest/GridTestBinaryClient.java   |  651 ++++++++
 .../processors/rest/GridTestMemcacheClient.java |  898 ++++++++++
 .../internal/processors/rest/TestTask1.java     |   52 +
 .../internal/processors/rest/TestTask2.java     |   54 +
 .../rest/protocols/tcp/GridMockNioSession.java  |  155 ++
 .../tcp/GridTcpRestParserSelfTest.java          |  451 +++++
 .../rest/GridAbstractRestProcessorSelfTest.java |   96 --
 .../GridClientMemcachedProtocolSelfTest.java    |  443 -----
 .../GridJettyRestProcessorAbstractSelfTest.java |  724 --------
 .../GridJettyRestProcessorSignedSelfTest.java   |  103 --
 .../GridJettyRestProcessorUnsignedSelfTest.java |   36 -
 .../rest/GridMemcacheRestProcessorTest.java     |   76 -
 .../rest/GridRestBinaryProtocolSelfTest.java    |  633 -------
 .../rest/GridRestMemcacheProtocolSelfTest.java  |  331 ----
 .../GridRestProcessorMultiStartSelfTest.java    |   55 -
 .../rest/GridRestProcessorStartSelfTest.java    |  163 --
 .../processors/rest/GridRestProcessorTest.java  |  346 ----
 .../rest/GridTaskCommandHandlerSelfTest.java    |  211 ---
 .../processors/rest/GridTestBinaryClient.java   |  651 --------
 .../processors/rest/GridTestMemcacheClient.java |  898 ----------
 .../grid/kernal/processors/rest/TestTask1.java  |   52 -
 .../grid/kernal/processors/rest/TestTask2.java  |   54 -
 .../rest/protocols/tcp/GridMockNioSession.java  |  155 --
 .../tcp/GridTcpRestParserSelfTest.java          |  451 -----
 .../GridClientMarshallerBenchmarkTest.java      |    4 +-
 .../GridClientConnectionManagerAdapter.java     |    2 +-
 .../connection/GridClientNioTcpConnection.java  |    4 +-
 .../GridClientOptimizedMarshaller.java          |    2 +-
 .../client/router/impl/GridTcpRouterImpl.java   |    2 +-
 .../impl/GridTcpRouterNioListenerAdapter.java   |    2 +-
 .../router/impl/GridTcpRouterNioParser.java     |    6 +-
 .../org/apache/ignite/internal/GridKernal.java  |    2 +-
 .../ignite/internal/GridKernalContext.java      |    2 +-
 .../ignite/internal/GridKernalContextImpl.java  |    2 +-
 .../processors/rest/GridRestCommand.java        |  160 ++
 .../processors/rest/GridRestProcessor.java      |  697 ++++++++
 .../processors/rest/GridRestProtocol.java       |   59 +
 .../rest/GridRestProtocolHandler.java           |   40 +
 .../processors/rest/GridRestResponse.java       |  177 ++
 .../message/GridClientAbstractMessage.java      |  117 ++
 .../GridClientAuthenticationRequest.java        |   85 +
 .../message/GridClientCacheQueryRequest.java    |  414 +++++
 .../client/message/GridClientCacheRequest.java  |  319 ++++
 .../message/GridClientGetMetaDataRequest.java   |   64 +
 .../message/GridClientHandshakeRequest.java     |  108 ++
 .../GridClientHandshakeRequestWrapper.java      |  129 ++
 .../message/GridClientHandshakeResponse.java    |   66 +
 .../GridClientHandshakeResponseWrapper.java     |   96 ++
 .../client/message/GridClientLogRequest.java    |  141 ++
 .../rest/client/message/GridClientMessage.java  |   82 +
 .../message/GridClientMessageWrapper.java       |  266 +++
 .../message/GridClientMetaDataResponse.java     |   57 +
 .../rest/client/message/GridClientNodeBean.java |  342 ++++
 .../message/GridClientNodeMetricsBean.java      | 1578 ++++++++++++++++++
 .../client/message/GridClientPingPacket.java    |   37 +
 .../message/GridClientPingPacketWrapper.java    |   89 +
 .../message/GridClientPortableMetaData.java     |   93 ++
 .../message/GridClientPutMetaDataRequest.java   |   64 +
 .../rest/client/message/GridClientResponse.java |  145 ++
 .../client/message/GridClientTaskRequest.java   |  152 ++
 .../message/GridClientTaskResultBean.java       |  147 ++
 .../message/GridClientTopologyRequest.java      |  174 ++
 .../rest/client/message/GridRouterRequest.java  |   57 +
 .../rest/client/message/GridRouterResponse.java |   84 +
 .../processors/rest/client/message/package.html |   23 +
 .../rest/handlers/GridRestCommandHandler.java   |   40 +
 .../handlers/GridRestCommandHandlerAdapter.java |   51 +
 .../cache/GridCacheClientQueryResult.java       |  119 ++
 .../handlers/cache/GridCacheCommandHandler.java | 1149 +++++++++++++
 .../cache/GridCacheQueryCommandHandler.java     |  493 ++++++
 .../handlers/cache/GridCacheRestMetrics.java    |  215 +++
 .../handlers/cache/GridCacheRestResponse.java   |   67 +
 .../processors/rest/handlers/cache/package.html |   23 +
 .../handlers/log/GridLogCommandHandler.java     |  307 ++++
 .../processors/rest/handlers/log/package.html   |   23 +
 .../metadata/GridPortableMetadataHandler.java   |  104 ++
 .../processors/rest/handlers/package.html       |   23 +
 .../handlers/task/GridTaskCommandHandler.java   |  638 +++++++
 .../handlers/task/GridTaskResultRequest.java    |  185 ++
 .../handlers/task/GridTaskResultResponse.java   |  233 +++
 .../top/GridTopologyCommandHandler.java         |  335 ++++
 .../processors/rest/handlers/top/package.html   |   23 +
 .../version/GridVersionCommandHandler.java      |   60 +
 .../rest/handlers/version/package.html          |   23 +
 .../internal/processors/rest/package.html       |   23 +
 .../rest/protocols/GridRestProtocolAdapter.java |  196 +++
 .../processors/rest/protocols/package.html      |   23 +
 .../protocols/tcp/GridClientPacketType.java     |   32 +
 .../protocols/tcp/GridMemcachedMessage.java     |  485 ++++++
 .../tcp/GridMemcachedMessageWrapper.java        |  269 +++
 .../tcp/GridTcpMemcachedNioListener.java        |  442 +++++
 .../protocols/tcp/GridTcpRestDirectParser.java  |  519 ++++++
 .../protocols/tcp/GridTcpRestNioListener.java   |  386 +++++
 .../rest/protocols/tcp/GridTcpRestParser.java   |  878 ++++++++++
 .../rest/protocols/tcp/GridTcpRestProtocol.java |  335 ++++
 .../processors/rest/protocols/tcp/package.html  |   23 +
 .../rest/request/GridRestCacheQueryRequest.java |  143 ++
 .../rest/request/GridRestCacheRequest.java      |  182 ++
 .../rest/request/GridRestLogRequest.java        |   81 +
 .../GridRestPortableGetMetaDataRequest.java     |   44 +
 .../GridRestPortablePutMetaDataRequest.java     |   44 +
 .../rest/request/GridRestRequest.java           |  167 ++
 .../rest/request/GridRestTaskRequest.java       |  134 ++
 .../rest/request/GridRestTopologyRequest.java   |  100 ++
 .../processors/rest/request/package.html        |   23 +
 .../GridTcpCommunicationMessageFactory.java     |    2 +-
 .../kernal/processors/rest/GridRestCommand.java |  160 --
 .../processors/rest/GridRestProcessor.java      |  697 --------
 .../processors/rest/GridRestProtocol.java       |   59 -
 .../rest/GridRestProtocolHandler.java           |   40 -
 .../processors/rest/GridRestResponse.java       |  177 --
 .../message/GridClientAbstractMessage.java      |  117 --
 .../GridClientAuthenticationRequest.java        |   85 -
 .../message/GridClientCacheQueryRequest.java    |  414 -----
 .../client/message/GridClientCacheRequest.java  |  319 ----
 .../message/GridClientGetMetaDataRequest.java   |   64 -
 .../message/GridClientHandshakeRequest.java     |  108 --
 .../GridClientHandshakeRequestWrapper.java      |  129 --
 .../message/GridClientHandshakeResponse.java    |   66 -
 .../GridClientHandshakeResponseWrapper.java     |   96 --
 .../client/message/GridClientLogRequest.java    |  141 --
 .../rest/client/message/GridClientMessage.java  |   82 -
 .../message/GridClientMessageWrapper.java       |  266 ---
 .../message/GridClientMetaDataResponse.java     |   57 -
 .../rest/client/message/GridClientNodeBean.java |  342 ----
 .../message/GridClientNodeMetricsBean.java      | 1578 ------------------
 .../client/message/GridClientPingPacket.java    |   37 -
 .../message/GridClientPingPacketWrapper.java    |   89 -
 .../message/GridClientPortableMetaData.java     |   93 --
 .../message/GridClientPutMetaDataRequest.java   |   64 -
 .../rest/client/message/GridClientResponse.java |  145 --
 .../client/message/GridClientTaskRequest.java   |  152 --
 .../message/GridClientTaskResultBean.java       |  147 --
 .../message/GridClientTopologyRequest.java      |  174 --
 .../rest/client/message/GridRouterRequest.java  |   57 -
 .../rest/client/message/GridRouterResponse.java |   84 -
 .../processors/rest/client/message/package.html |   23 -
 .../rest/handlers/GridRestCommandHandler.java   |   40 -
 .../handlers/GridRestCommandHandlerAdapter.java |   51 -
 .../cache/GridCacheClientQueryResult.java       |  119 --
 .../handlers/cache/GridCacheCommandHandler.java | 1149 -------------
 .../cache/GridCacheQueryCommandHandler.java     |  493 ------
 .../handlers/cache/GridCacheRestMetrics.java    |  215 ---
 .../handlers/cache/GridCacheRestResponse.java   |   67 -
 .../processors/rest/handlers/cache/package.html |   23 -
 .../handlers/log/GridLogCommandHandler.java     |  307 ----
 .../processors/rest/handlers/log/package.html   |   23 -
 .../metadata/GridPortableMetadataHandler.java   |  104 --
 .../processors/rest/handlers/package.html       |   23 -
 .../handlers/task/GridTaskCommandHandler.java   |  638 -------
 .../handlers/task/GridTaskResultRequest.java    |  185 --
 .../handlers/task/GridTaskResultResponse.java   |  233 ---
 .../top/GridTopologyCommandHandler.java         |  335 ----
 .../processors/rest/handlers/top/package.html   |   23 -
 .../version/GridVersionCommandHandler.java      |   60 -
 .../rest/handlers/version/package.html          |   23 -
 .../grid/kernal/processors/rest/package.html    |   23 -
 .../rest/protocols/GridRestProtocolAdapter.java |  196 ---
 .../processors/rest/protocols/package.html      |   23 -
 .../protocols/tcp/GridClientPacketType.java     |   32 -
 .../protocols/tcp/GridMemcachedMessage.java     |  485 ------
 .../tcp/GridMemcachedMessageWrapper.java        |  269 ---
 .../tcp/GridTcpMemcachedNioListener.java        |  442 -----
 .../protocols/tcp/GridTcpRestDirectParser.java  |  519 ------
 .../protocols/tcp/GridTcpRestNioListener.java   |  386 -----
 .../rest/protocols/tcp/GridTcpRestParser.java   |  878 ----------
 .../rest/protocols/tcp/GridTcpRestProtocol.java |  335 ----
 .../processors/rest/protocols/tcp/package.html  |   23 -
 .../rest/request/GridRestCacheQueryRequest.java |  143 --
 .../rest/request/GridRestCacheRequest.java      |  182 --
 .../rest/request/GridRestLogRequest.java        |   81 -
 .../GridRestPortableGetMetaDataRequest.java     |   44 -
 .../GridRestPortablePutMetaDataRequest.java     |   44 -
 .../rest/request/GridRestRequest.java           |  167 --
 .../rest/request/GridRestTaskRequest.java       |  134 --
 .../rest/request/GridRestTopologyRequest.java   |  100 --
 .../kernal/processors/rest/request/package.html |   23 -
 .../cache/GridCacheCommandHandlerSelfTest.java  |  263 +++
 .../cache/GridCacheCommandHandlerSelfTest.java  |  263 ---
 .../bamboo/GridRestHandlerTestSuite.java        |    2 +-
 .../http/jetty/GridJettyJsonConfig.java         |   50 +
 .../http/jetty/GridJettyRestHandler.java        |  595 +++++++
 .../http/jetty/GridJettyRestProtocol.java       |  409 +++++
 .../rest/protocols/http/jetty/favicon.ico       |  Bin 0 -> 1406 bytes
 .../rest/protocols/http/jetty/package.html      |   23 +
 .../rest/protocols/http/jetty/rest.html         |   96 ++
 .../http/jetty/GridJettyJsonConfig.java         |   50 -
 .../http/jetty/GridJettyRestHandler.java        |  595 -------
 .../http/jetty/GridJettyRestProtocol.java       |  409 -----
 .../rest/protocols/http/jetty/favicon.ico       |  Bin 1406 -> 0 bytes
 .../rest/protocols/http/jetty/package.html      |   23 -
 .../rest/protocols/http/jetty/rest.html         |   96 --
 207 files changed, 21636 insertions(+), 21637 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1b0e45a2/modules/clients/src/test/java/org/apache/ignite/client/GridClientTestRestServer.java
----------------------------------------------------------------------
diff --git 
a/modules/clients/src/test/java/org/apache/ignite/client/GridClientTestRestServer.java
 
b/modules/clients/src/test/java/org/apache/ignite/client/GridClientTestRestServer.java
index 737c310..176a91a 100644
--- 
a/modules/clients/src/test/java/org/apache/ignite/client/GridClientTestRestServer.java
+++ 
b/modules/clients/src/test/java/org/apache/ignite/client/GridClientTestRestServer.java
@@ -20,8 +20,8 @@ package org.apache.ignite.client;
 import org.apache.ignite.*;
 import org.apache.ignite.client.marshaller.*;
 import org.apache.ignite.client.marshaller.optimized.*;
-import org.gridgain.grid.kernal.processors.rest.client.message.*;
-import org.gridgain.grid.kernal.processors.rest.protocols.tcp.*;
+import org.apache.ignite.internal.processors.rest.client.message.*;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.*;
 import org.apache.ignite.internal.util.nio.*;
 import org.jetbrains.annotations.*;
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1b0e45a2/modules/clients/src/test/java/org/apache/ignite/client/impl/GridClientCacheFlagsCodecTest.java
----------------------------------------------------------------------
diff --git 
a/modules/clients/src/test/java/org/apache/ignite/client/impl/GridClientCacheFlagsCodecTest.java
 
b/modules/clients/src/test/java/org/apache/ignite/client/impl/GridClientCacheFlagsCodecTest.java
index a630745..e3683db 100644
--- 
a/modules/clients/src/test/java/org/apache/ignite/client/impl/GridClientCacheFlagsCodecTest.java
+++ 
b/modules/clients/src/test/java/org/apache/ignite/client/impl/GridClientCacheFlagsCodecTest.java
@@ -21,7 +21,7 @@ import junit.framework.*;
 import org.apache.ignite.cache.*;
 import org.apache.ignite.client.*;
 import org.apache.ignite.client.impl.connection.*;
-import org.gridgain.grid.kernal.processors.rest.handlers.cache.*;
+import org.apache.ignite.internal.processors.rest.handlers.cache.*;
 import org.apache.ignite.internal.util.typedef.*;
 
 import java.util.*;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1b0e45a2/modules/clients/src/test/java/org/apache/ignite/client/suite/GridClientTestSuite.java
----------------------------------------------------------------------
diff --git 
a/modules/clients/src/test/java/org/apache/ignite/client/suite/GridClientTestSuite.java
 
b/modules/clients/src/test/java/org/apache/ignite/client/suite/GridClientTestSuite.java
index caf0140..628a2d8 100644
--- 
a/modules/clients/src/test/java/org/apache/ignite/client/suite/GridClientTestSuite.java
+++ 
b/modules/clients/src/test/java/org/apache/ignite/client/suite/GridClientTestSuite.java
@@ -23,8 +23,8 @@ import org.apache.ignite.client.impl.*;
 import org.apache.ignite.client.integration.*;
 import org.apache.ignite.client.router.*;
 import org.apache.ignite.client.util.*;
-import org.gridgain.grid.kernal.processors.rest.*;
-import org.gridgain.grid.kernal.processors.rest.protocols.tcp.*;
+import org.apache.ignite.internal.processors.rest.*;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.*;
 
 /**
  * Test suite includes all test that concern REST processors.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1b0e45a2/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/GridAbstractRestProcessorSelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/GridAbstractRestProcessorSelfTest.java
 
b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/GridAbstractRestProcessorSelfTest.java
new file mode 100644
index 0000000..a0b933f
--- /dev/null
+++ 
b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/GridAbstractRestProcessorSelfTest.java
@@ -0,0 +1,95 @@
+/*
+ * 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 org.apache.ignite.cache.*;
+import org.apache.ignite.configuration.*;
+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.gridgain.testframework.junits.common.*;
+
+/**
+ * Abstract class for REST protocols tests.
+ */
+abstract class GridAbstractRestProcessorSelfTest extends 
GridCommonAbstractTest {
+    /** IP finder. */
+    private static final TcpDiscoveryIpFinder IP_FINDER = new 
TcpDiscoveryVmIpFinder(true);
+
+    /** Local host. */
+    protected static final String LOC_HOST = "127.0.0.1";
+
+    /**
+     * @return Grid count.
+     */
+    protected abstract int gridCount();
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        startGrids(gridCount());
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        assert grid(0).nodes().size() == gridCount();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        cache().clearAll();
+
+        assertTrue(cache().isEmpty());
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) 
throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        cfg.setLocalHost(LOC_HOST);
+
+        assert cfg.getClientConnectionConfiguration() == null;
+
+        ClientConnectionConfiguration clientCfg = new 
ClientConnectionConfiguration();
+
+        cfg.setClientConnectionConfiguration(clientCfg);
+
+        TcpDiscoverySpi disco = new TcpDiscoverySpi();
+
+        disco.setIpFinder(IP_FINDER);
+
+        cfg.setDiscoverySpi(disco);
+
+        CacheConfiguration ccfg = defaultCacheConfiguration();
+
+        cfg.setCacheConfiguration(ccfg);
+
+        return cfg;
+    }
+
+    /**
+     * @return Cache.
+     */
+    @Override protected <K, V> GridCache<K, V> cache() {
+        return grid(0).cache(null);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1b0e45a2/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/GridClientMemcachedProtocolSelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/GridClientMemcachedProtocolSelfTest.java
 
b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/GridClientMemcachedProtocolSelfTest.java
new file mode 100644
index 0000000..d299436
--- /dev/null
+++ 
b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/GridClientMemcachedProtocolSelfTest.java
@@ -0,0 +1,443 @@
+/*
+ * 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 net.spy.memcached.*;
+import org.apache.ignite.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.junit.*;
+
+import java.io.*;
+import java.net.*;
+import java.util.*;
+
+import static org.junit.Assert.*;
+
+/**
+ * Tests for TCP binary protocol.
+ */
+public class GridClientMemcachedProtocolSelfTest extends 
GridAbstractRestProcessorSelfTest {
+    /** Grid count. */
+    private static final int GRID_CNT = 1;
+
+    /** Custom port. */
+    private Integer customPort;
+
+    /** Memcache client. */
+    private MemcachedClientIF client;
+
+    /** {@inheritDoc} */
+    @Override protected int gridCount() {
+        return GRID_CNT;
+    }
+
+    /**
+     * @return Memcache client.
+     * @throws Exception If start failed.
+     */
+    private MemcachedClientIF startClient() throws Exception {
+        int port = customPort != null ? customPort : 
IgniteConfiguration.DFLT_TCP_PORT;
+
+        return new MemcachedClient(new BinaryConnectionFactory(),
+            F.asList(new InetSocketAddress(LOC_HOST, port)));
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        super.beforeTest();
+
+        client = startClient();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        super.afterTest();
+
+        client.shutdown();
+
+        customPort = null;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) 
throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        assert cfg.getClientConnectionConfiguration() != null;
+
+        if (customPort != null)
+            cfg.getClientConnectionConfiguration().setRestTcpPort(customPort);
+
+        return cfg;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testGet() throws Exception {
+        Assert.assertTrue(cache().putx("getKey1", "getVal1"));
+        Assert.assertTrue(cache().putx("getKey2", "getVal2"));
+
+        Assert.assertEquals("getVal1", client.get("getKey1"));
+        Assert.assertEquals("getVal2", client.get("getKey2"));
+        Assert.assertNull(client.get("wrongKey"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testGetBulk() throws Exception {
+        Assert.assertTrue(cache().putx("getKey1", "getVal1"));
+        Assert.assertTrue(cache().putx("getKey2", "getVal2"));
+        Assert.assertTrue(cache().putx("getKey3", "getVal3"));
+
+        Map<String, Object> map = client.getBulk("getKey1", "getKey2");
+
+        Assert.assertEquals(2, map.size());
+
+        Assert.assertEquals("getVal1", map.get("getKey1"));
+        Assert.assertEquals("getVal2", map.get("getKey2"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testSet() throws Exception {
+        Assert.assertTrue(client.set("setKey", 0, "setVal").get());
+
+        assertEquals("setVal", cache().get("setKey"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testSetWithExpiration() throws Exception {
+        Assert.assertTrue(client.set("setKey", 2000, "setVal").get());
+
+        assertEquals("setVal", cache().get("setKey"));
+
+        Thread.sleep(2100);
+
+        Assert.assertNull(cache().get("setKey"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testAdd() throws Exception {
+        Assert.assertTrue(cache().putx("addKey1", "addVal1"));
+
+        Assert.assertFalse(client.add("addKey1", 0, "addVal1New").get());
+        Assert.assertTrue(client.add("addKey2", 0, "addVal2").get());
+
+        assertEquals("addVal1", cache().get("addKey1"));
+        assertEquals("addVal2", cache().get("addKey2"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testAddWithExpiration() throws Exception {
+        Assert.assertTrue(client.add("addKey", 2000, "addVal").get());
+
+        assertEquals("addVal", cache().get("addKey"));
+
+        Thread.sleep(2100);
+
+        Assert.assertNull(cache().get("addKey"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testReplace() throws Exception {
+        Assert.assertFalse(client.replace("replaceKey", 0, 
"replaceVal").get());
+
+        Assert.assertNull(cache().get("replaceKey"));
+        Assert.assertTrue(cache().putx("replaceKey", "replaceVal"));
+
+        Assert.assertTrue(client.replace("replaceKey", 0, 
"replaceValNew").get());
+
+        assertEquals("replaceValNew", cache().get("replaceKey"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testReplaceWithExpiration() throws Exception {
+        Assert.assertTrue(cache().putx("replaceKey", "replaceVal"));
+
+        Assert.assertTrue(client.set("replaceKey", 2000, 
"replaceValNew").get());
+
+        assertEquals("replaceValNew", cache().get("replaceKey"));
+
+        Thread.sleep(2100);
+
+        Assert.assertNull(cache().get("replaceKey"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDelete() throws Exception {
+        Assert.assertFalse(client.delete("deleteKey").get());
+
+        Assert.assertTrue(cache().putx("deleteKey", "deleteVal"));
+
+        Assert.assertTrue(client.delete("deleteKey").get());
+
+        Assert.assertNull(cache().get("deleteKey"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testIncrement() throws Exception {
+        Assert.assertEquals(5, client.incr("incrKey", 3, 2));
+
+        assertEquals(5, cache().dataStructures().atomicLong("incrKey", 0, 
true).get());
+
+        Assert.assertEquals(15, client.incr("incrKey", 10, 0));
+
+        assertEquals(15, cache().dataStructures().atomicLong("incrKey", 0, 
true).get());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDecrement() throws Exception {
+        Assert.assertEquals(5, client.decr("decrKey", 10, 15));
+
+        assertEquals(5, cache().dataStructures().atomicLong("decrKey", 0, 
true).get());
+
+        Assert.assertEquals(2, client.decr("decrKey", 3, 0));
+
+        assertEquals(2, cache().dataStructures().atomicLong("decrKey", 0, 
true).get());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testFlush() throws Exception {
+        Assert.assertTrue(cache().putx("flushKey1", "flushVal1"));
+        Assert.assertTrue(cache().putx("flushKey2", "flushVal2"));
+
+        Assert.assertTrue(client.flush().get());
+
+        Assert.assertNull(cache().get("flushKey1"));
+        Assert.assertNull(cache().get("flushKey2"));
+        Assert.assertTrue(cache().isEmpty());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testStat() throws Exception {
+        Assert.assertTrue(cache().putx("statKey1", "statVal1"));
+        assertEquals("statVal1", cache().get("statKey1"));
+
+        Map<SocketAddress, Map<String, String>> map = client.getStats();
+
+        Assert.assertEquals(1, map.size());
+
+        Map<String, String> stats = F.first(map.values());
+
+        Assert.assertEquals(7, stats.size());
+        Assert.assertTrue(Integer.valueOf(stats.get("writes")) >= 1);
+        Assert.assertTrue(Integer.valueOf(stats.get("reads")) >= 1);
+
+        Assert.assertTrue(cache().putx("statKey2", "statVal2"));
+        assertEquals("statVal2", cache().get("statKey2"));
+
+        map = client.getStats();
+
+        Assert.assertEquals(1, map.size());
+
+        stats = F.first(map.values());
+
+        Assert.assertEquals(7, stats.size());
+        Assert.assertTrue(Integer.valueOf(stats.get("writes")) >= 2);
+        Assert.assertTrue(Integer.valueOf(stats.get("reads")) >= 2);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testAppend() throws Exception {
+        Assert.assertFalse(client.append(0, "appendKey", "_suffix").get());
+
+        Assert.assertTrue(cache().putx("appendKey", "appendVal"));
+
+        Assert.assertTrue(client.append(0, "appendKey", "_suffix").get());
+
+        Assert.assertEquals("appendVal_suffix", client.get("appendKey"));
+
+        assertEquals("appendVal_suffix", cache().get("appendKey"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPrepend() throws Exception {
+        Assert.assertFalse(client.append(0, "prependKey", "_suffix").get());
+
+        Assert.assertTrue(cache().putx("prependKey", "prependVal"));
+
+        Assert.assertTrue(client.append(0, "prependKey", "_suffix").get());
+
+        Assert.assertEquals("prependVal_suffix", client.get("prependKey"));
+
+        assertEquals("prependVal_suffix", cache().get("prependKey"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testSpecialTypes() throws Exception {
+        Assert.assertTrue(client.set("boolKey", 0, true).get());
+
+        Assert.assertEquals(true, client.get("boolKey"));
+
+        Assert.assertTrue(client.set("intKey", 0, 10).get());
+
+        Assert.assertEquals(10, client.get("intKey"));
+
+        Assert.assertTrue(client.set("longKey", 0, 100L).get());
+
+        Assert.assertEquals(100L, client.get("longKey"));
+
+        Date now = new Date();
+
+        Assert.assertTrue(client.set("dateKey", 0, now).get());
+
+        Assert.assertEquals(now, client.get("dateKey"));
+
+        Assert.assertTrue(client.set("byteKey", 0, (byte) 1).get());
+
+        Assert.assertEquals((byte) 1, client.get("byteKey"));
+
+        Assert.assertTrue(client.set("floatKey", 0, 1.1).get());
+
+        Assert.assertEquals(1.1, client.get("floatKey"));
+
+        Assert.assertTrue(client.set("doubleKey", 0, 100.001d).get());
+
+        Assert.assertEquals(100.001d, client.get("doubleKey"));
+
+        byte[] arr = new byte[5];
+
+        for (byte i = 0; i < arr.length; i++)
+            arr[i] = i;
+
+        Assert.assertTrue(client.set("arrKey", 0, arr).get());
+
+        assertArrayEquals(arr, (byte[])client.get("arrKey"));
+
+        Assert.assertTrue(client.set("shortKey", 0, (short) 1).get());
+
+        Assert.assertEquals((short) 1, client.get("shortKey"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testComplexObject() throws Exception {
+        Assert.assertTrue(client.set("objKey", 0, new ValueObject(10, 
"String")).get());
+
+        Assert.assertEquals(new ValueObject(10, "String"), 
client.get("objKey"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testCustomPort() throws Exception {
+        customPort = 11212;
+
+        Ignite g = startGrid();
+
+        assert g != null;
+        assert g.cluster().nodes().size() == gridCount() + 1;
+
+        MemcachedClientIF c = startClient();
+
+        Assert.assertTrue(c.set("key", 0, 1).get());
+
+        Assert.assertEquals(1, c.get("key"));
+
+        c.shutdown();
+
+        stopGrid();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testVersion() throws Exception {
+        Map<SocketAddress, String> map = client.getVersions();
+
+        Assert.assertEquals(1, map.size());
+
+        String ver = F.first(map.values());
+
+        Assert.assertFalse(F.isEmpty(ver));
+    }
+
+    /**
+     * Complex object.
+     */
+    private static class ValueObject implements Serializable {
+        /** */
+        private int intVal;
+
+        /** */
+        private String strVal;
+
+        /**
+         * @param intVal Integer value.
+         * @param strVal String value.
+         */
+        private ValueObject(int intVal, String strVal) {
+            this.intVal = intVal;
+            this.strVal = strVal;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object o) {
+            if (this == o)
+                return true;
+
+            if (o == null || getClass() != o.getClass())
+                return false;
+
+            ValueObject obj = (ValueObject)o;
+
+            return intVal == obj.intVal &&
+                !(strVal != null ? !strVal.equals(obj.strVal) : obj.strVal != 
null);
+
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            int res = intVal;
+
+            res = 31 * res + (strVal != null ? strVal.hashCode() : 0);
+
+            return res;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1b0e45a2/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/GridJettyRestProcessorAbstractSelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/GridJettyRestProcessorAbstractSelfTest.java
 
b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/GridJettyRestProcessorAbstractSelfTest.java
new file mode 100644
index 0000000..d7dc4aa
--- /dev/null
+++ 
b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/GridJettyRestProcessorAbstractSelfTest.java
@@ -0,0 +1,724 @@
+/*
+ * 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 org.apache.ignite.internal.util.typedef.*;
+
+import java.io.*;
+import java.net.*;
+import java.util.*;
+import java.util.regex.*;
+
+import static org.apache.ignite.IgniteSystemProperties.*;
+
+/**
+ * Tests for Jetty REST protocol.
+ */
+@SuppressWarnings("unchecked")
+abstract class GridJettyRestProcessorAbstractSelfTest extends 
GridAbstractRestProcessorSelfTest {
+    /** Grid count. */
+    private static final int GRID_CNT = 3;
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        System.setProperty(GG_JETTY_PORT, Integer.toString(restPort()));
+
+        super.beforeTestsStarted();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        super.afterTestsStopped();
+
+        System.clearProperty(GG_JETTY_PORT);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected int gridCount() {
+        return GRID_CNT;
+    }
+
+    /**
+     * @return Port to use for rest. Needs to be changed over time
+     *      because Jetty has some delay before port unbind.
+     */
+    protected abstract int restPort();
+
+    /**
+     * @param params Command parameters.
+     * @return Returned content.
+     * @throws Exception If failed.
+     */
+    private String content(Map<String, String> params) throws Exception {
+        String addr = "http://"; + LOC_HOST + ":" + restPort() + "/gridgain?";
+
+        for (Map.Entry<String, String> e : params.entrySet())
+            addr += e.getKey() + '=' + e.getValue() + '&';
+
+        URL url = new URL(addr);
+
+        URLConnection conn = url.openConnection();
+
+        String signature = signature();
+
+        if (signature != null)
+            conn.setRequestProperty("X-Signature", signature);
+
+        InputStream in = conn.getInputStream();
+
+        LineNumberReader rdr = new LineNumberReader(new InputStreamReader(in));
+
+        StringBuilder buf = new StringBuilder(256);
+
+        for (String line = rdr.readLine(); line != null; line = rdr.readLine())
+            buf.append(line);
+
+        return buf.toString();
+    }
+
+    /**
+     * @param json JSON response.
+     * @param ptrn Pattern to match.
+     */
+    @SuppressWarnings("TypeMayBeWeakened")
+    private void jsonEquals(String json, String ptrn) {
+        assertTrue("JSON mismatch [json=" + json + ", ptrn=" + ptrn + ']', 
Pattern.matches(ptrn, json));
+    }
+
+    /**
+     * @param res Response.
+     * @param success Success flag.
+     * @return Regex pattern for JSON.
+     */
+    private String cachePattern(String res, boolean success) {
+        return 
"\\{\\\"affinityNodeId\\\":\\\"\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12}\\\"\\," +
+            "\\\"error\\\":\\\"\\\"\\," +
+            "\\\"response\\\":\\\"" + res + "\\\"\\," +
+            "\\\"sessionToken\\\":\\\"\\\"," +
+            "\\\"successStatus\\\":" + (success ? 0 : 1) + "\\}";
+    }
+
+    /**
+     * @param res Response.
+     * @param success Success flag.
+     * @return Regex pattern for JSON.
+     */
+    private String cacheIntegerPattern(int res, boolean success) {
+        return 
"\\{\\\"affinityNodeId\\\":\\\"\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12}\\\"\\," +
+            "\\\"error\\\":\\\"\\\"\\," +
+            "\\\"response\\\":" + res + "\\," +
+            "\\\"sessionToken\\\":\\\"\\\"," +
+            "\\\"successStatus\\\":" + (success ? 0 : 1) + "\\}";
+    }
+
+    /**
+     * @param res Response.
+     * @param success Success flag.
+     * @return Regex pattern for JSON.
+     */
+    private String cacheBulkPattern(String res, boolean success) {
+        return "\\{\\\"affinityNodeId\\\":\\\"\\\"\\," +
+            "\\\"error\\\":\\\"\\\"\\," +
+            "\\\"response\\\":" + res + "\\," +
+            "\\\"sessionToken\\\":\\\"\\\"," +
+            "\\\"successStatus\\\":" + (success ? 0 : 1) + "\\}";
+    }
+
+    /**
+     * @param res Response.
+     * @param success Success flag.
+     * @return Regex pattern for JSON.
+     */
+    private String cachePattern(boolean res, boolean success) {
+        return 
"\\{\\\"affinityNodeId\\\":\\\"\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12}\\\"\\," +
+            "\\\"error\\\":\\\"\\\"\\," +
+            "\\\"response\\\":" + res + "\\," +
+            "\\\"sessionToken\\\":\\\"\\\"," +
+            "\\\"successStatus\\\":" + (success ? 0 : 1) + "\\}";
+    }
+
+    /**
+     * @param res Response.
+     * @param success Success flag.
+     * @return Regex pattern for JSON.
+     */
+    private String cacheBulkPattern(boolean res, boolean success) {
+        return "\\{\\\"affinityNodeId\\\":\\\"\\\"\\," +
+            "\\\"error\\\":\\\"\\\"\\," +
+            "\\\"response\\\":" + res + "\\," +
+            "\\\"sessionToken\\\":\\\"\\\"," +
+            "\\\"successStatus\\\":" + (success ? 0 : 1) + "\\}";
+    }
+
+    /**
+     * @param res Response.
+     * @param success Success flag.
+     * @return Regex pattern for JSON.
+     */
+    private String cacheMetricsPattern(String res, boolean success) {
+        return 
"\\{\\\"affinityNodeId\\\":\\\"(\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12})?\\\"\\," +
+            "\\\"error\\\":\\\"\\\"\\," +
+            "\\\"response\\\":" + res + "\\," +
+            "\\\"sessionToken\\\":\\\"\\\"," +
+            "\\\"successStatus\\\":" + (success ? 0 : 1) + "\\}";
+    }
+
+    /**
+     * @param res Response.
+     * @param success Success flag.
+     * @return Regex pattern for JSON.
+     */
+    private String pattern(String res, boolean success) {
+        return "\\{\\\"error\\\":\\\"" + (!success ? ".+" : "") + "\\\"\\," +
+            "\\\"response\\\":" + res + "\\," +
+            "\\\"sessionToken\\\":\\\"\\\"," +
+            "\\\"successStatus\\\":" + (success ? 0 : 1) + "\\}";
+    }
+
+    /**
+     * @param res Response.
+     * @param success Success flag.
+     * @return Regex pattern for JSON.
+     */
+    private String stringPattern(String res, boolean success) {
+        return "\\{\\\"error\\\":\\\"" + (!success ? ".+" : "") + "\\\"\\," +
+            "\\\"response\\\":\\\"" + res + "\\\"\\," +
+            "\\\"sessionToken\\\":\\\"\\\"," +
+            "\\\"successStatus\\\":" + (success ? 0 : 1) + "\\}";
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testGet() throws Exception {
+        assertTrue(cache().putx("getKey", "getVal"));
+
+        String ret = content(F.asMap("cmd", "get", "key", "getKey"));
+
+        assertNotNull(ret);
+        assertTrue(!ret.isEmpty());
+
+        info("Get command result: " + ret);
+
+        jsonEquals(ret, cachePattern("getVal", true));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testGetAll() throws Exception {
+        assertTrue(cache().putx("getKey1", "getVal1"));
+        assertTrue(cache().putx("getKey2", "getVal2"));
+
+        String ret = content(F.asMap("cmd", "getall", "k1", "getKey1", "k2", 
"getKey2"));
+
+        assertNotNull(ret);
+        assertTrue(!ret.isEmpty());
+
+        info("Get all command result: " + ret);
+
+        jsonEquals(ret, 
cacheBulkPattern("\\{\\\"getKey1\\\":\\\"getVal1\\\"\\,\\\"getKey2\\\":\\\"getVal2\\\"\\}",
+            true));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPut() throws Exception {
+        String ret = content(F.asMap("cmd", "put", "key", "putKey", "val", 
"putVal"));
+
+        assertNotNull(ret);
+        assertTrue(!ret.isEmpty());
+
+        info("Put command result: " + ret);
+
+        assertEquals("putVal", cache().peek("putKey"));
+
+        jsonEquals(ret, cachePattern(true, true));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPutWithExpiration() throws Exception {
+        String ret = content(F.asMap("cmd", "put", "key", "putKey", "val", 
"putVal", "exp", "2000"));
+
+        assertNotNull(ret);
+        assertTrue(!ret.isEmpty());
+
+        jsonEquals(ret, cachePattern(true, true));
+
+        assertEquals("putVal", cache().get("putKey"));
+
+        Thread.sleep(2100);
+
+        assertNull(cache().get("putKey"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testAdd() throws Exception {
+        assertTrue(cache().putx("addKey1", "addVal1"));
+
+        String ret = content(F.asMap("cmd", "add", "key", "addKey2", "val", 
"addVal2"));
+
+        assertNotNull(ret);
+        assertTrue(!ret.isEmpty());
+
+        jsonEquals(ret, cachePattern(true, true));
+
+        assertEquals("addVal1", cache().peek("addKey1"));
+        assertEquals("addVal2", cache().peek("addKey2"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testAddWithExpiration() throws Exception {
+        String ret = content(F.asMap("cmd", "add", "key", "addKey", "val", 
"addVal", "exp", "2000"));
+
+        assertNotNull(ret);
+        assertTrue(!ret.isEmpty());
+
+        jsonEquals(ret, cachePattern(true, true));
+
+        assertEquals("addVal", cache().get("addKey"));
+
+        Thread.sleep(2100);
+
+        assertNull(cache().get("addKey"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPutAll() throws Exception {
+        String ret = content(F.asMap("cmd", "putall", "k1", "putKey1", "k2", 
"putKey2",
+            "v1", "putVal1", "v2", "putVal2"));
+
+        assertNotNull(ret);
+        assertTrue(!ret.isEmpty());
+
+        info("Put all command result: " + ret);
+
+        assertEquals("putVal1", cache().peek("putKey1"));
+        assertEquals("putVal2", cache().peek("putKey2"));
+
+        jsonEquals(ret, cacheBulkPattern(true, true));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testRemove() throws Exception {
+        assertTrue(cache().putx("rmvKey", "rmvVal"));
+
+        assertEquals("rmvVal", cache().peek("rmvKey"));
+
+        String ret = content(F.asMap("cmd", "rmv", "key", "rmvKey"));
+
+        assertNotNull(ret);
+        assertTrue(!ret.isEmpty());
+
+        info("Remove command result: " + ret);
+
+        assertNull(cache().peek("rmvKey"));
+
+        jsonEquals(ret, cachePattern(true, true));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testRemoveAll() throws Exception {
+        assertTrue(cache().putx("rmvKey1", "rmvVal1"));
+        assertTrue(cache().putx("rmvKey2", "rmvVal2"));
+        assertTrue(cache().putx("rmvKey3", "rmvVal3"));
+        assertTrue(cache().putx("rmvKey4", "rmvVal4"));
+
+        assertEquals("rmvVal1", cache().peek("rmvKey1"));
+        assertEquals("rmvVal2", cache().peek("rmvKey2"));
+        assertEquals("rmvVal3", cache().peek("rmvKey3"));
+        assertEquals("rmvVal4", cache().peek("rmvKey4"));
+
+        String ret = content(F.asMap("cmd", "rmvall", "k1", "rmvKey1", "k2", 
"rmvKey2"));
+
+        assertNotNull(ret);
+        assertTrue(!ret.isEmpty());
+
+        info("Remove all command result: " + ret);
+
+        assertNull(cache().peek("rmvKey1"));
+        assertNull(cache().peek("rmvKey2"));
+        assertEquals("rmvVal3", cache().peek("rmvKey3"));
+        assertEquals("rmvVal4", cache().peek("rmvKey4"));
+
+        jsonEquals(ret, cacheBulkPattern(true, true));
+
+        ret = content(F.asMap("cmd", "rmvall"));
+
+        assertNotNull(ret);
+        assertTrue(!ret.isEmpty());
+
+        info("Remove all command result: " + ret);
+
+        assertNull(cache().peek("rmvKey1"));
+        assertNull(cache().peek("rmvKey2"));
+        assertNull(cache().peek("rmvKey3"));
+        assertNull(cache().peek("rmvKey4"));
+        assertTrue(cache().isEmpty());
+
+        jsonEquals(ret, cacheBulkPattern(true, true));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testCas() throws Exception {
+        assertTrue(cache().putx("casKey", "casOldVal"));
+
+        assertEquals("casOldVal", cache().peek("casKey"));
+
+        String ret = content(F.asMap("cmd", "cas", "key", "casKey", "val2", 
"casOldVal", "val1", "casNewVal"));
+
+        assertNotNull(ret);
+        assertTrue(!ret.isEmpty());
+
+        info("CAS command result: " + ret);
+
+        assertEquals("casNewVal", cache().peek("casKey"));
+
+        jsonEquals(ret, cachePattern(true, true));
+
+        cache().remove("casKey");
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testReplace() throws Exception {
+        assertTrue(cache().putx("repKey", "repOldVal"));
+
+        assertEquals("repOldVal", cache().peek("repKey"));
+
+        String ret = content(F.asMap("cmd", "rep", "key", "repKey", "val", 
"repVal"));
+
+        assertNotNull(ret);
+        assertTrue(!ret.isEmpty());
+
+        info("Replace command result: " + ret);
+
+        assertEquals("repVal", cache().peek("repKey"));
+
+        jsonEquals(ret, cachePattern(true, true));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testReplaceWithExpiration() throws Exception {
+        assertTrue(cache().putx("replaceKey", "replaceVal"));
+
+        assertEquals("replaceVal", cache().get("replaceKey"));
+
+        String ret = content(F.asMap("cmd", "rep", "key", "replaceKey", "val", 
"replaceValNew", "exp", "2000"));
+
+        assertNotNull(ret);
+        assertTrue(!ret.isEmpty());
+
+        jsonEquals(ret, cachePattern(true, true));
+
+        assertEquals("replaceValNew", cache().get("replaceKey"));
+
+        // Use larger value to avoid false positives.
+        Thread.sleep(2100);
+
+        assertNull(cache().get("replaceKey"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testAppend() throws Exception {
+        assertTrue(cache().putx("appendKey", "appendVal"));
+
+        String ret = content(F.asMap("cmd", "append", "key", "appendKey", 
"val", "_suffix"));
+
+        assertNotNull(ret);
+        assertTrue(!ret.isEmpty());
+
+        jsonEquals(ret, cachePattern(true, true));
+
+        assertEquals("appendVal_suffix", cache().get("appendKey"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPrepend() throws Exception {
+        assertTrue(cache().putx("prependKey", "prependVal"));
+
+        String ret = content(F.asMap("cmd", "prepend", "key", "prependKey", 
"val", "prefix_"));
+
+        assertNotNull(ret);
+        assertTrue(!ret.isEmpty());
+
+        jsonEquals(ret, cachePattern(true, true));
+
+        assertEquals("prefix_prependVal", cache().get("prependKey"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testIncrement() throws Exception {
+        String ret = content(F.asMap("cmd", "incr", "key", "incrKey", "init", 
"2", "delta", "3"));
+
+        assertNotNull(ret);
+        assertTrue(!ret.isEmpty());
+
+        jsonEquals(ret, cacheIntegerPattern(5, true));
+
+        assertEquals(5, cache().dataStructures().atomicLong("incrKey", 0, 
true).get());
+
+        ret = content(F.asMap("cmd", "incr", "key", "incrKey", "delta", "10"));
+
+        assertNotNull(ret);
+        assertTrue(!ret.isEmpty());
+
+        jsonEquals(ret, cacheIntegerPattern(15, true));
+
+        assertEquals(15, cache().dataStructures().atomicLong("incrKey", 0, 
true).get());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDecrement() throws Exception {
+        String ret = content(F.asMap("cmd", "decr", "key", "decrKey", "init", 
"15", "delta", "10"));
+
+        assertNotNull(ret);
+        assertTrue(!ret.isEmpty());
+
+        jsonEquals(ret, cacheIntegerPattern(5, true));
+
+        assertEquals(5, cache().dataStructures().atomicLong("decrKey", 0, 
true).get());
+
+        ret = content(F.asMap("cmd", "decr", "key", "decrKey", "delta", "3"));
+
+        assertNotNull(ret);
+        assertTrue(!ret.isEmpty());
+
+        jsonEquals(ret, cacheIntegerPattern(2, true));
+
+        assertEquals(2, cache().dataStructures().atomicLong("decrKey", 0, 
true).get());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testCar() throws Exception {
+        assertTrue(cache().putx("casKey", "casOldVal"));
+
+        assertEquals("casOldVal", cache().peek("casKey"));
+
+        String ret = content(F.asMap("cmd", "cas", "key", "casKey", "val2", 
"casOldVal"));
+
+        assertNotNull(ret);
+        assertTrue(!ret.isEmpty());
+
+        info("CAR command result: " + ret);
+
+        assertNull(cache().peek("casKey"));
+
+        jsonEquals(ret, cachePattern(true, true));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPutIfAbsent() throws Exception {
+        assertNull(cache().peek("casKey"));
+
+        String ret = content(F.asMap("cmd", "cas", "key", "casKey", "val1", 
"casNewVal"));
+
+        assertNotNull(ret);
+        assertTrue(!ret.isEmpty());
+
+        info("PutIfAbsent command result: " + ret);
+
+        assertEquals("casNewVal", cache().peek("casKey"));
+
+        jsonEquals(ret, cachePattern(true, true));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testCasRemove() throws Exception {
+        assertTrue(cache().putx("casKey", "casVal"));
+
+        assertEquals("casVal", cache().peek("casKey"));
+
+        String ret = content(F.asMap("cmd", "cas", "key", "casKey"));
+
+        assertNotNull(ret);
+        assertTrue(!ret.isEmpty());
+
+        info("CAS Remove command result: " + ret);
+
+        assertNull(cache().peek("casKey"));
+
+        jsonEquals(ret, cachePattern(true, true));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testMetrics() throws Exception {
+        String ret = content(F.asMap("cmd", "cache"));
+
+        assertNotNull(ret);
+        assertTrue(!ret.isEmpty());
+
+        info("Cache metrics command result: " + ret);
+
+        jsonEquals(ret, cacheMetricsPattern("\\{.+\\}", true));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTopology() throws Exception {
+        String ret = content(F.asMap("cmd", "top", "attr", "false", "mtr", 
"false"));
+
+        assertNotNull(ret);
+        assertTrue(!ret.isEmpty());
+
+        info("Topology command result: " + ret);
+
+        jsonEquals(ret, pattern("\\[\\{.+\\}\\]", true));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNode() throws Exception {
+        String ret = content(F.asMap("cmd", "node", "attr", "true", "mtr", 
"true", "id",
+            grid(0).localNode().id().toString()));
+
+        assertNotNull(ret);
+        assertTrue(!ret.isEmpty());
+
+        info("Topology command result: " + ret);
+
+        jsonEquals(ret, pattern("\\{.+\\}", true));
+
+        ret = content(F.asMap("cmd", "node", "attr", "false", "mtr", "false", 
"ip", LOC_HOST));
+
+        assertNotNull(ret);
+        assertTrue(!ret.isEmpty());
+
+        info("Topology command result: " + ret);
+
+        jsonEquals(ret, pattern("\\{.+\\}", true));
+
+        ret = content(F.asMap("cmd", "node", "attr", "false", "mtr", "false", 
"ip", LOC_HOST, "id",
+            UUID.randomUUID().toString()));
+
+        assertNotNull(ret);
+        assertTrue(!ret.isEmpty());
+
+        info("Topology command result: " + ret);
+
+        jsonEquals(ret, pattern("null", true));
+    }
+
+    /**
+     * Tests {@code exe} command.
+     * <p>
+     * Note that attempt to execute unknown task (UNKNOWN_TASK) will result in 
exception on server.
+     *
+     * @throws Exception If failed.
+     */
+    public void testExe() throws Exception {
+        String ret = content(F.asMap("cmd", "exe"));
+
+        assertNotNull(ret);
+        assertTrue(!ret.isEmpty());
+
+        info("Exe command result: " + ret);
+
+        jsonEquals(ret, pattern("null", false));
+
+        // Attempt to execute unknown task (UNKNOWN_TASK) will result in 
exception on server.
+        ret = content(F.asMap("cmd", "exe", "name", "UNKNOWN_TASK"));
+
+        assertNotNull(ret);
+        assertTrue(!ret.isEmpty());
+
+        info("Exe command result: " + ret);
+
+        jsonEquals(ret, pattern("null", false));
+
+        grid(0).compute().localDeployTask(TestTask1.class, 
TestTask1.class.getClassLoader());
+        grid(0).compute().localDeployTask(TestTask2.class, 
TestTask2.class.getClassLoader());
+
+        ret = content(F.asMap("cmd", "exe", "name", 
TestTask1.class.getName()));
+
+        assertNotNull(ret);
+        assertTrue(!ret.isEmpty());
+
+        info("Exe command result: " + ret);
+
+        jsonEquals(ret, pattern("\\{.+\\}", true));
+
+        ret = content(F.asMap("cmd", "exe", "name", 
TestTask2.class.getName()));
+
+        assertNotNull(ret);
+        assertTrue(!ret.isEmpty());
+
+        info("Exe command result: " + ret);
+
+        jsonEquals(ret, pattern("\\{.+" + TestTask2.RES + ".+\\}", true));
+
+        ret = content(F.asMap("cmd", "res"));
+
+        assertNotNull(ret);
+        assertTrue(!ret.isEmpty());
+
+        info("Exe command result: " + ret);
+
+        jsonEquals(ret, pattern("null", false));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testVersion() throws Exception {
+        String ret = content(F.asMap("cmd", "version"));
+
+        assertNotNull(ret);
+        assertTrue(!ret.isEmpty());
+
+        jsonEquals(ret, stringPattern(".+", true));
+    }
+
+    protected abstract String signature() throws Exception;
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1b0e45a2/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/GridJettyRestProcessorSignedSelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/GridJettyRestProcessorSignedSelfTest.java
 
b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/GridJettyRestProcessorSignedSelfTest.java
new file mode 100644
index 0000000..f072b38
--- /dev/null
+++ 
b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/GridJettyRestProcessorSignedSelfTest.java
@@ -0,0 +1,103 @@
+/*
+ * 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 org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+import sun.misc.*;
+
+import java.net.*;
+import java.security.*;
+
+/**
+ *
+ */
+public class GridJettyRestProcessorSignedSelfTest extends 
GridJettyRestProcessorAbstractSelfTest {
+    /** */
+    protected static final String REST_SECRET_KEY = "secret-key";
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) 
throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        assert cfg.getClientConnectionConfiguration() != null;
+
+        
cfg.getClientConnectionConfiguration().setRestSecretKey(REST_SECRET_KEY);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected int restPort() {
+        return 8092;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testUnauthorized() throws Exception {
+        String addr = "http://"; + LOC_HOST + ":" + restPort() + 
"/gridgain?cmd=top";
+
+        URL url = new URL(addr);
+
+        URLConnection conn = url.openConnection();
+
+        // Request has not been signed.
+        conn.connect();
+
+        assert ((HttpURLConnection)conn).getResponseCode() == 401;
+
+        // Request with authentication info.
+        addr = "http://"; + LOC_HOST + ":" + restPort() + "/gridgain?cmd=top";
+
+        url = new URL(addr);
+
+        conn = url.openConnection();
+
+        conn.setRequestProperty("X-Signature", signature());
+
+        conn.connect();
+
+        assertEquals(200, ((HttpURLConnection)conn).getResponseCode());
+    }
+
+    /**
+     * @return Signature.
+     * @throws Exception If failed.
+     */
+    @Override protected String signature() throws Exception {
+        long ts = U.currentTimeMillis();
+
+        String s = ts + ":" + REST_SECRET_KEY;
+
+        try {
+            MessageDigest md = MessageDigest.getInstance("SHA-1");
+
+            BASE64Encoder enc = new BASE64Encoder();
+
+            md.update(s.getBytes());
+
+            String hash = enc.encode(md.digest());
+
+            return ts + ":" + hash;
+        }
+        catch (NoSuchAlgorithmException e) {
+            throw new Exception("Failed to create authentication signature.", 
e);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1b0e45a2/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/GridJettyRestProcessorUnsignedSelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/GridJettyRestProcessorUnsignedSelfTest.java
 
b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/GridJettyRestProcessorUnsignedSelfTest.java
new file mode 100644
index 0000000..5a36eb7
--- /dev/null
+++ 
b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/GridJettyRestProcessorUnsignedSelfTest.java
@@ -0,0 +1,36 @@
+/*
+ * 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;
+
+/**
+ *
+ */
+public class GridJettyRestProcessorUnsignedSelfTest extends 
GridJettyRestProcessorAbstractSelfTest {
+    /** {@inheritDoc} */
+    @Override protected int restPort() {
+        return 8091;
+    }
+
+    /**
+     * @return Signature.
+     * @throws Exception If failed.
+     */
+    @Override protected String signature() throws Exception {
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1b0e45a2/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/GridMemcacheRestProcessorTest.java
----------------------------------------------------------------------
diff --git 
a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/GridMemcacheRestProcessorTest.java
 
b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/GridMemcacheRestProcessorTest.java
new file mode 100644
index 0000000..169c2f0
--- /dev/null
+++ 
b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/GridMemcacheRestProcessorTest.java
@@ -0,0 +1,76 @@
+/*
+ * 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 net.spy.memcached.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.gridgain.testframework.junits.common.*;
+
+import java.net.*;
+import java.util.*;
+
+/**
+ */
+public class GridMemcacheRestProcessorTest extends GridCommonAbstractTest {
+    /** Client. */
+    private MemcachedClientIF client;
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        client = new MemcachedClient(new BinaryConnectionFactory(),
+                F.asList(new InetSocketAddress("127.0.0.1", 11211)));
+
+        assert client.flush().get();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testGetBulk() throws Exception {
+        assert client.add("key1", 0, 1).get();
+        assert client.add("key2", 0, 2).get();
+
+        Map<String, Object> map = client.getBulk("key1", "key2");
+
+        assert map.size() == 2;
+        assert map.get("key1").equals(1);
+        assert map.get("key2").equals(2);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testAppend() throws Exception {
+        assert client.add("key", 0, "val").get();
+
+        assert client.append(0, "key", "_1").get();
+
+        assert "val_1".equals(client.get("key"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPrepend() throws Exception {
+        assert client.add("key", 0, "val").get();
+
+        assert client.prepend(0, "key", "1_").get();
+
+        assert "1_val".equals(client.get("key"));
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1b0e45a2/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/GridRestBinaryProtocolSelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/GridRestBinaryProtocolSelfTest.java
 
b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/GridRestBinaryProtocolSelfTest.java
new file mode 100644
index 0000000..332951c
--- /dev/null
+++ 
b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/GridRestBinaryProtocolSelfTest.java
@@ -0,0 +1,633 @@
+/*
+ * 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 org.apache.ignite.*;
+import org.apache.ignite.cache.*;
+import org.apache.ignite.compute.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.*;
+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.processors.rest.client.message.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+import org.gridgain.testframework.*;
+import org.gridgain.testframework.junits.common.*;
+import org.jetbrains.annotations.*;
+
+import java.io.*;
+import java.lang.reflect.*;
+import java.util.*;
+import java.util.concurrent.*;
+
+import static org.apache.ignite.cache.GridCacheMode.*;
+import static org.apache.ignite.cache.GridCacheWriteSynchronizationMode.*;
+
+/**
+ * TCP protocol test.
+ */
+@SuppressWarnings("unchecked")
+public class GridRestBinaryProtocolSelfTest extends GridCommonAbstractTest {
+    /** */
+    private static final TcpDiscoveryIpFinder IP_FINDER = new 
TcpDiscoveryVmIpFinder(true);
+
+    /** */
+    private static final String CACHE_NAME = "cache";
+
+    /** */
+    private static final String HOST = "127.0.0.1";
+
+    /** */
+    private static final int PORT = 11212;
+
+    /** */
+    private GridTestBinaryClient client;
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        startGrid();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        client = client();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        client.shutdown();
+
+        grid().cache(null).clearAll();
+        grid().cache(CACHE_NAME).clearAll();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) 
throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        cfg.setLocalHost(HOST);
+
+        assert cfg.getClientConnectionConfiguration() == null;
+
+        ClientConnectionConfiguration clientCfg = new 
ClientConnectionConfiguration();
+
+        clientCfg.setRestTcpPort(PORT);
+
+        cfg.setClientConnectionConfiguration(clientCfg);
+
+        TcpDiscoverySpi disco = new TcpDiscoverySpi();
+
+        disco.setIpFinder(IP_FINDER);
+
+        cfg.setDiscoverySpi(disco);
+
+        cfg.setCacheConfiguration(cacheConfiguration(null), 
cacheConfiguration(CACHE_NAME));
+
+        return cfg;
+    }
+
+    /**
+     * @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.setCacheMode(LOCAL);
+        cfg.setName(cacheName);
+        cfg.setWriteSynchronizationMode(FULL_SYNC);
+
+        return cfg;
+    }
+
+    /**
+     * @return Client.
+     * @throws IgniteCheckedException In case of error.
+     */
+    private GridTestBinaryClient client() throws IgniteCheckedException {
+        return new GridTestBinaryClient(HOST, PORT);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPut() throws Exception {
+        assertTrue(client.cachePut(null, "key1", "val1"));
+        assertEquals("val1", grid().cache(null).get("key1"));
+
+        assertTrue(client.cachePut(CACHE_NAME, "key1", "val1"));
+        assertEquals("val1", grid().cache(CACHE_NAME).get("key1"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPutAll() throws Exception {
+        client.cachePutAll(null, F.asMap("key1", "val1", "key2", "val2"));
+
+        Map<String, String> map = grid().<String, 
String>cache(null).getAll(Arrays.asList("key1", "key2"));
+
+        assertEquals(2, map.size());
+        assertEquals("val1", map.get("key1"));
+        assertEquals("val2", map.get("key2"));
+
+        client.cachePutAll(CACHE_NAME, F.asMap("key1", "val1", "key2", 
"val2"));
+
+        map = grid().<String, 
String>cache(CACHE_NAME).getAll(Arrays.asList("key1", "key2"));
+
+        assertEquals(2, map.size());
+        assertEquals("val1", map.get("key1"));
+        assertEquals("val2", map.get("key2"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testGet() throws Exception {
+        assertTrue(grid().cache(null).putx("key", "val"));
+
+        assertEquals("val", client.cacheGet(null, "key"));
+
+        assertTrue(grid().cache(CACHE_NAME).putx("key", "val"));
+
+        assertEquals("val", client.cacheGet(CACHE_NAME, "key"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testFailure() throws Exception {
+        GridKernal kernal = ((GridKernal)grid());
+
+        GridRestProcessor proc = kernal.context().rest();
+
+        // Clearing handlers collection to force failure.
+        Field hndField = proc.getClass().getDeclaredField("handlers");
+
+        hndField.setAccessible(true);
+
+        Map handlers = (Map)hndField.get(proc);
+
+        Map cp = new HashMap(handlers);
+
+        handlers.clear();
+
+        try {
+            GridTestUtils.assertThrows(
+                log,
+                new Callable<Object>() {
+                    @Override public Object call() throws Exception {
+                        return client.cacheGet(null, "key");
+                    }
+                },
+                IgniteCheckedException.class,
+                "Failed to process client request: Failed to find registered 
handler for command: CACHE_GET");
+        }
+        finally {
+            handlers.putAll(cp);
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testGetAll() throws Exception {
+        assertTrue(grid().cache(null).putx("key1", "val1"));
+        assertTrue(grid().cache(null).putx("key2", "val2"));
+
+        Map<String, String> map = client.cacheGetAll(null, "key1", "key2");
+
+        assertEquals(2, map.size());
+        assertEquals("val1", map.get("key1"));
+        assertEquals("val2", map.get("key2"));
+
+        assertTrue(grid().cache(null).putx("key3", "val3"));
+        assertTrue(grid().cache(null).putx("key4", "val4"));
+
+        map = client.cacheGetAll(null, "key3", "key4");
+
+        assertEquals(2, map.size());
+        assertEquals("val3", map.get("key3"));
+        assertEquals("val4", map.get("key4"));
+
+        assertTrue(grid().cache(CACHE_NAME).putx("key1", "val1"));
+        assertTrue(grid().cache(CACHE_NAME).putx("key2", "val2"));
+
+        map = client.cacheGetAll(CACHE_NAME, "key1", "key2");
+
+        assertEquals(2, map.size());
+        assertEquals("val1", map.get("key1"));
+        assertEquals("val2", map.get("key2"));
+
+        assertTrue(grid().cache(CACHE_NAME).putx("key3", "val3"));
+        assertTrue(grid().cache(CACHE_NAME).putx("key4", "val4"));
+
+        map = client.cacheGetAll(CACHE_NAME, "key3", "key4");
+
+        assertEquals(2, map.size());
+        assertEquals("val3", map.get("key3"));
+        assertEquals("val4", map.get("key4"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testRemove() throws Exception {
+        assertTrue(grid().cache(null).putx("key", "val"));
+
+        assertTrue(client.cacheRemove(null, "key"));
+        assertFalse(client.cacheRemove(null, "wrongKey"));
+
+        assertNull(grid().cache(null).get("key"));
+
+        assertTrue(grid().cache(CACHE_NAME).putx("key", "val"));
+
+        assertTrue(client.cacheRemove(CACHE_NAME, "key"));
+        assertFalse(client.cacheRemove(CACHE_NAME, "wrongKey"));
+
+        assertNull(grid().cache(CACHE_NAME).get("key"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testRemoveAll() throws Exception {
+        assertTrue(grid().cache(null).putx("key1", "val1"));
+        assertTrue(grid().cache(null).putx("key2", "val2"));
+        assertTrue(grid().cache(null).putx("key3", "val3"));
+        assertTrue(grid().cache(null).putx("key4", "val4"));
+
+        client.cacheRemoveAll(null, "key1", "key2");
+
+        assertNull(grid().cache(null).get("key1"));
+        assertNull(grid().cache(null).get("key2"));
+        assertNotNull(grid().cache(null).get("key3"));
+        assertNotNull(grid().cache(null).get("key4"));
+
+        assertTrue(grid().cache(CACHE_NAME).putx("key1", "val1"));
+        assertTrue(grid().cache(CACHE_NAME).putx("key2", "val2"));
+        assertTrue(grid().cache(CACHE_NAME).putx("key3", "val3"));
+        assertTrue(grid().cache(CACHE_NAME).putx("key4", "val4"));
+
+        client.cacheRemoveAll(CACHE_NAME, "key1", "key2");
+
+        assertNull(grid().cache(CACHE_NAME).get("key1"));
+        assertNull(grid().cache(CACHE_NAME).get("key2"));
+        assertNotNull(grid().cache(CACHE_NAME).get("key3"));
+        assertNotNull(grid().cache(CACHE_NAME).get("key4"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testReplace() throws Exception {
+        assertFalse(client.cacheReplace(null, "key1", "val1"));
+        assertTrue(grid().cache(null).putx("key1", "val1"));
+        assertTrue(client.cacheReplace(null, "key1", "val2"));
+
+        assertFalse(client.cacheReplace(null, "key2", "val1"));
+        assertTrue(grid().cache(null).putx("key2", "val1"));
+        assertTrue(client.cacheReplace(null, "key2", "val2"));
+
+        grid().cache(null).clearAll();
+
+        assertFalse(client.cacheReplace(CACHE_NAME, "key1", "val1"));
+        assertTrue(grid().cache(CACHE_NAME).putx("key1", "val1"));
+        assertTrue(client.cacheReplace(CACHE_NAME, "key1", "val2"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testCompareAndSet() throws Exception {
+        assertFalse(client.cacheCompareAndSet(null, "key", null, null));
+        assertTrue(grid().cache(null).putx("key", "val"));
+        assertTrue(client.cacheCompareAndSet(null, "key", null, null));
+        assertNull(grid().cache(null).get("key"));
+
+        assertFalse(client.cacheCompareAndSet(null, "key", null, "val"));
+        assertTrue(grid().cache(null).putx("key", "val"));
+        assertFalse(client.cacheCompareAndSet(null, "key", null, "wrongVal"));
+        assertEquals("val", grid().cache(null).get("key"));
+        assertTrue(client.cacheCompareAndSet(null, "key", null, "val"));
+        assertNull(grid().cache(null).get("key"));
+
+        assertTrue(client.cacheCompareAndSet(null, "key", "val", null));
+        assertEquals("val", grid().cache(null).get("key"));
+        assertFalse(client.cacheCompareAndSet(null, "key", "newVal", null));
+        assertEquals("val", grid().cache(null).get("key"));
+        assertTrue(grid().cache(null).removex("key"));
+
+        assertFalse(client.cacheCompareAndSet(null, "key", "val1", "val2"));
+        assertTrue(grid().cache(null).putx("key", "val2"));
+        assertFalse(client.cacheCompareAndSet(null, "key", "val1", 
"wrongVal"));
+        assertEquals("val2", grid().cache(null).get("key"));
+        assertTrue(client.cacheCompareAndSet(null, "key", "val1", "val2"));
+        assertEquals("val1", grid().cache(null).get("key"));
+        assertTrue(grid().cache(null).removex("key"));
+
+        assertFalse(client.cacheCompareAndSet(CACHE_NAME, "key", null, null));
+        assertTrue(grid().cache(CACHE_NAME).putx("key", "val"));
+        assertTrue(client.cacheCompareAndSet(CACHE_NAME, "key", null, null));
+        assertNull(grid().cache(CACHE_NAME).get("key"));
+
+        assertFalse(client.cacheCompareAndSet(CACHE_NAME, "key", null, "val"));
+        assertTrue(grid().cache(CACHE_NAME).putx("key", "val"));
+        assertFalse(client.cacheCompareAndSet(CACHE_NAME, "key", null, 
"wrongVal"));
+        assertEquals("val", grid().cache(CACHE_NAME).get("key"));
+        assertTrue(client.cacheCompareAndSet(CACHE_NAME, "key", null, "val"));
+        assertNull(grid().cache(CACHE_NAME).get("key"));
+
+        assertTrue(client.cacheCompareAndSet(CACHE_NAME, "key", "val", null));
+        assertEquals("val", grid().cache(CACHE_NAME).get("key"));
+        assertFalse(client.cacheCompareAndSet(CACHE_NAME, "key", "newVal", 
null));
+        assertEquals("val", grid().cache(CACHE_NAME).get("key"));
+        assertTrue(grid().cache(CACHE_NAME).removex("key"));
+
+        assertFalse(client.cacheCompareAndSet(CACHE_NAME, "key", "val1", 
"val2"));
+        assertTrue(grid().cache(CACHE_NAME).putx("key", "val2"));
+        assertFalse(client.cacheCompareAndSet(CACHE_NAME, "key", "val1", 
"wrongVal"));
+        assertEquals("val2", grid().cache(CACHE_NAME).get("key"));
+        assertTrue(client.cacheCompareAndSet(CACHE_NAME, "key", "val1", 
"val2"));
+        assertEquals("val1", grid().cache(CACHE_NAME).get("key"));
+        assertTrue(grid().cache(CACHE_NAME).removex("key"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testMetrics() throws Exception {
+        grid().cache(null).resetMetrics();
+        grid().cache(CACHE_NAME).resetMetrics();
+
+        grid().cache(null).putx("key1", "val");
+        grid().cache(null).putx("key2", "val");
+        grid().cache(null).putx("key2", "val");
+
+        grid().cache(null).get("key1");
+        grid().cache(null).get("key2");
+        grid().cache(null).get("key2");
+
+        grid().cache(CACHE_NAME).putx("key1", "val");
+        grid().cache(CACHE_NAME).putx("key2", "val");
+        grid().cache(CACHE_NAME).putx("key2", "val");
+
+        grid().cache(CACHE_NAME).get("key1");
+        grid().cache(CACHE_NAME).get("key2");
+        grid().cache(CACHE_NAME).get("key2");
+
+        Map<String, Long> m = client.cacheMetrics(null);
+
+        assertNotNull(m);
+        assertEquals(7, m.size());
+        assertEquals(3, m.get("reads").longValue());
+        assertEquals(3, m.get("writes").longValue());
+
+        m = client.cacheMetrics(CACHE_NAME);
+
+        assertNotNull(m);
+        assertEquals(7, m.size());
+        assertEquals(3, m.get("reads").longValue());
+        assertEquals(3, m.get("writes").longValue());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testAppend() throws Exception {
+        grid().cache(null).remove("key");
+        grid().cache(CACHE_NAME).remove("key");
+
+        assertFalse(client.cacheAppend(null, "key", ".val"));
+        assertFalse(client.cacheAppend(CACHE_NAME, "key", ".val"));
+
+        grid().cache(null).put("key", "orig");
+        grid().cache(CACHE_NAME).put("key", "orig");
+
+        assertTrue(client.cacheAppend(null, "key", ".val"));
+        assertEquals("orig.val", grid().cache(null).get("key"));
+        assertTrue(client.cacheAppend(null, "key", ".newVal"));
+        assertEquals("orig.val.newVal", grid().cache(null).get("key"));
+
+        assertTrue(client.cacheAppend(CACHE_NAME, "key", ".val"));
+        assertEquals("orig.val", grid().cache(CACHE_NAME).get("key"));
+        assertTrue(client.cacheAppend(CACHE_NAME, "key", ".newVal"));
+        assertEquals("orig.val.newVal", grid().cache(CACHE_NAME).get("key"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPrepend() throws Exception {
+        grid().cache(null).remove("key");
+        grid().cache(CACHE_NAME).remove("key");
+
+        assertFalse(client.cachePrepend(null, "key", ".val"));
+        assertFalse(client.cachePrepend(CACHE_NAME, "key", ".val"));
+
+        grid().cache(null).put("key", "orig");
+        grid().cache(CACHE_NAME).put("key", "orig");
+
+        assertTrue(client.cachePrepend(null, "key", "val."));
+        assertEquals("val.orig", grid().cache(null).get("key"));
+        assertTrue(client.cachePrepend(null, "key", "newVal."));
+        assertEquals("newVal.val.orig", grid().cache(null).get("key"));
+
+        assertTrue(client.cachePrepend(CACHE_NAME, "key", "val."));
+        assertEquals("val.orig", grid().cache(CACHE_NAME).get("key"));
+        assertTrue(client.cachePrepend(CACHE_NAME, "key", "newVal."));
+        assertEquals("newVal.val.orig", grid().cache(CACHE_NAME).get("key"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testExecute() throws Exception {
+        GridClientTaskResultBean res = client.execute(TestTask.class.getName(),
+            Arrays.asList("executing", 3, "test", 5, "task"));
+
+        assertTrue(res.isFinished());
+        assertEquals(25, res.getResult());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNode() throws Exception {
+        assertNull(client.node(UUID.randomUUID(), false, false));
+        assertNull(client.node("wrongHost", false, false));
+
+        GridClientNodeBean node = client.node(grid().localNode().id(), true, 
true);
+
+        assertNotNull(node);
+        assertFalse(node.getAttributes().isEmpty());
+        assertNotNull(node.getMetrics());
+        assertNotNull(node.getTcpAddresses());
+        assertEquals(PORT,  node.getTcpPort());
+        assertEquals(grid().localNode().id(), node.getNodeId());
+
+        node = client.node(grid().localNode().id(), false, false);
+
+        assertNotNull(node);
+        assertNull(node.getAttributes());
+        assertNull(node.getMetrics());
+        assertNotNull(node.getTcpAddresses());
+        assertEquals(PORT,  node.getTcpPort());
+        assertEquals(grid().localNode().id(), node.getNodeId());
+
+        node = client.node(HOST, true, true);
+
+        assertNotNull(node);
+        assertFalse(node.getAttributes().isEmpty());
+        assertNotNull(node.getMetrics());
+        assertNotNull(node.getTcpAddresses());
+        assertEquals(PORT,  node.getTcpPort());
+        assertEquals(grid().localNode().id(), node.getNodeId());
+
+        node = client.node(HOST, false, false);
+
+        assertNotNull(node);
+        assertNull(node.getAttributes());
+        assertNull(node.getMetrics());
+        assertNotNull(node.getTcpAddresses());
+        assertEquals(PORT,  node.getTcpPort());
+        assertEquals(grid().localNode().id(), node.getNodeId());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTopology() throws Exception {
+        List<GridClientNodeBean> top = client.topology(true, true);
+
+        assertNotNull(top);
+        assertEquals(1, top.size());
+
+        GridClientNodeBean node = F.first(top);
+
+        assertNotNull(node);
+        assertFalse(node.getAttributes().isEmpty());
+        assertNotNull(node.getMetrics());
+        assertNotNull(node.getTcpAddresses());
+        assertEquals(grid().localNode().id(), node.getNodeId());
+
+        top = client.topology(false, false);
+
+        assertNotNull(top);
+        assertEquals(1, top.size());
+
+        node = F.first(top);
+
+        assertNotNull(node);
+        assertNull(node.getAttributes());
+        assertNull(node.getMetrics());
+        assertNotNull(node.getTcpAddresses());
+        assertEquals(grid().localNode().id(), node.getNodeId());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testLog() throws Exception {
+        String path = "work/log/gridgain.log." + System.currentTimeMillis();
+
+        File file = new File(U.getGridGainHome(), path);
+
+        assert !file.exists();
+
+        FileWriter writer = new FileWriter(file);
+
+        String sep = System.getProperty("line.separator");
+
+        writer.write("Line 1" + sep);
+        writer.write(sep);
+        writer.write("Line 2" + sep);
+        writer.write("Line 3" + sep);
+
+        writer.flush();
+        writer.close();
+
+        List<String> log = client.log(path, 0, 10);
+
+        assertNotNull(log);
+        assertEquals(4, log.size());
+
+        file.delete();
+
+        GridTestUtils.assertThrows(
+            log(),
+            new Callable<Object>() {
+                @Override
+                public Object call() throws Exception {
+                    client.log("wrong/path", 0, 10);
+
+                    return null;
+                }
+            },
+            IgniteCheckedException.class,
+            null
+        );
+    }
+
+    /**
+     * Test task.
+     */
+    private static class TestTask extends 
ComputeTaskSplitAdapter<List<Object>, Integer> {
+        /** {@inheritDoc} */
+        @Override protected Collection<? extends ComputeJob> split(int 
gridSize, List<Object> args)
+            throws IgniteCheckedException {
+            Collection<ComputeJobAdapter> jobs = new ArrayList<>(args.size());
+
+            for (final Object arg : args) {
+                jobs.add(new ComputeJobAdapter() {
+                    @SuppressWarnings("OverlyStrongTypeCast")
+                    @Override public Object execute() {
+                        try {
+                            return ((String)arg).length();
+                        }
+                        catch (ClassCastException ignored) {
+                            assert arg instanceof Integer;
+
+                            return arg;
+                        }
+                    }
+                });
+            }
+
+            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;
+        }
+    }
+}

Reply via email to