Simplify unknown compression handling
This commit is contained in:
parent
ca9f623d05
commit
ef9ebffc54
|
@ -1,5 +1,8 @@
|
|||
package com.datadog.profiling.uploader;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
enum CompressionType {
|
||||
/** No compression */
|
||||
OFF,
|
||||
|
@ -8,13 +11,11 @@ enum CompressionType {
|
|||
/** Lower compression ratio with less CPU overhead * */
|
||||
LOW,
|
||||
/** Better compression ratio for the price of higher CPU usage * */
|
||||
MEDIUM,
|
||||
/** Unknown compression config value */
|
||||
UNKNOWN;
|
||||
MEDIUM;
|
||||
|
||||
static CompressionType of(final String type) {
|
||||
static CompressionType of(String type) {
|
||||
if (type == null) {
|
||||
return UNKNOWN;
|
||||
type = "";
|
||||
}
|
||||
|
||||
switch (type.toLowerCase()) {
|
||||
|
@ -27,7 +28,8 @@ enum CompressionType {
|
|||
case "medium":
|
||||
return MEDIUM;
|
||||
default:
|
||||
return UNKNOWN;
|
||||
log.warn("Unrecognizable compression type: {}. Defaulting to 'on'.", type);
|
||||
return ON;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -244,27 +244,23 @@ public final class RecordingUploader {
|
|||
// currently only gzip and off are supported
|
||||
// this needs to be updated once more compression types are added
|
||||
switch (type) {
|
||||
case ON:
|
||||
case MEDIUM:
|
||||
default:
|
||||
{
|
||||
compression = (is, expectedSize) -> StreamUtils.gzipStream(is, expectedSize, consumer);
|
||||
break;
|
||||
}
|
||||
case LOW:
|
||||
{
|
||||
compression = (is, expectedSize) -> StreamUtils.lz4Stream(is, expectedSize, consumer);
|
||||
break;
|
||||
}
|
||||
case ON:
|
||||
case MEDIUM:
|
||||
{
|
||||
compression = (is, expectedSize) -> StreamUtils.gzipStream(is, expectedSize, consumer);
|
||||
break;
|
||||
}
|
||||
case OFF:
|
||||
{
|
||||
compression = (is, expectedSize) -> StreamUtils.readStream(is, expectedSize, consumer);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
log.warn("Unrecognizable compression type: {}. Defaulting to 'on'.", type);
|
||||
compression = (is, expectedSize) -> StreamUtils.gzipStream(is, expectedSize, consumer);
|
||||
}
|
||||
}
|
||||
return compression;
|
||||
}
|
||||
|
|
|
@ -9,10 +9,15 @@ import org.junit.jupiter.params.ParameterizedTest;
|
|||
import org.junit.jupiter.params.provider.EnumSource;
|
||||
|
||||
class CompressionTypeTest {
|
||||
|
||||
@Test
|
||||
void testDefault() {
|
||||
assertEquals(CompressionType.UNKNOWN, CompressionType.of(""));
|
||||
assertEquals(CompressionType.UNKNOWN, CompressionType.of(null));
|
||||
void testEmpty() {
|
||||
assertEquals(CompressionType.ON, CompressionType.of(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNull() {
|
||||
assertEquals(CompressionType.ON, CompressionType.of(null));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
|
|
Loading…
Reference in New Issue