1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
// Copyright 2018 Zach Miller
//
// Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
// or the MIT License (https://opensource.org/licenses/MIT), at your option.
//
// This file may not be copied, modified, or distributed except according to those terms.

use bincode;
use serde::de::DeserializeOwned;
use serde::ser::Serialize;

use std::collections::HashMap;
use std::sync::{Arc, Mutex};

use error::{Error, Result};
use storage::{CommittedCheckpoint, Storage, UncommittedCheckpoint};
use wrappers::GuardWrapper;

type Checkpoint = HashMap<String, Vec<u8>>;
type Checkpoints = Arc<Mutex<HashMap<String, Checkpoint>>>;

/// Provides in-memory checkpoint storage.
#[derive(Debug)]
pub struct MemoryStorage {
    checkpoints: Checkpoints,
}

impl MemoryStorage {
    /// Creates a new `MemoryStorage` wrapped in a
    /// [`GuardWrapper`](
    ///     https://docs.rs/checkpoint/0.1.5/checkpoint/wrappers/struct.GuardWrapper.html).
    pub fn new() -> Result<GuardWrapper<Self>> {
        GuardWrapper::wrap(MemoryStorage {
            checkpoints: Checkpoints::default(),
        })
    }
}

impl Storage for MemoryStorage {
    type Committed = Committed;
    type Uncommitted = Uncommitted;

    fn create_checkpoint(&mut self, identifier: &str) -> Result<Self::Uncommitted> {
        Ok(Self::Uncommitted {
            identifier: identifier.to_string(),
            checkpoint: Checkpoint::default(),
        })
    }

    fn commit_checkpoint(&mut self, uncommitted: Self::Uncommitted) -> Result<Self::Committed> {
        let mut checkpoints = self.checkpoints.lock().unwrap();
        checkpoints.insert(uncommitted.identifier.clone(), uncommitted.checkpoint);

        Ok(Self::Committed {
            identifier: uncommitted.identifier,
            checkpoints: self.checkpoints.clone(),
        })
    }

    fn load_checkpoint(&mut self, identifier: &str) -> Result<Self::Committed> {
        Ok(Self::Committed {
            identifier: identifier.to_string(),
            checkpoints: self.checkpoints.clone(),
        })
    }

    fn remove_checkpoint(&mut self, identifier: &str) -> Result<()> {
        let mut checkpoints = self.checkpoints.lock().unwrap();
        checkpoints.remove(identifier);
        Ok(())
    }

    fn checkpoint_identifiers(&mut self) -> Result<Vec<String>> {
        let committed = self.checkpoints.lock().unwrap();
        let mut identifiers = Vec::new();
        for identifier in committed.keys() {
            identifiers.push(identifier.to_string());
        }

        Ok(identifiers)
    }
}

/// Provides access to committed checkpoint data stored in memory.
#[derive(Debug)]
pub struct Committed {
    identifier: String,
    checkpoints: Checkpoints,
}

impl CommittedCheckpoint for Committed {
    fn get<T: DeserializeOwned + Serialize>(&mut self, key: &str) -> Result<T> {
        let checkpoints = self.checkpoints.lock().unwrap();
        let checkpoint = match checkpoints.get(&self.identifier) {
            None => Err(Error::cp_doesnt_exist(format!(
                "Checkpoint {} doesn't exist",
                &self.identifier
            )))?,
            Some(c) => c,
        };

        let data = match checkpoint.get(key) {
            None => Err(Error::cp_key_doesnt_exist(format!(
                "No value stored for checkpoint: {}, key: {}",
                &self.identifier, key
            )))?,
            Some(d) => d,
        };

        let value = bincode::deserialize(data).map_err(|_| {
            Error::deserialize(format!(
                "Failed to deserialize value from checkpoint: {}, key: {}",
                &self.identifier, key
            ))
        })?;

        Ok(value)
    }

    fn keys(&mut self) -> Result<Vec<String>> {
        let checkpoints = self.checkpoints.lock().unwrap();
        let checkpoint = match checkpoints.get(&self.identifier) {
            None => Err(Error::cp_doesnt_exist(format!(
                "Checkpoint {} doesn't exist",
                &self.identifier
            )))?,
            Some(c) => c,
        };

        let mut keys = Vec::new();
        for key in checkpoint.keys() {
            keys.push(key.to_string());
        }

        Ok(keys)
    }

    fn identifier(&mut self) -> Result<&str> {
        Ok(&self.identifier)
    }
}

/// Provides access to uncommitted checkpoint data stored in memory.
#[derive(Debug)]
pub struct Uncommitted {
    identifier: String,
    checkpoint: Checkpoint,
}

impl UncommittedCheckpoint for Uncommitted {
    fn get<T: DeserializeOwned + Serialize>(&mut self, key: &str) -> Result<T> {
        let data = match self.checkpoint.get(key) {
            None => Err(Error::cp_key_doesnt_exist(format!(
                "No value stored for checkpoint: {}, key: {}",
                &self.identifier, key
            )))?,
            Some(d) => d,
        };

        let value = bincode::deserialize(data).map_err(|_| {
            Error::deserialize(format!(
                "Failed to deserialize value from checkpoint: {}, key: {}",
                &self.identifier, key
            ))
        })?;

        Ok(value)
    }

    fn keys(&mut self) -> Result<Vec<String>> {
        let mut keys = Vec::new();
        for key in self.checkpoint.keys() {
            keys.push(key.to_string());
        }

        Ok(keys)
    }

    fn identifier(&mut self) -> Result<&str> {
        Ok(&self.identifier)
    }

    fn put<T: DeserializeOwned + Serialize>(&mut self, key: &str, value: &T) -> Result<()> {
        let data = bincode::serialize(value).map_err(|_| {
            Error::serialize(format!(
                "Failed to serialize value into checkpoint: {}, key: {}",
                &self.identifier, key
            ))
        })?;

        self.checkpoint.insert(key.to_string(), data);
        Ok(())
    }

    fn remove(&mut self, key: &str) -> Result<()> {
        if !self.checkpoint.contains_key(key) {
            Err(Error::cp_key_doesnt_exist(format!(
                "No value to remove for checkpoint: {}, key: {}",
                &self.identifier, key
            )))?;
        }

        self.checkpoint.remove(key);
        Ok(())
    }
}

#[cfg(test)]
mod test {
    use std::mem;
    use error::ErrorKind;
    use storage::{CommittedCheckpoint, MemoryStorage, Storage, UncommittedCheckpoint};

    // Verify that checkpoint creation and commit behave as expected.
    #[test]
    fn memory_storage_create_and_commit_checkpoint() {
        let mut storage = MemoryStorage::new().unwrap();

        // Verify that create_checkpoint() can be called twice with the same checkpoint identifier
        // as long as the uncommitted checkpoint returned from the first call is dropped before
        // the second call.
        assert!(storage.create_checkpoint("CP").is_ok());
        assert!(storage.create_checkpoint("CP").is_ok());

        // Verify that create_checkpoint() returns an error when a checkpoint creation is attempted
        // with the same identifier as an uncommitted checkpoint.
        let uncommitted_cp = storage.create_checkpoint("CP").unwrap();
        assert_eq!(
            storage.create_checkpoint("CP").unwrap_err().kind(),
            ErrorKind::CpAlreadyExists
        );

        // Verify that create_checkpoint() returns an error when a checkpoint creation is attempted
        // with the same identifier as a committed checkpoint that is in use (i.e. has a variable
        // binding).
        let committed_cp = storage.commit_checkpoint(uncommitted_cp).unwrap();
        assert_eq!(
            storage.create_checkpoint("CP").unwrap_err().kind(),
            ErrorKind::CpAlreadyExists
        );

        // Verify that create_checkpoint() returns an error when a checkpoint creation is attempted
        // with the same identifier as a committed checkpoint that is not in use (i.e. has no
        // variable binding).
        mem::drop(committed_cp);
        assert_eq!(
            storage.create_checkpoint("CP").unwrap_err().kind(),
            ErrorKind::CpAlreadyExists
        );
    }

    // Verify that checkpoint loading and removal behave as expected.
    #[test]
    fn memory_storage_load_and_remove_checkpoint() {
        let mut storage = MemoryStorage::new().unwrap();

        // Verify that load_checkpoint() returns an error when a checkpoint load is attempted but
        // a committed checkpoint with the given identifier does not exist.
        assert_eq!(
            storage.load_checkpoint("CP").unwrap_err().kind(),
            ErrorKind::CpDoesntExist
        );

        // Verify that load_checkpoint() returns an error when a checkpoint load is attempted, even
        // if an uncommitted checkpoint with the given identifier exists.
        let uncommitted_cp = storage.create_checkpoint("CP").unwrap();
        assert_eq!(
            storage.load_checkpoint("CP").unwrap_err().kind(),
            ErrorKind::CpDoesntExist
        );

        // Verify that load_checkpoint() returns a committed checkpoint binding when a committed
        // checkpoint with the given identifier exists and is in use (i.e. has a variable binding).
        let committed_cp = storage.commit_checkpoint(uncommitted_cp).unwrap();
        assert!(storage.load_checkpoint("CP").is_ok());

        // Verify that load_checkpoint() returns a committed checkpoint binding when a committed
        // checkpoint with the given identifier exists and is not in use (i.e. has no
        // variable binding).
        mem::drop(committed_cp);
        let result = storage.load_checkpoint("CP");
        assert!(result.is_ok());

        // Verify that remove_checkpoint() returns an error when an attempt to remove a checkpoint
        // that is in use (i.e. has a variable binding) is made.
        let committed_cp = result.unwrap();
        assert_eq!(
            storage.remove_checkpoint("CP").unwrap_err().kind(),
            ErrorKind::CpInUse
        );

        // Verify that remove_checkpoint() is successful when an attempt to remove a checkpoint
        // that is not in use (i.e. does not have a variable binding) is made.
        mem::drop(committed_cp);
        assert!(storage.remove_checkpoint("CP").is_ok());

        // Verify that remove_checkpoint() returns an error when an attempt to remove a checkpoint
        // that does not exist is made.
        assert_eq!(
            storage.remove_checkpoint("CP").unwrap_err().kind(),
            ErrorKind::CpDoesntExist
        );

        // Verify that the mechanism which keeps track of the number of times a committed
        // checkpoint has been loaded works as expected.
        let uncommitted_cp = storage.create_checkpoint("CP").unwrap();
        let cp1 = storage.commit_checkpoint(uncommitted_cp).unwrap();
        assert_eq!(
            storage.remove_checkpoint("CP").unwrap_err().kind(),
            ErrorKind::CpInUse
        );

        let cp2 = storage.load_checkpoint("CP").unwrap();
        assert_eq!(
            storage.remove_checkpoint("CP").unwrap_err().kind(),
            ErrorKind::CpInUse
        );

        mem::drop(cp1);
        assert_eq!(
            storage.remove_checkpoint("CP").unwrap_err().kind(),
            ErrorKind::CpInUse
        );

        let cp3 = storage.load_checkpoint("CP").unwrap();
        assert_eq!(
            storage.remove_checkpoint("CP").unwrap_err().kind(),
            ErrorKind::CpInUse
        );

        let cp4 = storage.load_checkpoint("CP").unwrap();
        assert_eq!(
            storage.remove_checkpoint("CP").unwrap_err().kind(),
            ErrorKind::CpInUse
        );

        let cp5 = storage.load_checkpoint("CP").unwrap();
        assert_eq!(
            storage.remove_checkpoint("CP").unwrap_err().kind(),
            ErrorKind::CpInUse
        );

        // Start dropping loaded checkpoints in an arbitrary order.
        mem::drop(cp4);
        assert_eq!(
            storage.remove_checkpoint("CP").unwrap_err().kind(),
            ErrorKind::CpInUse
        );

        mem::drop(cp2);
        assert_eq!(
            storage.remove_checkpoint("CP").unwrap_err().kind(),
            ErrorKind::CpInUse
        );

        mem::drop(cp5);
        assert_eq!(
            storage.remove_checkpoint("CP").unwrap_err().kind(),
            ErrorKind::CpInUse
        );

        mem::drop(cp3);
        assert!(storage.remove_checkpoint("CP").is_ok());
    }

    // Verify that checkpoint identifiers are returned properly.
    #[test]
    fn memory_storage_checkpoint_identifiers() {
        let mut storage = MemoryStorage::new().unwrap();

        // Verify that checkpoint_identifiers() returns an empty list when there are no
        // committed checkpoints.
        assert_eq!(
            storage.checkpoint_identifiers().unwrap(),
            Vec::<String>::new()
        );

        // Verify that checkpoint_identifiers() returns an empty list even when there are
        // uncommitted checkpoints.
        let uncommitted_cp_1 = storage.create_checkpoint("CP1").unwrap();
        assert_eq!(
            storage.checkpoint_identifiers().unwrap(),
            Vec::<String>::new()
        );

        // Verify that checkpoint_identifiers() returns a list of identifiers when committed
        // checkpoints exist and are loaded (i.e. when they have variable bindings).
        let committed_cp_1 = storage.commit_checkpoint(uncommitted_cp_1).unwrap();
        assert_eq!(
            storage.checkpoint_identifiers().unwrap(),
            vec!["CP1".to_string()]
        );

        let uncommitted_cp_2 = storage.create_checkpoint("CP2").unwrap();
        let committed_cp_2 = storage.commit_checkpoint(uncommitted_cp_2).unwrap();
        let mut identifiers = storage.checkpoint_identifiers().unwrap();
        identifiers.sort();
        assert_eq!(identifiers, vec!["CP1".to_string(), "CP2".to_string()]);

        let uncommitted_cp_3 = storage.create_checkpoint("CP3").unwrap();
        let committed_cp_3 = storage.commit_checkpoint(uncommitted_cp_3).unwrap();
        let mut identifiers = storage.checkpoint_identifiers().unwrap();
        identifiers.sort();
        assert_eq!(
            identifiers,
            vec!["CP1".to_string(), "CP2".to_string(), "CP3".to_string()]
        );

        // Verify that checkpoint_identifiers() returns a list of identifiers when committed
        // checkpoints exist and are not loaded (i.e. when they do not have variable bindings).
        mem::drop(committed_cp_1);
        mem::drop(committed_cp_2);
        mem::drop(committed_cp_3);

        let mut identifiers = storage.checkpoint_identifiers().unwrap();
        identifiers.sort();
        assert_eq!(
            identifiers,
            vec!["CP1".to_string(), "CP2".to_string(), "CP3".to_string()]
        );

        // Verify that checkpoint identifiers are removed from the list of identifiers returned by
        // checkpoint_identifiers() when the associated checkpoint is removed.
        storage.remove_checkpoint("CP2").unwrap();
        let mut identifiers = storage.checkpoint_identifiers().unwrap();
        identifiers.sort();
        assert_eq!(identifiers, vec!["CP1".to_string(), "CP3".to_string()]);

        storage.remove_checkpoint("CP1").unwrap();
        let mut identifiers = storage.checkpoint_identifiers().unwrap();
        identifiers.sort();
        assert_eq!(identifiers, vec!["CP3".to_string()]);

        storage.remove_checkpoint("CP3").unwrap();
        let mut identifiers = storage.checkpoint_identifiers().unwrap();
        identifiers.sort();
        assert_eq!(identifiers, Vec::<String>::new());
    }

    // Verify that uncommitted and committed checkpoints behave as expected.
    #[test]
    fn uncommitted_and_committed() {
        let mut storage = MemoryStorage::new().unwrap();

        // Verify that the methods of an empty uncommitted checkpoint behave as expected.
        let mut uncommitted_cp_1 = storage.create_checkpoint("CP1").unwrap();
        assert_eq!(uncommitted_cp_1.identifier().unwrap(), "CP1");
        assert_eq!(uncommitted_cp_1.keys().unwrap(), Vec::<String>::new());
        assert_eq!(
            uncommitted_cp_1.get::<u8>("Key1").unwrap_err().kind(),
            ErrorKind::CpKeyDoesntExist
        );
        assert_eq!(
            uncommitted_cp_1.remove("Key1").unwrap_err().kind(),
            ErrorKind::CpKeyDoesntExist
        );

        // Add data to the uncommitted checkpoint.
        let data_1 = 0u8;
        let data_2 = String::from("Test String.");
        let data_3 = Some(true);
        assert!(uncommitted_cp_1.put("Key1", &data_1).is_ok());
        assert!(uncommitted_cp_1.put("Key2", &data_2).is_ok());
        assert!(uncommitted_cp_1.put("Key3", &data_3).is_ok());

        // Verify that adding and removing values to existing checkpoints works as expected and
        // that creating a new uncommitted checkpoint does not affect the data stored in another
        // uncommitted checkpoint.
        let mut uncommitted_cp_2 = storage.create_checkpoint("CP2").unwrap();
        assert_eq!(uncommitted_cp_2.identifier().unwrap(), "CP2");
        assert_eq!(uncommitted_cp_2.keys().unwrap(), Vec::<String>::new());
        assert_eq!(
            uncommitted_cp_2.get::<u8>("Key1").unwrap_err().kind(),
            ErrorKind::CpKeyDoesntExist
        );
        assert_eq!(
            uncommitted_cp_2.remove("Key1").unwrap_err().kind(),
            ErrorKind::CpKeyDoesntExist
        );

        assert_eq!(uncommitted_cp_1.identifier().unwrap(), "CP1");
        let mut keys = uncommitted_cp_1.keys().unwrap();
        keys.sort();
        assert_eq!(keys, vec!["Key1", "Key2", "Key3"]);
        assert_eq!(uncommitted_cp_1.get::<u8>("Key1").unwrap(), data_1);
        assert_eq!(uncommitted_cp_1.get::<String>("Key2").unwrap(), data_2);
        assert_eq!(
            uncommitted_cp_1.get::<Option<bool>>("Key3").unwrap(),
            data_3
        );
        assert!(uncommitted_cp_1.remove("Key2").is_ok());
        assert_eq!(
            uncommitted_cp_1.remove("Key2").unwrap_err().kind(),
            ErrorKind::CpKeyDoesntExist
        );
        let mut keys = uncommitted_cp_1.keys().unwrap();
        keys.sort();
        assert_eq!(keys, vec!["Key1", "Key3"]);
        assert!(uncommitted_cp_1.remove("Key1").is_ok());
        assert_eq!(
            uncommitted_cp_1.remove("Key1").unwrap_err().kind(),
            ErrorKind::CpKeyDoesntExist
        );
        let mut keys = uncommitted_cp_1.keys().unwrap();
        keys.sort();
        assert_eq!(keys, vec!["Key3"]);
        assert!(uncommitted_cp_1.remove("Key3").is_ok());
        assert_eq!(
            uncommitted_cp_1.remove("Key3").unwrap_err().kind(),
            ErrorKind::CpKeyDoesntExist
        );
        assert_eq!(uncommitted_cp_1.keys().unwrap(), Vec::<String>::new());

        // Verify that the value for a given key can be added even if the key was previously
        // removed.
        assert!(uncommitted_cp_1.put("Key1", &data_1).is_ok());
        assert!(uncommitted_cp_1.put("Key2", &data_2).is_ok());
        assert!(uncommitted_cp_1.put("Key3", &data_3).is_ok());
        assert_eq!(uncommitted_cp_1.identifier().unwrap(), "CP1");
        let mut keys = uncommitted_cp_1.keys().unwrap();
        keys.sort();
        assert_eq!(keys, vec!["Key1", "Key2", "Key3"]);
        assert_eq!(uncommitted_cp_1.get::<u8>("Key1").unwrap(), data_1);
        assert_eq!(uncommitted_cp_1.get::<String>("Key2").unwrap(), data_2);
        assert_eq!(
            uncommitted_cp_1.get::<Option<bool>>("Key3").unwrap(),
            data_3
        );

        // Verify that the value for a given key can be changed.
        let data_1 = String::from("Test String.");
        let data_2 = Some(true);
        let data_3 = 0u8;
        assert!(uncommitted_cp_1.put("Key1", &data_1).is_ok());
        assert!(uncommitted_cp_1.put("Key2", &data_2).is_ok());
        assert!(uncommitted_cp_1.put("Key3", &data_3).is_ok());
        assert!(uncommitted_cp_1.put("Key1", &data_1).is_ok());
        assert!(uncommitted_cp_1.put("Key2", &data_2).is_ok());
        assert!(uncommitted_cp_1.put("Key3", &data_3).is_ok());
        assert_eq!(uncommitted_cp_1.identifier().unwrap(), "CP1");
        let mut keys = uncommitted_cp_1.keys().unwrap();
        keys.sort();
        assert_eq!(keys, vec!["Key1", "Key2", "Key3"]);
        assert_eq!(uncommitted_cp_1.get::<String>("Key1").unwrap(), data_1);
        assert_eq!(
            uncommitted_cp_1.get::<Option<bool>>("Key2").unwrap(),
            data_2
        );
        assert_eq!(uncommitted_cp_1.get::<u8>("Key3").unwrap(), data_3);

        // Verify that uncommitted checkpoints contain the same values after being committed.
        let mut committed_cp_1 = storage.commit_checkpoint(uncommitted_cp_1).unwrap();
        let mut committed_cp_2 = storage.commit_checkpoint(uncommitted_cp_2).unwrap();

        assert_eq!(committed_cp_1.identifier().unwrap(), "CP1");
        let mut keys = committed_cp_1.keys().unwrap();
        keys.sort();
        assert_eq!(keys, vec!["Key1", "Key2", "Key3"]);
        assert_eq!(committed_cp_1.get::<String>("Key1").unwrap(), data_1);
        assert_eq!(committed_cp_1.get::<Option<bool>>("Key2").unwrap(), data_2);
        assert_eq!(committed_cp_1.get::<u8>("Key3").unwrap(), data_3);
        assert_eq!(
            committed_cp_1.get::<u8>("Key4").unwrap_err().kind(),
            ErrorKind::CpKeyDoesntExist
        );

        assert_eq!(committed_cp_2.identifier().unwrap(), "CP2");
        assert_eq!(committed_cp_2.keys().unwrap(), Vec::<String>::new());
        assert_eq!(
            committed_cp_2.get::<u8>("Key1").unwrap_err().kind(),
            ErrorKind::CpKeyDoesntExist
        );
    }
}