Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/clients/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
<version>8.0.1</version>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,41 +18,37 @@
package org.apache.ignite.internal.processors.rest.protocols.tcp.redis;

import org.apache.commons.lang3.RandomStringUtils;
import org.apache.ignite.testframework.GridTestUtils;
import org.junit.Assert;
import org.junit.Test;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.exceptions.JedisDataException;

import static org.apache.ignite.internal.util.IgniteUtils.KB;

/**
* Tests for Connection commands of Redis protocol.
*/
public class RedisProtocolConnectSelfTest extends RedisCommonAbstractTest {
/**
* @throws Exception If failed.
*/
/** */
@Test
public void testPing() throws Exception {
public void testPing() {
try (Jedis jedis = pool.getResource()) {
Assert.assertEquals("PONG", jedis.ping());
}
}

/**
* @throws Exception If failed.
*/
/** */
@Test
public void testEcho() throws Exception {
public void testEcho() {
try (Jedis jedis = pool.getResource()) {
Assert.assertEquals("Hello, grid!", jedis.echo("Hello, grid!"));
}
}

/**
* @throws Exception If failed.
*/
/** */
@Test
public void testSelect() throws Exception {
public void testSelect() {
try (Jedis jedis = pool.getResource()) {
// connected to cache with index 0
jedis.set("k0", "v0");
Expand All @@ -78,6 +74,36 @@ public void testSelect() throws Exception {
}
}

/** */
@Test
public void testClient() {
try (Jedis jedis = pool.getResource()) {
Assert.assertNull(jedis.clientGetname());

Assert.assertEquals("OK", jedis.clientSetname("test-client"));
Assert.assertEquals("test-client", jedis.clientGetname());

// The name is connection-scoped.
try (Jedis jedis2 = pool.getResource()) {
Assert.assertNull(jedis2.clientGetname());
}

Assert.assertEquals("test-client", jedis.clientGetname());
}
}

/** */
@Test
public void testClientUnknownSubcommand() {
try (Jedis jedis = pool.getResource()) {
GridTestUtils.assertThrows(log, () -> jedis.clientUnpause(), JedisDataException.class,
"Unknown subcommand 'UNPAUSE' for 'client' command");

// The connection is still usable.
Assert.assertEquals("PONG", jedis.ping());
}
}

/** */
@Test
public void testSetGetLongString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,15 @@
import org.junit.Test;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.exceptions.JedisDataException;
import redis.clients.jedis.params.SetParams;

/**
* Tests for String commands of Redis protocol.
*/
public class RedisProtocolStringSelfTest extends RedisCommonAbstractTest {
/**
* @throws Exception If failed.
*/
/** */
@Test
public void testGet() throws Exception {
public void testGet() {
try (Jedis jedis = pool.getResource()) {
jcache().put("getKey1", "getVal1");

Expand All @@ -55,11 +54,9 @@ public void testGet() throws Exception {
}
}

/**
* @throws Exception If failed.
*/
/** */
@Test
public void testGetSet() throws Exception {
public void testGetSet() {
try (Jedis jedis = pool.getResource()) {
jcache().put("getSetKey1", "1");

Expand All @@ -79,11 +76,9 @@ public void testGetSet() throws Exception {
}
}

/**
* @throws Exception If failed.
*/
/** */
@Test
public void testMGet() throws Exception {
public void testMGet() {
try (Jedis jedis = pool.getResource()) {
jcache().put("getKey1", "getVal1");
jcache().put("getKey2", 0);
Expand All @@ -99,19 +94,15 @@ public void testMGet() throws Exception {
}
}

/**
* @throws Exception If failed.
*/
/** */
@Test
public void testMGetDirectOrder() throws Exception {
public void testMGetDirectOrder() {
testMGetOrder(true);
}

/**
* @throws Exception If failed.
*/
/** */
@Test
public void testMGetReverseOrder() throws Exception {
public void testMGetReverseOrder() {
testMGetOrder(false);
}

Expand Down Expand Up @@ -153,11 +144,9 @@ public void testMGetOrder(boolean directOrder) {
}


/**
* @throws Exception If failed.
*/
/** */
@Test
public void testMGetDuplicates() throws Exception {
public void testMGetDuplicates() {
try (Jedis jedis = pool.getResource()) {
jcache().put("key-A", "value-A");
jcache().put("key-B", "value-B");
Expand Down Expand Up @@ -188,14 +177,14 @@ public void testSet() throws Exception {
Assert.assertEquals("b0", jcache().get("setKey2"));

// test options.
jedis.set("setKey1", "2", "nx");
jedis.set("setKey3", "3", "nx", "px", EXPIRE_MS);
jedis.set("setKey1", "2", SetParams.setParams().nx());
jedis.set("setKey3", "3", SetParams.setParams().nx().px(EXPIRE_MS));

Assert.assertEquals("1", jcache().get("setKey1"));
Assert.assertEquals("3", jcache().get("setKey3"));

jedis.set("setKey1", "2", "xx", "ex", EXPIRE_SEC);
jedis.set("setKey4", "4", "xx");
jedis.set("setKey1", "2", SetParams.setParams().xx().ex(EXPIRE_SEC));
jedis.set("setKey4", "4", SetParams.setParams().xx());

Assert.assertEquals("2", jcache().get("setKey1"));
Assert.assertNull(jcache().get("setKey4"));
Expand All @@ -208,11 +197,9 @@ public void testSet() throws Exception {
}
}

/**
* @throws Exception If failed.
*/
/** */
@Test
public void testMSet() throws Exception {
public void testMSet() {
try (Jedis jedis = pool.getResource()) {
jedis.mset("setKey1", "1", "setKey2", "2");

Expand All @@ -221,11 +208,9 @@ public void testMSet() throws Exception {
}
}

/**
* @throws Exception If failed.
*/
/** */
@Test
public void testIncrDecr() throws Exception {
public void testIncrDecr() {
try (Jedis jedis = pool.getResource()) {
Assert.assertEquals(1, (long)jedis.incr("newKeyIncr"));
Assert.assertEquals(-1, (long)jedis.decr("newKeyDecr"));
Expand Down Expand Up @@ -305,11 +290,9 @@ public void testIncrDecr() throws Exception {
}
}

/**
* @throws Exception If failed.
*/
/** */
@Test
public void testIncrDecrBy() throws Exception {
public void testIncrDecrBy() {
try (Jedis jedis = pool.getResource()) {
Assert.assertEquals(2, (long)jedis.incrBy("newKeyIncrBy", 2));
Assert.assertEquals(-2, (long)jedis.decrBy("newKeyDecrBy", 2));
Expand Down Expand Up @@ -362,11 +345,9 @@ public void testIncrDecrBy() throws Exception {
}
}

/**
* @throws Exception If failed.
*/
/** */
@Test
public void testAppend() throws Exception {
public void testAppend() {
try (Jedis jedis = pool.getResource()) {
Assert.assertEquals(5, (long)jedis.append("appendKey1", "Hello"));
Assert.assertEquals(12, (long)jedis.append("appendKey1", " World!"));
Expand All @@ -384,11 +365,9 @@ public void testAppend() throws Exception {
}
}

/**
* @throws Exception If failed.
*/
/** */
@Test
public void testStrlen() throws Exception {
public void testStrlen() {
try (Jedis jedis = pool.getResource()) {
Assert.assertEquals(0, (long)jedis.strlen("strlenKeyNonExisting"));

Expand All @@ -409,11 +388,9 @@ public void testStrlen() throws Exception {
}
}

/**
* @throws Exception If failed.
*/
/** */
@Test
public void testSetRange() throws Exception {
public void testSetRange() {
try (Jedis jedis = pool.getResource()) {
Assert.assertEquals(0, (long)jedis.setrange("setRangeKey1", 0, ""));

Expand Down Expand Up @@ -458,11 +435,9 @@ public void testSetRange() throws Exception {
}
}

/**
* @throws Exception If failed.
*/
/** */
@Test
public void testGetRange() throws Exception {
public void testGetRange() {
try (Jedis jedis = pool.getResource()) {
Assert.assertEquals("", jedis.getrange("getRangeKeyNonExisting", 0, 0));

Expand All @@ -486,11 +461,9 @@ public void testGetRange() throws Exception {
}
}

/**
* @throws Exception If failed.
*/
/** */
@Test
public void testDel() throws Exception {
public void testDel() {
jcache().put("delKey1", "abc");
jcache().put("delKey2", "abcd");
try (Jedis jedis = pool.getResource()) {
Expand All @@ -500,11 +473,9 @@ public void testDel() throws Exception {
}
}

/**
* @throws Exception If failed.
*/
/** */
@Test
public void testExists() throws Exception {
public void testExists() {
jcache().put("existsKey1", "abc");
jcache().put("existsKey2", "abcd");
try (Jedis jedis = pool.getResource()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,10 @@ public enum GridRestCommand {
WARM_UP("warmup"),

/** probe. */
PROBE("probe");
PROBE("probe"),

/** Client info. */
CLIENT("client");

/** Enum values. */
private static final GridRestCommand[] VALS = values();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.apache.ignite.internal.processors.rest.handlers.memory.MemoryMetricsCommandHandler;
import org.apache.ignite.internal.processors.rest.handlers.probe.GridProbeCommandHandler;
import org.apache.ignite.internal.processors.rest.handlers.query.QueryCommandHandler;
import org.apache.ignite.internal.processors.rest.handlers.server.GridClientInfoCommandHandler;
import org.apache.ignite.internal.processors.rest.handlers.task.GridTaskCommandHandler;
import org.apache.ignite.internal.processors.rest.handlers.top.GridTopologyCommandHandler;
import org.apache.ignite.internal.processors.rest.handlers.user.UserActionCommandHandler;
Expand Down Expand Up @@ -557,6 +558,7 @@ public GridRestProcessor(GridKernalContext ctx) {
addHandler(new MemoryMetricsCommandHandler(ctx));
addHandler(new NodeStateBeforeStartCommandHandler(ctx));
addHandler(new GridProbeCommandHandler(ctx));
addHandler(new GridClientInfoCommandHandler(ctx));

// Start protocols.
startTcpProtocol();
Expand Down Expand Up @@ -955,6 +957,7 @@ private void authorize(GridRestRequest req) throws SecurityException {
case REMOVE_USER:
case UPDATE_USER:
case PROBE:
case CLIENT:
break;

default:
Expand Down
Loading
Loading