Package com.linkedin.venice.utils
Class TestUtils
java.lang.Object
com.linkedin.venice.utils.TestUtils
General-purpose utility functions for tests.
-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends ControllerResponse>
TassertCommand
(T response) static <T extends ControllerResponse>
TassertCommand
(T response, String assertionErrorMessage) static void
checkMissingFieldInAvroRecord
(org.apache.avro.generic.GenericRecord record, String fieldName) static void
createAndVerifyStoreInAllRegions
(String storeName, ControllerClient parentControllerClient, List<ControllerClient> controllerClientList) static ETLStoreConfig
static HybridStoreConfig
createTestHybridStoreConfig
(Random random) static PartitionerConfig
createTestPartitionerConfig
(Random random) static Store
createTestStore
(String name, String owner, long createdTime) static SystemStoreAttributes
createTestSystemStoreAttributes
(String storeName, Random random) static Map<String,
SystemStoreAttributes> createTestSystemStores
(String storeName, Random random) createTestVersions
(String storeName, Random random) static Map<String,
ViewConfig> createTestViewConfigs
(Random random) createTestViewParams
(Random random) static VersionCreationResponse
createVersionWithBatchData
(ControllerClient controllerClient, String storeName, String keySchema, String valueSchema, Stream<Map.Entry> batchData, int valueSchemaId, PubSubProducerAdapterFactory pubSubProducerAdapterFactory, Map<String, String> additionalProperties) static VersionCreationResponse
createVersionWithBatchData
(ControllerClient controllerClient, String storeName, String keySchema, String valueSchema, Stream<Map.Entry> batchData, PubSubProducerAdapterFactory pubSubProducerAdapterFactory, Map<String, String> additionalProperties) static void
deleteDirectory
(File fileToDelete) static String
dequalifyClassName
(String className) static boolean
directoryContainsFolder
(String directoryPath, String folderName) findFoldersWithFileExtension
(File directory, String fileExtension) static Map<byte[],
byte[]> generateInput
(int recordCnt, boolean sorted, int startId, AvroSerializer serializer) static String
getClusterToD2String
(Map<String, String> clusterToD2) static int
WARNING: The code which generates the free port and uses it must always be called within a try/catch and a loop.getMultiClusterConfigFromOneCluster
(VeniceControllerClusterConfig controllerConfig) static OffsetRecord
getOffsetRecord
(long currentOffset) static OffsetRecord
getOffsetRecord
(long currentOffset, boolean complete) static OffsetRecord
getOffsetRecord
(long currentOffset, Optional<Long> endOfPushOffset) static SafeHelixManager
getParticipant
(String cluster, String nodeId, String zkAddress, int httpPort, String stateModelDef) Deprecated.TODO: migrate to use ServiceFactory for generating a participantstatic SafeHelixManager
getParticipant
(String cluster, String nodeId, String zkAddress, int httpPort, org.apache.helix.participant.statemachine.StateModelFactory<org.apache.helix.participant.statemachine.StateModel> stateModelFactory, String stateModelDef) static Properties
static Store
getStoreIngestionTaskBuilder
(String storeName) static String
getUniqueTopicString
(String prefix) static VeniceWriterFactory
getVeniceWriterFactory
(Properties properties, PubSubProducerAdapterFactory pubSubProducerAdapterFactory) static String
loadFileAsString
(String fileName) mergeConfigs
(List<Map<String, String>> configMaps) static void
static void
searchForFileExtension
(File directory, String fileExtension) static void
shutdownExecutor
(ExecutorService executor) static void
shutdownExecutor
(ExecutorService executor, long timeout, TimeUnit unit) static void
shutdownThread
(Thread thread) static void
shutdownThread
(Thread thread, long timeout, TimeUnit unit) static ControllerResponse
updateStoreToHybrid
(String storeName, ControllerClient parentControllerClient, Optional<Boolean> enableNativeReplication, Optional<Boolean> enableActiveActiveReplication, Optional<Boolean> enableChunking) static void
verifyDCConfigNativeAndActiveRepl
(String storeName, boolean enabledNR, boolean enabledAA, ControllerClient... controllerClients) static void
waitForNonDeterministicAssertion
(long timeout, TimeUnit timeoutUnit, boolean exponentialBackOff, boolean retryOnThrowable, TestUtils.NonDeterministicAssertion assertion) static void
waitForNonDeterministicAssertion
(long timeout, TimeUnit timeoutUnit, boolean exponentialBackOff, TestUtils.NonDeterministicAssertion assertion) static void
waitForNonDeterministicAssertion
(long timeout, TimeUnit timeoutUnit, TestUtils.NonDeterministicAssertion assertion) To be used for tests when we need to wait for an async operation to complete.static void
waitForNonDeterministicCompletion
(long timeout, TimeUnit timeoutUnit, BooleanSupplier condition) To be used for tests when we need to wait for an async operation to complete.static void
waitForNonDeterministicPushCompletion
(String topicName, ControllerClient controllerClient, long timeout, TimeUnit timeoutUnit) Wait for the push job for a store version or topic to be completed.static void
writeBatchData
(VersionCreationResponse response, String keySchema, String valueSchema, Stream<Map.Entry> batchData, int valueSchemaId, CompressionStrategy compressionStrategy, Function<String, ByteBuffer> compressionDictionaryGenerator, PubSubProducerAdapterFactory pubSubProducerAdapterFactory, Map<String, String> additionalProperties) static void
writeBatchData
(VersionCreationResponse response, String keySchema, String valueSchema, Stream<Map.Entry> batchData, int valueSchemaId, PubSubProducerAdapterFactory pubSubProducerAdapterFactory, Map<String, String> additionalProperties)
-
Constructor Details
-
TestUtils
public TestUtils()
-
-
Method Details
-
dequalifyClassName
-
waitForNonDeterministicCompletion
public static void waitForNonDeterministicCompletion(long timeout, TimeUnit timeoutUnit, BooleanSupplier condition) throws AssertionError To be used for tests when we need to wait for an async operation to complete. Pass a timeout, and a lambda for checking if the operation is complete.- Parameters:
timeout
- amount of time to waittimeoutUnit
-TimeUnit
for thecondition
- ABooleanSupplier
which should execute the non-deterministic action and return true if it is successful, false otherwise.- Throws:
AssertionError
-
updateStoreToHybrid
public static ControllerResponse updateStoreToHybrid(String storeName, ControllerClient parentControllerClient, Optional<Boolean> enableNativeReplication, Optional<Boolean> enableActiveActiveReplication, Optional<Boolean> enableChunking) -
waitForNonDeterministicAssertion
public static void waitForNonDeterministicAssertion(long timeout, TimeUnit timeoutUnit, TestUtils.NonDeterministicAssertion assertion) throws AssertionError To be used for tests when we need to wait for an async operation to complete. Pass a timeout, and a labmda for checking if the operation is complete. There is an issue within Mockito where it emits VerifyError instead of ArgumentsAreDifferent Exception. Check out "ExceptionFactory#JunitArgsAreDifferent" for details. The workaround here is to catch both assert and verify error. TODO: find a better way resolve it- Parameters:
timeout
- amount of time to waittimeoutUnit
-TimeUnit
for theassertion
- ATestUtils.NonDeterministicAssertion
which should simply execute without exception if it is successful, or throw anAssertionError
otherwise.- Throws:
AssertionError
- throws the exception thrown by theTestUtils.NonDeterministicAssertion
if the maximum wait time has been exceeded.
-
waitForNonDeterministicAssertion
public static void waitForNonDeterministicAssertion(long timeout, TimeUnit timeoutUnit, boolean exponentialBackOff, TestUtils.NonDeterministicAssertion assertion) throws AssertionError - Throws:
AssertionError
-
waitForNonDeterministicAssertion
public static void waitForNonDeterministicAssertion(long timeout, TimeUnit timeoutUnit, boolean exponentialBackOff, boolean retryOnThrowable, TestUtils.NonDeterministicAssertion assertion) throws AssertionError - Throws:
AssertionError
-
createVersionWithBatchData
public static VersionCreationResponse createVersionWithBatchData(ControllerClient controllerClient, String storeName, String keySchema, String valueSchema, Stream<Map.Entry> batchData, PubSubProducerAdapterFactory pubSubProducerAdapterFactory, Map<String, String> additionalProperties) -
createVersionWithBatchData
public static VersionCreationResponse createVersionWithBatchData(ControllerClient controllerClient, String storeName, String keySchema, String valueSchema, Stream<Map.Entry> batchData, int valueSchemaId, PubSubProducerAdapterFactory pubSubProducerAdapterFactory, Map<String, String> additionalProperties) -
writeBatchData
public static void writeBatchData(VersionCreationResponse response, String keySchema, String valueSchema, Stream<Map.Entry> batchData, int valueSchemaId, PubSubProducerAdapterFactory pubSubProducerAdapterFactory, Map<String, String> additionalProperties) -
writeBatchData
public static void writeBatchData(VersionCreationResponse response, String keySchema, String valueSchema, Stream<Map.Entry> batchData, int valueSchemaId, CompressionStrategy compressionStrategy, Function<String, ByteBuffer> compressionDictionaryGenerator, PubSubProducerAdapterFactory pubSubProducerAdapterFactory, Map<String, String> additionalProperties) -
waitForNonDeterministicPushCompletion
public static void waitForNonDeterministicPushCompletion(String topicName, ControllerClient controllerClient, long timeout, TimeUnit timeoutUnit) Wait for the push job for a store version or topic to be completed. The polling will fast fail if the push is found to be in ERROR state. -
createTestStore
-
createTestHybridStoreConfig
-
createTestViewConfigs
-
createTestViewParams
-
createTestETLStoreConfig
-
createTestPartitionerConfig
-
createTestVersions
-
createTestSystemStores
public static Map<String,SystemStoreAttributes> createTestSystemStores(String storeName, Random random) -
createTestSystemStoreAttributes
public static SystemStoreAttributes createTestSystemStoreAttributes(String storeName, Random random) -
getParticipant
@Deprecated public static SafeHelixManager getParticipant(String cluster, String nodeId, String zkAddress, int httpPort, String stateModelDef) Deprecated.TODO: migrate to use ServiceFactory for generating a participant -
getParticipant
public static SafeHelixManager getParticipant(String cluster, String nodeId, String zkAddress, int httpPort, org.apache.helix.participant.statemachine.StateModelFactory<org.apache.helix.participant.statemachine.StateModel> stateModelFactory, String stateModelDef) -
getOffsetRecord
-
getOffsetRecord
-
getOffsetRecord
-
getMultiClusterConfigFromOneCluster
public static VeniceControllerMultiClusterConfig getMultiClusterConfigFromOneCluster(VeniceControllerClusterConfig controllerConfig) -
getPropertiesForControllerConfig
-
getClusterToD2String
-
getVeniceWriterFactory
public static VeniceWriterFactory getVeniceWriterFactory(Properties properties, PubSubProducerAdapterFactory pubSubProducerAdapterFactory) -
getRandomStore
-
assertCommand
-
assertCommand
public static <T extends ControllerResponse> T assertCommand(T response, String assertionErrorMessage) -
preventSystemExit
public static void preventSystemExit() -
restoreSystemExit
public static void restoreSystemExit() -
createAndVerifyStoreInAllRegions
public static void createAndVerifyStoreInAllRegions(String storeName, ControllerClient parentControllerClient, List<ControllerClient> controllerClientList) -
verifyDCConfigNativeAndActiveRepl
public static void verifyDCConfigNativeAndActiveRepl(String storeName, boolean enabledNR, boolean enabledAA, ControllerClient... controllerClients) -
getStoreIngestionTaskBuilder
-
generateInput
public static Map<byte[],byte[]> generateInput(int recordCnt, boolean sorted, int startId, AvroSerializer serializer) -
shutdownThread
- Throws:
InterruptedException
-
shutdownThread
public static void shutdownThread(Thread thread, long timeout, TimeUnit unit) throws InterruptedException - Throws:
InterruptedException
-
shutdownExecutor
- Throws:
InterruptedException
-
shutdownExecutor
public static void shutdownExecutor(ExecutorService executor, long timeout, TimeUnit unit) throws InterruptedException - Throws:
InterruptedException
-
getIngestionIsolationPropertyMap
-
getUniqueTopicString
-
getFreePort
public static int getFreePort()WARNING: The code which generates the free port and uses it must always be called within a try/catch and a loop. There is no guarantee that the port returned will still be available at the time it is used. This is best-effort only.- Returns:
- a free port to be used by tests.
-
mergeConfigs
-
checkMissingFieldInAvroRecord
public static void checkMissingFieldInAvroRecord(org.apache.avro.generic.GenericRecord record, String fieldName) -
findFoldersWithFileExtension
-
searchForFileExtension
-
directoryContainsFolder
-
deleteDirectory
-
loadFileAsString
-