Package com.linkedin.venice.utils
Class TestUtils
java.lang.Object
com.linkedin.venice.utils.TestUtils
General-purpose utility functions for tests.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final PubSubContext**FOR UNIT TESTING PURPOSES ONLY** - Do not use in production code. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends ControllerResponse>
TassertCommand(T response) static <T extends ControllerResponse>
TassertCommand(T response, String assertionErrorMessage) static <T extends ControllerResponse>
TassertCommandFailure(T response, String assertionErrorMessage) static voidcheckMissingFieldInAvroRecord(org.apache.avro.generic.GenericRecord record, String fieldName) static voidcreateAndVerifyStoreInAllRegions(String storeName, ControllerClient parentControllerClient, List<ControllerClient> controllerClientList) static ETLStoreConfigstatic HybridStoreConfigcreateTestHybridStoreConfig(Random random) static PartitionerConfigcreateTestPartitionerConfig(Random random) static StorecreateTestStore(String name, String owner, long createdTime) static SystemStoreAttributescreateTestSystemStoreAttributes(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 VersionCreationResponsecreateVersionWithBatchData(ControllerClient controllerClient, String storeName, String keySchema, String valueSchema, Stream<Map.Entry> batchData, int valueSchemaId, PubSubProducerAdapterFactory pubSubProducerAdapterFactory, Map<String, String> additionalProperties, PubSubPositionTypeRegistry pubSubPositionTypeRegistry) static VersionCreationResponsecreateVersionWithBatchData(ControllerClient controllerClient, String storeName, String keySchema, String valueSchema, Stream<Map.Entry> batchData, PubSubProducerAdapterFactory pubSubProducerAdapterFactory, Map<String, String> additionalProperties, PubSubPositionTypeRegistry pubSubPositionTypeRegistry) static voiddeleteDirectory(File fileToDelete) static StringdequalifyClassName(String className) static booleandirectoryContainsFolder(String directoryPath, String folderName) findFoldersWithFileExtension(File directory, String fileExtension) static Map<byte[],byte[]> generateInput(int recordCnt, boolean sorted, int startId, AvroSerializer serializer) static StringgetClusterToD2String(Map<String, String> clusterToD2) static intWARNING: 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 OffsetRecordgetOffsetRecord(PubSubPosition currentPosition, Optional<PubSubPosition> endOfPushOffset, PubSubContext pubSubContext) static SafeHelixManagergetParticipant(String cluster, String nodeId, String zkAddress, int httpPort, String stateModelDef) Deprecated.TODO: migrate to use ServiceFactory for generating a participantstatic SafeHelixManagergetParticipant(String cluster, String nodeId, String zkAddress, int httpPort, org.apache.helix.participant.statemachine.StateModelFactory<org.apache.helix.participant.statemachine.StateModel> stateModelFactory, String stateModelDef) static Propertiesstatic StoregetStoreIngestionTaskBuilder(String storeName) getStoreIngestionTaskBuilder(String storeName, boolean isHybrid) static StringgetUniqueTopicString(String prefix) static VenicePathParsergetVenicePathParser(CompressorFactory compressorFactory, boolean decompressOnClient) static VeniceWriterFactorygetVeniceWriterFactory(Properties properties, PubSubProducerAdapterFactory pubSubProducerAdapterFactory, PubSubPositionTypeRegistry pubSubPositionTypeRegistry) static StringloadFileAsString(String fileName) mergeConfigs(List<Map<String, String>> configMaps) static ZKStorepopulateZKStore(ZKStore store, Random random) static voidstatic voidsearchForFileExtension(File directory, String fileExtension) static voidshutdownExecutor(ExecutorService executor) static voidshutdownExecutor(ExecutorService executor, long timeout, TimeUnit unit) static voidshutdownThread(Thread thread) static voidshutdownThread(Thread thread, long timeout, TimeUnit unit) static ControllerResponseupdateStoreToHybrid(String storeName, ControllerClient parentControllerClient, Optional<Boolean> enableNativeReplication, Optional<Boolean> enableActiveActiveReplication, Optional<Boolean> enableChunking) static voidverifyDCConfigNativeAndActiveRepl(String storeName, boolean enabledNR, boolean enabledAA, ControllerClient... controllerClients) static voidwaitForNonDeterministicAssertion(long timeout, TimeUnit timeoutUnit, boolean exponentialBackOff, boolean retryOnThrowable, TestUtils.NonDeterministicAssertion assertion) static voidwaitForNonDeterministicAssertion(long timeout, TimeUnit timeoutUnit, boolean exponentialBackOff, TestUtils.NonDeterministicAssertion assertion) static voidwaitForNonDeterministicAssertion(long timeout, TimeUnit timeoutUnit, TestUtils.NonDeterministicAssertion assertion) To be used for tests when we need to wait for an async operation to complete.static voidwaitForNonDeterministicCompletion(long timeout, TimeUnit timeoutUnit, BooleanSupplier condition) To be used for tests when we need to wait for an async operation to complete.static voidwaitForNonDeterministicPushCompletion(String topicName, ControllerClient controllerClient, long timeout, TimeUnit timeoutUnit) Wait for the push job for a store version or topic to be completed.static voidwriteBatchData(VersionCreationResponse response, String keySchema, String valueSchema, Stream<Map.Entry> batchData, int valueSchemaId, CompressionStrategy compressionStrategy, Function<String, ByteBuffer> compressionDictionaryGenerator, PubSubProducerAdapterFactory pubSubProducerAdapterFactory, Map<String, String> additionalProperties, PubSubPositionTypeRegistry pubSubPositionTypeRegistry) static voidwriteBatchData(VersionCreationResponse response, String keySchema, String valueSchema, Stream<Map.Entry> batchData, int valueSchemaId, PubSubProducerAdapterFactory pubSubProducerAdapterFactory, Map<String, String> additionalProperties, PubSubPositionTypeRegistry pubSubPositionTypeRegistry)
-
Field Details
-
DEFAULT_PUBSUB_CONTEXT_FOR_UNIT_TESTING
**FOR UNIT TESTING PURPOSES ONLY** - Do not use in production code. A pre-configured PubSubContext instance with default test values for use in unit tests. This instance is initialized with basic default components suitable for testing scenarios where a fully configured PubSubContext is not required. Production code should propagate properly configured PubSubContext instances with appropriate TopicManagerRepository and other production-ready components.
-
-
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-TimeUnitfor thecondition- ABooleanSupplierwhich 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-TimeUnitfor theassertion- ATestUtils.NonDeterministicAssertionwhich should simply execute without exception if it is successful, or throw anAssertionErrorotherwise.- Throws:
AssertionError- throws the exception thrown by theTestUtils.NonDeterministicAssertionif 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, PubSubPositionTypeRegistry pubSubPositionTypeRegistry) -
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, PubSubPositionTypeRegistry pubSubPositionTypeRegistry) -
writeBatchData
public static void writeBatchData(VersionCreationResponse response, String keySchema, String valueSchema, Stream<Map.Entry> batchData, int valueSchemaId, PubSubProducerAdapterFactory pubSubProducerAdapterFactory, Map<String, String> additionalProperties, PubSubPositionTypeRegistry pubSubPositionTypeRegistry) -
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, PubSubPositionTypeRegistry pubSubPositionTypeRegistry) -
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
-
populateZKStore
-
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
public static OffsetRecord getOffsetRecord(PubSubPosition currentPosition, Optional<PubSubPosition> endOfPushOffset, PubSubContext pubSubContext) -
getMultiClusterConfigFromOneCluster
public static VeniceControllerMultiClusterConfig getMultiClusterConfigFromOneCluster(VeniceControllerClusterConfig controllerConfig) -
getPropertiesForControllerConfig
-
getClusterToD2String
-
getVeniceWriterFactory
public static VeniceWriterFactory getVeniceWriterFactory(Properties properties, PubSubProducerAdapterFactory pubSubProducerAdapterFactory, PubSubPositionTypeRegistry pubSubPositionTypeRegistry) -
getRandomStore
-
assertCommand
-
assertCommand
public static <T extends ControllerResponse> T assertCommand(T response, String assertionErrorMessage) -
assertCommandFailure
public static <T extends ControllerResponse> T assertCommandFailure(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
-
getStoreIngestionTaskBuilder
public static StoreIngestionTaskFactory.Builder getStoreIngestionTaskBuilder(String storeName, boolean isHybrid) -
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
-
getVenicePathParser
public static VenicePathParser getVenicePathParser(CompressorFactory compressorFactory, boolean decompressOnClient)
-