Skip to content

Commit

Permalink
GEODE-8555: SimpleDiskRegionJunitTest fails on Windows (apache#5569)
Browse files Browse the repository at this point in the history
  • Loading branch information
sabbey37 authored Oct 1, 2020
1 parent 64e5682 commit a4c6c24
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeFalse;

import java.io.File;
import java.util.Collections;
Expand All @@ -32,7 +31,6 @@
import org.junit.Test;

import org.apache.geode.StatisticsFactory;
import org.apache.geode.internal.lang.SystemUtils;
import org.apache.geode.test.dunit.ThreadUtils;

/**
Expand All @@ -56,9 +54,8 @@ protected final void postSetUp() throws Exception {
*/
@Test
public void testBasicClose() {
assumeFalse(SystemUtils.isWindows());
{
deleteFiles();
forceDeleteFiles();
try {
region = DiskRegionHelperFactory.getAsyncOverFlowAndPersistRegion(cache, diskProps);
} catch (Exception e) {
Expand All @@ -70,7 +67,7 @@ public void testBasicClose() {
checkIfContainsFileWithExt("lk");
}
{
deleteFiles();
forceDeleteFiles();
try {
region = DiskRegionHelperFactory.getAsyncOverFlowOnlyRegion(cache, diskProps);
} catch (Exception e) {
Expand All @@ -82,7 +79,7 @@ public void testBasicClose() {
checkIfContainsFileWithExt("lk");
}
{
deleteFiles();
forceDeleteFiles();
try {
region = DiskRegionHelperFactory.getAsyncPersistOnlyRegion(cache, diskProps);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
import java.util.Iterator;
import java.util.Properties;

import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.rules.ErrorCollector;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestName;

Expand Down Expand Up @@ -79,6 +81,9 @@ public abstract class DiskRegionTestingBase {
@Rule
public TemporaryFolder tempDir = new TemporaryFolder();

@Rule
public ErrorCollector errorCollector = new ErrorCollector();

@Before
public final void setUp() throws Exception {
preSetUp();
Expand Down Expand Up @@ -200,6 +205,21 @@ protected void deleteFiles() {
tempDir.delete();
}

protected void forceDeleteFiles() {
closeDiskStores();
File file = tempDir.getRoot();
File[] files = file.listFiles();
for (File each : files) {
try {
if (!each.getName().contains(".gfs")) {
FileUtils.forceDelete(each);
}
} catch (IOException e) {
errorCollector.addError(e);
}
}
}

protected void closeDiskStores() {
if (cache != null) {
((GemFireCacheImpl) cache).closeDiskStores();
Expand Down

0 comments on commit a4c6c24

Please sign in to comment.