2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.cluster.raft.utils;
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;
19 import java.util.concurrent.Callable;
20 import scala.concurrent.Future;
22 public class MockAkkaJournal extends AsyncWriteJournal {
24 private static Map<Long, Object> journal = Maps.newLinkedHashMap();
26 public static void addToJournal(long sequenceNr, Object message) {
27 journal.put(sequenceNr, message);
30 public static void clearJournal() {
35 public Future<Void> doAsyncReplayMessages(final String persistenceId, long fromSequenceNr,
36 long toSequenceNr, long max, final Procedure<PersistentRepr> replayCallback) {
38 return Futures.future(new Callable<Void>() {
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);
48 }, context().dispatcher());
52 public Future<Long> doAsyncReadHighestSequenceNr(String s, long l) {
53 return Futures.successful(new Long(0));
57 public Future<Void> doAsyncWriteMessages(Iterable<PersistentRepr> persistentReprs) {
58 return Futures.successful(null);
62 public Future<Void> doAsyncWriteConfirmations(Iterable<PersistentConfirmation> persistentConfirmations) {
63 return Futures.successful(null);
67 public Future<Void> doAsyncDeleteMessages(Iterable<PersistentId> persistentIds, boolean b) {
68 return Futures.successful(null);
72 public Future<Void> doAsyncDeleteMessagesTo(String s, long l, boolean b) {
73 return Futures.successful(null);