mirror of
https://gitee.com/shikong-sk/springcloud-study
synced 2025-02-22 21:32:14 +08:00
简单测试
This commit is contained in:
parent
ab92069b81
commit
49f6994a56
@ -44,5 +44,29 @@
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
<version>4.10.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>5.8.16</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.minio</groupId>
|
||||
<artifactId>minio</artifactId>
|
||||
<version>8.5.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -0,0 +1,16 @@
|
||||
package cn.skcks.study.springcloud.project01.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
|
||||
@Data
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "seaweedfs")
|
||||
public class SeaweedfsConfig {
|
||||
private String url;
|
||||
private String accessKey;
|
||||
private String secretKey;
|
||||
}
|
@ -9,3 +9,8 @@ spring:
|
||||
nacos:
|
||||
discovery:
|
||||
server-addr: 10.10.10.20:8848
|
||||
|
||||
seaweedfs:
|
||||
url: http://192.168.3.3:9321
|
||||
accessKey: 123456
|
||||
secretKey: 123456
|
||||
|
@ -0,0 +1,68 @@
|
||||
package cn.skcks.study.springcloud.project01;
|
||||
|
||||
import cn.skcks.study.springcloud.project01.config.SeaweedfsConfig;
|
||||
import io.minio.BucketExistsArgs;
|
||||
import io.minio.MakeBucketArgs;
|
||||
import io.minio.MinioClient;
|
||||
import io.minio.PutObjectArgs;
|
||||
import io.minio.messages.Bucket;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@Slf4j
|
||||
public class ApplicationTest {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ApplicationTest.class,args);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private SeaweedfsConfig seaweedfsConfig;
|
||||
@Test
|
||||
void contextLoad() throws Exception {
|
||||
log.info("{}",seaweedfsConfig);
|
||||
|
||||
MinioClient mc = MinioClient.builder()
|
||||
.endpoint(seaweedfsConfig.getUrl())
|
||||
.credentials(seaweedfsConfig.getAccessKey(),seaweedfsConfig.getSecretKey())
|
||||
.build();
|
||||
|
||||
String bucket = "simple-test";
|
||||
if(!mc.bucketExists(BucketExistsArgs.builder().bucket(bucket).build())){
|
||||
mc.makeBucket(MakeBucketArgs.builder().bucket(bucket).build());
|
||||
}
|
||||
|
||||
for(Bucket buckets:mc.listBuckets()){
|
||||
log.info("{}",buckets.name());
|
||||
}
|
||||
|
||||
String path = "E:\\Repository\\skcks.cn\\temp\\temp.zip";
|
||||
try(ZipFile zipFile = new ZipFile(path)){
|
||||
ZipInputStream zipInputStream = new ZipInputStream(new BufferedInputStream(Files.newInputStream(Paths.get(path))));
|
||||
ZipEntry zipEntry;
|
||||
while ((zipEntry = zipInputStream.getNextEntry()) != null) {
|
||||
String fileName = zipEntry.getName();
|
||||
long size = zipEntry.getSize();
|
||||
log.info("{} {}",fileName,size);
|
||||
mc.putObject(PutObjectArgs.builder()
|
||||
.bucket(bucket)
|
||||
.object(fileName)
|
||||
.stream(zipFile.getInputStream(zipEntry),size,-1)
|
||||
.build());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user