-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed jedis connecting and added more jedis tests
- Loading branch information
1 parent
7c65bad
commit f55decd
Showing
7 changed files
with
260 additions
and
25 deletions.
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
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
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
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
70 changes: 70 additions & 0 deletions
70
meteor-jedis/src/test/java/com/meteormsg/transport/redis/RedisPacketListenerTest.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,70 @@ | ||
package com.meteormsg.transport.redis; | ||
|
||
import com.meteormsg.base.interfaces.SubscriptionHandler; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import java.util.Base64; | ||
import java.util.Collection; | ||
import java.util.logging.Logger; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.Mockito.*; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class RedisPacketListenerTest { | ||
|
||
@Mock | ||
SubscriptionHandler subscriptionHandler; | ||
|
||
@Test | ||
void onMessageWithValidChannel_ThenSuccess() throws Exception { | ||
String topic = "test"; | ||
String message = "message"; | ||
byte[] expected = Base64.getDecoder().decode(message); | ||
|
||
RedisPacketListener redisPacketListener = new RedisPacketListener(subscriptionHandler, topic, Logger.getAnonymousLogger()); | ||
|
||
redisPacketListener.onMessage(topic, message); | ||
verify(subscriptionHandler, times(1)).onPacket(expected); | ||
verify(subscriptionHandler).onPacket(argThat(argument -> { | ||
assertArrayEquals(expected,argument); | ||
return true; | ||
})); | ||
} | ||
|
||
|
||
@Test | ||
void onMessageWithUnKnownChannel_ThenFail() throws Exception { | ||
String topic = "test"; | ||
String message = "message"; | ||
|
||
RedisPacketListener redisPacketListener = new RedisPacketListener(subscriptionHandler, topic, Logger.getAnonymousLogger()); | ||
|
||
assertThrows(NullPointerException.class, () -> redisPacketListener.onMessage("fake-test", message)); | ||
} | ||
|
||
@Test | ||
void subscribe() { | ||
} | ||
|
||
@Test | ||
void stop() { | ||
} | ||
|
||
@Test | ||
void getCustomSubscribedChannels_ThenSuccess() { | ||
String topic = "test"; | ||
String message = "message"; | ||
|
||
RedisPacketListener redisPacketListener = new RedisPacketListener(subscriptionHandler, topic, Logger.getAnonymousLogger()); | ||
|
||
Collection<String> result = redisPacketListener.getCustomSubscribedChannels(); | ||
|
||
assertNotNull(result); | ||
assertEquals(1, result.size()); | ||
assertTrue(result.contains(topic)); | ||
} | ||
} |
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
Oops, something went wrong.