Skip to content

Commit 3c596fe

Browse files
committed
feat(bindingtester): implement last instructions
1 parent 711edff commit 3c596fe

File tree

4 files changed

+61
-25
lines changed

4 files changed

+61
-25
lines changed

foundationdb-bindingtester/src/main.rs

Lines changed: 61 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1835,7 +1835,7 @@ impl StackMachine {
18351835
}
18361836
};
18371837

1838-
let directory_subspace = match directory
1838+
match directory
18391839
.create_or_open(
18401840
txn,
18411841
(*path.get(0).unwrap().to_owned()).to_vec(),
@@ -1844,19 +1844,17 @@ impl StackMachine {
18441844
)
18451845
.await
18461846
{
1847-
Ok(s) => s,
1848-
Err(e) => {
1849-
panic!("could not call directory.create: {:?}", e);
1847+
Ok(directory_subspace) => {
1848+
debug!(
1849+
"pushing created_or_opened {:?} at index {}",
1850+
&directory_subspace,
1851+
self.directory_stack.len()
1852+
);
1853+
self.directory_stack
1854+
.push(DirectoryStackItem::DirectorySubspace(directory_subspace));
18501855
}
1856+
Err(e) => self.push_directory_err(&instr.code, number, e),
18511857
};
1852-
1853-
debug!(
1854-
"pushing created_or_opened {:?} at index {}",
1855-
&directory_subspace,
1856-
self.directory_stack.len()
1857-
);
1858-
self.directory_stack
1859-
.push(DirectoryStackItem::DirectorySubspace(directory_subspace));
18601858
}
18611859

18621860
// Pop the top item off the stack as [index]. Set the current directory list
@@ -2003,10 +2001,12 @@ impl StackMachine {
20032001
};
20042002

20052003
let paths = paths.get(0).expect("could not retrieve a path");
2006-
directory
2007-
.remove(txn, paths.to_owned())
2008-
.await
2009-
.expect("could not delete");
2004+
match directory.remove(txn, paths.to_owned()).await {
2005+
Ok(_) => {}
2006+
Err(e) => {
2007+
self.push_directory_err(&instr.code, number, e);
2008+
}
2009+
}
20102010
}
20112011

20122012
// Use the current directory for this operation.
@@ -2177,13 +2177,36 @@ impl StackMachine {
21772177
//
21782178
// Pop 1 item off the stack as [key]. Check if the current directory contains
21792179
// the specified key. Push 1 if it does and 0 if it doesn't.
2180-
DirectoryContains => unimplemented!(),
2180+
DirectoryContains => {
2181+
let raw_prefix = self.pop_bytes().await;
2182+
let b = self
2183+
.get_current_directory_subspace()
2184+
.unwrap()
2185+
.subspace(&())
2186+
.is_start_of(&raw_prefix);
2187+
self.push(number, Element::Bool(b));
2188+
}
21812189

21822190
// Use the current directory for this operation.
21832191
//
21842192
// Pop 1 tuple off the stack as [tuple]. Open the subspace of the current
21852193
// directory specified by tuple and push it onto the directory list.
2186-
DirectoryOpenSubspace => unimplemented!(),
2194+
DirectoryOpenSubspace => {
2195+
debug!("directory_open_subspace stack: {:?}", self.stack);
2196+
let n: usize = self.pop_usize().await;
2197+
debug!("DirectoryRange {}", n);
2198+
let mut buf = Vec::new();
2199+
for _ in 0..n {
2200+
let element: Element = self.pop_element().await;
2201+
debug!(" - {:?}", element);
2202+
buf.push(element);
2203+
}
2204+
2205+
let tuple = Element::Tuple(buf);
2206+
self.directory_stack.push(DirectoryStackItem::Subspace(
2207+
self.subspace_with_current(&tuple).unwrap(),
2208+
));
2209+
}
21872210

21882211
// Use the current directory for this operation.
21892212
//
@@ -2269,7 +2292,26 @@ impl StackMachine {
22692292
// subspace and store the result as [prefix]. Throw an error if the popped
22702293
// array does not start with prefix. Otherwise, remove the prefix from the
22712294
// popped array and push the result onto the stack.
2272-
DirectoryStripPrefix => unimplemented!(),
2295+
DirectoryStripPrefix => {
2296+
debug!("directory_strip_prefix stack: {:?}", self.stack);
2297+
let raw_prefix = self.pop_bytes().await;
2298+
let subspace_bytes_length =
2299+
self.get_current_directory_subspace().unwrap().bytes().len();
2300+
if raw_prefix.len() != subspace_bytes_length {
2301+
self.push_directory_err(
2302+
&instr.code,
2303+
number,
2304+
DirectoryError::Version(String::from(
2305+
"String does not start with raw prefix",
2306+
)),
2307+
);
2308+
} else {
2309+
self.push(
2310+
number,
2311+
Element::Bytes(Bytes::from(raw_prefix[subspace_bytes_length..].to_owned())),
2312+
);
2313+
}
2314+
}
22732315
}
22742316

22752317
if is_db && pending {

foundationdb/src/directory/directory_layer.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ impl Directory for DirectoryLayer {
218218
trx: &Transaction,
219219
path: Vec<String>,
220220
) -> Result<Vec<String>, DirectoryError> {
221-
dbg!(&path);
222221
let node = self
223222
.find_or_create_node(trx, path.to_owned(), false, None)
224223
.await?;
@@ -245,7 +244,6 @@ impl DirectoryLayer {
245244
allow_create: bool,
246245
allow_open: bool,
247246
) -> Result<DirectorySubspace, DirectoryError> {
248-
dbg!(&path, &prefix, &layer, allow_create, allow_open);
249247
self.check_version(trx, allow_create).await?;
250248

251249
if prefix.is_some() && !self.allow_manual_prefix {

foundationdb/src/directory/directory_subspace.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@ impl Directory for DirectorySubspace {
112112
return Err(DirectoryError::CannotMoveBetweenPartition);
113113
}
114114

115-
dbg!(&new_path, &self.path);
116-
117115
if compare_slice_string(&new_path[..partition_length], &self.path) != Ordering::Equal {
118116
Err(DirectoryError::CannotMoveBetweenPartition)
119117
} else {
@@ -157,7 +155,6 @@ impl Directory for DirectorySubspace {
157155
trx: &Transaction,
158156
path: Vec<String>,
159157
) -> Result<Vec<String>, DirectoryError> {
160-
dbg!(&path);
161158
self.directory
162159
.list(
163160
trx,

foundationdb/src/directory/node.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ impl Node {
4040
/// `check_layer` is checking the layer, throwing `IncompatibleLayer` when
4141
/// the provided layer does not match the one provided.
4242
pub(crate) fn check_layer(&self, layer: Vec<u8>) -> Result<(), DirectoryError> {
43-
dbg!(&self.layer, &layer);
4443
match &self.layer {
4544
None => Err(DirectoryError::IncompatibleLayer),
4645
Some(layer_bytes) => {

0 commit comments

Comments
 (0)