[ 
https://issues.apache.org/jira/browse/GEODE-3539?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16321174#comment-16321174
 ] 

ASF GitHub Bot commented on GEODE-3539:
---------------------------------------

jinmeiliao closed pull request #1242: GEODE-3539: Rule cleanup. delete all 
files in the workingDir when cleaning up MemberVM
URL: https://github.com/apache/geode/pull/1242
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/JdbcDUnitTest.java
 
b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/JdbcDUnitTest.java
index d571ecba38..ea1878ffec 100644
--- 
a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/JdbcDUnitTest.java
+++ 
b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/JdbcDUnitTest.java
@@ -32,7 +32,6 @@
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
-import org.apache.geode.cache.CacheFactory;
 import org.apache.geode.cache.Region;
 import org.apache.geode.pdx.PdxInstance;
 import org.apache.geode.test.dunit.IgnoredException;
@@ -84,7 +83,6 @@ private void createTable() throws SQLException {
   @After
   public void tearDown() throws Exception {
     server.invoke(() -> {
-      CacheFactory.getAnyInstance().close();
       closeDB();
     });
   }
@@ -112,9 +110,9 @@ public void throwsExceptionWhenNoMappingExistsUsingWriter() 
throws Exception {
 
     server.invoke(() -> {
       PdxInstance pdxEmployee1 =
-          
CacheFactory.getAnyInstance().createPdxInstanceFactory(Employee.class.getName())
+          
ClusterStartupRule.getCache().createPdxInstanceFactory(Employee.class.getName())
               .writeString("name", "Emp1").writeInt("age", 55).create();
-      Region region = CacheFactory.getAnyInstance().getRegion(REGION_NAME);
+      Region region = ClusterStartupRule.getCache().getRegion(REGION_NAME);
       assertThatThrownBy(() -> region.put("key1", pdxEmployee1))
           .isExactlyInstanceOf(IllegalStateException.class).hasMessage(
               "JDBC mapping for region employees not found. Create the mapping 
with the gfsh command 'create jdbc-mapping'.");
@@ -129,12 +127,12 @@ public void 
throwsExceptionWhenNoMappingExistsUsingAsyncWriter() throws Exceptio
 
     server.invoke(() -> {
       PdxInstance pdxEmployee1 =
-          
CacheFactory.getAnyInstance().createPdxInstanceFactory(Employee.class.getName())
+          
ClusterStartupRule.getCache().createPdxInstanceFactory(Employee.class.getName())
               .writeString("name", "Emp1").writeInt("age", 55).create();
-      Region region = CacheFactory.getAnyInstance().getRegion(REGION_NAME);
+      Region region = ClusterStartupRule.getCache().getRegion(REGION_NAME);
       region.put("key1", pdxEmployee1);
 
-      JdbcAsyncWriter asyncWriter = (JdbcAsyncWriter) 
CacheFactory.getAnyInstance()
+      JdbcAsyncWriter asyncWriter = (JdbcAsyncWriter) 
ClusterStartupRule.getCache()
           .getAsyncEventQueue("JAW").getAsyncEventListener();
       Awaitility.await().atMost(30, TimeUnit.SECONDS).until(() -> {
         assertThat(asyncWriter.getFailedEvents()).isEqualTo(1);
@@ -151,9 +149,9 @@ public void throwsExceptionWhenNoMappingMatches() throws 
Exception {
 
     server.invoke(() -> {
       PdxInstance pdxEmployee1 =
-          
CacheFactory.getAnyInstance().createPdxInstanceFactory(Employee.class.getName())
+          
ClusterStartupRule.getCache().createPdxInstanceFactory(Employee.class.getName())
               .writeString("name", "Emp1").writeInt("age", 55).create();
-      Region region = CacheFactory.getAnyInstance().getRegion(REGION_NAME);
+      Region region = ClusterStartupRule.getCache().getRegion(REGION_NAME);
       assertThatThrownBy(() -> region.put("key1", pdxEmployee1))
           .isExactlyInstanceOf(IllegalStateException.class).hasMessage(
               "JDBC mapping for region employees not found. Create the mapping 
with the gfsh command 'create jdbc-mapping'.");
@@ -167,9 +165,9 @@ public void throwsExceptionWhenNoConnectionExists() throws 
Exception {
 
     server.invoke(() -> {
       PdxInstance pdxEmployee1 =
-          
CacheFactory.getAnyInstance().createPdxInstanceFactory(Employee.class.getName())
+          
ClusterStartupRule.getCache().createPdxInstanceFactory(Employee.class.getName())
               .writeString("name", "Emp1").writeInt("age", 55).create();
-      Region region = CacheFactory.getAnyInstance().getRegion(REGION_NAME);
+      Region region = ClusterStartupRule.getCache().getRegion(REGION_NAME);
       assertThatThrownBy(() -> region.put("key1", pdxEmployee1))
           .isExactlyInstanceOf(IllegalStateException.class).hasMessage(
               "JDBC connection with name TestConnection not found. Create the 
connection with the gfsh command 'create jdbc-connection'");
@@ -183,11 +181,11 @@ public void putWritesToDB() throws Exception {
     createMapping(REGION_NAME, CONNECTION_NAME);
     server.invoke(() -> {
       PdxInstance pdxEmployee1 =
-          
CacheFactory.getAnyInstance().createPdxInstanceFactory(Employee.class.getName())
+          
ClusterStartupRule.getCache().createPdxInstanceFactory(Employee.class.getName())
               .writeString("id", "key1").writeString("name", 
"Emp1").writeInt("age", 55).create();
 
       String key = "emp1";
-      CacheFactory.getAnyInstance().getRegion(REGION_NAME).put(key, 
pdxEmployee1);
+      ClusterStartupRule.getCache().getRegion(REGION_NAME).put(key, 
pdxEmployee1);
       assertTableHasEmployeeData(1, pdxEmployee1, key);
     });
   }
@@ -199,11 +197,11 @@ public void putAsyncWritesToDB() throws Exception {
     createMapping(REGION_NAME, CONNECTION_NAME);
     server.invoke(() -> {
       PdxInstance pdxEmployee1 =
-          
CacheFactory.getAnyInstance().createPdxInstanceFactory(Employee.class.getName())
+          
ClusterStartupRule.getCache().createPdxInstanceFactory(Employee.class.getName())
               .writeString("id", "key1").writeString("name", 
"Emp1").writeInt("age", 55).create();
 
       String key = "emp1";
-      CacheFactory.getAnyInstance().getRegion(REGION_NAME).put(key, 
pdxEmployee1);
+      ClusterStartupRule.getCache().getRegion(REGION_NAME).put(key, 
pdxEmployee1);
       assertTableHasEmployeeData(1, pdxEmployee1, key);
     });
   }
@@ -215,7 +213,7 @@ public void getReadsFromEmptyDB() throws Exception {
     createMapping(REGION_NAME, CONNECTION_NAME);
     server.invoke(() -> {
       String key = "emp1";
-      Region region = CacheFactory.getAnyInstance().getRegion(REGION_NAME);
+      Region region = ClusterStartupRule.getCache().getRegion(REGION_NAME);
       region.get(key);
       assertThat(region.size()).isEqualTo(0);
     });
@@ -228,11 +226,11 @@ public void getReadsFromDB() throws Exception {
     createMapping(REGION_NAME, CONNECTION_NAME);
     server.invoke(() -> {
       PdxInstance pdxEmployee1 =
-          
CacheFactory.getAnyInstance().createPdxInstanceFactory(Employee.class.getName())
+          
ClusterStartupRule.getCache().createPdxInstanceFactory(Employee.class.getName())
               .writeString("id", "id1").writeString("name", 
"Emp1").writeInt("age", 55).create();
 
       String key = "id1";
-      Region region = CacheFactory.getAnyInstance().getRegion(REGION_NAME);
+      Region region = ClusterStartupRule.getCache().getRegion(REGION_NAME);
       region.put(key, pdxEmployee1);
       region.invalidate(key);
 
diff --git 
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsDUnitTest.java
 
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsDUnitTest.java
index 7ae41b10ef..38598a75bc 100644
--- 
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsDUnitTest.java
+++ 
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsDUnitTest.java
@@ -65,7 +65,7 @@
   private static final String ERROR_LOG_PREFIX = "[IGNORE]";
 
   @Rule
-  public ClusterStartupRule lsRule = new 
ClusterStartupRule().withTempWorkingDir().withLogFile();
+  public ClusterStartupRule lsRule = new ClusterStartupRule().withLogFile();
 
   @Rule
   public GfshCommandRule gfshConnector = new GfshCommandRule();
@@ -253,7 +253,6 @@ private void verifyLogFileContents(Set<String> 
acceptedLogLevels, File dirForMem
 
     File logFileForMember = new File(dirForMember, memberName + ".log");
     assertThat(logFileForMember).exists();
-    assertThat(fileNamesInDir).hasSize(1);
 
     String logFileContents = FileUtils.readLines(logFileForMember, 
Charset.defaultCharset())
         .stream().collect(joining("\n"));
@@ -283,7 +282,7 @@ private File unzipExportedLogs() throws IOException {
         
.describedAs(filesInDir.stream().map(File::getAbsolutePath).collect(joining(",")))
         .hasSize(1);
 
-    File unzippedLogFileDir = 
lsRule.getTempWorkingDir().newFolder("unzippedLogs");
+    File unzippedLogFileDir = new File(locatorWorkingDir, "unzippedLogs");
     ZipUtils.unzip(zipFilesInDir.get(0).getCanonicalPath(), 
unzippedLogFileDir.getCanonicalPath());
     return unzippedLogFileDir;
   }
diff --git 
a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/ClusterStartupRule.java
 
b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/ClusterStartupRule.java
index 89029c65e6..39d3438040 100644
--- 
a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/ClusterStartupRule.java
+++ 
b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/ClusterStartupRule.java
@@ -103,8 +103,14 @@ public static ClientCache getClientCache() {
    *
    * use this if you want to examine each member's file system without 
worrying about it's being
    * contaminated with DUnitLauncher's log files that exists in each dunit/vm 
folder such as
-   * locator0View.dat and locator0views.log and other random log files. This 
will cause the VMs to
-   * be bounced after test is done, because it dynamically changes the 
user.dir system property.
+   * locatorxxxView.dat and locatorxxxviews.log and other random log files.
+   *
+   * If the product code is doing new File(".") or new 
File("relative-path.log"), it will still
+   * pointing to the a File under the old CWD. So avoid using relative path 
and always use absolute
+   * path or with a parent dir when creating new File object.
+   *
+   * But this will cause the VMs to be bounced after test is done, because it 
dynamically changes
+   * the user.dir system property, causing slow running tests. Use with 
discretion.
    */
   public ClusterStartupRule withTempWorkingDir() {
     tempWorkingDir = new SerializableTemporaryFolder();
diff --git 
a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/MemberVM.java 
b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/MemberVM.java
index 96bede2a6e..c9f1212258 100644
--- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/MemberVM.java
+++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/MemberVM.java
@@ -103,10 +103,9 @@ public void stopVM(boolean cleanWorkingDir) {
        */
       vm.bounce();
     } else
-      // if using the dunit/vm dir as the preset working dir, need to cleanup 
dir except
-      // the locator0view* file, so that regions/indexes won't get persisted 
across tests
-      Arrays.stream(getWorkingDir().listFiles((dir, name) -> 
!name.startsWith("locator0view")))
-          .forEach(FileUtils::deleteQuietly);
+      // if using the dunit/vm dir as the preset working dir, need to cleanup 
dir
+      // so that regions/indexes won't get persisted across tests
+      
Arrays.stream(getWorkingDir().listFiles()).forEach(FileUtils::deleteQuietly);
   }
 
   /**


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Add more test coverage for p2p commands
> ---------------------------------------
>
>                 Key: GEODE-3539
>                 URL: https://issues.apache.org/jira/browse/GEODE-3539
>             Project: Geode
>          Issue Type: Improvement
>          Components: gfsh
>            Reporter: Jinmei Liao
>
> Add more command tests that would eventually get rid of the legacy tests.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to