Merge "Dynamically update DatastoreContext properties"
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / test / java / org / opendaylight / controller / cluster / raft / utils / MockAkkaJournal.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 package org.opendaylight.controller.cluster.raft.utils;
9
10 import akka.dispatch.Futures;
11 import akka.japi.Procedure;
12 import akka.persistence.PersistentConfirmation;
13 import akka.persistence.PersistentId;
14 import akka.persistence.PersistentImpl;
15 import akka.persistence.PersistentRepr;
16 import akka.persistence.journal.japi.AsyncWriteJournal;
17 import com.google.common.collect.Maps;
18 import java.util.Map;
19 import java.util.concurrent.Callable;
20 import scala.concurrent.Future;
21
22 public class MockAkkaJournal extends AsyncWriteJournal {
23
24     private static Map<Long, Object> journal = Maps.newLinkedHashMap();
25
26     public static void addToJournal(long sequenceNr, Object message) {
27         journal.put(sequenceNr, message);
28     }
29
30     public static void clearJournal() {
31         journal.clear();
32     }
33
34     @Override
35     public Future<Void> doAsyncReplayMessages(final String persistenceId, long fromSequenceNr,
36         long toSequenceNr, long max, final Procedure<PersistentRepr> replayCallback) {
37
38         return Futures.future(new Callable<Void>() {
39             @Override
40             public Void call() throws Exception {
41                 for (Map.Entry<Long,Object> entry : journal.entrySet()) {
42                     PersistentRepr persistentMessage =
43                         new PersistentImpl(entry.getValue(), entry.getKey(), persistenceId, false, null, null);
44                     replayCallback.apply(persistentMessage);
45                 }
46                 return null;
47             }
48         }, context().dispatcher());
49     }
50
51     @Override
52     public Future<Long> doAsyncReadHighestSequenceNr(String s, long l) {
53         return Futures.successful(new Long(0));
54     }
55
56     @Override
57     public Future<Void> doAsyncWriteMessages(Iterable<PersistentRepr> persistentReprs) {
58         return Futures.successful(null);
59     }
60
61     @Override
62     public Future<Void> doAsyncWriteConfirmations(Iterable<PersistentConfirmation> persistentConfirmations) {
63         return Futures.successful(null);
64     }
65
66     @Override
67     public Future<Void> doAsyncDeleteMessages(Iterable<PersistentId> persistentIds, boolean b) {
68         return Futures.successful(null);
69     }
70
71     @Override
72     public Future<Void> doAsyncDeleteMessagesTo(String s, long l, boolean b) {
73         return Futures.successful(null);
74     }
75 }