Esempio n. 1
0
    /** Interrupt the thread and stop the blocking subscription. */
    private void shutdown() {
      running.getAndSet(false);
      this.interrupt();

      try {
        if (subscriber != null) {
          subscriber.unsubscribe();
        }
      } finally {
        JedisUtils.closeJedis(sentinelJedis);
      }
    }
  @Test(expected = JedisConnectionException.class)
  public void unsubscribeWhenNotSusbscribed() throws InterruptedException {
    JedisPubSub pubsub =
        new JedisPubSub() {
          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();
  }