X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-akka-raft%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fraft%2Fbehaviors%2FSnapshotTrackerTest.java;h=80348263c86c9626a96765afe5953f2820c26e9d;hp=1b3a8f5fb5077a57f9071f8bf55bbbdfda3a2db0;hb=ecccb6d5b43dd73aef0d2d19349d19ee9b4728f7;hpb=191ad68d71f30f6ad6258ac458c60c663e5b1b85 diff --git a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/SnapshotTrackerTest.java b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/SnapshotTrackerTest.java index 1b3a8f5fb5..80348263c8 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/SnapshotTrackerTest.java +++ b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/SnapshotTrackerTest.java @@ -1,8 +1,14 @@ +/* + * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.controller.cluster.raft.behaviors; import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.mock; -import akka.event.LoggingAdapter; import com.google.common.base.Optional; import com.google.protobuf.ByteString; import java.io.ByteArrayOutputStream; @@ -13,9 +19,13 @@ import java.util.Map; import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class SnapshotTrackerTest { + Logger logger = LoggerFactory.getLogger(getClass()); + Map data; ByteString byteString; ByteString chunk1; @@ -37,14 +47,14 @@ public class SnapshotTrackerTest { @Test public void testAddChunk() throws SnapshotTracker.InvalidChunkException { - SnapshotTracker tracker1 = new SnapshotTracker(mock(LoggingAdapter.class), 5); + SnapshotTracker tracker1 = new SnapshotTracker(logger, 5); tracker1.addChunk(1, chunk1, Optional.absent()); tracker1.addChunk(2, chunk2, Optional.absent()); tracker1.addChunk(3, chunk3, Optional.absent()); // Verify that an InvalidChunkException is thrown when we try to add a chunk to a sealed tracker - SnapshotTracker tracker2 = new SnapshotTracker(mock(LoggingAdapter.class), 2); + SnapshotTracker tracker2 = new SnapshotTracker(logger, 2); tracker2.addChunk(1, chunk1, Optional.absent()); tracker2.addChunk(2, chunk2, Optional.absent()); @@ -57,7 +67,7 @@ public class SnapshotTrackerTest { } // The first chunk's index must at least be FIRST_CHUNK_INDEX - SnapshotTracker tracker3 = new SnapshotTracker(mock(LoggingAdapter.class), 2); + SnapshotTracker tracker3 = new SnapshotTracker(logger, 2); try { tracker3.addChunk(AbstractLeader.FIRST_CHUNK_INDEX - 1, chunk1, Optional.absent()); @@ -67,7 +77,7 @@ public class SnapshotTrackerTest { } // Out of sequence chunk indexes won't work - SnapshotTracker tracker4 = new SnapshotTracker(mock(LoggingAdapter.class), 2); + SnapshotTracker tracker4 = new SnapshotTracker(logger, 2); tracker4.addChunk(AbstractLeader.FIRST_CHUNK_INDEX, chunk1, Optional.absent()); @@ -80,7 +90,7 @@ public class SnapshotTrackerTest { // No exceptions will be thrown when invalid chunk is added with the right sequence // If the lastChunkHashCode is missing - SnapshotTracker tracker5 = new SnapshotTracker(mock(LoggingAdapter.class), 2); + SnapshotTracker tracker5 = new SnapshotTracker(logger, 2); tracker5.addChunk(AbstractLeader.FIRST_CHUNK_INDEX, chunk1, Optional.absent()); // Look I can add the same chunk again @@ -88,7 +98,7 @@ public class SnapshotTrackerTest { // An exception will be thrown when an invalid chunk is addedd with the right sequence // when the lastChunkHashCode is present - SnapshotTracker tracker6 = new SnapshotTracker(mock(LoggingAdapter.class), 2); + SnapshotTracker tracker6 = new SnapshotTracker(logger, 2); tracker6.addChunk(AbstractLeader.FIRST_CHUNK_INDEX, chunk1, Optional.of(-1)); @@ -106,7 +116,7 @@ public class SnapshotTrackerTest { public void testGetSnapShot() throws SnapshotTracker.InvalidChunkException { // Trying to get a snapshot before all chunks have been received will throw an exception - SnapshotTracker tracker1 = new SnapshotTracker(mock(LoggingAdapter.class), 5); + SnapshotTracker tracker1 = new SnapshotTracker(logger, 5); tracker1.addChunk(1, chunk1, Optional.absent()); try { @@ -116,7 +126,7 @@ public class SnapshotTrackerTest { } - SnapshotTracker tracker2 = new SnapshotTracker(mock(LoggingAdapter.class), 3); + SnapshotTracker tracker2 = new SnapshotTracker(logger, 3); tracker2.addChunk(1, chunk1, Optional.absent()); tracker2.addChunk(2, chunk2, Optional.absent()); @@ -129,7 +139,7 @@ public class SnapshotTrackerTest { @Test public void testGetCollectedChunks() throws SnapshotTracker.InvalidChunkException { - SnapshotTracker tracker1 = new SnapshotTracker(mock(LoggingAdapter.class), 5); + SnapshotTracker tracker1 = new SnapshotTracker(logger, 5); ByteString chunks = chunk1.concat(chunk2); @@ -152,7 +162,7 @@ public class SnapshotTrackerTest { return bs.substring(start, start + size); } - private ByteString toByteString(Map state) { + private static ByteString toByteString(Map state) { ByteArrayOutputStream b = null; ObjectOutputStream o = null; try {