Skip to content

Commit

Permalink
tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
paulgb committed Sep 1, 2024
1 parent 65d493a commit 27c5edf
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 22 deletions.
5 changes: 1 addition & 4 deletions aper/src/aper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,8 @@ impl<A: Aper> AperClient<A> {
self.store.pop_overlay();
self.verified_server_version = server_version;

println!("mutate called; before: {:?}", self.store);

self.store.mutate(mutations);

println!("mutate called; after: {:?}", self.store);

// push new speculative overlay
self.store.push_overlay();

Expand All @@ -167,6 +163,7 @@ impl<A: Aper> AperClient<A> {
for speculative_intent in self.intent_stack.iter() {
// push a working overlay
self.store.push_overlay();

let mut sm = A::attach(self.store.handle());

if sm.apply(&speculative_intent.intent).is_err() {
Expand Down
2 changes: 0 additions & 2 deletions aper/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ impl<A: Aper> ClientConnection<A> {
}

pub fn receive(&mut self, message: &MessageToClient) {
println!("Received message: {:?}", message);

match &message.message {
MessageToClientType::Apply {
mutations,
Expand Down
16 changes: 9 additions & 7 deletions aper/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ pub enum PrefixMap {
}

impl PrefixMap {
fn get(&self, key: &Bytes) -> Option<Bytes> {
fn get(&self, key: &Bytes) -> Option<PrefixMapValue> {
match self {
PrefixMap::Children(children) => {
if let Some(PrefixMapValue::Value(value)) = children.get(key) {
if let Some(value) = children.get(key) {
Some(value.clone())
} else {
None
}
}
PrefixMap::DeletedPrefixMap => None,
PrefixMap::DeletedPrefixMap => Some(PrefixMapValue::Deleted),
}
}

Expand Down Expand Up @@ -212,13 +212,15 @@ impl Store {

for layer in inner.layers.iter().rev() {
if let Some(map) = layer.layer.get(prefix) {
println!("yy {:?} {:?}", prefix, key);
return map.get(key);
if let Some(value) = map.get(key) {
match value {
PrefixMapValue::Value(value) => return Some(value.clone()),
PrefixMapValue::Deleted => return None,
}
}
}
}

println!("xx {:?} {:?}", prefix, key);

None
}

Expand Down
11 changes: 2 additions & 9 deletions aper/tests/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,6 @@ impl Aper for LinkedFields {
type Error = ();

fn apply(&mut self, intent: &Self::Intent) -> Result<(), Self::Error> {
println!("apply: {:?}", intent);
println!("lhs: {:?}", self.lhs.get());
println!("rhs: {:?}", self.rhs.get());

match intent {
LinkedFieldIntent::SetLhs(value) => self.lhs.set(*value),
LinkedFieldIntent::SetRhs(value) => self.rhs.set(*value),
Expand Down Expand Up @@ -169,13 +165,14 @@ fn test_mutate_listener_incidental() {
assert_eq!(1, st.lhs.get());
assert_eq!(1, st.sum.get());

client.mutate(&vec![], None, 1);

assert!(lhs_recv.try_recv().is_ok());
assert!(rhs_recv.try_recv().is_err());
assert!(sum_recv.try_recv().is_ok());

// now mutate the rhs, which should cause the sum to be recomputed

println!("mutating rhs");
client.mutate(
&vec![create_mutation(
vec![b"rhs"],
Expand All @@ -187,10 +184,6 @@ fn test_mutate_listener_incidental() {
None,
1,
);
println!("done mutating rhs");

// TODO: this should not cause a failure, but does?
// let st = client.state();

assert_eq!(26, st.rhs.get());
assert_eq!(27, st.sum.get());
Expand Down

0 comments on commit 27c5edf

Please sign in to comment.