Introduce (Binary)JedisPubSubAdaptor
* Actually it's in JedisSentinelPool but not exposed to users
This commit is contained in:
@@ -0,0 +1,33 @@
|
|||||||
|
package redis.clients.jedis;
|
||||||
|
|
||||||
|
public class BinaryJedisPubSubAdaptor extends BinaryJedisPubSub {
|
||||||
|
@Override
|
||||||
|
public void onMessage(byte[] channel, byte[] message) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPMessage(byte[] pattern, byte[] channel, byte[] message) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSubscribe(byte[] channel, int subscribedChannels) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onUnsubscribe(byte[] channel, int subscribedChannels) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPUnsubscribe(byte[] pattern, int subscribedChannels) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPSubscribe(byte[] pattern, int subscribedChannels) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
34
src/main/java/redis/clients/jedis/JedisPubSubAdaptor.java
Normal file
34
src/main/java/redis/clients/jedis/JedisPubSubAdaptor.java
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
package redis.clients.jedis;
|
||||||
|
|
||||||
|
public class JedisPubSubAdaptor extends JedisPubSub {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onMessage(String channel, String message) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPMessage(String pattern, String channel, String message) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSubscribe(String channel, int subscribedChannels) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onUnsubscribe(String channel, int subscribedChannels) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPUnsubscribe(String pattern, int subscribedChannels) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPSubscribe(String pattern, int subscribedChannels) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -222,32 +222,6 @@ public class JedisSentinelPool extends Pool<Jedis> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected class JedisPubSubAdapter extends JedisPubSub {
|
|
||||||
@Override
|
|
||||||
public void onMessage(String channel, String message) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPMessage(String pattern, String channel, String message) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPSubscribe(String pattern, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPUnsubscribe(String pattern, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSubscribe(String channel, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onUnsubscribe(String channel, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected class MasterListener extends Thread {
|
protected class MasterListener extends Thread {
|
||||||
|
|
||||||
protected String masterName;
|
protected String masterName;
|
||||||
@@ -281,7 +255,7 @@ public class JedisSentinelPool extends Pool<Jedis> {
|
|||||||
j = new Jedis(host, port);
|
j = new Jedis(host, port);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
j.subscribe(new JedisPubSubAdapter() {
|
j.subscribe(new JedisPubSubAdaptor() {
|
||||||
@Override
|
@Override
|
||||||
public void onMessage(String channel, String message) {
|
public void onMessage(String channel, String message) {
|
||||||
log.fine("Sentinel " + host + ":" + port
|
log.fine("Sentinel " + host + ":" + port
|
||||||
|
|||||||
@@ -10,9 +10,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import redis.clients.jedis.BinaryJedisPubSub;
|
import redis.clients.jedis.*;
|
||||||
import redis.clients.jedis.Jedis;
|
|
||||||
import redis.clients.jedis.JedisPubSub;
|
|
||||||
import redis.clients.jedis.exceptions.JedisConnectionException;
|
import redis.clients.jedis.exceptions.JedisConnectionException;
|
||||||
import redis.clients.util.SafeEncoder;
|
import redis.clients.util.SafeEncoder;
|
||||||
|
|
||||||
@@ -33,7 +31,7 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void subscribe() throws InterruptedException {
|
public void subscribe() throws InterruptedException {
|
||||||
jedis.subscribe(new JedisPubSub() {
|
jedis.subscribe(new JedisPubSubAdaptor() {
|
||||||
public void onMessage(String channel, String message) {
|
public void onMessage(String channel, String message) {
|
||||||
assertEquals("foo", channel);
|
assertEquals("foo", channel);
|
||||||
assertEquals("exit", message);
|
assertEquals("exit", message);
|
||||||
@@ -52,16 +50,6 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
|||||||
assertEquals("foo", channel);
|
assertEquals("foo", channel);
|
||||||
assertEquals(0, subscribedChannels);
|
assertEquals(0, subscribedChannels);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onPSubscribe(String pattern, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onPUnsubscribe(String pattern, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onPMessage(String pattern, String channel,
|
|
||||||
String message) {
|
|
||||||
}
|
|
||||||
}, "foo");
|
}, "foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,13 +57,9 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
|||||||
public void pubSubChannels() {
|
public void pubSubChannels() {
|
||||||
final List<String> expectedActiveChannels = Arrays.asList("testchan1",
|
final List<String> expectedActiveChannels = Arrays.asList("testchan1",
|
||||||
"testchan2", "testchan3");
|
"testchan2", "testchan3");
|
||||||
jedis.subscribe(new JedisPubSub() {
|
jedis.subscribe(new JedisPubSubAdaptor() {
|
||||||
private int count = 0;
|
private int count = 0;
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onUnsubscribe(String channel, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSubscribe(String channel, int subscribedChannels) {
|
public void onSubscribe(String channel, int subscribedChannels) {
|
||||||
count++;
|
count++;
|
||||||
@@ -89,43 +73,14 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
|||||||
unsubscribe();
|
unsubscribe();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPUnsubscribe(String pattern, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPSubscribe(String pattern, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPMessage(String pattern, String channel,
|
|
||||||
String message) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onMessage(String channel, String message) {
|
|
||||||
}
|
|
||||||
}, "testchan1", "testchan2", "testchan3");
|
}, "testchan1", "testchan2", "testchan3");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void pubSubNumPat() {
|
public void pubSubNumPat() {
|
||||||
jedis.psubscribe(new JedisPubSub() {
|
jedis.psubscribe(new JedisPubSubAdaptor() {
|
||||||
private int count = 0;
|
private int count = 0;
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onUnsubscribe(String channel, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSubscribe(String channel, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPUnsubscribe(String pattern, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPSubscribe(String pattern, int subscribedChannels) {
|
public void onPSubscribe(String pattern, int subscribedChannels) {
|
||||||
count++;
|
count++;
|
||||||
@@ -137,14 +92,6 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPMessage(String pattern, String channel,
|
|
||||||
String message) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onMessage(String channel, String message) {
|
|
||||||
}
|
|
||||||
}, "test*", "test*", "chan*");
|
}, "test*", "test*", "chan*");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,13 +100,9 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
|||||||
final Map<String, String> expectedNumSub = new HashMap<String, String>();
|
final Map<String, String> expectedNumSub = new HashMap<String, String>();
|
||||||
expectedNumSub.put("testchannel2", "1");
|
expectedNumSub.put("testchannel2", "1");
|
||||||
expectedNumSub.put("testchannel1", "1");
|
expectedNumSub.put("testchannel1", "1");
|
||||||
jedis.subscribe(new JedisPubSub() {
|
jedis.subscribe(new JedisPubSubAdaptor() {
|
||||||
private int count = 0;
|
private int count = 0;
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onUnsubscribe(String channel, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSubscribe(String channel, int subscribedChannels) {
|
public void onSubscribe(String channel, int subscribedChannels) {
|
||||||
count++;
|
count++;
|
||||||
@@ -171,30 +114,13 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
|||||||
unsubscribe();
|
unsubscribe();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPUnsubscribe(String pattern, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPSubscribe(String pattern, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPMessage(String pattern, String channel,
|
|
||||||
String message) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onMessage(String channel, String message) {
|
|
||||||
}
|
|
||||||
}, "testchannel1", "testchannel2");
|
}, "testchannel1", "testchannel2");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void subscribeMany() throws UnknownHostException, IOException,
|
public void subscribeMany() throws UnknownHostException, IOException,
|
||||||
InterruptedException {
|
InterruptedException {
|
||||||
jedis.subscribe(new JedisPubSub() {
|
jedis.subscribe(new JedisPubSubAdaptor() {
|
||||||
public void onMessage(String channel, String message) {
|
public void onMessage(String channel, String message) {
|
||||||
unsubscribe(channel);
|
unsubscribe(channel);
|
||||||
}
|
}
|
||||||
@@ -203,34 +129,13 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
|||||||
publishOne(channel, "exit");
|
publishOne(channel, "exit");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onUnsubscribe(String channel, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onPSubscribe(String pattern, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onPUnsubscribe(String pattern, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onPMessage(String pattern, String channel,
|
|
||||||
String message) {
|
|
||||||
}
|
|
||||||
}, "foo", "bar");
|
}, "foo", "bar");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void psubscribe() throws UnknownHostException, IOException,
|
public void psubscribe() throws UnknownHostException, IOException,
|
||||||
InterruptedException {
|
InterruptedException {
|
||||||
jedis.psubscribe(new JedisPubSub() {
|
jedis.psubscribe(new JedisPubSubAdaptor() {
|
||||||
public void onMessage(String channel, String message) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onSubscribe(String channel, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onUnsubscribe(String channel, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onPSubscribe(String pattern, int subscribedChannels) {
|
public void onPSubscribe(String pattern, int subscribedChannels) {
|
||||||
assertEquals("foo.*", pattern);
|
assertEquals("foo.*", pattern);
|
||||||
assertEquals(1, subscribedChannels);
|
assertEquals(1, subscribedChannels);
|
||||||
@@ -256,23 +161,11 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
|||||||
@Test
|
@Test
|
||||||
public void psubscribeMany() throws UnknownHostException, IOException,
|
public void psubscribeMany() throws UnknownHostException, IOException,
|
||||||
InterruptedException {
|
InterruptedException {
|
||||||
jedis.psubscribe(new JedisPubSub() {
|
jedis.psubscribe(new JedisPubSubAdaptor() {
|
||||||
public void onMessage(String channel, String message) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onSubscribe(String channel, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onUnsubscribe(String channel, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onPSubscribe(String pattern, int subscribedChannels) {
|
public void onPSubscribe(String pattern, int subscribedChannels) {
|
||||||
publishOne(pattern.replace("*", "123"), "exit");
|
publishOne(pattern.replace("*", "123"), "exit");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onPUnsubscribe(String pattern, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onPMessage(String pattern, String channel,
|
public void onPMessage(String pattern, String channel,
|
||||||
String message) {
|
String message) {
|
||||||
punsubscribe(pattern);
|
punsubscribe(pattern);
|
||||||
@@ -283,7 +176,7 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
|||||||
@Test
|
@Test
|
||||||
public void subscribeLazily() throws UnknownHostException, IOException,
|
public void subscribeLazily() throws UnknownHostException, IOException,
|
||||||
InterruptedException {
|
InterruptedException {
|
||||||
final JedisPubSub pubsub = new JedisPubSub() {
|
final JedisPubSub pubsub = new JedisPubSubAdaptor() {
|
||||||
public void onMessage(String channel, String message) {
|
public void onMessage(String channel, String message) {
|
||||||
unsubscribe(channel);
|
unsubscribe(channel);
|
||||||
}
|
}
|
||||||
@@ -296,16 +189,10 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onUnsubscribe(String channel, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onPSubscribe(String pattern, int subscribedChannels) {
|
public void onPSubscribe(String pattern, int subscribedChannels) {
|
||||||
publishOne(pattern.replace("*", "123"), "exit");
|
publishOne(pattern.replace("*", "123"), "exit");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onPUnsubscribe(String pattern, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onPMessage(String pattern, String channel,
|
public void onPMessage(String pattern, String channel,
|
||||||
String message) {
|
String message) {
|
||||||
punsubscribe(pattern);
|
punsubscribe(pattern);
|
||||||
@@ -318,7 +205,7 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
|||||||
@Test
|
@Test
|
||||||
public void binarySubscribe() throws UnknownHostException, IOException,
|
public void binarySubscribe() throws UnknownHostException, IOException,
|
||||||
InterruptedException {
|
InterruptedException {
|
||||||
jedis.subscribe(new BinaryJedisPubSub() {
|
jedis.subscribe(new BinaryJedisPubSubAdaptor() {
|
||||||
public void onMessage(byte[] channel, byte[] message) {
|
public void onMessage(byte[] channel, byte[] message) {
|
||||||
assertTrue(Arrays.equals(SafeEncoder.encode("foo"), channel));
|
assertTrue(Arrays.equals(SafeEncoder.encode("foo"), channel));
|
||||||
assertTrue(Arrays.equals(SafeEncoder.encode("exit"), message));
|
assertTrue(Arrays.equals(SafeEncoder.encode("exit"), message));
|
||||||
@@ -335,23 +222,13 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
|||||||
assertTrue(Arrays.equals(SafeEncoder.encode("foo"), channel));
|
assertTrue(Arrays.equals(SafeEncoder.encode("foo"), channel));
|
||||||
assertEquals(0, subscribedChannels);
|
assertEquals(0, subscribedChannels);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onPSubscribe(byte[] pattern, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onPUnsubscribe(byte[] pattern, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onPMessage(byte[] pattern, byte[] channel,
|
|
||||||
byte[] message) {
|
|
||||||
}
|
|
||||||
}, SafeEncoder.encode("foo"));
|
}, SafeEncoder.encode("foo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void binarySubscribeMany() throws UnknownHostException, IOException,
|
public void binarySubscribeMany() throws UnknownHostException, IOException,
|
||||||
InterruptedException {
|
InterruptedException {
|
||||||
jedis.subscribe(new BinaryJedisPubSub() {
|
jedis.subscribe(new BinaryJedisPubSubAdaptor() {
|
||||||
public void onMessage(byte[] channel, byte[] message) {
|
public void onMessage(byte[] channel, byte[] message) {
|
||||||
unsubscribe(channel);
|
unsubscribe(channel);
|
||||||
}
|
}
|
||||||
@@ -359,35 +236,13 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
|||||||
public void onSubscribe(byte[] channel, int subscribedChannels) {
|
public void onSubscribe(byte[] channel, int subscribedChannels) {
|
||||||
publishOne(SafeEncoder.encode(channel), "exit");
|
publishOne(SafeEncoder.encode(channel), "exit");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onUnsubscribe(byte[] channel, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onPSubscribe(byte[] pattern, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onPUnsubscribe(byte[] pattern, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onPMessage(byte[] pattern, byte[] channel,
|
|
||||||
byte[] message) {
|
|
||||||
}
|
|
||||||
}, SafeEncoder.encode("foo"), SafeEncoder.encode("bar"));
|
}, SafeEncoder.encode("foo"), SafeEncoder.encode("bar"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void binaryPsubscribe() throws UnknownHostException, IOException,
|
public void binaryPsubscribe() throws UnknownHostException, IOException,
|
||||||
InterruptedException {
|
InterruptedException {
|
||||||
jedis.psubscribe(new BinaryJedisPubSub() {
|
jedis.psubscribe(new BinaryJedisPubSubAdaptor() {
|
||||||
public void onMessage(byte[] channel, byte[] message) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onSubscribe(byte[] channel, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onUnsubscribe(byte[] channel, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onPSubscribe(byte[] pattern, int subscribedChannels) {
|
public void onPSubscribe(byte[] pattern, int subscribedChannels) {
|
||||||
assertTrue(Arrays.equals(SafeEncoder.encode("foo.*"), pattern));
|
assertTrue(Arrays.equals(SafeEncoder.encode("foo.*"), pattern));
|
||||||
assertEquals(1, subscribedChannels);
|
assertEquals(1, subscribedChannels);
|
||||||
@@ -414,24 +269,12 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
|||||||
@Test
|
@Test
|
||||||
public void binaryPsubscribeMany() throws UnknownHostException,
|
public void binaryPsubscribeMany() throws UnknownHostException,
|
||||||
IOException, InterruptedException {
|
IOException, InterruptedException {
|
||||||
jedis.psubscribe(new BinaryJedisPubSub() {
|
jedis.psubscribe(new BinaryJedisPubSubAdaptor() {
|
||||||
public void onMessage(byte[] channel, byte[] message) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onSubscribe(byte[] channel, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onUnsubscribe(byte[] channel, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onPSubscribe(byte[] pattern, int subscribedChannels) {
|
public void onPSubscribe(byte[] pattern, int subscribedChannels) {
|
||||||
publishOne(SafeEncoder.encode(pattern).replace("*", "123"),
|
publishOne(SafeEncoder.encode(pattern).replace("*", "123"),
|
||||||
"exit");
|
"exit");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onPUnsubscribe(byte[] pattern, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onPMessage(byte[] pattern, byte[] channel,
|
public void onPMessage(byte[] pattern, byte[] channel,
|
||||||
byte[] message) {
|
byte[] message) {
|
||||||
punsubscribe(pattern);
|
punsubscribe(pattern);
|
||||||
@@ -442,7 +285,7 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
|||||||
@Test
|
@Test
|
||||||
public void binarySubscribeLazily() throws UnknownHostException,
|
public void binarySubscribeLazily() throws UnknownHostException,
|
||||||
IOException, InterruptedException {
|
IOException, InterruptedException {
|
||||||
final BinaryJedisPubSub pubsub = new BinaryJedisPubSub() {
|
final BinaryJedisPubSub pubsub = new BinaryJedisPubSubAdaptor() {
|
||||||
public void onMessage(byte[] channel, byte[] message) {
|
public void onMessage(byte[] channel, byte[] message) {
|
||||||
unsubscribe(channel);
|
unsubscribe(channel);
|
||||||
}
|
}
|
||||||
@@ -456,17 +299,11 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onUnsubscribe(byte[] channel, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onPSubscribe(byte[] pattern, int subscribedChannels) {
|
public void onPSubscribe(byte[] pattern, int subscribedChannels) {
|
||||||
publishOne(SafeEncoder.encode(pattern).replace("*", "123"),
|
publishOne(SafeEncoder.encode(pattern).replace("*", "123"),
|
||||||
"exit");
|
"exit");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onPUnsubscribe(byte[] pattern, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onPMessage(byte[] pattern, byte[] channel,
|
public void onPMessage(byte[] pattern, byte[] channel,
|
||||||
byte[] message) {
|
byte[] message) {
|
||||||
punsubscribe(pattern);
|
punsubscribe(pattern);
|
||||||
@@ -478,26 +315,7 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
|||||||
|
|
||||||
@Test(expected = JedisConnectionException.class)
|
@Test(expected = JedisConnectionException.class)
|
||||||
public void unsubscribeWhenNotSusbscribed() throws InterruptedException {
|
public void unsubscribeWhenNotSusbscribed() throws InterruptedException {
|
||||||
JedisPubSub pubsub = new JedisPubSub() {
|
JedisPubSub pubsub = new JedisPubSubAdaptor();
|
||||||
public void onMessage(String channel, String message) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onPMessage(String pattern, String channel,
|
|
||||||
String message) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onSubscribe(String channel, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onUnsubscribe(String channel, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onPUnsubscribe(String pattern, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onPSubscribe(String pattern, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
};
|
|
||||||
pubsub.unsubscribe();
|
pubsub.unsubscribe();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -533,7 +351,7 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
|||||||
});
|
});
|
||||||
t.start();
|
t.start();
|
||||||
try {
|
try {
|
||||||
jedis.subscribe(new JedisPubSub() {
|
jedis.subscribe(new JedisPubSubAdaptor() {
|
||||||
public void onMessage(String channel, String message) {
|
public void onMessage(String channel, String message) {
|
||||||
try {
|
try {
|
||||||
// wait 0.5 secs to slow down subscribe and
|
// wait 0.5 secs to slow down subscribe and
|
||||||
@@ -550,23 +368,6 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
|||||||
fail(e.getMessage());
|
fail(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onSubscribe(String channel, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onUnsubscribe(String channel, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onPSubscribe(String pattern, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onPUnsubscribe(String pattern,
|
|
||||||
int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onPMessage(String pattern, String channel,
|
|
||||||
String message) {
|
|
||||||
}
|
|
||||||
}, "foo");
|
}, "foo");
|
||||||
} finally {
|
} finally {
|
||||||
// exit the publisher thread. if exception is thrown, thread might
|
// exit the publisher thread. if exception is thrown, thread might
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import java.util.concurrent.atomic.AtomicReference;
|
|||||||
|
|
||||||
import redis.clients.jedis.HostAndPort;
|
import redis.clients.jedis.HostAndPort;
|
||||||
import redis.clients.jedis.Jedis;
|
import redis.clients.jedis.Jedis;
|
||||||
import redis.clients.jedis.JedisPubSub;
|
import redis.clients.jedis.JedisPubSubAdaptor;
|
||||||
|
|
||||||
public class JedisSentinelTestUtil {
|
public class JedisSentinelTestUtil {
|
||||||
public static HostAndPort waitForNewPromotedMaster(final String masterName,
|
public static HostAndPort waitForNewPromotedMaster(final String masterName,
|
||||||
@@ -14,11 +14,7 @@ public class JedisSentinelTestUtil {
|
|||||||
final AtomicReference<String> newmaster = new AtomicReference<String>(
|
final AtomicReference<String> newmaster = new AtomicReference<String>(
|
||||||
"");
|
"");
|
||||||
|
|
||||||
sentinelJedis.psubscribe(new JedisPubSub() {
|
sentinelJedis.psubscribe(new JedisPubSubAdaptor() {
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onMessage(String channel, String message) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPMessage(String pattern, String channel,
|
public void onPMessage(String pattern, String channel,
|
||||||
@@ -34,18 +30,6 @@ public class JedisSentinelTestUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSubscribe(String channel, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onUnsubscribe(String channel, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPUnsubscribe(String pattern, int subscribedChannels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPSubscribe(String pattern, int subscribedChannels) {
|
public void onPSubscribe(String pattern, int subscribedChannels) {
|
||||||
commandJedis.sentinelFailover(masterName);
|
commandJedis.sentinelFailover(masterName);
|
||||||
|
|||||||
Reference in New Issue
Block a user