X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-clustering-commons%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fpersistence%2FLocalSnapshotStoreSpecTest.java;fp=opendaylight%2Fmd-sal%2Fsal-clustering-commons%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fpersistence%2FLocalSnapshotStoreSpecTest.java;h=7b70063afa9fad2c16fbb296214c958b8673cf59;hb=ed6ec368fa9aa9b4cd770769e264c19ddc7549ea;hp=0000000000000000000000000000000000000000;hpb=8002139af5e8da4643ae203031184793a60087b3;p=controller.git diff --git a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/persistence/LocalSnapshotStoreSpecTest.java b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/persistence/LocalSnapshotStoreSpecTest.java new file mode 100644 index 0000000000..7b70063afa --- /dev/null +++ b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/persistence/LocalSnapshotStoreSpecTest.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2017 Brocade Communications 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.persistence; + +import akka.persistence.snapshot.SnapshotStoreSpec; +import com.typesafe.config.ConfigFactory; +import java.io.File; +import java.io.IOException; +import org.apache.commons.io.FileUtils; +import org.junit.runner.RunWith; +import org.scalatest.junit.JUnitRunner; + +/** + * Tests the LocalSnapshotStore using akka's standard test suite for snapshot store plugins via SnapshotStoreSpec. + * This class basically does the setup and tear down with SnapshotStoreSpec doing the rest. SnapshotStoreSpec uses + * ScalaTest so needs to be run with scala's JUnitRunner. + * + * @author Thomas Pantelis + */ +@RunWith(JUnitRunner.class) +public class LocalSnapshotStoreSpecTest extends SnapshotStoreSpec { + private static final long serialVersionUID = 1L; + static final File SNAPSHOT_DIR = new File("target/snapshots"); + + public LocalSnapshotStoreSpecTest() { + super(ConfigFactory.load("LocalSnapshotStoreTest.conf")); + } + + @Override + public void afterAll() { + super.afterAll(); + FileUtils.deleteQuietly(SNAPSHOT_DIR); + } + + static void cleanSnapshotDir() { + if (!SNAPSHOT_DIR.exists()) { + return; + } + + try { + FileUtils.cleanDirectory(SNAPSHOT_DIR); + } catch (IOException e) { + // Ignore + } + } + + static void createSnapshotDir() { + if (!SNAPSHOT_DIR.exists() && !SNAPSHOT_DIR.mkdirs()) { + throw new RuntimeException("Failed to create " + SNAPSHOT_DIR); + } + + cleanSnapshotDir(); + } +}