-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[all] Minor code cleanup in various enums (#1182)
Added a valueOf function in EnumUtils to reduce code duplication and standardize the error message for badly handled enums. Also added unit tests for the mappings of all VeniceEnumValue.
- Loading branch information
Showing
16 changed files
with
323 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
internal/venice-client-common/src/main/java/com/linkedin/venice/utils/VeniceEnumValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,18 @@ | ||
package com.linkedin.venice.utils; | ||
|
||
/** | ||
* N.B.: Although there is no way to force this via Java interfaces, the convention is that all enums implementing this | ||
* interface should have static "valueOf" function to return the correct enum value from a given numeric value, i.e.: | ||
* | ||
* {@snippet id='valueOf': | ||
* public static MyEnumType valueOf(int value) { | ||
* return EnumUtils.valueOf(TYPES_ARRAY, value, MyEnumTpe.class); | ||
* } | ||
* } | ||
* | ||
* Note that VeniceEnumValueTest makes it easy to test the above, and we should have a subclass of that test for all | ||
* implementations of this interface. | ||
*/ | ||
public interface VeniceEnumValue { | ||
int getValue(); | ||
} |
22 changes: 22 additions & 0 deletions
22
...-client-common/src/test/java/com/linkedin/venice/compression/CompressionStrategyTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.linkedin.venice.compression; | ||
|
||
import com.linkedin.alpini.base.misc.CollectionUtil; | ||
import com.linkedin.venice.utils.VeniceEnumValueTest; | ||
import java.util.Map; | ||
|
||
|
||
public class CompressionStrategyTest extends VeniceEnumValueTest<CompressionStrategy> { | ||
public CompressionStrategyTest() { | ||
super(CompressionStrategy.class); | ||
} | ||
|
||
@Override | ||
protected Map<Integer, CompressionStrategy> expectedMapping() { | ||
return CollectionUtil.<Integer, CompressionStrategy>mapBuilder() | ||
.put(0, CompressionStrategy.NO_OP) | ||
.put(1, CompressionStrategy.GZIP) | ||
.put(2, CompressionStrategy.ZSTD) | ||
.put(3, CompressionStrategy.ZSTD_WITH_DICT) | ||
.build(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...est/java/com/linkedin/venice/compute/protocol/request/enums/ComputeOperationTypeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.linkedin.venice.compute.protocol.request.enums; | ||
|
||
import com.linkedin.alpini.base.misc.CollectionUtil; | ||
import com.linkedin.venice.utils.VeniceEnumValueTest; | ||
import java.util.Map; | ||
|
||
|
||
public class ComputeOperationTypeTest extends VeniceEnumValueTest<ComputeOperationType> { | ||
public ComputeOperationTypeTest() { | ||
super(ComputeOperationType.class); | ||
} | ||
|
||
@Override | ||
protected Map<Integer, ComputeOperationType> expectedMapping() { | ||
return CollectionUtil.<Integer, ComputeOperationType>mapBuilder() | ||
.put(0, ComputeOperationType.DOT_PRODUCT) | ||
.put(1, ComputeOperationType.COSINE_SIMILARITY) | ||
.put(2, ComputeOperationType.HADAMARD_PRODUCT) | ||
.put(3, ComputeOperationType.COUNT) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.