Change string size to make test fail faster
This commit is contained in:
@@ -3,6 +3,7 @@ package redis.clients.jedis.tests.commands;
|
||||
import java.io.IOException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
@@ -246,8 +247,8 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
||||
try {
|
||||
Jedis j = createJedis();
|
||||
Thread.sleep(1000);
|
||||
j.publish(SafeEncoder.encode("foo"), SafeEncoder
|
||||
.encode("exit"));
|
||||
j.publish(SafeEncoder.encode("foo"),
|
||||
SafeEncoder.encode("exit"));
|
||||
j.disconnect();
|
||||
} catch (Exception ex) {
|
||||
fail(ex.getMessage());
|
||||
@@ -293,11 +294,11 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
||||
try {
|
||||
Jedis j = createJedis();
|
||||
Thread.sleep(1000);
|
||||
j.publish(SafeEncoder.encode("foo"), SafeEncoder
|
||||
.encode("exit"));
|
||||
j.publish(SafeEncoder.encode("foo"),
|
||||
SafeEncoder.encode("exit"));
|
||||
Thread.sleep(1000);
|
||||
j.publish(SafeEncoder.encode("bar"), SafeEncoder
|
||||
.encode("exit"));
|
||||
j.publish(SafeEncoder.encode("bar"),
|
||||
SafeEncoder.encode("exit"));
|
||||
j.disconnect();
|
||||
} catch (Exception ex) {
|
||||
fail(ex.getMessage());
|
||||
@@ -337,8 +338,8 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
||||
try {
|
||||
Jedis j = createJedis();
|
||||
Thread.sleep(1000);
|
||||
j.publish(SafeEncoder.encode("foo.bar"), SafeEncoder
|
||||
.encode("exit"));
|
||||
j.publish(SafeEncoder.encode("foo.bar"),
|
||||
SafeEncoder.encode("exit"));
|
||||
j.disconnect();
|
||||
} catch (Exception ex) {
|
||||
fail(ex.getMessage());
|
||||
@@ -386,11 +387,11 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
||||
try {
|
||||
Jedis j = createJedis();
|
||||
Thread.sleep(1000);
|
||||
j.publish(SafeEncoder.encode("foo.123"), SafeEncoder
|
||||
.encode("exit"));
|
||||
j.publish(SafeEncoder.encode("foo.123"),
|
||||
SafeEncoder.encode("exit"));
|
||||
Thread.sleep(1000);
|
||||
j.publish(SafeEncoder.encode("bar.123"), SafeEncoder
|
||||
.encode("exit"));
|
||||
j.publish(SafeEncoder.encode("bar.123"),
|
||||
SafeEncoder.encode("exit"));
|
||||
j.disconnect();
|
||||
} catch (Exception ex) {
|
||||
fail(ex.getMessage());
|
||||
@@ -455,12 +456,12 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
||||
Thread.sleep(1000);
|
||||
pubsub.subscribe(SafeEncoder.encode("bar"));
|
||||
pubsub.psubscribe(SafeEncoder.encode("bar.*"));
|
||||
j.publish(SafeEncoder.encode("foo"), SafeEncoder
|
||||
.encode("exit"));
|
||||
j.publish(SafeEncoder.encode("bar"), SafeEncoder
|
||||
.encode("exit"));
|
||||
j.publish(SafeEncoder.encode("bar.123"), SafeEncoder
|
||||
.encode("exit"));
|
||||
j.publish(SafeEncoder.encode("foo"),
|
||||
SafeEncoder.encode("exit"));
|
||||
j.publish(SafeEncoder.encode("bar"),
|
||||
SafeEncoder.encode("exit"));
|
||||
j.publish(SafeEncoder.encode("bar.123"),
|
||||
SafeEncoder.encode("exit"));
|
||||
j.disconnect();
|
||||
} catch (Exception ex) {
|
||||
fail(ex.getMessage());
|
||||
@@ -472,7 +473,8 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
||||
t.join();
|
||||
}
|
||||
|
||||
@Test @Ignore
|
||||
@Test
|
||||
@Ignore
|
||||
public void subscribeWithoutConnecting() {
|
||||
try {
|
||||
Jedis jedis = new Jedis(hnp.getHost(), hnp.getPort());
|
||||
@@ -530,37 +532,44 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
||||
}
|
||||
|
||||
@Test(expected = JedisConnectionException.class)
|
||||
public void handleClientOutputBufferLimitForSubscribeTooSlow() throws InterruptedException {
|
||||
public void handleClientOutputBufferLimitForSubscribeTooSlow()
|
||||
throws InterruptedException {
|
||||
final Jedis j = createJedis();
|
||||
final AtomicBoolean exit = new AtomicBoolean(false);
|
||||
|
||||
final Thread t = new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
Jedis j = createJedis();
|
||||
|
||||
Thread.sleep(1000);
|
||||
|
||||
// we already set jedis1 config to client-output-buffer-limit pubsub 256k 128k 5
|
||||
// it means if subscriber delayed to receive over 256k or 128k continuously 5 sec,
|
||||
// we already set jedis1 config to
|
||||
// client-output-buffer-limit pubsub 256k 128k 5
|
||||
// it means if subscriber delayed to receive over 256k or
|
||||
// 128k continuously 5 sec,
|
||||
// redis disconnects subscriber
|
||||
|
||||
// we publish over 10M data for making situation for exceed client-output-buffer-limit
|
||||
String veryLargeString = makeLargeString(1024 * 10);
|
||||
// we publish over 100M data for making situation for exceed
|
||||
// client-output-buffer-limit
|
||||
String veryLargeString = makeLargeString(10485760);
|
||||
|
||||
// 10K * 1024 = 10M
|
||||
for (int i = 0 ; i < 1024 ; i++)
|
||||
j.publish("foo", veryLargeString); // 1k
|
||||
// 10M * 10 = 100M
|
||||
for (int i = 0; i < 10 && !exit.get(); i++) {
|
||||
j.publish("foo", veryLargeString);
|
||||
}
|
||||
|
||||
j.disconnect();
|
||||
} catch (Exception ex) {
|
||||
fail(ex.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
t.start();
|
||||
try {
|
||||
jedis.subscribe(new JedisPubSub() {
|
||||
public void onMessage(String channel, String message) {
|
||||
try {
|
||||
// wait 0.5 secs to slow down subscribe and client-output-buffer exceed
|
||||
//System.out.println("channel - " + channel + " / message - " + message);
|
||||
// wait 0.5 secs to slow down subscribe and
|
||||
// client-output-buffer exceed
|
||||
// System.out.println("channel - " + channel +
|
||||
// " / message - " + message);
|
||||
Thread.sleep(500);
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
@@ -581,7 +590,8 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
||||
public void onPSubscribe(String pattern, int subscribedChannels) {
|
||||
}
|
||||
|
||||
public void onPUnsubscribe(String pattern, int subscribedChannels) {
|
||||
public void onPUnsubscribe(String pattern,
|
||||
int subscribedChannels) {
|
||||
}
|
||||
|
||||
public void onPMessage(String pattern, String channel,
|
||||
@@ -589,6 +599,14 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
||||
}
|
||||
}, "foo");
|
||||
t.join();
|
||||
} finally {
|
||||
// exit the publisher thread. if exception is thrown, thread might
|
||||
// still keep publishing things.
|
||||
exit.set(true);
|
||||
if (t.isAlive()) {
|
||||
t.wait();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String makeLargeString(int size) {
|
||||
|
||||
Reference in New Issue
Block a user