简单测试

This commit is contained in:
Shikong 2023-03-29 21:29:18 +08:00
parent 43090f34b7
commit 54a6ece1f1
2 changed files with 40 additions and 10 deletions

View File

@ -11,6 +11,6 @@ spring:
server-addr: 10.10.10.20:8848
seaweedfs:
url: http://192.168.3.3:9321
accessKey: 123456
secretKey: 123456
url: http://10.10.10.100:18333
accessKey: fb64fcb7bbe24883b2b49c1e8d1bd02e
secretKey: b40afae726aa7e2783e47b9af60f6c6f

View File

@ -5,7 +5,10 @@ import io.minio.BucketExistsArgs;
import io.minio.MakeBucketArgs;
import io.minio.MinioClient;
import io.minio.PutObjectArgs;
import io.minio.errors.*;
import io.minio.messages.Bucket;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@ -15,8 +18,13 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;
@ -28,19 +36,22 @@ public class ApplicationTest {
public static void main(String[] args) {
SpringApplication.run(ApplicationTest.class,args);
}
private SeaweedfsConfig seaweedfsConfig;
private MinioClient mc;
private final static String bucket = "simple-test";
@Autowired
private SeaweedfsConfig seaweedfsConfig;
@Test
void contextLoad() throws Exception {
public void setSeaweedfsConfig(SeaweedfsConfig seaweedfsConfig) {
this.seaweedfsConfig = seaweedfsConfig;
log.info("{}",seaweedfsConfig);
MinioClient mc = MinioClient.builder()
this.mc = MinioClient.builder()
.endpoint(seaweedfsConfig.getUrl())
.credentials(seaweedfsConfig.getAccessKey(),seaweedfsConfig.getSecretKey())
.build();
}
String bucket = "simple-test";
@Test
void checkBucket() throws Exception {
if(!mc.bucketExists(BucketExistsArgs.builder().bucket(bucket).build())){
mc.makeBucket(MakeBucketArgs.builder().bucket(bucket).build());
}
@ -48,8 +59,27 @@ public class ApplicationTest {
for(Bucket buckets:mc.listBuckets()){
log.info("{}",buckets.name());
}
}
String path = "D:\\Temp\\temp.zip";
@Test
void upload() throws Exception{
checkBucket();
String f = "D:\\Temp\\video.zip";
Path path = Paths.get(f);
try(InputStream is = Files.newInputStream(path)){
mc.putObject(PutObjectArgs.builder()
.bucket(bucket)
.object(path.getFileName().toString())
.stream(is,-1,1024 * 1024 * 1024)
.build());
}
}
@Test
void uploadZipFile() throws Exception {
checkBucket();
String path = "D:\\Temp\\video.zip";
try(ZipFile zipFile = new ZipFile(path)){
ZipInputStream zipInputStream = new ZipInputStream(new BufferedInputStream(Files.newInputStream(Paths.get(path))));
ZipEntry zipEntry;