mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
rename DB to TaskDB for consistency
This commit is contained in:
parent
8e2b4c3f6c
commit
2296d0fa35
4 changed files with 34 additions and 34 deletions
|
@ -1,7 +1,7 @@
|
|||
use crate::errors::Error;
|
||||
use crate::server::Server;
|
||||
use crate::task::{Status, Task};
|
||||
use crate::taskdb::DB;
|
||||
use crate::taskdb::TaskDB;
|
||||
use crate::taskstorage::{Operation, TaskMap, TaskStorage};
|
||||
use chrono::Utc;
|
||||
use failure::Fallible;
|
||||
|
@ -11,13 +11,13 @@ use uuid::Uuid;
|
|||
/// A replica represents an instance of a user's task data, providing an easy interface
|
||||
/// for querying and modifying that data.
|
||||
pub struct Replica {
|
||||
taskdb: DB,
|
||||
taskdb: TaskDB,
|
||||
}
|
||||
|
||||
impl Replica {
|
||||
pub fn new(storage: Box<dyn TaskStorage>) -> Replica {
|
||||
return Replica {
|
||||
taskdb: DB::new(storage),
|
||||
taskdb: TaskDB::new(storage),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ use std::collections::HashSet;
|
|||
use std::str;
|
||||
use uuid::Uuid;
|
||||
|
||||
pub struct DB {
|
||||
pub struct TaskDB {
|
||||
storage: Box<dyn TaskStorage>,
|
||||
}
|
||||
|
||||
|
@ -17,24 +17,24 @@ struct Version {
|
|||
operations: Vec<Operation>,
|
||||
}
|
||||
|
||||
impl DB {
|
||||
/// Create a new DB with the given backend storage
|
||||
pub fn new(storage: Box<dyn TaskStorage>) -> DB {
|
||||
DB { storage }
|
||||
impl TaskDB {
|
||||
/// Create a new TaskDB with the given backend storage
|
||||
pub fn new(storage: Box<dyn TaskStorage>) -> TaskDB {
|
||||
TaskDB { storage }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub fn new_inmemory() -> DB {
|
||||
DB::new(Box::new(crate::taskstorage::InMemoryStorage::new()))
|
||||
pub fn new_inmemory() -> TaskDB {
|
||||
TaskDB::new(Box::new(crate::taskstorage::InMemoryStorage::new()))
|
||||
}
|
||||
|
||||
/// Apply an operation to the DB. Aside from synchronization operations, this is the only way
|
||||
/// to modify the DB. In cases where an operation does not make sense, this function will do
|
||||
/// nothing and return an error (but leave the DB in a consistent state).
|
||||
/// Apply an operation to the TaskDB. Aside from synchronization operations, this is the only way
|
||||
/// to modify the TaskDB. In cases where an operation does not make sense, this function will do
|
||||
/// nothing and return an error (but leave the TaskDB in a consistent state).
|
||||
pub fn apply(&mut self, op: Operation) -> Fallible<()> {
|
||||
// TODO: differentiate error types here?
|
||||
let mut txn = self.storage.txn()?;
|
||||
if let err @ Err(_) = DB::apply_op(txn.as_mut(), &op) {
|
||||
if let err @ Err(_) = TaskDB::apply_op(txn.as_mut(), &op) {
|
||||
return err;
|
||||
}
|
||||
txn.add_operation(op)?;
|
||||
|
@ -183,7 +183,7 @@ impl DB {
|
|||
assert_eq!(version.version, txn.base_version()? + 1);
|
||||
println!("applying version {:?} from server", version.version);
|
||||
|
||||
DB::apply_version(txn.as_mut(), version)?;
|
||||
TaskDB::apply_version(txn.as_mut(), version)?;
|
||||
}
|
||||
|
||||
let operations: Vec<Operation> = txn.operations()?.iter().map(|o| o.clone()).collect();
|
||||
|
@ -254,7 +254,7 @@ impl DB {
|
|||
}
|
||||
}
|
||||
if let Some(o) = svr_op {
|
||||
if let Err(e) = DB::apply_op(txn, &o) {
|
||||
if let Err(e) = TaskDB::apply_op(txn, &o) {
|
||||
println!("Invalid operation when syncing: {} (ignored)", e);
|
||||
}
|
||||
}
|
||||
|
@ -309,7 +309,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_apply_create() {
|
||||
let mut db = DB::new_inmemory();
|
||||
let mut db = TaskDB::new_inmemory();
|
||||
let uuid = Uuid::new_v4();
|
||||
let op = Operation::Create { uuid };
|
||||
db.apply(op.clone()).unwrap();
|
||||
|
@ -320,7 +320,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_apply_create_exists() {
|
||||
let mut db = DB::new_inmemory();
|
||||
let mut db = TaskDB::new_inmemory();
|
||||
let uuid = Uuid::new_v4();
|
||||
let op = Operation::Create { uuid };
|
||||
db.apply(op.clone()).unwrap();
|
||||
|
@ -335,7 +335,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_apply_create_update() {
|
||||
let mut db = DB::new_inmemory();
|
||||
let mut db = TaskDB::new_inmemory();
|
||||
let uuid = Uuid::new_v4();
|
||||
let op1 = Operation::Create { uuid };
|
||||
db.apply(op1.clone()).unwrap();
|
||||
|
@ -356,7 +356,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_apply_create_update_delete_prop() {
|
||||
let mut db = DB::new_inmemory();
|
||||
let mut db = TaskDB::new_inmemory();
|
||||
let uuid = Uuid::new_v4();
|
||||
let op1 = Operation::Create { uuid };
|
||||
db.apply(op1.clone()).unwrap();
|
||||
|
@ -398,7 +398,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_apply_update_does_not_exist() {
|
||||
let mut db = DB::new_inmemory();
|
||||
let mut db = TaskDB::new_inmemory();
|
||||
let uuid = Uuid::new_v4();
|
||||
let op = Operation::Update {
|
||||
uuid,
|
||||
|
@ -417,7 +417,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_apply_create_delete() {
|
||||
let mut db = DB::new_inmemory();
|
||||
let mut db = TaskDB::new_inmemory();
|
||||
let uuid = Uuid::new_v4();
|
||||
let op1 = Operation::Create { uuid };
|
||||
db.apply(op1.clone()).unwrap();
|
||||
|
@ -431,7 +431,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_apply_delete_not_present() {
|
||||
let mut db = DB::new_inmemory();
|
||||
let mut db = TaskDB::new_inmemory();
|
||||
let uuid = Uuid::new_v4();
|
||||
|
||||
let op1 = Operation::Delete { uuid };
|
||||
|
@ -446,7 +446,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn rebuild_working_set() -> Fallible<()> {
|
||||
let mut db = DB::new_inmemory();
|
||||
let mut db = TaskDB::new_inmemory();
|
||||
let uuids = vec![
|
||||
Uuid::new_v4(), // 0: pending, not already in working set
|
||||
Uuid::new_v4(), // 1: pending, already in working set
|
||||
|
@ -455,7 +455,7 @@ mod tests {
|
|||
Uuid::new_v4(), // 4: pending, already in working set
|
||||
];
|
||||
|
||||
// add everything to the DB
|
||||
// add everything to the TaskDB
|
||||
for uuid in &uuids {
|
||||
db.apply(Operation::Create { uuid: uuid.clone() })?;
|
||||
}
|
||||
|
@ -513,8 +513,8 @@ mod tests {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn newdb() -> DB {
|
||||
DB::new(Box::new(InMemoryStorage::new()))
|
||||
fn newdb() -> TaskDB {
|
||||
TaskDB::new(Box::new(InMemoryStorage::new()))
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -666,7 +666,7 @@ mod tests {
|
|||
#[test]
|
||||
// check that various sequences of operations on mulitple db's do not get the db's into an
|
||||
// incompatible state. The main concern here is that there might be a sequence of create
|
||||
// and delete operations that results in a task existing in one DB but not existing in
|
||||
// and delete operations that results in a task existing in one TaskDB but not existing in
|
||||
// another. So, the generated sequences focus on a single task UUID.
|
||||
fn transform_sequences_of_operations(action_sequence in action_sequence_strategy()) {
|
||||
let mut server = TestServer::new();
|
||||
|
|
|
@ -68,7 +68,7 @@ pub trait TaskStorageTxn {
|
|||
fn operations<'a>(&mut self) -> Fallible<Vec<Operation>>;
|
||||
|
||||
/// Add an operation to the end of the list of operations in the storage. Note that this
|
||||
/// merely *stores* the operation; it is up to the DB to apply it.
|
||||
/// merely *stores* the operation; it is up to the TaskDB to apply it.
|
||||
fn add_operation(&mut self, op: Operation) -> Fallible<()>;
|
||||
|
||||
/// Replace the current list of operations with a new list.
|
||||
|
|
|
@ -128,7 +128,7 @@ impl Operation {
|
|||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use crate::taskdb::DB;
|
||||
use crate::taskdb::TaskDB;
|
||||
use crate::taskstorage::InMemoryStorage;
|
||||
use chrono::{Duration, Utc};
|
||||
use proptest::prelude::*;
|
||||
|
@ -148,7 +148,7 @@ mod test {
|
|||
|
||||
// check that the two operation sequences have the same effect, enforcing the invariant of
|
||||
// the transform function.
|
||||
let mut db1 = DB::new_inmemory();
|
||||
let mut db1 = TaskDB::new_inmemory();
|
||||
if let Some(ref o) = setup {
|
||||
db1.apply(o.clone()).unwrap();
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ mod test {
|
|||
db1.apply(o).unwrap();
|
||||
}
|
||||
|
||||
let mut db2 = DB::new_inmemory();
|
||||
let mut db2 = TaskDB::new_inmemory();
|
||||
if let Some(ref o) = setup {
|
||||
db2.apply(o.clone()).unwrap();
|
||||
}
|
||||
|
@ -310,8 +310,8 @@ mod test {
|
|||
fn transform_invariant_holds(o1 in operation_strategy(), o2 in operation_strategy()) {
|
||||
let (o1p, o2p) = Operation::transform(o1.clone(), o2.clone());
|
||||
|
||||
let mut db1 = DB::new(Box::new(InMemoryStorage::new()));
|
||||
let mut db2 = DB::new(Box::new(InMemoryStorage::new()));
|
||||
let mut db1 = TaskDB::new(Box::new(InMemoryStorage::new()));
|
||||
let mut db2 = TaskDB::new(Box::new(InMemoryStorage::new()));
|
||||
|
||||
// Ensure that any expected tasks already exist
|
||||
if let Operation::Update{ ref uuid, .. } = o1 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue