@@ -23,35 +23,10 @@ use hyperactor::mailbox::MailboxServer;
23
23
use hyperactor:: proc:: Proc ;
24
24
25
25
pub mod client;
26
+ pub mod log_writer;
26
27
pub mod object;
27
28
pub mod state_actor;
28
29
29
- /// Creates a state actor server at given address. Returns the server address and a handle to the
30
- /// state actor.
31
- #[ allow( dead_code) ]
32
- pub async fn spawn_actor < T : Actor + RemoteActor + Binds < T > > (
33
- addr : ChannelAddr ,
34
- proc_id : ProcId ,
35
- actor_name : & str ,
36
- params : T :: Params ,
37
- ) -> Result < ( ChannelAddr , ActorHandle < T > ) > {
38
- // Use the provided ProcId directly
39
- let proc = Proc :: new ( proc_id, BoxedMailboxSender :: new ( DialMailboxRouter :: new ( ) ) ) ;
40
-
41
- // Set up the channel server
42
- let ( local_addr, rx) = channel:: serve ( addr. clone ( ) ) . await ?;
43
-
44
- // Spawn the actor with just a name - the system will generate the full actor ID
45
- let actor_handle: ActorHandle < T > = proc. spawn ( actor_name, params) . await ?;
46
-
47
- // Undeliverable messages encountered by the mailbox server
48
- // are to be returned to the system actor.
49
- let _mailbox_handle = proc. clone ( ) . serve ( rx, actor_handle. port ( ) ) ;
50
-
51
- // Return the address and handle (not a ref)
52
- Ok ( ( local_addr, actor_handle) )
53
- }
54
-
55
30
/// Creates a remote client that can send message to actors in the remote addr.
56
31
/// It is important to keep the client proc alive for the remote_client's lifetime.
57
32
pub async fn create_remote_client ( addr : ChannelAddr ) -> Result < ( Proc , Mailbox ) > {
@@ -66,26 +41,57 @@ pub async fn create_remote_client(addr: ChannelAddr) -> Result<(Proc, Mailbox)>
66
41
}
67
42
68
43
pub mod test_utils {
44
+ use super :: * ;
69
45
use crate :: object:: GenericStateObject ;
46
+ use crate :: object:: Kind ;
70
47
use crate :: object:: LogSpec ;
71
48
use crate :: object:: LogState ;
49
+ use crate :: object:: Name ;
72
50
use crate :: object:: StateMetadata ;
73
51
use crate :: object:: StateObject ;
74
52
75
- pub fn log_items ( seq_low : usize , seq_high : usize ) -> Vec < GenericStateObject > {
53
+ pub fn log_items ( seq_low : u64 , seq_high : u64 ) -> Vec < GenericStateObject > {
76
54
let mut log_items = vec ! [ ] ;
77
55
let metadata = StateMetadata {
78
- name : "test ". to_string ( ) ,
79
- kind : "log" . to_string ( ) ,
56
+ name : Name :: StdoutLog ( ( "test_host ". to_string ( ) , 12345 ) ) ,
57
+ kind : Kind :: Log ,
80
58
} ;
81
59
let spec = LogSpec { } ;
82
60
for seq in seq_low..seq_high {
83
- let state = LogState :: new ( seq, format ! ( "state {}" , seq) ) ;
61
+ let state = LogState :: from_string ( seq, format ! ( "state {}" , seq) ) . unwrap ( ) ;
84
62
let state_object =
85
63
StateObject :: < LogSpec , LogState > :: new ( metadata. clone ( ) , spec. clone ( ) , state) ;
86
64
let generic_state_object = GenericStateObject :: try_from ( state_object) . unwrap ( ) ;
87
65
log_items. push ( generic_state_object) ;
88
66
}
89
67
log_items
90
68
}
69
+
70
+ /// Creates a state actor server at given address. Returns the server address, a handle to the
71
+ /// state actor, and a client mailbox for sending messages to the actor.
72
+ pub async fn spawn_actor < T : Actor + RemoteActor + Binds < T > > (
73
+ addr : ChannelAddr ,
74
+ proc_id : ProcId ,
75
+ actor_name : & str ,
76
+ params : T :: Params ,
77
+ ) -> Result < ( ChannelAddr , ActorHandle < T > , Mailbox ) > {
78
+ // Use the provided ProcId directly
79
+ let proc = Proc :: new ( proc_id, BoxedMailboxSender :: new ( DialMailboxRouter :: new ( ) ) ) ;
80
+
81
+ // Set up the channel server
82
+ let ( local_addr, rx) = channel:: serve ( addr. clone ( ) ) . await ?;
83
+
84
+ // Spawn the actor with just a name - the system will generate the full actor ID
85
+ let actor_handle: ActorHandle < T > = proc. spawn ( actor_name, params) . await ?;
86
+
87
+ // Create a client mailbox for sending messages to the actor
88
+ let client_mailbox = proc. attach ( "client" ) ?;
89
+
90
+ // Undeliverable messages encountered by the mailbox server
91
+ // are to be returned to the system actor.
92
+ let _mailbox_handle = proc. clone ( ) . serve ( rx, actor_handle. port ( ) ) ;
93
+
94
+ // Return the address, handle, and client mailbox
95
+ Ok ( ( local_addr, actor_handle, client_mailbox) )
96
+ }
91
97
}
0 commit comments