From 4bf2c7ba0c6a38e28bda6a6f8fc769cb508afd21 Mon Sep 17 00:00:00 2001 From: Greg Burd Date: Mon, 25 Nov 2019 12:39:35 -0500 Subject: [PATCH] Fixes --- .scalafmt.conf | 44 +++++++++++--- build.sbt | 45 ++++++++++---- .../je/EnvironmentMutableConfig.java | 3 +- .../com/sleepycat/je/dbi/DbConfigManager.java | 2 +- .../com/sleepycat/je/dbi/EnvironmentImpl.java | 4 +- .../com/sleepycat/je/utilint/Timestamp.java | 17 ++++-- .../je/rep/persist/test/AppImpl.java | 0 .../je/rep/persist/test/AppImpl.java | 0 .../test/serial/StoredClassCatalogTest.java | 21 ++++--- .../serial/StoredClassCatalogTestInit.java | 14 ++--- .../sleepycat/je/EnvironmentConfigTest.java | 3 +- .../com/sleepycat/je/StatCaptureTest.java | 18 +++--- .../je/cleaner/ReadOnlyLockingTest.java | 2 +- .../com/sleepycat/je/dbi/DbEnvPoolTest.java | 2 +- .../je/rep/persist/test/UpgradeTest.java | 9 ++- .../je/rep/utilint/RepTestUtils.java | 58 ++++--------------- .../sleepycat/util/test/SharedTestUtils.java | 23 ++++---- 17 files changed, 144 insertions(+), 121 deletions(-) rename stasis-test/src/test/java/com/sleepycat/je/rep/persist/test/AppImpl.java.0 => stasis-test-dpl-v0/src/test/java/com/sleepycat/je/rep/persist/test/AppImpl.java (100%) rename stasis-test/src/test/java/com/sleepycat/je/rep/persist/test/AppImpl.java.1 => stasis-test-dpl-v1/src/test/java/com/sleepycat/je/rep/persist/test/AppImpl.java (100%) diff --git a/.scalafmt.conf b/.scalafmt.conf index 85fbd5e..d327b4e 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,13 +1,41 @@ version=2.0.0-RC5 project.git = true -project.excludeFilters = [ - scalafmt-benchmarks/src/resources, - sbt-test - bin/issue -] align = none -# Disabled in default since this operation is potentially -# dangerous if you define your own stripMargin with different -# semantics from the stdlib stripMargin. assumeStandardLibraryStripMargin = true onTestFailure = "To fix this, run ./scalafmt from the project root directory" +style = default +align.openParenCallSite=false +align.openParenDefnSite=false +align.tokens = [] +assumeStandardLibraryStripMargin = true +binPack.parentConstructors = false +danglingParentheses = false +docstrings = ScalaDoc +maxColumn = 100 +optIn.annotationNewlines = true +optIn.breakChainOnFirstMethodDot = true +optIn.selfAnnotationNewline = true +project.git = true +project.includeFilters = [ + build.sbt + ExpectSuite.scala + scalameta/contrib + scalameta/semanticdb +] +project.excludeFilters = [ + scalafmt-benchmarks/src/resources + sbt-test + bin/issue + semanticdb/semanticdb/src/main/generated + sbt-test + contrib/package.scala + scalac-plugin.xml + SemanticdbAnalyzer.scala + Scalalib.scala + com.sun.source.util.Plugin + /java/ + .proto + .md +] +runner.dialect = Scala212 +runner.optimizer.forceConfigStyleOnOffset = -1 diff --git a/build.sbt b/build.sbt index 15266ee..74cd199 100644 --- a/build.sbt +++ b/build.sbt @@ -154,6 +154,11 @@ lazy val rep = project ) .dependsOn(core) +val testLibraryDependencies = Seq ( + "junit" % "junit" % "4.12" % Test, + "com.novocode" % "junit-interface" % "0.11" % Test + ) + lazy val test = project .in(file("stasis-test")) .settings( @@ -204,27 +209,43 @@ lazy val test = project s"-Ddoclet.jar=${docdir}/HidingDoclet.jar", ) }, - libraryDependencies ++= Seq( - "junit" % "junit" % "4.12" % Test, - "com.novocode" % "junit-interface" % "0.11" % Test - ) + libraryDependencies ++= testLibraryDependencies ) .disablePlugins(plugins.JUnitXmlReportPlugin) .dependsOn(core, persist, rep) +val testJavacOptions =Seq( + "-Xlint:deprecation", + "-Xlint:unchecked" +) + lazy val test_examples = project .in(file("stasis-test-examples")) .settings( moduleName := "stasis-test-examples", assemblyJarName.in(assembly) := "stasis-test-examples.jar", - Test / javacOptions := Seq( - "-Xlint:deprecation", - "-Xlint:unchecked" - ), - libraryDependencies ++= Seq( - "junit" % "junit" % "4.12" % Test, - "com.novocode" % "junit-interface" % "0.11" % Test - ) + Test / javacOptions := testJavacOptions, + libraryDependencies ++= testLibraryDependencies + ) + .dependsOn(core, persist, rep, test) + +lazy val test_dpl_v0 = project + .in(file("stasis-test-dpl-v0")) + .settings( + moduleName := "stasis-test-dpl-v0", + assemblyJarName.in(assembly) := "stasis-test-dpl-v0.jar", + Test / javacOptions := testJavacOptions, + libraryDependencies ++= testLibraryDependencies + ) + .dependsOn(core, persist, rep, test) + +lazy val test_dpl_v1 = project + .in(file("stasis-test-dpl-v1")) + .settings( + moduleName := "stasis-test-dpl-v1", + assemblyJarName.in(assembly) := "stasis-test-dpl-v1.jar", + Test / javacOptions := testJavacOptions, + libraryDependencies ++= testLibraryDependencies ) .dependsOn(core, persist, rep, test) diff --git a/stasis-core/src/main/java/com/sleepycat/je/EnvironmentMutableConfig.java b/stasis-core/src/main/java/com/sleepycat/je/EnvironmentMutableConfig.java index df4ae7c..65f9e7a 100644 --- a/stasis-core/src/main/java/com/sleepycat/je/EnvironmentMutableConfig.java +++ b/stasis-core/src/main/java/com/sleepycat/je/EnvironmentMutableConfig.java @@ -614,8 +614,7 @@ public class EnvironmentMutableConfig implements Cloneable, Serializable { void checkImmutablePropsForEquality(Properties handleConfigProps) throws IllegalArgumentException { - Iterator iter = - EnvironmentParams.SUPPORTED_PARAMS.keySet().iterator(); + Iterator iter = EnvironmentParams.SUPPORTED_PARAMS.keySet().iterator(); while (iter.hasNext()) { String paramName = iter.next(); ConfigParam param = diff --git a/stasis-core/src/main/java/com/sleepycat/je/dbi/DbConfigManager.java b/stasis-core/src/main/java/com/sleepycat/je/dbi/DbConfigManager.java index 04e42c1..70b1b93 100644 --- a/stasis-core/src/main/java/com/sleepycat/je/dbi/DbConfigManager.java +++ b/stasis-core/src/main/java/com/sleepycat/je/dbi/DbConfigManager.java @@ -505,7 +505,7 @@ public class DbConfigManager { if (param == null) { - /* See if the parameter is an multi-value parameter. */ + /* See if the parameter is a multi-value parameter. */ String mvParamName = ConfigParam.multiValueParamName(paramName); param = EnvironmentParams.SUPPORTED_PARAMS.get(mvParamName); if (param == null) { diff --git a/stasis-core/src/main/java/com/sleepycat/je/dbi/EnvironmentImpl.java b/stasis-core/src/main/java/com/sleepycat/je/dbi/EnvironmentImpl.java index ee139f5..cfe5805 100644 --- a/stasis-core/src/main/java/com/sleepycat/je/dbi/EnvironmentImpl.java +++ b/stasis-core/src/main/java/com/sleepycat/je/dbi/EnvironmentImpl.java @@ -41,6 +41,7 @@ import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; +import java.lang.reflect.Constructor; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -1031,7 +1032,8 @@ public class EnvironmentImpl implements EnvConfigObserver { try { Class newClass = Class.forName(className); - MBeanRegistrar mBeanReg = (MBeanRegistrar) newClass.newInstance(); + Constructor constructor = newClass.getConstructor(String.class); + MBeanRegistrar mBeanReg = (MBeanRegistrar)constructor.newInstance(); mBeanReg.doRegister(env); mBeanRegList.add(mBeanReg); } catch (Exception e) { diff --git a/stasis-core/src/main/java/com/sleepycat/je/utilint/Timestamp.java b/stasis-core/src/main/java/com/sleepycat/je/utilint/Timestamp.java index 13ee52c..71c1560 100644 --- a/stasis-core/src/main/java/com/sleepycat/je/utilint/Timestamp.java +++ b/stasis-core/src/main/java/com/sleepycat/je/utilint/Timestamp.java @@ -13,6 +13,10 @@ package com.sleepycat.je.utilint; +import java.util.Calendar; +import java.util.GregorianCalendar; +import java.util.TimeZone; + /** * Duplicate of java.sql.Timestamp * This duplicate keeps our implementation constant in case the java.sql.Timestamp implementation @@ -62,12 +66,13 @@ public class Timestamp extends java.util.Date { * {@code yyyy-mm-dd hh:mm:ss.fffffffff} format */ public String toString() { - int year = super.getYear() + 1900; - int month = super.getMonth() + 1; - int day = super.getDate(); - int hour = super.getHours(); - int minute = super.getMinutes(); - int second = super.getSeconds(); + Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC")); + int year = cal.get(Calendar.YEAR) - 1900; + int month = cal.get(Calendar.MONTH) + 1; + int day = cal.get(Calendar.DAY_OF_MONTH) + 1; + int hour = cal.get(Calendar.HOUR_OF_DAY) + 1; + int minute = cal.get(Calendar.MINUTE) + 1; + int second = cal.get(Calendar.SECOND) + 1; String yearString; String monthString; String dayString; diff --git a/stasis-test/src/test/java/com/sleepycat/je/rep/persist/test/AppImpl.java.0 b/stasis-test-dpl-v0/src/test/java/com/sleepycat/je/rep/persist/test/AppImpl.java similarity index 100% rename from stasis-test/src/test/java/com/sleepycat/je/rep/persist/test/AppImpl.java.0 rename to stasis-test-dpl-v0/src/test/java/com/sleepycat/je/rep/persist/test/AppImpl.java diff --git a/stasis-test/src/test/java/com/sleepycat/je/rep/persist/test/AppImpl.java.1 b/stasis-test-dpl-v1/src/test/java/com/sleepycat/je/rep/persist/test/AppImpl.java similarity index 100% rename from stasis-test/src/test/java/com/sleepycat/je/rep/persist/test/AppImpl.java.1 rename to stasis-test-dpl-v1/src/test/java/com/sleepycat/je/rep/persist/test/AppImpl.java diff --git a/stasis-test/src/test/java/com/sleepycat/collections/test/serial/StoredClassCatalogTest.java b/stasis-test/src/test/java/com/sleepycat/collections/test/serial/StoredClassCatalogTest.java index 32632a6..bae99ef 100644 --- a/stasis-test/src/test/java/com/sleepycat/collections/test/serial/StoredClassCatalogTest.java +++ b/stasis-test/src/test/java/com/sleepycat/collections/test/serial/StoredClassCatalogTest.java @@ -96,20 +96,24 @@ public class StoredClassCatalogTest extends TestBase * Copy the environment generated by StoredClassCatalogTestInit in * test dest dir, which is required to perform this test. */ - SharedTestUtils.copyDir( - new File(SharedTestUtils.getDestDir(), customName), - new File(SharedTestUtils.getTestDir(), customName)); - + File dirA = new File(SharedTestUtils.getDestDir().getAbsolutePath(), customName); + File dirB = new File(SharedTestUtils.getTestDir().getAbsolutePath(), customName); + if (!dirA.exists()) { + dirA.mkdirs(); + } + if (!dirB.exists()) { + dirB.mkdirs(); + } + SharedTestUtils.copyDir(dirA, dirB); + env = testEnv.open(customName, false); runner = new TransactionRunner(env); catalog = new StoredClassCatalog(openDb(CATALOG_FILE, false)); catalog2 = new StoredClassCatalog(openDb("catalog2.db", true)); - SerialBinding keyBinding = new SerialBinding(catalog, - String.class); - SerialBinding valueBinding = new SerialBinding(catalog, - TestSerial.class); + SerialBinding keyBinding = new SerialBinding(catalog, String.class); + SerialBinding valueBinding = new SerialBinding(catalog, TestSerial.class); store = openDb(STORE_FILE, false); map = new StoredMap(store, keyBinding, valueBinding, true); @@ -158,7 +162,6 @@ public class StoredClassCatalogTest extends TestBase } } - @Ignore @Test public void runTest() throws Exception { diff --git a/stasis-test/src/test/java/com/sleepycat/collections/test/serial/StoredClassCatalogTestInit.java b/stasis-test/src/test/java/com/sleepycat/collections/test/serial/StoredClassCatalogTestInit.java index a70e6fb..1aaa1ad 100644 --- a/stasis-test/src/test/java/com/sleepycat/collections/test/serial/StoredClassCatalogTestInit.java +++ b/stasis-test/src/test/java/com/sleepycat/collections/test/serial/StoredClassCatalogTestInit.java @@ -90,8 +90,7 @@ public class StoredClassCatalogTestInit extends TestBase catalog = new StoredClassCatalog(openDb(CATALOG_FILE)); SerialBinding keyBinding = new SerialBinding(catalog, String.class); - SerialBinding valueBinding = - new SerialBinding(catalog, TestSerial.class); + SerialBinding valueBinding = new SerialBinding(catalog, TestSerial.class); store = openDb(STORE_FILE); map = new StoredMap(store, keyBinding, valueBinding, true); @@ -128,9 +127,12 @@ public class StoredClassCatalogTestInit extends TestBase * Copy environment generated by this test to test dest dir. * Since the environment is necessary for StoreClassCatalogTest. */ - SharedTestUtils.copyDir(testEnv.getDirectory(customName, false), - new File(SharedTestUtils.getDestDir(), customName)); - + File destDir = new File(SharedTestUtils.getDestDir().getAbsolutePath(), customName); + if (!destDir.isDirectory()) { + destDir.mkdirs(); + } + SharedTestUtils.copyDir(testEnv.getDirectory(customName, false), destDir); + } catch (Exception e) { System.err.println("Ignored exception during tearDown: "); e.printStackTrace(); @@ -145,11 +147,9 @@ public class StoredClassCatalogTestInit extends TestBase } } - @Ignore @Test public void runTest() throws Exception { - runner.run(this); } diff --git a/stasis-test/src/test/java/com/sleepycat/je/EnvironmentConfigTest.java b/stasis-test/src/test/java/com/sleepycat/je/EnvironmentConfigTest.java index 9fa3ed1..d21ee06 100644 --- a/stasis-test/src/test/java/com/sleepycat/je/EnvironmentConfigTest.java +++ b/stasis-test/src/test/java/com/sleepycat/je/EnvironmentConfigTest.java @@ -128,8 +128,7 @@ public class EnvironmentConfigTest extends TestBase { } /* Read the je.properties. */ - ArrayList formerLines = TestUtils.readWriteJEProperties - (envHome, propName + "=" + propValue + "\n"); + ArrayList formerLines = TestUtils.readWriteJEProperties(envHome, propName + "=" + propValue + "\n"); /* Check this behavior is valid. */ Environment env = null; diff --git a/stasis-test/src/test/java/com/sleepycat/je/StatCaptureTest.java b/stasis-test/src/test/java/com/sleepycat/je/StatCaptureTest.java index bb910ed..19a7e65 100644 --- a/stasis-test/src/test/java/com/sleepycat/je/StatCaptureTest.java +++ b/stasis-test/src/test/java/com/sleepycat/je/StatCaptureTest.java @@ -52,7 +52,7 @@ public class StatCaptureTest extends TestBase { private static final String DB_NAME = "foo"; public StatCaptureTest() { - envHome = SharedTestUtils.getTestDir(); + envHome = new File(SharedTestUtils.getTestDir().getAbsolutePath()); } /** @@ -573,14 +573,14 @@ public class StatCaptureTest extends TestBase { envConfig.setConfigParam( EnvironmentParams.STATS_COLLECT_INTERVAL.getName(), "1 s"); envConfig.setConfigParam(EnvironmentConfig.VERIFY_BTREE, "false"); - repEnvInfo = RepTestUtils.setupEnvInfos( - envHome, 2, envConfig, new ReplicationConfig()); + repEnvInfo = RepTestUtils.setupEnvInfos(envHome, 2, envConfig, new ReplicationConfig()); repEnvHome = new File[repEnvInfo.length]; for (int i = 0; i < repEnvInfo.length; i++) { repEnvHome[i] = repEnvInfo[i].getEnvHome(); + SharedTestUtils.cleanUpTestDir(repEnvHome[i]); } - /* remove any existing stats files. */ + /* Remove any existing stats files. */ for (RepEnvInfo ri : repEnvInfo) { File[] files = ri.getEnvHome().listFiles(ff); for (File f : files) { @@ -602,8 +602,7 @@ public class StatCaptureTest extends TestBase { fastconfig.setClear(true); /* - * sleep to allow at least one row to be captured in stat file - * before doing work. + * Sleep to allow at least one row to be captured in stat file before doing work. */ Thread.sleep(1000); ReplicatedEnvironmentStats rs = replica.getRepStats(fastconfig); @@ -628,10 +627,9 @@ public class StatCaptureTest extends TestBase { Thread.sleep(2000); RepTestUtils.shutdownRepEnvs(repEnvInfo); } - /* Check master statistics */ - File statcsv = - new File(repEnvHome[0].getAbsolutePath() + File.separator + - "je.stat.csv"); + + /* Check master statistics. */ + File statcsv = new File(repEnvHome[0].getAbsolutePath() + File.separator + "je.stat.csv"); Map values = StatFile.sumItUp(statcsv); Long putCount = values.get("Op:priInsert"); assertEquals(putCount.longValue(), DATACOUNT); diff --git a/stasis-test/src/test/java/com/sleepycat/je/cleaner/ReadOnlyLockingTest.java b/stasis-test/src/test/java/com/sleepycat/je/cleaner/ReadOnlyLockingTest.java index d3e475c..e1dd088 100644 --- a/stasis-test/src/test/java/com/sleepycat/je/cleaner/ReadOnlyLockingTest.java +++ b/stasis-test/src/test/java/com/sleepycat/je/cleaner/ReadOnlyLockingTest.java @@ -66,7 +66,7 @@ public class ReadOnlyLockingTest extends CleanerTestBase { private Process readerProcess; private static File getProcessFile() { - return SharedTestUtils.getDestDirChlid("ReadOnlyProcessFile"); + return SharedTestUtils.getDestDirChild("ReadOnlyProcessFile"); } private static void deleteProcessFile() { diff --git a/stasis-test/src/test/java/com/sleepycat/je/dbi/DbEnvPoolTest.java b/stasis-test/src/test/java/com/sleepycat/je/dbi/DbEnvPoolTest.java index fec2e9f..2829279 100644 --- a/stasis-test/src/test/java/com/sleepycat/je/dbi/DbEnvPoolTest.java +++ b/stasis-test/src/test/java/com/sleepycat/je/dbi/DbEnvPoolTest.java @@ -86,7 +86,7 @@ public class DbEnvPoolTest extends TestBase { Environment envA = new Environment(envHomeA, envConfig); /* Look in the environment pool with the relative path name. */ - File file2 = new File(SharedTestUtils.DEFAULT_DEST_DIR); + File file2 = new File(SharedTestUtils.defaultDestDir()); assertTrue(DbEnvPool.getInstance().isOpen(file2)); envA.close(); diff --git a/stasis-test/src/test/java/com/sleepycat/je/rep/persist/test/UpgradeTest.java b/stasis-test/src/test/java/com/sleepycat/je/rep/persist/test/UpgradeTest.java index 1b6894b..e0102c6 100644 --- a/stasis-test/src/test/java/com/sleepycat/je/rep/persist/test/UpgradeTest.java +++ b/stasis-test/src/test/java/com/sleepycat/je/rep/persist/test/UpgradeTest.java @@ -147,11 +147,10 @@ public class UpgradeTest extends TestBase { } final ClassLoader parentClassLoader = Thread.currentThread().getContextClassLoader(); for (int i = 0; i < N_APP_VERSIONS; i += 1) { - final ClassLoader myLoader = new SimpleClassLoader - (parentClassLoader, - new File(evolveParentDir, "dplUpgrade." + i)); - appClasses[i] = - Class.forName(APP_IMPL, true /*initialize*/, myLoader); + File dir = new File(new File(SharedTestUtils.getCwd()).getParentFile().getParentFile().getAbsolutePath(), + "stasis-test-dpl-v" + String.valueOf(i) + File.separator + SharedTestUtils.defaultDestDir()); + final ClassLoader myLoader = new SimpleClassLoader(parentClassLoader, dir); + appClasses[i] = Class.forName(APP_IMPL, true /*initialize*/, myLoader); } /* Open v0 app objects. */ diff --git a/stasis-test/src/test/java/com/sleepycat/je/rep/utilint/RepTestUtils.java b/stasis-test/src/test/java/com/sleepycat/je/rep/utilint/RepTestUtils.java index d734e70..310ebf1 100644 --- a/stasis-test/src/test/java/com/sleepycat/je/rep/utilint/RepTestUtils.java +++ b/stasis-test/src/test/java/com/sleepycat/je/rep/utilint/RepTestUtils.java @@ -214,49 +214,17 @@ public class RepTestUtils { /** * Create a directory within the envRoot directory nodes for housing a - * single replicated environment. The directory will be named - * /rep + * single replicated environment. Name the directory `/rep`. */ public static File makeRepEnvDir(File envRoot, int i) throws IOException { - File jeProperties = new File(envRoot, "je.properties"); + /* Make a sub-directory for the replica. */ File envHome = new File(envRoot, REPDIR + i); envHome.mkdir(); - /* Copy the test je.properties into the new directories. */ - File repProperties = new File(envHome, "je.properties"); - FileInputStream from = null; - FileOutputStream to = null; - try { - try { - from = new FileInputStream(jeProperties); - } catch (FileNotFoundException e) { - jeProperties.createNewFile(); - - from = new FileInputStream(jeProperties); - } - to = new FileOutputStream(repProperties); - byte[] buffer = new byte[4096]; - int bytesRead; - - while ((bytesRead = from.read(buffer)) != -1) { - to.write(buffer, 0, bytesRead); - } - } finally { - if (from != null) { - try { - from.close(); - } catch (IOException ignore) { - } - } - if (to != null) { - try { - to.close(); - } catch (IOException ignore) { - } - } - } + /* Copy the test je.properties into the directory. */ + SharedTestUtils.copyFile(new File(envRoot, "je.properties"), envHome); return envHome; } @@ -439,17 +407,16 @@ public class RepTestUtils { /* * Give all the environments the same environment configuration. * - * If the file size is not set by the calling test, stagger their log - * file length to give them slightly different logs and VLSNs. Disable - * parameter validation because we want to make the log file length - * smaller than the minimums, for testing. + * Stagger the log file length when not set to give them slightly + * different logs and VLSNs. Disable parameter validation because + * we want to make the log file length smaller than the minimums, + * for testing. */ if (!envConfig.isConfigParamSet(EnvironmentConfig.LOG_FILE_MAX)) { DbInternal.disableParameterValidation(envConfig); - /* Vary the file size */ + /* Vary the file size. */ long fileLen = ((envCount++ % 100) + 1) * 10000; - envConfig.setConfigParam(EnvironmentConfig.LOG_FILE_MAX, - Long.toString(fileLen)); + envConfig.setConfigParam(EnvironmentConfig.LOG_FILE_MAX, Long.toString(fileLen)); } repConfig.setHelperHosts((helper == null) ? @@ -457,7 +424,7 @@ public class RepTestUtils { helper.getRepConfig().getNodeHostPort()); /* - * If -DlongTimeout is true, then this test will run with very long + * NOTE: When `-DlongTimeout` is `true`, then this test will run with very long * timeouts, to make interactive debugging easier. */ if (longTimeout) { @@ -465,8 +432,7 @@ public class RepTestUtils { } /* - * If -DlongAckTimeout is true, then the test will set the - * REPLICA_TIMEOUT to 50secs. + * When `-DlongAckTimeout` is `true`, then the test will set the `REPLICA_TIMEOUT` to `50secs`. */ if (Boolean.getBoolean("longAckTimeout")) { repConfig.setReplicaAckTimeout(50, TimeUnit.SECONDS); diff --git a/stasis-test/src/test/java/com/sleepycat/util/test/SharedTestUtils.java b/stasis-test/src/test/java/com/sleepycat/util/test/SharedTestUtils.java index dd405c4..d667a2c 100644 --- a/stasis-test/src/test/java/com/sleepycat/util/test/SharedTestUtils.java +++ b/stasis-test/src/test/java/com/sleepycat/util/test/SharedTestUtils.java @@ -34,11 +34,13 @@ import com.sleepycat.je.DatabaseConfig; */ public class SharedTestUtils { + /* @see defaultDestDir() */ + private static String DEFAULT_DEST_DIR = "target/scala-%s/test-classes"; // util.Properties.versionNumberString + /* Common system properties for running tests */ public static String DEST_DIR = "testdestdir"; public static String TEST_ENV_DIR = "testenvdirroot"; public static String FAILURE_DIR = "failurecopydir"; - public static String DEFAULT_DEST_DIR = "target/scala-%s/test-classes"; // util.Properties.versionNumberString public static String DEFAULT_TEST_DIR_ROOT = "target/envdata"; public static String DEFAULT_FAIL_DIR = "target/failures"; public static String NO_SYNC = "txnnosync"; @@ -50,6 +52,10 @@ public class SharedTestUtils { DBCONFIG_CREATE.setAllowCreate(true); } + public static String getCwd() { + return System.getProperty("user.dir"); + } + public static String defaultDestDir() { String version = System.getProperty("scala.version"); return String.format(DEFAULT_DEST_DIR, version == null ? "2.13" : version); @@ -72,7 +78,7 @@ public class SharedTestUtils { * The environment store compiled class files and generated environment by * test that is distinctive with test environment. */ - public static File getDestDirChlid(String child) { + public static File getDestDirChild(String child) { String dir = System.getProperty(DEST_DIR, defaultDestDir()); File file = new File(dir, child); @@ -280,8 +286,8 @@ public class SharedTestUtils { /** * Copy file to specified location. */ - private static void copyFile(File from, File to) - throws Exception { + public static void copyFile(File from, File to) + throws IOException { if (to.isDirectory()) to = new File(to, from.getName()); @@ -313,8 +319,7 @@ public class SharedTestUtils { */ public static void cleanUpTestDir(File dir) { if (!dir.isDirectory() || !dir.exists()) - throw new IllegalStateException( - "Not an existing directory: " + dir); + throw new IllegalStateException("Not an existing directory: " + dir); File[] files = dir.listFiles(); if (files == null) return; @@ -327,12 +332,10 @@ public class SharedTestUtils { cleanUpTestDir(file); if (file.list().length == 0 && !file.delete()) - throw new IllegalStateException( - "Unable to delete" + file); + throw new IllegalStateException("Unable to delete" + file); } else { if(!file.delete()) - throw new IllegalStateException( - "Unable to delete " + file); + throw new IllegalStateException("Unable to delete " + file); } } }