package org.oskari.cache;

import fi.nls.oskari.cache.JedisManager;
import org.junit.Test;

import static org.junit.Assert.*;

public class JedisSubscriberClientTest {

    @Test
    public void testPubSub() throws Exception {
        final String[] receivedMessage = new String[1];
        final String[] receivedMessage2 = new String[1];
        final JedisSubscriberClient sub1 = new JedisSubscriberClient("test", (msg) -> receivedMessage[0] = msg);
        final JedisSubscriberClient sub2 = new JedisSubscriberClient("test", (msg) -> receivedMessage2[0] = msg);

        Thread.sleep(500); // give time for subscriptions to complete
        String sentMessage = "test message";
        JedisManager.connect();
        Long res = JedisManager.publish("test", "test message");
        assertTrue(res == 2);
        System.out.println(receivedMessage[0]);
        assertNotNull(receivedMessage[0]);
        assertEquals(receivedMessage[0], sentMessage);
        assertNotNull(receivedMessage2[0]);
        assertEquals(receivedMessage2[0], sentMessage);
        sub1.stopListening();
        sub2.stopListening();
    }
}
@@ -220,16 +220,72 @@
 ption %7B%0A
+        org.junit.Assume.assumeTrue(redisAvailable());%0A%0A
         
@@ -324,32 +324,32 @@
  new String%5B1%5D;%0A
-
         final St
@@ -628,27 +628,8 @@
     
- Thread.sleep(500);
  // 
@@ -668,16 +668,44 @@
 omplete%0A
+        Thread.sleep(500);%0A%0A
         
@@ -745,40 +745,8 @@
 e%22;%0A
-        JedisManager.connect();%0A
     
@@ -840,56 +840,9 @@
 2);%0A
-        System.out.println(receivedMessage%5B0%5D);
 %0A
+
     
@@ -1027,32 +1027,33 @@
 , sentMessage);%0A
+%0A
         sub1.sto
@@ -1062,24 +1062,24 @@
 istening();%0A
-
         sub2
@@ -1101,10 +1101,662 @@
 );%0A    %7D
+%0A%0A    /**%0A     * Checks if we are able to connect to redis with a simple scenario%0A     * No point in running Redis tests if it is not available on the env we are running the test.%0A     * @return%0A     */%0A    private static boolean redisAvailable() %7B%0A        // once we call connect here we don't need to connect on the actual test%0A        JedisManager.connect();%0A        final String testKey = %22testing%22;%0A        final String testValue = %22availability%22;%0A        final String msg = JedisManager.setex(testKey, 10, testValue);%0A        if (msg == null) %7B%0A            return false;%0A        %7D%0A        return testValue.equals(JedisManager.get(testKey));%0A    %7D
 %0A%7D

Remove duplicate connect()