Skip to content

Commit

Permalink
refactor(client)!: refactor MaintenanceClient::alarm
Browse files Browse the repository at this point in the history
Signed-off-by: lxl66566 <[email protected]>
  • Loading branch information
lxl66566 committed Aug 15, 2024
1 parent 0e6f32c commit 8852084
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
22 changes: 18 additions & 4 deletions crates/xline-client/src/clients/maintenance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use std::{fmt::Debug, sync::Arc};

use tonic::{transport::Channel, Streaming};
use xlineapi::{
AlarmRequest, AlarmResponse, SnapshotRequest, SnapshotResponse, StatusRequest, StatusResponse,
AlarmAction, AlarmRequest, AlarmResponse, AlarmType, SnapshotRequest, SnapshotResponse,
StatusRequest, StatusResponse,
};

use crate::{error::Result, AuthService};
Expand Down Expand Up @@ -95,14 +96,27 @@ impl MaintenanceClient {
/// .await?
/// .maintenance_client();
///
/// client.alarm(AlarmRequest::new(AlarmAction::Get, 0, AlarmType::None)).await?;
/// client.alarm(AlarmAction::Get, 0, AlarmType::None).await?;
///
/// Ok(())
/// }
/// ```
#[inline]
pub async fn alarm(&mut self, request: AlarmRequest) -> Result<AlarmResponse> {
Ok(self.inner.alarm(request).await?.into_inner())
pub async fn alarm(
&mut self,
action: AlarmAction,
member_id: u64,
alarm_type: AlarmType,
) -> Result<AlarmResponse> {
Ok(self
.inner
.alarm(AlarmRequest {
action: action.into(),
member_id,
alarm: alarm_type.into(),
})
.await?
.into_inner())
}

/// Sends a status request
Expand Down
1 change: 0 additions & 1 deletion crates/xline-client/src/types/maintenance.rs

This file was deleted.

2 changes: 0 additions & 2 deletions crates/xline-client/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ pub mod cluster;
pub mod kv;
/// Lease type definitions
pub mod lease;
/// Maintenance type definitions.
pub mod maintenance;
/// Range Option definitions, to build a `range_end` from key.
pub mod range_end;
/// Watch type definitions.
Expand Down
4 changes: 2 additions & 2 deletions crates/xline/tests/it/maintenance_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use tokio::io::AsyncWriteExt;
use xline::restore::restore;
use xline_client::error::XlineClientError;
use xline_test_utils::{Client, ClientOptions, Cluster};
use xlineapi::{execute_error::ExecuteError, AlarmAction, AlarmRequest, AlarmType};
use xlineapi::{execute_error::ExecuteError, AlarmAction, AlarmType};

#[tokio::test(flavor = "multi_thread")]
#[abort_on_panic]
Expand Down Expand Up @@ -92,7 +92,7 @@ async fn test_alarm(idx: usize) {
}
tokio::time::sleep(tokio::time::Duration::from_millis(500)).await;
let res = m_client
.alarm(AlarmRequest::new(AlarmAction::Get, 0, AlarmType::None))
.alarm(AlarmAction::Get, 0, AlarmType::None)
.await
.unwrap();
assert!(!res.alarms.is_empty());
Expand Down

0 comments on commit 8852084

Please sign in to comment.