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;
18 import scala.concurrent.Future;
21 import java.util.concurrent.Callable;
23 public class MockAkkaJournal extends AsyncWriteJournal {
25 private static Map<Long, Object> journal = Maps.newHashMap();
27 public static void addToJournal(long sequenceNr, Object message) {
28 journal.put(sequenceNr, message);
31 public static void clearJournal() {
36 public Future<Void> doAsyncReplayMessages(final String persistenceId, long fromSequenceNr,
37 long toSequenceNr, long max, final Procedure<PersistentRepr> replayCallback) {
39 return Futures.future(new Callable<Void>() {
41 public Void call() throws Exception {
42 for (Map.Entry<Long,Object> entry : journal.entrySet()) {
43 PersistentRepr persistentMessage =
44 new PersistentImpl(entry.getValue(), entry.getKey(), persistenceId, false, null, null);
45 replayCallback.apply(persistentMessage);
49 }, context().dispatcher());
53 public Future<Long> doAsyncReadHighestSequenceNr(String s, long l) {
54 return Futures.successful(new Long(0));
58 public Future<Void> doAsyncWriteMessages(Iterable<PersistentRepr> persistentReprs) {
59 return Futures.successful(null);
63 public Future<Void> doAsyncWriteConfirmations(Iterable<PersistentConfirmation> persistentConfirmations) {
64 return Futures.successful(null);
68 public Future<Void> doAsyncDeleteMessages(Iterable<PersistentId> persistentIds, boolean b) {
69 return Futures.successful(null);
73 public Future<Void> doAsyncDeleteMessagesTo(String s, long l, boolean b) {
74 return Futures.successful(null);