1
0

Fix wrong use of TemporaryFolder junit rule

This commit is contained in:
Xavier Jodoin
2018-03-28 13:09:57 -04:00
committed by vinoth chandar
parent 8f1d362015
commit 8ad8030f2a
5 changed files with 36 additions and 22 deletions

View File

@@ -69,7 +69,6 @@ import org.apache.hadoop.fs.LocatedFileStatus;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.RemoteIterator; import org.apache.hadoop.fs.RemoteIterator;
import org.apache.hadoop.util.StringUtils; import org.apache.hadoop.util.StringUtils;
import org.junit.rules.TemporaryFolder;
public class HoodieTestUtils { public class HoodieTestUtils {
@@ -83,7 +82,13 @@ public class HoodieTestUtils {
return new Configuration(); return new Configuration();
} }
public static HoodieTableMetaClient init(Configuration hadoopConf, String basePath) throws IOException { public static HoodieTableMetaClient init(String basePath)
throws IOException {
return initTableType(getDefaultHadoopConf(), basePath, HoodieTableType.COPY_ON_WRITE);
}
public static HoodieTableMetaClient init(Configuration hadoopConf, String basePath)
throws IOException {
return initTableType(hadoopConf, basePath, HoodieTableType.COPY_ON_WRITE); return initTableType(hadoopConf, basePath, HoodieTableType.COPY_ON_WRITE);
} }
@@ -96,14 +101,6 @@ public class HoodieTestUtils {
return HoodieTableMetaClient.initializePathAsHoodieDataset(hadoopConf, basePath, properties); return HoodieTableMetaClient.initializePathAsHoodieDataset(hadoopConf, basePath, properties);
} }
public static HoodieTableMetaClient initOnTemp() throws IOException {
// Create a temp folder as the base path
TemporaryFolder folder = new TemporaryFolder();
folder.create();
String basePath = folder.getRoot().getAbsolutePath();
return HoodieTestUtils.init(HoodieTestUtils.getDefaultHadoopConf(), basePath);
}
public static String makeNewCommitTime() { public static String makeNewCommitTime() {
return new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()); return new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
} }

View File

@@ -35,16 +35,21 @@ import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.io.SequenceFile; import org.apache.hadoop.io.SequenceFile;
import org.apache.hadoop.io.Text; import org.apache.hadoop.io.Text;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TemporaryFolder;
public class HoodieTableMetaClientTest { public class HoodieTableMetaClientTest {
private HoodieTableMetaClient metaClient; private HoodieTableMetaClient metaClient;
private String basePath; private String basePath;
@Rule
public TemporaryFolder tmpFolder = new TemporaryFolder();
@Before @Before
public void init() throws IOException { public void init() throws IOException {
metaClient = HoodieTestUtils.initOnTemp(); metaClient = HoodieTestUtils.init(tmpFolder.getRoot().getAbsolutePath());
basePath = metaClient.getBasePath(); basePath = metaClient.getBasePath();
} }

View File

@@ -28,12 +28,11 @@ import com.uber.hoodie.common.table.timeline.HoodieInstant;
import java.io.IOException; import java.io.IOException;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Stream; import java.util.stream.Stream;
import org.apache.hadoop.fs.Path;
import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
public class HoodieActiveTimelineTest { public class HoodieActiveTimelineTest {
@@ -41,15 +40,12 @@ public class HoodieActiveTimelineTest {
private HoodieTableMetaClient metaClient; private HoodieTableMetaClient metaClient;
@Rule @Rule
public final ExpectedException exception = ExpectedException.none(); public final ExpectedException exception = ExpectedException.none();
@Rule
public TemporaryFolder tmpFolder = new TemporaryFolder();
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
this.metaClient = HoodieTestUtils.initOnTemp(); this.metaClient = HoodieTestUtils.init(tmpFolder.getRoot().getAbsolutePath());
}
@After
public void tearDown() throws Exception {
metaClient.getFs().delete(new Path(this.metaClient.getBasePath()), true);
} }
@Test @Test

View File

@@ -44,7 +44,9 @@ import java.util.stream.Collectors;
import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TemporaryFolder;
@SuppressWarnings("ResultOfMethodCallIgnored") @SuppressWarnings("ResultOfMethodCallIgnored")
public class HoodieTableFileSystemViewTest { public class HoodieTableFileSystemViewTest {
@@ -55,9 +57,12 @@ public class HoodieTableFileSystemViewTest {
private TableFileSystemView.ReadOptimizedView roView; private TableFileSystemView.ReadOptimizedView roView;
private TableFileSystemView.RealtimeView rtView; private TableFileSystemView.RealtimeView rtView;
@Rule
public TemporaryFolder tmpFolder = new TemporaryFolder();
@Before @Before
public void init() throws IOException { public void init() throws IOException {
metaClient = HoodieTestUtils.initOnTemp(); metaClient = HoodieTestUtils.init(tmpFolder.getRoot().getAbsolutePath());;
basePath = metaClient.getBasePath(); basePath = metaClient.getBasePath();
fsView = new HoodieTableFileSystemView(metaClient, fsView = new HoodieTableFileSystemView(metaClient,
metaClient.getActiveTimeline().getCommitTimeline().filterCompletedInstants()); metaClient.getActiveTimeline().getCommitTimeline().filterCompletedInstants());

View File

@@ -24,6 +24,8 @@ import com.uber.hoodie.common.table.HoodieTableMetaClient;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TemporaryFolder; import org.junit.rules.TemporaryFolder;
@@ -32,10 +34,19 @@ import org.junit.rules.TemporaryFolder;
*/ */
public class TestHoodieROTablePathFilter { public class TestHoodieROTablePathFilter {
@Rule
public TemporaryFolder tmpFolder = new TemporaryFolder();
private HoodieTableMetaClient metaClient;
@Before
public void setUp() throws Exception {
this.metaClient = HoodieTestUtils.init(tmpFolder.getRoot().getAbsolutePath());
}
@Test @Test
public void testHoodiePaths() throws IOException { public void testHoodiePaths() throws IOException {
// Create a temp folder as the base path // Create a temp folder as the base path
HoodieTableMetaClient metaClient = HoodieTestUtils.initOnTemp();
String basePath = metaClient.getBasePath(); String basePath = metaClient.getBasePath();
HoodieTestUtils.createCommitFiles(basePath, "001", "002"); HoodieTestUtils.createCommitFiles(basePath, "001", "002");