d70bf920ae843665bea03c0c21cd6e85ca2ffd0f
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / test / java / org / opendaylight / controller / cluster / raft / utils / MockSnapshotStore.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.controller.cluster.raft.utils;
10
11 import akka.dispatch.Futures;
12 import akka.japi.Option;
13 import akka.persistence.SelectedSnapshot;
14 import akka.persistence.SnapshotMetadata;
15 import akka.persistence.SnapshotSelectionCriteria;
16 import akka.persistence.snapshot.japi.SnapshotStore;
17 import org.opendaylight.controller.cluster.raft.Snapshot;
18 import scala.concurrent.Future;
19
20
21 public class MockSnapshotStore  extends SnapshotStore {
22
23     private static Snapshot mockSnapshot;
24     private static String persistenceId;
25
26     public static void setMockSnapshot(Snapshot s) {
27         mockSnapshot = s;
28     }
29
30     public static void setPersistenceId(String pId) {
31         persistenceId = pId;
32     }
33
34     @Override
35     public Future<Option<SelectedSnapshot>> doLoadAsync(String s, SnapshotSelectionCriteria snapshotSelectionCriteria) {
36         if (mockSnapshot == null) {
37             return Futures.successful(Option.<SelectedSnapshot>none());
38         }
39
40         SnapshotMetadata smd = new SnapshotMetadata(persistenceId, 1, 12345);
41         SelectedSnapshot selectedSnapshot =
42             new SelectedSnapshot(smd, mockSnapshot);
43         return Futures.successful(Option.some(selectedSnapshot));
44     }
45
46     @Override
47     public Future<Void> doSaveAsync(SnapshotMetadata snapshotMetadata, Object o) {
48         return null;
49     }
50
51     @Override
52     public void onSaved(SnapshotMetadata snapshotMetadata) throws Exception {
53
54     }
55
56     @Override
57     public void doDelete(SnapshotMetadata snapshotMetadata) throws Exception {
58
59     }
60
61     @Override
62     public void doDelete(String s, SnapshotSelectionCriteria snapshotSelectionCriteria) throws Exception {
63
64     }
65 }