File tree 2 files changed +26
-0
lines changed
2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -1605,6 +1605,10 @@ impl ClientBuilder {
1605
1605
}
1606
1606
1607
1607
/// Connects to ZooKeeper cluster.
1608
+ ///
1609
+ /// # Notable errors
1610
+ /// * [Error::NoHosts] if no host is available
1611
+ /// * [Error::SessionExpired] if specified session expired
1608
1612
pub async fn connect ( & mut self , cluster : & str ) -> Result < Client > {
1609
1613
let ( hosts, chroot) = util:: parse_connect_string ( cluster) ?;
1610
1614
let mut buf = Vec :: with_capacity ( 4096 ) ;
Original file line number Diff line number Diff line change @@ -145,6 +145,28 @@ async fn connect(cluster: &str, chroot: &str) -> zk::Client {
145
145
client. chroot ( chroot) . unwrap ( )
146
146
}
147
147
148
+ #[ test_log:: test( tokio:: test) ]
149
+ async fn test_connect_nohosts ( ) {
150
+ assert_that ! ( zk:: Client :: connect( "127.0.0.1:100,127.0.0.1:101" ) . await . unwrap_err( ) ) . is_equal_to ( zk:: Error :: NoHosts ) ;
151
+ }
152
+
153
+ #[ test_log:: test( tokio:: test) ]
154
+ async fn test_connect_session_expired ( ) {
155
+ let docker = DockerCli :: default ( ) ;
156
+ let zookeeper = docker. run ( zookeeper_image ( ) ) ;
157
+ let zk_port = zookeeper. get_host_port ( 2181 ) ;
158
+
159
+ let cluster = format ! ( "127.0.0.1:{}" , zk_port) ;
160
+ let client = zk:: Client :: builder ( ) . detach ( ) . connect ( & cluster) . await . unwrap ( ) ;
161
+ let timeout = client. session_timeout ( ) ;
162
+ let ( id, password) = client. into_session ( ) ;
163
+
164
+ tokio:: time:: sleep ( timeout * 2 ) . await ;
165
+
166
+ assert_that ! ( zk:: Client :: builder( ) . with_session( id, password) . connect( & cluster) . await . unwrap_err( ) )
167
+ . is_equal_to ( zk:: Error :: SessionExpired ) ;
168
+ }
169
+
148
170
#[ test_case( "/" ; "no_chroot" ) ]
149
171
#[ test_case( "/x" ; "chroot_x" ) ]
150
172
#[ test_case( "/x/y" ; "chroot_x_y" ) ]
You can’t perform that action at this time.
0 commit comments