refactor(性能测试): 保存测试日志内容时使用zip压缩
This commit is contained in:
parent
1c4828154e
commit
cc4d4ffa5b
|
@ -1,6 +1,9 @@
|
|||
package io.metersphere.commons.utils;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.zip.*;
|
||||
|
||||
|
@ -229,4 +232,32 @@ public class CompressUtils {
|
|||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
public static Object zipString(Object data) {
|
||||
if (!(data instanceof String)) {
|
||||
return data;
|
||||
}
|
||||
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
||||
try (DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(out)) {
|
||||
deflaterOutputStream.write(((String) data).getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
return Base64.encodeBase64String(out.toByteArray());
|
||||
} catch (Exception e) {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
public static Object unzipString(Object data) {
|
||||
if (!(data instanceof String)) {
|
||||
return data;
|
||||
}
|
||||
try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
|
||||
try (OutputStream outputStream = new InflaterOutputStream(os)) {
|
||||
outputStream.write(Base64.decodeBase64((String) data));
|
||||
}
|
||||
return os.toString(StandardCharsets.UTF_8);
|
||||
} catch (Exception e) {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,10 +3,7 @@ package io.metersphere.config;
|
|||
import com.fit2cloud.quartz.anno.QuartzDataSource;
|
||||
import com.github.pagehelper.PageInterceptor;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import io.metersphere.base.domain.ApiTestReportDetail;
|
||||
import io.metersphere.base.domain.AuthSource;
|
||||
import io.metersphere.base.domain.FileContent;
|
||||
import io.metersphere.base.domain.TestResource;
|
||||
import io.metersphere.base.domain.*;
|
||||
import io.metersphere.commons.utils.CompressUtils;
|
||||
import io.metersphere.commons.utils.MybatisInterceptorConfig;
|
||||
import io.metersphere.interceptor.MybatisInterceptor;
|
||||
|
@ -54,6 +51,7 @@ public class DatabaseConfig {
|
|||
configList.add(new MybatisInterceptorConfig(ApiTestReportDetail.class, "content", CompressUtils.class, "compress", "decompress"));
|
||||
configList.add(new MybatisInterceptorConfig(TestResource.class, "configuration"));
|
||||
configList.add(new MybatisInterceptorConfig(AuthSource.class, "configuration"));
|
||||
configList.add(new MybatisInterceptorConfig(LoadTestReportLog.class, "content", CompressUtils.class, "zipString", "unzipString"));
|
||||
interceptor.setInterceptorConfigList(configList);
|
||||
return interceptor;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue