mirror of
https://gitee.com/shikong-sk/springcloud-study
synced 2025-02-23 13:52:15 +08:00
简单测试
This commit is contained in:
parent
43090f34b7
commit
54a6ece1f1
@ -11,6 +11,6 @@ spring:
|
|||||||
server-addr: 10.10.10.20:8848
|
server-addr: 10.10.10.20:8848
|
||||||
|
|
||||||
seaweedfs:
|
seaweedfs:
|
||||||
url: http://192.168.3.3:9321
|
url: http://10.10.10.100:18333
|
||||||
accessKey: 123456
|
accessKey: fb64fcb7bbe24883b2b49c1e8d1bd02e
|
||||||
secretKey: 123456
|
secretKey: b40afae726aa7e2783e47b9af60f6c6f
|
||||||
|
@ -5,7 +5,10 @@ import io.minio.BucketExistsArgs;
|
|||||||
import io.minio.MakeBucketArgs;
|
import io.minio.MakeBucketArgs;
|
||||||
import io.minio.MinioClient;
|
import io.minio.MinioClient;
|
||||||
import io.minio.PutObjectArgs;
|
import io.minio.PutObjectArgs;
|
||||||
|
import io.minio.errors.*;
|
||||||
import io.minio.messages.Bucket;
|
import io.minio.messages.Bucket;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
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 org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.security.InvalidKeyException;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipFile;
|
import java.util.zip.ZipFile;
|
||||||
import java.util.zip.ZipInputStream;
|
import java.util.zip.ZipInputStream;
|
||||||
@ -28,19 +36,22 @@ public class ApplicationTest {
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(ApplicationTest.class,args);
|
SpringApplication.run(ApplicationTest.class,args);
|
||||||
}
|
}
|
||||||
|
private SeaweedfsConfig seaweedfsConfig;
|
||||||
|
private MinioClient mc;
|
||||||
|
private final static String bucket = "simple-test";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SeaweedfsConfig seaweedfsConfig;
|
public void setSeaweedfsConfig(SeaweedfsConfig seaweedfsConfig) {
|
||||||
@Test
|
this.seaweedfsConfig = seaweedfsConfig;
|
||||||
void contextLoad() throws Exception {
|
|
||||||
log.info("{}",seaweedfsConfig);
|
log.info("{}",seaweedfsConfig);
|
||||||
|
this.mc = MinioClient.builder()
|
||||||
MinioClient mc = MinioClient.builder()
|
|
||||||
.endpoint(seaweedfsConfig.getUrl())
|
.endpoint(seaweedfsConfig.getUrl())
|
||||||
.credentials(seaweedfsConfig.getAccessKey(),seaweedfsConfig.getSecretKey())
|
.credentials(seaweedfsConfig.getAccessKey(),seaweedfsConfig.getSecretKey())
|
||||||
.build();
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
String bucket = "simple-test";
|
@Test
|
||||||
|
void checkBucket() throws Exception {
|
||||||
if(!mc.bucketExists(BucketExistsArgs.builder().bucket(bucket).build())){
|
if(!mc.bucketExists(BucketExistsArgs.builder().bucket(bucket).build())){
|
||||||
mc.makeBucket(MakeBucketArgs.builder().bucket(bucket).build());
|
mc.makeBucket(MakeBucketArgs.builder().bucket(bucket).build());
|
||||||
}
|
}
|
||||||
@ -48,8 +59,27 @@ public class ApplicationTest {
|
|||||||
for(Bucket buckets:mc.listBuckets()){
|
for(Bucket buckets:mc.listBuckets()){
|
||||||
log.info("{}",buckets.name());
|
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)){
|
try(ZipFile zipFile = new ZipFile(path)){
|
||||||
ZipInputStream zipInputStream = new ZipInputStream(new BufferedInputStream(Files.newInputStream(Paths.get(path))));
|
ZipInputStream zipInputStream = new ZipInputStream(new BufferedInputStream(Files.newInputStream(Paths.get(path))));
|
||||||
ZipEntry zipEntry;
|
ZipEntry zipEntry;
|
||||||
|
Loading…
Reference in New Issue
Block a user