Merge "Add missing copyright text"
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / main / java / org / opendaylight / controller / cluster / datastore / DataPersistenceProviderMonitor.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.datastore;
10
11 import akka.japi.Procedure;
12 import akka.persistence.SnapshotSelectionCriteria;
13 import java.util.concurrent.CountDownLatch;
14 import org.opendaylight.controller.cluster.DataPersistenceProvider;
15
16 /**
17  * This class is intended for testing purposes. It just triggers CountDownLatch's in each method.
18  * This class really should be under src/test/java but it was problematic trying to uses it in other projects.
19  */
20 public class DataPersistenceProviderMonitor implements DataPersistenceProvider {
21
22     private CountDownLatch persistLatch = new CountDownLatch(1);
23     private CountDownLatch saveSnapshotLatch = new CountDownLatch(1);
24     private CountDownLatch deleteSnapshotsLatch = new CountDownLatch(1);;
25     private CountDownLatch deleteMessagesLatch = new CountDownLatch(1);;
26
27     @Override
28     public boolean isRecoveryApplicable() {
29         return false;
30     }
31
32     @Override
33     public <T> void persist(T o, Procedure<T> procedure) {
34         persistLatch.countDown();
35     }
36
37     @Override
38     public void saveSnapshot(Object o) {
39         saveSnapshotLatch.countDown();
40     }
41
42     @Override
43     public void deleteSnapshots(SnapshotSelectionCriteria criteria) {
44         deleteSnapshotsLatch.countDown();
45     }
46
47     @Override
48     public void deleteMessages(long sequenceNumber) {
49         deleteMessagesLatch.countDown();
50     }
51
52     public void setPersistLatch(CountDownLatch persistLatch) {
53         this.persistLatch = persistLatch;
54     }
55
56     public void setSaveSnapshotLatch(CountDownLatch saveSnapshotLatch) {
57         this.saveSnapshotLatch = saveSnapshotLatch;
58     }
59
60     public void setDeleteSnapshotsLatch(CountDownLatch deleteSnapshotsLatch) {
61         this.deleteSnapshotsLatch = deleteSnapshotsLatch;
62     }
63
64     public void setDeleteMessagesLatch(CountDownLatch deleteMessagesLatch) {
65         this.deleteMessagesLatch = deleteMessagesLatch;
66     }
67
68     @Override
69     public long getLastSequenceNumber() {
70         return -1;
71     }
72 }