pub async fn kvcounter_binding_first() -> Result<()> {
    use redis::Commands;
    let h = HostBuilder::new().build();
    h.start(None, None).await?;

    let web_port = 9998_u32;

    // Set the bindings before there's any provider to invoke OP_BIND_ACTOR

    let mut webvalues: HashMap<String, String> = HashMap::new();
    webvalues.insert("PORT".to_string(), format!("{}", web_port));

    let mut values: HashMap<String, String> = HashMap::new();
    values.insert("URL".to_string(), "redis://127.0.0.1:6379".to_string());

    let arc = par_from_file("./tests/modules/libwascc_redis.par.gz")?;
    let arc2 = par_from_file("./tests/modules/libwascc_httpsrv.par.gz")?;

    let redis_id = arc.claims().unwrap().subject;
    let websrv_id = arc2.claims().unwrap().subject;

    let kvcounter = Actor::from_file("./tests/modules/kvcounter.wasm")?;
    let kvcounter_key = kvcounter.public_key();

    h.set_binding(
        &kvcounter_key,
        "wascc:http_server",
        None,
        websrv_id,
        webvalues,
    )
    .await?;

    h.set_binding(&kvcounter_key, "wascc:keyvalue", None, redis_id, values)
        .await?;

    h.start_actor(kvcounter).await?;
    await_actor_count(&h, 1, Duration::from_millis(50), 3).await?;

    let redis = NativeCapability::from_archive(&arc, None)?;
    let websrv = NativeCapability::from_archive(&arc2, None)?;

    // When we start these, with pre-existing bindings, they should trigger OP_BIND_ACTOR invocations
    // for each.
    h.start_native_capability(redis).await?;
    h.start_native_capability(websrv).await?;
    await_provider_count(&h, 3, Duration::from_millis(50), 3).await?; // 2 providers plus wascc:extras

    let key = uuid::Uuid::new_v4().to_string();
    let rkey = format!(":{}", key); // the kv wasm logic does a replace on '/' with ':'
    let url = format!("http://localhost:{}/{}", web_port, key);

    let mut resp = reqwest::get(&url).await?;
    assert!(resp.status().is_success());
    assert_eq!(resp.text().await?, "{\"counter\":1}");

    let client = redis::Client::open("redis://127.0.0.1/")?;
    let mut con = client.get_connection()?;
    let _: () = con.del(&rkey)?;
    h.stop().await;

    Ok(())
}
// Set the binding before either the actor or the provider are running in
// the host, and verify that we can then hit the HTTP endpoint.
Set the binding before either the actor or the provider are running in
the host, and verify that we can then hit the HTTP endpoint.
Set the binding before either the actor or the provider are running in the host and verify that we can then hit the HTTP endpoint .
pub async fn kvcounter_binding_first() -> Result<()> {
    use redis::Commands;
    let h = HostBuilder::new().build();
    h.start(None, None).await?;
    let web_port = 9998_u32;
    // Set the bindings before there's any provider to invoke OP_BIND_ACTOR
    let mut webvalues: HashMap<String, String> = HashMap::new();
    webvalues.insert("PORT".to_string(), format!("{}", web_port));
    let mut values: HashMap<String, String> = HashMap::new();
    values.insert("URL".to_string(), "redis://127.0.0.1:6379".to_string());
    let arc = par_from_file("./tests/modules/libwascc_redis.par.gz")?;
    let arc2 = par_from_file("./tests/modules/libwascc_httpsrv.par.gz")?;
    let redis_id = arc.claims().unwrap().subject;
    let websrv_id = arc2.claims().unwrap().subject;
    let kvcounter = Actor::from_file("./tests/modules/kvcounter.wasm")?;
    let kvcounter_key = kvcounter.public_key();
    h.set_binding(
        &kvcounter_key,
        "wascc:http_server",
        None,
        websrv_id,
        webvalues,
    )
    .await?;
    h.set_binding(&kvcounter_key, "wascc:keyvalue", None, redis_id, values)
        .await?;
    h.start_actor(kvcounter).await?;
    await_actor_count(&h, 1, Duration::from_millis(50), 3).await?;
    let redis = NativeCapability::from_archive(&arc, None)?;
    let websrv = NativeCapability::from_archive(&arc2, None)?;
    // When we start these, with pre-existing bindings, they should trigger OP_BIND_ACTOR invocations
    // for each.
    h.start_native_capability(redis).await?;
    h.start_native_capability(websrv).await?;
    await_provider_count(&h, 3, Duration::from_millis(50), 3).await?; // 2 providers plus wascc:extras
    let key = uuid::Uuid::new_v4().to_string();
    let rkey = format!(":{}", key); // the kv wasm logic does a replace on '/' with ':'
    let url = format!("http://localhost:{}/{}", web_port, key);
    let mut resp = reqwest::get(&url).await?;
    assert!(resp.status().is_success());
    assert_eq!(resp.text().await?, "{\"counter\":1}");
    let client = redis::Client::open("redis://127.0.0.1/")?;
    let mut con = client.get_connection()?;
    let _: () = con.del(&rkey)?;
    h.stop().await;
    Ok(())
}
pub async fn kvcounter_binding_first ( ) -> Result < ( ) > { use redis :: Commands ; let h = HostBuilder :: new ( ) . build ( ) ; h . start ( None , None ) . await ? ; let web_port = 9998_u32 ; // Set the bindings before there's any provider to invoke OP_BIND_ACTOR let mut webvalues : HashMap < String , String > = HashMap :: new ( ) ; webvalues . insert ( " " . to_string ( ) , format ! ( " " web_port ) ) ; let mut values : HashMap < String , String > = HashMap :: new ( ) ; values . insert ( " " . to_string ( ) , " " . to_string ( ) ) ; let arc = par_from_file ( " " ) ? ; let arc2 = par_from_file ( " " ) ? ; let redis_id = arc . claims ( ) . unwrap ( ) . subject ; let websrv_id = arc2 . claims ( ) . unwrap ( ) . subject ; let kvcounter = Actor :: from_file ( " " ) ? ; let kvcounter_key = kvcounter . public_key ( ) ; h . set_binding ( & kvcounter_key , " " , None , websrv_id , webvalues , ) . await ? ; h . set_binding ( & kvcounter_key , " " , None , redis_id , values ) . await ? ; h . start_actor ( kvcounter ) . await ? ; await_actor_count ( & h , 1 , Duration :: from_millis ( 50 ) , 3 ) . await ? ; let redis = NativeCapability :: from_archive ( & arc , None ) ? ; let websrv = NativeCapability :: from_archive ( & arc2 , None ) ? ; // When we start these, with pre-existing bindings, they should trigger OP_BIND_ACTOR invocations // for each. h . start_native_capability ( redis ) . await ? ; h . start_native_capability ( websrv ) . await ? ; await_provider_count ( & h , 3 , Duration :: from_millis ( 50 ) , 3 ) . await ? ; // 2 providers plus wascc:extras let key = uuid :: Uuid :: new_v4 ( ) . to_string ( ) ; let rkey = format ! ( " " key ) ; // the kv wasm logic does a replace on '/' with ':' let url = format ! ( " " web_port key ) ; let mut resp = reqwest :: get ( & url ) . await ? ; assert ! ( resp status ( ) is_success ( ) ) ; assert_eq ! ( resp text ( ) await " \" \" " ) ; let client = redis :: Client :: open ( " " ) ? ; let mut con = client . get_connection ( ) ? ; let _ : ( ) = con . del ( & rkey ) ? ; h . stop ( ) . await ; Ok ( ( ) ) }
Set the binding before either the actor or the provider are running in
the host, and verify that we can then hit the HTTP endpoint.
Set the binding before either the actor or the provider are running in the host and verify that we can then hit the HTTP endpoint .