forked from microsoft/regorus
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
arc
feature to enable using Engine and other data structures from m…
…ultiple threads (microsoft#142) * `arc` feature to make engine usable from multiple threads. `arc` is turned on by default. When enabled, std::sync::Arc will be used instead of std::rc::Rc. The former makes regorus types like Engine, Value, ast nodes etc Send, allowing for usability from multiple threads. Arc would add a performance overhead though since the reference counting will now become atomic. Signed-off-by: Anand Krishnamoorthi <[email protected]> * Make engine and related types Debug Signed-off-by: Anand Krishnamoorthi <[email protected]> * Input, Data as json. Evaluate bool queries. Signed-off-by: Anand Krishnamoorthi <[email protected]> --------- Signed-off-by: Anand Krishnamoorthi <[email protected]>
- Loading branch information
Showing
14 changed files
with
96 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
use lazy_static::lazy_static; | ||
use std::sync::Mutex; | ||
|
||
use regorus::*; | ||
|
||
// Ensure that types can be s | ||
lazy_static! { | ||
static ref VALUE: Value = Value::Null; | ||
static ref ENGINE: Mutex<Engine> = Mutex::new(Engine::new()); | ||
// static ref ENGINE: Engine = Engine::new(); | ||
} | ||
|
||
#[test] | ||
fn shared_engine() -> anyhow::Result<()> { | ||
let e_guard = ENGINE.lock(); | ||
let mut engine = e_guard.expect("failed to lock engine"); | ||
|
||
engine.add_policy( | ||
"hello.rego".to_string(), | ||
r#" | ||
package test | ||
allow = true | ||
"# | ||
.to_string(), | ||
)?; | ||
|
||
let results = engine.eval_query("data.test.allow".to_string(), false)?; | ||
assert_eq!(results.result[0].expressions[0].value, Value::from(true)); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,6 @@ mod engine; | |
mod lexer; | ||
mod parser; | ||
mod value; | ||
|
||
#[cfg(feature = "arc")] | ||
mod arc; |