X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-clustering-commons%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fpersistence%2FLocalSnapshotStoreTest.java;h=d45042567d9fa16d2b2a5b1ec2dc49038c405581;hp=b69b6345cc4cf71a111c9d8d4a327619480a6d76;hb=02215a58e5c9ebe4624e6ca2103b00a796fcd5f7;hpb=62d2f37a4e9ff4c637ff83e3d9dbbfd292552aaa diff --git a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/persistence/LocalSnapshotStoreTest.java b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/persistence/LocalSnapshotStoreTest.java index b69b6345cc..d45042567d 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/persistence/LocalSnapshotStoreTest.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/persistence/LocalSnapshotStoreTest.java @@ -27,13 +27,11 @@ import akka.persistence.SnapshotProtocol.LoadSnapshotResult; import akka.persistence.SnapshotSelectionCriteria; import akka.persistence.serialization.Snapshot; import akka.persistence.serialization.SnapshotSerializer; -import akka.testkit.JavaTestKit; -import com.google.common.base.Throwables; +import akka.testkit.javadsl.TestKit; import com.typesafe.config.ConfigFactory; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; -import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import org.apache.commons.io.FileUtils; @@ -43,7 +41,8 @@ import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import org.mockito.MockitoAnnotations; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; import scala.Option; /** @@ -52,6 +51,7 @@ import scala.Option; * * @author Thomas Pantelis */ +@RunWith(MockitoJUnitRunner.StrictStubs.class) public class LocalSnapshotStoreTest { private static final String PERSISTENCE_ID = "member-1-shard-default-config"; private static final String PREFIX_BASED_SHARD_PERSISTENCE_ID = "member-1-shard-id-ints!-config"; @@ -64,18 +64,17 @@ public class LocalSnapshotStoreTest { createSnapshotDir(); system = ActorSystem.create("test", ConfigFactory.load("LocalSnapshotStoreTest.conf")); - snapshotStore = system.registerExtension(Persistence.lookup()).snapshotStoreFor(null); + snapshotStore = system.registerExtension(Persistence.lookup()).snapshotStoreFor(null, ConfigFactory.empty()); } @AfterClass public static void staticCleanup() { FileUtils.deleteQuietly(SNAPSHOT_DIR); - JavaTestKit.shutdownActorSystem(system); + TestKit.shutdownActorSystem(system); } @Before public void setup() { - MockitoAnnotations.initMocks(this); cleanSnapshotDir(); } @@ -101,7 +100,7 @@ public class LocalSnapshotStoreTest { SnapshotMetadata metadata3 = new SnapshotMetadata(PERSISTENCE_ID, 1, 3000); - JavaTestKit probe = new JavaTestKit(system); + TestKit probe = new TestKit(system); snapshotStore.tell(new LoadSnapshot(PERSISTENCE_ID, SnapshotSelectionCriteria.latest(), Long.MAX_VALUE), probe.getRef()); LoadSnapshotResult result = probe.expectMsgClass(LoadSnapshotResult.class); @@ -124,8 +123,8 @@ public class LocalSnapshotStoreTest { } @Test - public void testDoLoadAsyncWithNoSnapshots() throws IOException { - JavaTestKit probe = new JavaTestKit(system); + public void testDoLoadAsyncWithNoSnapshots() { + TestKit probe = new TestKit(system); snapshotStore.tell(new LoadSnapshot(PERSISTENCE_ID, SnapshotSelectionCriteria.latest(), Long.MAX_VALUE), probe.getRef()); LoadSnapshotResult result = probe.expectMsgClass(LoadSnapshotResult.class); @@ -141,7 +140,7 @@ public class LocalSnapshotStoreTest { SnapshotMetadata metadata = new SnapshotMetadata(PERSISTENCE_ID, 0, 1000); - JavaTestKit probe = new JavaTestKit(system); + TestKit probe = new TestKit(system); snapshotStore.tell(new LoadSnapshot(PERSISTENCE_ID, SnapshotSelectionCriteria.latest(), Long.MAX_VALUE), probe.getRef()); LoadSnapshotResult result = probe.expectMsgClass(LoadSnapshotResult.class); @@ -152,15 +151,16 @@ public class LocalSnapshotStoreTest { assertEquals("SelectedSnapshot snapshot", "one", possibleSnapshot.get().snapshot()); } + @SuppressWarnings("checkstyle:illegalThrows") @Test(expected = IOException.class) - public void testDoLoadAsyncWithFailure() throws IOException { + public void testDoLoadAsyncWithFailure() throws Throwable { createSnapshotFile(PERSISTENCE_ID, null, 1, 2000); - JavaTestKit probe = new JavaTestKit(system); + TestKit probe = new TestKit(system); snapshotStore.tell(new SnapshotProtocol.LoadSnapshot(PERSISTENCE_ID, SnapshotSelectionCriteria.latest(), Long.MAX_VALUE), probe.getRef()); LoadSnapshotFailed failed = probe.expectMsgClass(LoadSnapshotFailed.class); - Throwables.propagateIfInstanceOf(failed.cause(), IOException.class); + throw failed.cause(); } @Test @@ -174,7 +174,7 @@ public class LocalSnapshotStoreTest { SnapshotMetadata metadata = new SnapshotMetadata(PERSISTENCE_ID, 1, 1000); - JavaTestKit probe = new JavaTestKit(system); + TestKit probe = new TestKit(system); snapshotStore.tell(new LoadSnapshot(PERSISTENCE_ID, SnapshotSelectionCriteria.latest(), Long.MAX_VALUE), probe.getRef()); LoadSnapshotResult result = probe.expectMsgClass(LoadSnapshotResult.class); @@ -185,7 +185,8 @@ public class LocalSnapshotStoreTest { assertEquals("SelectedSnapshot snapshot", "one", possibleSnapshot.get().snapshot()); } - private void createSnapshotFile(String persistenceId, String payload, int seqNr, int timestamp) throws IOException { + private static void createSnapshotFile(final String persistenceId, final String payload, final int seqNr, + final int timestamp) throws IOException { String name = toSnapshotName(persistenceId, seqNr, timestamp); try (FileOutputStream fos = new FileOutputStream(new File(SNAPSHOT_DIR, name))) { if (payload != null) { @@ -194,9 +195,7 @@ public class LocalSnapshotStoreTest { } } - private static String toSnapshotName(String persistenceId, int seqNr, int timestamp) - throws UnsupportedEncodingException { - final String encodedPersistenceId = URLEncoder.encode(persistenceId, StandardCharsets.UTF_8.name()); - return "snapshot-" + encodedPersistenceId + "-" + seqNr + "-" + timestamp; + private static String toSnapshotName(final String persistenceId, final int seqNr, final int timestamp) { + return "snapshot-" + URLEncoder.encode(persistenceId, StandardCharsets.UTF_8) + "-" + seqNr + "-" + timestamp; } }