aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2017-11-04 16:21:33 -0700
committerBryan Newbold <bnewbold@robocracy.org>2017-11-04 16:21:33 -0700
commit9296dffe28f178c3611d4379d41876fcd507b1c8 (patch)
treed11574e5bbe26ce710fed970a15ba8a5badc0fe7 /src
parenta2a99f18d43dbfb76f72fe2771c292b9090e21f0 (diff)
downloadgeniza-9296dffe28f178c3611d4379d41876fcd507b1c8.tar.gz
geniza-9296dffe28f178c3611d4379d41876fcd507b1c8.zip
clarify and test sleep indexing
Diffstat (limited to 'src')
-rw-r--r--src/sleep_register.rs11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/sleep_register.rs b/src/sleep_register.rs
index 7d2d38e..c169cbb 100644
--- a/src/sleep_register.rs
+++ b/src/sleep_register.rs
@@ -29,7 +29,8 @@ pub trait HyperRegister {
/// Reads a single data entry from the store.
fn get_data_entry(&mut self, entry_index: u64) -> Result<Vec<u8>>;
- /// Writes an entry to the store. Requires the private key to be present.
+ /// Writes an entry to the store. Requires the private key to be present. Returns the entry
+ /// index written to.
fn append(&mut self, data: &[u8]) -> Result<u64>;
/// Count of data entries for this register. This is the total count (highest entry index plus
@@ -597,14 +598,16 @@ fn test_sdr_append() {
let tmp_dir = TempDir::new("geniza-test").unwrap();
let mut sdr = SleepDirRegister::create(tmp_dir.path(), "dummy").unwrap();
- sdr.append("hello world!".as_bytes()).unwrap();
+ let index = sdr.append("hello world!".as_bytes()).unwrap();
+ assert_eq!(index, 0);
assert!(sdr.check().is_ok());
assert!(sdr.verify().is_ok());
assert_eq!(sdr.len().unwrap(), 1);
assert_eq!(sdr.len_bytes().unwrap(), 12);
let count = 100; // TODO: make this >1000 when things are faster
- for _ in 0..count {
- sdr.append(&[1, 2, 3, 4, 5]).unwrap();
+ for i in 0..count {
+ let index = sdr.append(&[1, 2, 3, 4, 5]).unwrap();
+ assert_eq!(index, i+1);
}
assert!(sdr.check().is_ok());
assert!(sdr.verify().is_ok());