[refactor](fe-core src test catalog): refactor and replace use NIO #12818 (#12818)

This commit is contained in:
DingGeGe
2022-09-26 16:51:46 +08:00
committed by GitHub
parent 1bb42a7bc0
commit 3902b2bfad
16 changed files with 127 additions and 132 deletions

View File

@ -26,15 +26,15 @@ import org.apache.doris.persist.SetReplicaStatusOperationLog;
import org.apache.doris.utframe.TestWithFeService;
import com.google.common.collect.Lists;
import org.junit.Assert;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
public class AdminStmtTest extends TestWithFeService {
@ -55,9 +55,9 @@ public class AdminStmtTest extends TestWithFeService {
@Test
public void testAdminSetReplicaStatus() throws Exception {
Database db = Env.getCurrentInternalCatalog().getDbNullable("default_cluster:test");
Assert.assertNotNull(db);
Assertions.assertNotNull(db);
OlapTable tbl = (OlapTable) db.getTableNullable("tbl1");
Assert.assertNotNull(tbl);
Assertions.assertNotNull(tbl);
// tablet id, backend id
List<Pair<Long, Long>> tabletToBackendList = Lists.newArrayList();
for (Partition partition : tbl.getPartitions()) {
@ -69,11 +69,11 @@ public class AdminStmtTest extends TestWithFeService {
}
}
}
Assert.assertEquals(3, tabletToBackendList.size());
Assertions.assertEquals(3, tabletToBackendList.size());
long tabletId = tabletToBackendList.get(0).first;
long backendId = tabletToBackendList.get(0).second;
Replica replica = Env.getCurrentInvertedIndex().getReplica(tabletId, backendId);
Assert.assertFalse(replica.isBad());
Assertions.assertFalse(replica.isBad());
// set replica to bad
String adminStmt = "admin set replica status properties ('tablet_id' = '" + tabletId + "', 'backend_id' = '"
@ -81,7 +81,7 @@ public class AdminStmtTest extends TestWithFeService {
AdminSetReplicaStatusStmt stmt = (AdminSetReplicaStatusStmt) parseAndAnalyzeStmt(adminStmt);
Env.getCurrentEnv().setReplicaStatus(stmt);
replica = Env.getCurrentInvertedIndex().getReplica(tabletId, backendId);
Assert.assertTrue(replica.isBad());
Assertions.assertTrue(replica.isBad());
// set replica to ok
adminStmt = "admin set replica status properties ('tablet_id' = '" + tabletId + "', 'backend_id' = '"
@ -89,17 +89,17 @@ public class AdminStmtTest extends TestWithFeService {
stmt = (AdminSetReplicaStatusStmt) parseAndAnalyzeStmt(adminStmt);
Env.getCurrentEnv().setReplicaStatus(stmt);
replica = Env.getCurrentInvertedIndex().getReplica(tabletId, backendId);
Assert.assertFalse(replica.isBad());
Assertions.assertFalse(replica.isBad());
}
@Test
public void testSetReplicaStatusOperationLog() throws IOException, AnalysisException {
String fileName = "./SetReplicaStatusOperationLog";
Path path = Paths.get(fileName);
try {
// 1. Write objects to file
File file = new File(fileName);
file.createNewFile();
DataOutputStream out = new DataOutputStream(new FileOutputStream(file));
Files.createFile(path);
DataOutputStream out = new DataOutputStream(Files.newOutputStream(path));
SetReplicaStatusOperationLog log = new SetReplicaStatusOperationLog(10000, 100001, ReplicaStatus.BAD);
log.write(out);
@ -107,17 +107,16 @@ public class AdminStmtTest extends TestWithFeService {
out.close();
// 2. Read objects from file
DataInputStream in = new DataInputStream(new FileInputStream(file));
DataInputStream in = new DataInputStream(Files.newInputStream(path));
SetReplicaStatusOperationLog readLog = SetReplicaStatusOperationLog.read(in);
Assert.assertEquals(log.getBackendId(), readLog.getBackendId());
Assert.assertEquals(log.getTabletId(), readLog.getTabletId());
Assert.assertEquals(log.getReplicaStatus(), readLog.getReplicaStatus());
Assertions.assertEquals(log.getBackendId(), readLog.getBackendId());
Assertions.assertEquals(log.getTabletId(), readLog.getTabletId());
Assertions.assertEquals(log.getReplicaStatus(), readLog.getReplicaStatus());
in.close();
} finally {
File file = new File(fileName);
file.delete();
Files.deleteIfExists(path);
}
}

View File

@ -32,9 +32,9 @@ import org.junit.Test;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
@ -116,9 +116,9 @@ public class BackendTest {
@Test
public void testSerialization() throws Exception {
// Write 100 objects to file
File file = new File("./backendTest");
file.createNewFile();
DataOutputStream dos = new DataOutputStream(new FileOutputStream(file));
Path path = Paths.get("./backendTest");
Files.createFile(path);
DataOutputStream dos = new DataOutputStream(Files.newOutputStream(path));
List<Backend> list1 = new LinkedList<Backend>();
List<Backend> list2 = new LinkedList<Backend>();
@ -147,7 +147,7 @@ public class BackendTest {
dos.close();
// 2. Read objects from file
DataInputStream dis = new DataInputStream(new FileInputStream(file));
DataInputStream dis = new DataInputStream(Files.newInputStream(path));
for (int count = 0; count < 200; ++count) {
Backend backend = Backend.read(dis);
list2.add(backend);
@ -206,7 +206,7 @@ public class BackendTest {
// 3. delete files
dis.close();
file.delete();
Files.deleteIfExists(path);
}
}

View File

@ -27,9 +27,9 @@ import org.junit.Test;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
@ -60,9 +60,9 @@ public class ColocateTableIndexTest {
metaContext.setThreadLocalInfo();
// 1. Write objects to file
File file = new File("./GroupIdTest");
file.createNewFile();
DataOutputStream dos = new DataOutputStream(new FileOutputStream(file));
Path path = Paths.get("./GroupIdTest");
Files.createFile(path);
DataOutputStream dos = new DataOutputStream(Files.newOutputStream(path));
ColocateTableIndex.GroupId groupId = new ColocateTableIndex.GroupId(1, 2);
groupId.write(dos);
@ -70,13 +70,13 @@ public class ColocateTableIndexTest {
dos.close();
// 2. Read objects from file
DataInputStream dis = new DataInputStream(new FileInputStream(file));
DataInputStream dis = new DataInputStream(Files.newInputStream(path));
ColocateTableIndex.GroupId rGroupId = ColocateTableIndex.GroupId.read(dis);
Assert.assertTrue(groupId.equals(rGroupId));
// 3. delete files
dis.close();
file.delete();
Files.deleteIfExists(path);
}
}

View File

@ -32,20 +32,20 @@ import java.io.DataInput;
import java.io.DataInputStream;
import java.io.DataOutput;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
public class ColumnGsonSerializationTest {
private static String fileName = "./ColumnGsonSerializationTest";
private static Path path = Paths.get(fileName);
@After
public void tearDown() {
File file = new File(fileName);
file.delete();
public void tearDown() throws IOException {
Files.deleteIfExists(path);
}
public static class ColumnList implements Writable {
@ -67,9 +67,8 @@ public class ColumnGsonSerializationTest {
@Test
public void testSerializeColumn() throws IOException, AnalysisException {
// 1. Write objects to file
File file = new File(fileName);
file.createNewFile();
DataOutputStream out = new DataOutputStream(new FileOutputStream(file));
Files.createFile(path);
DataOutputStream out = new DataOutputStream(Files.newOutputStream(path));
Column c1 = new Column("c1", Type.fromPrimitiveType(PrimitiveType.BIGINT), true, null, true, "1", "abc");
@ -79,20 +78,21 @@ public class ColumnGsonSerializationTest {
out.close();
// 2. Read objects from file
DataInputStream in = new DataInputStream(new FileInputStream(file));
DataInputStream in = new DataInputStream(Files.newInputStream(path));
String readJson = Text.readString(in);
Column readC1 = GsonUtils.GSON.fromJson(readJson, Column.class);
Assert.assertEquals(c1, readC1);
// 3.close
in.close();
}
@Test
public void testSerializeColumnList() throws IOException, AnalysisException {
// 1. Write objects to file
File file = new File(fileName);
file.createNewFile();
DataOutputStream out = new DataOutputStream(new FileOutputStream(file));
Files.createFile(path);
DataOutputStream out = new DataOutputStream(Files.newOutputStream(path));
Column c1 = new Column("c1", Type.fromPrimitiveType(PrimitiveType.BIGINT), true, null, true, "1", "abc");
Column c2 = new Column("c2", ScalarType.createType(PrimitiveType.VARCHAR, 32, -1, -1), true, null, true, "cmy", "");
@ -108,7 +108,7 @@ public class ColumnGsonSerializationTest {
out.close();
// 2. Read objects from file
DataInputStream in = new DataInputStream(new FileInputStream(file));
DataInputStream in = new DataInputStream(Files.newInputStream(path));
ColumnList readList = ColumnList.read(in);
List<Column> columns = readList.columns;
@ -117,6 +117,8 @@ public class ColumnGsonSerializationTest {
Assert.assertEquals(c1, columns.get(0));
Assert.assertEquals(c2, columns.get(1));
Assert.assertEquals(c3, columns.get(2));
// 3.close
in.close();
}
}

View File

@ -22,18 +22,17 @@ import org.junit.Test;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class ColumnStatsTest {
@Test
public void testSerialization() throws Exception {
// 1. Write objects to file
File file = new File("./columnStats");
file.createNewFile();
DataOutputStream dos = new DataOutputStream(new FileOutputStream(file));
Path path = Files.createFile(Paths.get("./columnStats"));
DataOutputStream dos = new DataOutputStream(Files.newOutputStream(path));
ColumnStats stats1 = new ColumnStats();
stats1.write(dos);
@ -59,7 +58,7 @@ public class ColumnStatsTest {
dos.close();
// 2. Read objects from file
DataInputStream dis = new DataInputStream(new FileInputStream(file));
DataInputStream dis = new DataInputStream(Files.newInputStream(path));
ColumnStats rStats1 = new ColumnStats();
rStats1.readFields(dis);
Assert.assertTrue(rStats1.equals(stats1));
@ -81,7 +80,7 @@ public class ColumnStatsTest {
// 3. delete files
dis.close();
file.delete();
Files.deleteIfExists(path);
}
}

View File

@ -28,9 +28,9 @@ import org.junit.Test;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class ColumnTypeTest {
private FakeEnv fakeEnv;
@ -222,9 +222,8 @@ public class ColumnTypeTest {
@Test
public void testSerialization() throws Exception {
// 1. Write objects to file
File file = new File("./columnType");
file.createNewFile();
DataOutputStream dos = new DataOutputStream(new FileOutputStream(file));
Path path = Files.createFile(Paths.get("./columnType"));
DataOutputStream dos = new DataOutputStream(Files.newOutputStream(path));
ScalarType type1 = Type.NULL;
ColumnType.write(dos, type1);
@ -239,7 +238,7 @@ public class ColumnTypeTest {
ColumnType.write(dos, type4);
// 2. Read objects from file
DataInputStream dis = new DataInputStream(new FileInputStream(file));
DataInputStream dis = new DataInputStream(Files.newInputStream(path));
Type rType1 = ColumnType.read(dis);
Assert.assertTrue(rType1.equals(type1));
@ -255,6 +254,6 @@ public class ColumnTypeTest {
// 3. delete files
dis.close();
file.delete();
Files.deleteIfExists(path);
}
}

View File

@ -27,10 +27,10 @@ import org.junit.Test;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class DiskInfoTest {
@ -54,10 +54,8 @@ public class DiskInfoTest {
@Test
public void testSerialization() throws IOException {
// write disk info to file
File file = new File("./diskInfoTest");
file.createNewFile();
file.deleteOnExit();
DataOutputStream dos = new DataOutputStream(new FileOutputStream(file));
Path path = Files.createFile(Paths.get("./diskInfoTest"));
DataOutputStream dos = new DataOutputStream(Files.newOutputStream(path));
DiskInfo diskInfo1 = new DiskInfo("/disk1");
// 1 GB
@ -74,7 +72,7 @@ public class DiskInfoTest {
dos.close();
// read disk info from file
DataInputStream dis = new DataInputStream(new FileInputStream(file));
DataInputStream dis = new DataInputStream(Files.newInputStream(path));
DiskInfo result = DiskInfo.read(dis);
// check
@ -82,5 +80,8 @@ public class DiskInfoTest {
Assert.assertEquals(totalCapacityB, result.getTotalCapacityB());
Assert.assertEquals(dataUsedCapacityB, result.getDataUsedCapacityB());
Assert.assertTrue(result.getStorageMedium() == null);
// close
dis.close();
Files.deleteIfExists(path);
}
}

View File

@ -38,30 +38,29 @@ import org.junit.Test;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.Map;
public class MaterializedIndexMetaTest {
private static String fileName = "./MaterializedIndexMetaSerializeTest";
private static Path path = Paths.get(fileName);
@After
public void tearDown() {
File file = new File(fileName);
file.delete();
public void tearDown() throws IOException {
Files.deleteIfExists(path);
}
@Test
public void testSerializeMaterializedIndexMeta(@Mocked CreateMaterializedViewStmt stmt)
throws IOException, AnalysisException {
// 1. Write objects to file
File file = new File(fileName);
file.createNewFile();
DataOutputStream out = new DataOutputStream(new FileOutputStream(file));
Files.createFile(path);
DataOutputStream out = new DataOutputStream(Files.newOutputStream(path));
String mvColumnName = CreateMaterializedViewStmt.MATERIALIZED_VIEW_NAME_PREFIX + FunctionSet.BITMAP_UNION + "_" + "k1";
List<Column> schema = Lists.newArrayList();
@ -104,7 +103,7 @@ public class MaterializedIndexMetaTest {
// 2. Read objects from file
DataInputStream in = new DataInputStream(new FileInputStream(file));
DataInputStream in = new DataInputStream(Files.newInputStream(path));
MaterializedIndexMeta readIndexMeta = MaterializedIndexMeta.read(in);
Assert.assertEquals(1, readIndexMeta.getIndexId());
List<Column> resultColumns = readIndexMeta.getSchema();
@ -118,5 +117,7 @@ public class MaterializedIndexMetaTest {
Assert.assertEquals(null, column.getDefineExpr());
}
}
// 3.close
in.close();
}
}

View File

@ -27,9 +27,9 @@ import org.junit.Test;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.LinkedList;
import java.util.List;
@ -67,9 +67,8 @@ public class MaterializedIndexTest {
@Test
public void testSerialization() throws Exception {
// 1. Write objects to file
File file = new File("./index");
file.createNewFile();
DataOutputStream dos = new DataOutputStream(new FileOutputStream(file));
Path path = Files.createFile(Paths.get("./index"));
DataOutputStream dos = new DataOutputStream(Files.newOutputStream(path));
index.write(dos);
@ -77,12 +76,12 @@ public class MaterializedIndexTest {
dos.close();
// 2. Read objects from file
DataInputStream dis = new DataInputStream(new FileInputStream(file));
DataInputStream dis = new DataInputStream(Files.newInputStream(path));
MaterializedIndex rIndex = MaterializedIndex.read(dis);
Assert.assertTrue(index.equals(rIndex));
// 3. delete files
dis.close();
file.delete();
Files.deleteIfExists(path);
}
}

View File

@ -38,9 +38,9 @@ import org.junit.Test;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
@ -117,9 +117,8 @@ public class OdbcCatalogResourceTest {
metaContext.setThreadLocalInfo();
// 1. Write objects to file
File file = new File("./odbcCatalogResource");
file.createNewFile();
DataOutputStream dos = new DataOutputStream(new FileOutputStream(file));
Path path = Files.createFile(Paths.get("./odbcCatalogResource"));
DataOutputStream dos = new DataOutputStream(Files.newOutputStream(path));
OdbcCatalogResource odbcCatalogResource1 = new OdbcCatalogResource("odbc1");
odbcCatalogResource1.write(dos);
@ -137,7 +136,7 @@ public class OdbcCatalogResourceTest {
dos.close();
// 2. Read objects from file
DataInputStream dis = new DataInputStream(new FileInputStream(file));
DataInputStream dis = new DataInputStream(Files.newInputStream(path));
OdbcCatalogResource rOdbcCatalogResource1 = (OdbcCatalogResource) OdbcCatalogResource.read(dis);
OdbcCatalogResource rOdbcCatalogResource2 = (OdbcCatalogResource) OdbcCatalogResource.read(dis);
@ -152,6 +151,6 @@ public class OdbcCatalogResourceTest {
// 3. delete files
dis.close();
file.delete();
Files.deleteIfExists(path);
}
}

View File

@ -70,6 +70,7 @@ public class OlapTableTest {
DataInputStream in = new DataInputStream(byteArrayOutputStream.getInputStream());
Table copiedTbl = OlapTable.read(in);
System.out.println("copied table id: " + copiedTbl.getId());
in.close();
}
}

View File

@ -27,9 +27,9 @@ import org.junit.Test;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@ -202,9 +202,8 @@ public class PartitionKeyTest {
FakeEnv.setMetaVersion(FeConstants.meta_version);
// 1. Write objects to file
File file = new File("./keyRangePartition");
file.createNewFile();
DataOutputStream dos = new DataOutputStream(new FileOutputStream(file));
Path path = Files.createFile(Paths.get("./keyRangePartition"));
DataOutputStream dos = new DataOutputStream(Files.newOutputStream(path));
PartitionKey keyEmpty = new PartitionKey();
keyEmpty.write(dos);
@ -239,7 +238,7 @@ public class PartitionKeyTest {
dos.close();
// 2. Read objects from file
DataInputStream dis = new DataInputStream(new FileInputStream(file));
DataInputStream dis = new DataInputStream(Files.newInputStream(path));
PartitionKey rKeyEmpty = PartitionKey.read(dis);
Assert.assertTrue(keyEmpty.equals(rKeyEmpty));
@ -251,6 +250,6 @@ public class PartitionKeyTest {
// 3. delete files
dis.close();
file.delete();
Files.deleteIfExists(path);
}
}

View File

@ -30,10 +30,10 @@ import org.junit.Test;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map;
public class ReplicaAllocationTest {
@ -134,9 +134,8 @@ public class ReplicaAllocationTest {
metaContext.setThreadLocalInfo();
// 1. Write objects to file
File file = new File("./replicaInfo");
file.createNewFile();
DataOutputStream dos = new DataOutputStream(new FileOutputStream(file));
Path path = Files.createFile(Paths.get("./replicaInfo"));
DataOutputStream dos = new DataOutputStream(Files.newOutputStream(path));
ReplicaAllocation replicaAlloc = new ReplicaAllocation();
replicaAlloc.put(Tag.create(Tag.TYPE_LOCATION, "zone1"), (short) 3);
@ -147,12 +146,12 @@ public class ReplicaAllocationTest {
dos.close();
// 2. Read objects from file
DataInputStream dis = new DataInputStream(new FileInputStream(file));
DataInputStream dis = new DataInputStream(Files.newInputStream(path));
ReplicaAllocation newAlloc = ReplicaAllocation.read(dis);
Assert.assertEquals(replicaAlloc, newAlloc);
// 3. delete files
dis.close();
file.delete();
Files.deleteIfExists(path);
}
}

View File

@ -26,9 +26,9 @@ import org.junit.Test;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
@ -81,9 +81,8 @@ public class ReplicaTest {
@Test
public void testSerialization() throws Exception {
// 1. Write objects to file
File file = new File("./olapReplicaTest");
file.createNewFile();
DataOutputStream dos = new DataOutputStream(new FileOutputStream(file));
Path path = Files.createFile(Paths.get("./olapReplicaTest"));
DataOutputStream dos = new DataOutputStream(Files.newOutputStream(path));
List<Replica> list1 = new ArrayList<Replica>();
List<Replica> list2 = new ArrayList<Replica>();
@ -101,7 +100,7 @@ public class ReplicaTest {
dos.close();
// 2. Read a object from file
DataInputStream dis = new DataInputStream(new FileInputStream(file));
DataInputStream dis = new DataInputStream(Files.newInputStream(path));
for (int count = 0; count < 10; ++count) {
Replica olapReplica = new Replica();
olapReplica.readFields(dis);
@ -126,7 +125,7 @@ public class ReplicaTest {
Assert.assertFalse(list1.get(1).equals(list1));
dis.close();
file.delete();
Files.deleteIfExists(path);
}
@Test

View File

@ -154,7 +154,6 @@ public class ResourceMgrTest {
Map<String, String> copiedS3Properties = Maps.newHashMap(s3Properties);
copiedS3Properties.put("s3_region", s3Region);
copiedS3Properties.remove("type");
alterResourceStmt = new AlterResourceStmt(s3ResName, copiedS3Properties);
// current not support modify s3 property
// mgr.alterResource(alterResourceStmt);
// Assert.assertEquals(s3Region, ((S3Resource) mgr.getResource(s3ResName)).getProperty("s3_region"));

View File

@ -37,9 +37,9 @@ import org.junit.Test;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
@ -154,9 +154,8 @@ public class S3ResourceTest {
metaContext.setThreadLocalInfo();
// 1. write
File s3File = new File("./s3Resource");
s3File.createNewFile();
DataOutputStream s3Dos = new DataOutputStream(new FileOutputStream(s3File));
Path path = Files.createFile(Paths.get("./s3Resource"));
DataOutputStream s3Dos = new DataOutputStream(Files.newOutputStream(path));
S3Resource s3Resource1 = new S3Resource("s3_1");
s3Resource1.write(s3Dos);
@ -176,7 +175,7 @@ public class S3ResourceTest {
s3Dos.close();
// 2. read
DataInputStream s3Dis = new DataInputStream(new FileInputStream(s3File));
DataInputStream s3Dis = new DataInputStream(Files.newInputStream(path));
S3Resource rS3Resource1 = (S3Resource) S3Resource.read(s3Dis);
S3Resource rS3Resource2 = (S3Resource) S3Resource.read(s3Dis);
@ -194,6 +193,6 @@ public class S3ResourceTest {
// 3. delete
s3Dis.close();
s3File.delete();
Files.deleteIfExists(path);
}
}