-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
check for thread interrupt in process
- Loading branch information
1 parent
64b5aac
commit cc7bb72
Showing
2 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/test/java/redis/clients/jedis/JedisShardedPubSubBaseTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package redis.clients.jedis; | ||
|
||
import junit.framework.TestCase; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
import static redis.clients.jedis.Protocol.ResponseKeyword.SMESSAGE; | ||
import static redis.clients.jedis.Protocol.ResponseKeyword.SSUBSCRIBE; | ||
|
||
public class JedisShardedPubSubBaseTest extends TestCase { | ||
|
||
public void testProceed() throws InterruptedException { | ||
// setup | ||
final JedisShardedPubSubBase<String> pubSub = new JedisShardedPubSubBase<String>() { | ||
|
||
@Override | ||
public void onSMessage(String channel, String message) { | ||
fail("this should not happen when thread is interrupted"); | ||
} | ||
|
||
@Override | ||
protected String encode(byte[] raw) { | ||
return new String(raw); | ||
} | ||
|
||
}; | ||
|
||
final Connection mockConnection = mock(Connection.class); | ||
final List<Object> mockSubscribe = Arrays.asList( | ||
SSUBSCRIBE.getRaw(), "channel".getBytes(), 1L | ||
); | ||
final List<Object> mockResponse = Arrays.asList( | ||
SMESSAGE.getRaw(), "channel".getBytes(), "message".getBytes() | ||
); | ||
when(mockConnection.getUnflushedObject()).thenReturn(mockSubscribe, mockResponse); | ||
|
||
|
||
final CountDownLatch countDownLatch = new CountDownLatch(1); | ||
// action | ||
final Thread thread = new Thread(() -> { | ||
Thread.currentThread().interrupt(); | ||
pubSub.proceed(mockConnection, "channel"); | ||
|
||
countDownLatch.countDown(); | ||
}); | ||
thread.start(); | ||
|
||
assertTrue(countDownLatch.await(10, TimeUnit.MILLISECONDS)); | ||
|
||
} | ||
} |