"Fossies" - the Fresh Open Source Software Archive

Member "redis-7.0.5/tests/cluster/tests/26-pubsubshard.tcl" (21 Sep 2022, 3088 Bytes) of package /linux/misc/redis-7.0.5.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Tcl/Tk source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 # Test PUBSUB shard propagation in a cluster slot.
    2 
    3 source "../tests/includes/init-tests.tcl"
    4 
    5 test "Create a 3 nodes cluster" {
    6     cluster_create_with_continuous_slots 3 3
    7 }
    8 
    9 set cluster [redis_cluster 127.0.0.1:[get_instance_attrib redis 0 port]]
   10 test "Pub/Sub shard basics" {
   11 
   12     set slot [$cluster cluster keyslot "channel.0"]
   13     array set publishnode [$cluster masternode_for_slot $slot]
   14     array set notshardnode [$cluster masternode_notfor_slot $slot]
   15 
   16     set publishclient [redis_client_by_addr $publishnode(host) $publishnode(port)]
   17     set subscribeclient [redis_deferring_client_by_addr $publishnode(host) $publishnode(port)]
   18     set subscribeclient2 [redis_deferring_client_by_addr $publishnode(host) $publishnode(port)]
   19     set anotherclient [redis_deferring_client_by_addr $notshardnode(host) $notshardnode(port)]
   20 
   21     $subscribeclient ssubscribe channel.0
   22     $subscribeclient read
   23 
   24     $subscribeclient2 ssubscribe channel.0
   25     $subscribeclient2 read
   26 
   27     $anotherclient ssubscribe channel.0
   28     catch {$anotherclient read} err
   29     assert_match {MOVED *} $err
   30 
   31     set data [randomValue]
   32     $publishclient spublish channel.0 $data
   33 
   34     set msg [$subscribeclient read]
   35     assert_equal $data [lindex $msg 2]
   36 
   37     set msg [$subscribeclient2 read]
   38     assert_equal $data [lindex $msg 2]
   39 
   40     $publishclient close
   41     $subscribeclient close
   42     $subscribeclient2 close
   43     $anotherclient close
   44 }
   45 
   46 test "client can't subscribe to multiple shard channels across different slots in same call" {
   47     catch {$cluster ssubscribe channel.0 channel.1} err
   48     assert_match {CROSSSLOT Keys*} $err
   49 }
   50 
   51 test "client can subscribe to multiple shard channels across different slots in separate call" {
   52     $cluster ssubscribe ch3
   53     $cluster ssubscribe ch7
   54 
   55     $cluster sunsubscribe ch3
   56     $cluster sunsubscribe ch7
   57 }
   58 
   59 
   60 test "Verify Pub/Sub and Pub/Sub shard no overlap" {
   61     set slot [$cluster cluster keyslot "channel.0"]
   62     array set publishnode [$cluster masternode_for_slot $slot]
   63     array set notshardnode [$cluster masternode_notfor_slot $slot]
   64 
   65     set publishshardclient [redis_client_by_addr $publishnode(host) $publishnode(port)]
   66     set publishclient [redis_deferring_client_by_addr $publishnode(host) $publishnode(port)]
   67     set subscribeshardclient [redis_deferring_client_by_addr $publishnode(host) $publishnode(port)]
   68     set subscribeclient [redis_deferring_client_by_addr $publishnode(host) $publishnode(port)]
   69 
   70     $subscribeshardclient deferred 1
   71     $subscribeshardclient ssubscribe channel.0
   72     $subscribeshardclient read
   73 
   74     $subscribeclient deferred 1
   75     $subscribeclient subscribe channel.0
   76     $subscribeclient read
   77 
   78     set sharddata "testingpubsubdata"
   79     $publishshardclient spublish channel.0 $sharddata
   80 
   81     set data "somemoredata"
   82     $publishclient publish channel.0 $data
   83 
   84     set msg [$subscribeshardclient read]
   85     assert_equal $sharddata [lindex $msg 2]
   86 
   87     set msg [$subscribeclient read]
   88     assert_equal $data [lindex $msg 2]
   89 
   90     $cluster close
   91     $publishclient close
   92     $subscribeclient close
   93     $subscribeshardclient close
   94 }